File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ export function formatString ( input : string ) : string {
2
+ return input . trim ( ) . toLowerCase ( ) . replace ( / \s + / g, '-' ) ;
3
+ }
4
+
5
+ export function calculateSum ( numbers : number [ ] ) : number {
6
+ return numbers . reduce ( ( acc , num ) => acc + num , 0 ) ;
7
+ }
8
+
9
+ export function isValidEmail ( email : string ) : boolean {
10
+ const emailRegex = / ^ [ ^ \s @ ] + @ [ ^ \s @ ] + \. [ ^ \s @ ] + $ / ;
11
+ return emailRegex . test ( email ) ;
12
+ }
13
+
14
+ export function debounce < T extends ( ...args : any [ ] ) => any > (
15
+ func : T ,
16
+ delay : number
17
+ ) : ( ...args : Parameters < T > ) => void {
18
+ let timeoutId : NodeJS . Timeout ;
19
+ return ( ...args : Parameters < T > ) => {
20
+ clearTimeout ( timeoutId ) ;
21
+ timeoutId = setTimeout ( ( ) => func ( ...args ) , delay ) ;
22
+ } ;
23
+ }
24
+
25
+ export function chunk < T > ( array : T [ ] , size : number ) : T [ ] [ ] {
26
+ const chunks : T [ ] [ ] = [ ] ;
27
+ for ( let i = 0 ; i < array . length ; i += size ) {
28
+ chunks . push ( array . slice ( i , i + size ) ) ;
29
+ }
30
+ return chunks ;
31
+ }
You can’t perform that action at this time.
0 commit comments