File tree Expand file tree Collapse file tree 5 files changed +29
-1
lines changed Expand file tree Collapse file tree 5 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -178,6 +178,9 @@ Is.Uuid('not-valid-uuid') // false
178178Is .Cep (' not-valid-cep' ) // false
179179Is .Cpf (' not-valid-cpf' ) // false
180180Is .Cnpj (' not-valid-cnpj' ) // false
181+ Is .Async (() => {}) // false
182+ Is .Async (async () => {}) // true
183+ Is .Async (() => { new Promise ((resolve => resolve ())) }) // true
181184
182185Is .String (' value' ) // true
183186Is .Undefined (' value' ) // false
Original file line number Diff line number Diff line change 11{
22 "name" : " @secjs/utils" ,
3- "version" : " 1.6.2 " ,
3+ "version" : " 1.6.3 " ,
44 "description" : " " ,
55 "license" : " MIT" ,
66 "author" : " João Lenon" ,
Original file line number Diff line number Diff line change @@ -123,6 +123,22 @@ export class Is {
123123 return isCnpj ( cnpj )
124124 }
125125
126+ /**
127+ * Verify if is an async function
128+ *
129+ * @param value The value
130+ * @return true or false
131+ */
132+ static Async ( value : any ) {
133+ const fnString = value . toString ( ) . trim ( )
134+
135+ const validation = ! ! (
136+ fnString . match ( / ^ a s y n c / ) || fnString . match ( / r e t u r n _ r e f [ ^ . ] * \. a p p l y / )
137+ )
138+
139+ return validation || fnString . includes ( 'new Promise(' )
140+ }
141+
126142 /**
127143 * Verify if value is undefined
128144 *
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ declare global {
3131 static Cep ( cep : string | number ) : boolean
3232 static Cpf ( cpf : string | number ) : boolean
3333 static Cpnj ( cnpj : string | number ) : boolean
34+ static Async ( value : any ) : boolean
3435 static Undefined ( value : any ) : value is undefined
3536 static Null ( value : any ) : value is null
3637 static Boolean ( value : any ) : value is boolean
Original file line number Diff line number Diff line change @@ -22,6 +22,14 @@ describe('\n Is Class', () => {
2222 expect ( Is . Cpf ( '529.461.090-62' ) ) . toBe ( true )
2323 } )
2424
25+ it ( 'should verify if is a valid async function' , async ( ) => {
26+ expect ( Is . Async ( 0 ) ) . toBe ( false )
27+ expect ( Is . Async ( '' ) ) . toBe ( false )
28+ expect ( Is . Async ( ( ) => '' ) ) . toBe ( false )
29+ expect ( Is . Async ( async ( ) => '' ) ) . toBe ( true )
30+ expect ( Is . Async ( ( ) => new Promise ( resolve => resolve ) ) ) . toBe ( true )
31+ } )
32+
2533 it ( 'should verify if is a valid cnpj' , async ( ) => {
2634 expect ( Is . Cnpj ( 0 ) ) . toBe ( false )
2735 expect ( Is . Cnpj ( '' ) ) . toBe ( false )
You can’t perform that action at this time.
0 commit comments