The Node.js® Website
1export const getAcronymFromString = (str: string) =>
2 [...(str.trim().match(/\b(\w)/g) || '')].join('').toUpperCase();
3
4// Note: We don't remove Markdown Headers delimiters as they're useful for delimiting sections
5export const parseRichTextIntoPlainText = (richText: string) =>
6 richText
7 // replaces JSX and HTML and their properties with an empty string
8 // keeping only the content left
9 .replace(/<[^>]+>/gm, '')
10 // replaces Markdown links with their text content
11 .replace(/\[([^\]]+)\]\([^)]+\)/gm, '$1')
12 // replaces Markdown lists with their content
13 .replace(/^[*-] (.*)$/gm, '$1')
14 // replaces Markdown underscore, bold and italic with their content
15 .replace(/(\*\*|\*|__|_)(.*?)\1/gm, '$2')
16 // replaces Markdown multiline codeblocks with their content
17 .replace(/```.+?```/gms, '')
18 // replaces empty lines or lines just with spaces with an empty string
19 .replace(/^\s*\n/gm, '')
20 // replaces leading and trailing spaces from each line with an empty string
21 .replace(/^[ ]+|[ ]+$/gm, '')
22 // replaces leading numbers and dots from each line with an empty string
23 .replace(/^\d+\.\s/gm, '');
24
25export const dashToCamelCase = (str: string) =>
26 str
27 .replace(/-([a-z])/g, (match, chr) => chr.toUpperCase())
28 .replace(/^[A-Z]/, chr => chr.toLowerCase());