Skip to content

Commit 0df09c2

Browse files
committed
restore files to match main
1 parent 282e2dd commit 0df09c2

File tree

12 files changed

+1295
-1811
lines changed

12 files changed

+1295
-1811
lines changed

Node-1st-gen/text-moderation/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ For instance if a user added the message "I DON'T LIKE THIS APP!! This is POOP!!
99

1010
See file [functions/index.js](functions/index.js) for the moderation code.
1111

12-
Moderation of the messages is performed using [bad-words](https://www.npmjs.com/package/bad-words) a bad words remover that uses an external [list of bad-words](https://github.com/web-mech/badwords-list) and is currently mostly aimed at filtering english bad words. Also messages that contains mostly upper case characters are re-capitalized correctly.
12+
Moderation of the messages is performed using [bad-words](https://www.npmjs.com/package/bad-words) a bad words remover that uses an external [list of bad-words](https://github.com/web-mech/badwords-list) and is currently mostly aimed at filtering english bad words. Also messages that contains mostly upper case characters are re-capitalized correctly using [capitalize-sentence](https://www.npmjs.com/package/capitalize-sentence).
1313

1414
The dependencies are listed in [functions/package.json](functions/package.json).
1515

Node-1st-gen/text-moderation/functions/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
'use strict';
1717

1818
const functions = require('firebase-functions/v1');
19-
const capitalizeSentence = require('capitalize-sentence');
2019
const Filter = require('bad-words');
2120
const badWordsFilter = new Filter();
2221

@@ -81,5 +80,11 @@ function isShouting(message) {
8180
// Correctly capitalize the string as a sentence (e.g. uppercase after dots)
8281
// and remove exclamation points.
8382
function stopShouting(message) {
84-
return capitalizeSentence(message.toLowerCase()).replace(/!+/g, '.');
83+
const sentenceCaseRegex = /(:?\.\s?|^)([A-Za-z\u00C0-\u1FFF\u2800-\uFFFD])/gi;
84+
const noExclamationsRegex = /!+/g;
85+
86+
return message
87+
.toLowerCase()
88+
.replace(sentenceCaseRegex, (match) => match.toUpperCase())
89+
.replace(noExclamationsRegex, ".");
8590
}

Node-1st-gen/text-moderation/functions/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"description": "Moderate text using Firebase Functions",
44
"dependencies": {
55
"bad-words": "^3.0.4",
6-
"capitalize-sentence": "^0.1.5",
76
"eslint-plugin-promise": "^7.2.1",
87
"firebase-admin": "^13.0.2",
98
"firebase-functions": "^6.3.0"

Node-1st-gen/text-moderation/functions/pnpm-lock.yaml

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Node/quickstarts/callable-functions/functions/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"main": "index.js",
1818
"dependencies": {
1919
"bad-words": "^3.0.4",
20-
"capitalize-sentence": "^0.1.5",
2120
"firebase-admin": "^13.0.2",
2221
"firebase-functions": "^6.3.0"
2322
},

Node/quickstarts/callable-functions/functions/pnpm-lock.yaml

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Node/quickstarts/callable-functions/functions/sanitizer.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
"use strict";
1717

18-
const capitalizeSentence = require("capitalize-sentence");
1918
const Filter = require("bad-words");
2019
const badWordsFilter = new Filter();
2120

@@ -72,5 +71,11 @@ function isShouting(message) {
7271
* @return {string} capitalized string
7372
*/
7473
function stopShouting(message) {
75-
return capitalizeSentence(message.toLowerCase()).replace(/!+/g, ".");
74+
const sentenceCaseRegex = /(:?\.\s?|^)([A-Za-z\u00C0-\u1FFF\u2800-\uFFFD])/gi;
75+
const noExclamationsRegex = /!+/g;
76+
77+
return message
78+
.toLowerCase()
79+
.replace(sentenceCaseRegex, (match) => match.toUpperCase())
80+
.replace(noExclamationsRegex, ".");
7681
}

0 commit comments

Comments
 (0)