Skip to content

Commit f8d6246

Browse files
authored
remove capitalize-sentence (#1218)
1 parent 8bff8c5 commit f8d6246

File tree

7 files changed

+5324
-22
lines changed

7 files changed

+5324
-22
lines changed

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)