Elffuss BraidHub

kikocis/continue public

99fe51849b68 · 1.1 KiBRawPermalink
1export const capitalizeFirstLetter = (val: string) => {
2 if (val.length === 0) {
3 return "";
4 }
5 return val[0].toUpperCase() + val.slice(1);
6};
7
8export function replaceEscapedCharacters(str: string): string {
9 return str.replaceAll(/\\(n|t|r|\\|"|')/g, (match, p1) => {
10 switch (p1) {
11 case "n":
12 return "\n";
13 case "t":
14 return "\t";
15 case "r":
16 return "\r";
17 case "\\":
18 return "\\";
19 case '"':
20 return '"';
21 case "'":
22 return "'";
23 default:
24 return match; // NOTE: Handle unexpected escapes better than this.
25 }
26 });
27}
28
29export function escapeForSVG(text: string): string {
30 return text
31 .replace(/&/g, "&") // must be first
32 .replace(/</g, "&lt;")
33 .replace(/>/g, "&gt;")
34 .replace(/"/g, "&quot;")
35 .replace(/'/g, "&apos;");
36}
37
38export function kebabOfStr(str: string): string {
39 return str
40 .replace(/([a-z])([A-Z])/g, "$1-$2") // handle camelCase and PascalCase
41 .replace(/[\s_]+/g, "-") // replace spaces and underscores with hyphens
42 .toLowerCase();
43}