-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings.ts
More file actions
30 lines (24 loc) · 708 Bytes
/
strings.ts
File metadata and controls
30 lines (24 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const { snakeCase, pascalCase, constantCase } = require( 'change-case' );
function capitalize( text: string ): string {
return text.charAt( 0 ).toUpperCase() + text.slice( 1 );
}
function uncapitalize( text: string ): string {
return text.charAt( 0 ).toLowerCase() + text.slice( 1 );
}
function slugify( text: string ): string {
return snakeCase( text ).replace( /_/g, '-' );
}
function componentCase( text: string ): string {
return capitalize( pascalCase( text ) );
}
function generateRandomNumberString(): string {
return Math.ceil( Math.random() * 1000000 ).toString();
}
export {
capitalize,
uncapitalize,
slugify,
componentCase,
constantCase,
generateRandomNumberString,
};