Skip to content

Commit 884810f

Browse files
feat: Add 2nd-gen YouTube sample to Node folder
This commit introduces a new 2nd-gen Cloud Function sample for YouTube, located in the `Node/youtube` directory. This sample is the TypeScript equivalent of the existing 1st-gen sample in `Node-1st-gen/youtube`. Key features of this new sample include: - Use of 2nd-gen Cloud Functions. - Written in TypeScript, leveraging Node 22's optional type stripping. - Implements a secret parameter for the YouTube API key, enhancing security. - Provides a clear and updated README.md with instructions for setup and deployment.
1 parent e7c539c commit 884810f

File tree

9 files changed

+1528
-1131
lines changed

9 files changed

+1528
-1131
lines changed

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

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

1818
const functions = require('firebase-functions/v1');
19+
const capitalizeSentence = require('capitalize-sentence');
1920
const Filter = require('bad-words');
2021
const badWordsFilter = new Filter();
2122

@@ -80,11 +81,5 @@ function isShouting(message) {
8081
// Correctly capitalize the string as a sentence (e.g. uppercase after dots)
8182
// and remove exclamation points.
8283
function stopShouting(message) {
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, ".");
84+
return capitalizeSentence(message.toLowerCase()).replace(/!+/g, '.');
9085
}

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

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

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

Lines changed: 8 additions & 0 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"main": "index.js",
1818
"dependencies": {
1919
"bad-words": "^3.0.4",
20+
"capitalize-sentence": "^0.1.5",
2021
"firebase-admin": "^13.0.2",
2122
"firebase-functions": "^6.3.0"
2223
},

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

Lines changed: 8 additions & 0 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: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
"use strict";
1717

18+
const capitalizeSentence = require("capitalize-sentence");
1819
const Filter = require("bad-words");
1920
const badWordsFilter = new Filter();
2021

@@ -71,11 +72,5 @@ function isShouting(message) {
7172
* @return {string} capitalized string
7273
*/
7374
function stopShouting(message) {
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, ".");
75+
return capitalizeSentence(message.toLowerCase()).replace(/!+/g, ".");
8176
}

0 commit comments

Comments
 (0)