@@ -5,8 +5,10 @@ import {
55import is , {
66 isArray ,
77 isArrayOf ,
8+ isBigInt ,
89 isBoolean ,
910 isFunction ,
11+ isInstanceOf ,
1012 isNull ,
1113 isNullish ,
1214 isNumber ,
@@ -15,6 +17,7 @@ import is, {
1517 isRecord ,
1618 isRecordOf ,
1719 isString ,
20+ isSymbol ,
1821 isTupleOf ,
1922 isUndefined ,
2023 Predicate ,
@@ -23,16 +26,19 @@ import is, {
2326const examples = {
2427 string : [ "" , "Hello world" ] ,
2528 number : [ 0 , 1234567890 ] ,
29+ bigint : [ 0n , 1234567890n ] ,
2630 boolean : [ true , false ] ,
2731 array : [ [ ] , [ 0 , 1 , 2 ] , [ "a" , "b" , "c" ] , [ 0 , "a" , true ] ] ,
2832 record : [ { } , { a : 0 , b : 1 , c : 2 } , { a : "a" , b : "b" , c : "c" } ] ,
2933 function : [ function ( ) { } ] ,
3034 null : [ null ] ,
3135 undefined : [ undefined ] ,
36+ symbol : [ Symbol ( "a" ) , Symbol ( "b" ) , Symbol ( "c" ) ] ,
3237} ;
3338
3439function stringify ( x : unknown ) : string {
3540 if ( typeof x === "function" ) return x . toString ( ) ;
41+ if ( typeof x === "bigint" ) return `${ x } n` ;
3642 return JSON . stringify ( x ) ;
3743}
3844
@@ -62,6 +68,10 @@ Deno.test("isNumber", async (t) => {
6268 await testWithExamples ( t , isNumber , [ "number" ] ) ;
6369} ) ;
6470
71+ Deno . test ( "isBigInt" , async ( t ) => {
72+ await testWithExamples ( t , isBigInt , [ "bigint" ] ) ;
73+ } ) ;
74+
6575Deno . test ( "isBoolean" , async ( t ) => {
6676 await testWithExamples ( t , isBoolean , [ "boolean" ] ) ;
6777} ) ;
@@ -180,6 +190,46 @@ Deno.test("isFunction", async (t) => {
180190 await testWithExamples ( t , isFunction , [ "function" ] ) ;
181191} ) ;
182192
193+ Deno . test ( "isInstanceOf<T>" , async ( t ) => {
194+ await t . step ( "returns true on T instance" , ( ) => {
195+ class Cls { }
196+ assertEquals ( isInstanceOf ( Cls ) ( new Cls ( ) ) , true ) ;
197+ assertEquals ( isInstanceOf ( Date ) ( new Date ( ) ) , true ) ;
198+ assertEquals ( isInstanceOf ( Promise < string > ) ( new Promise ( ( ) => { } ) ) , true ) ;
199+ } ) ;
200+ await t . step ( "returns false on non function" , ( ) => {
201+ class Cls { }
202+ assertEquals ( isInstanceOf ( Cls ) ( new Date ( ) ) , false ) ;
203+ assertEquals ( isInstanceOf ( Cls ) ( new Promise ( ( ) => { } ) ) , false ) ;
204+ assertEquals ( isInstanceOf ( Cls ) ( "" ) , false ) ;
205+ assertEquals ( isInstanceOf ( Cls ) ( 0 ) , false ) ;
206+ assertEquals ( isInstanceOf ( Cls ) ( true ) , false ) ;
207+ assertEquals ( isInstanceOf ( Cls ) ( false ) , false ) ;
208+ assertEquals ( isInstanceOf ( Cls ) ( [ ] ) , false ) ;
209+ assertEquals ( isInstanceOf ( Cls ) ( { } ) , false ) ;
210+ assertEquals ( isInstanceOf ( Cls ) ( function ( ) { } ) , false ) ;
211+ assertEquals ( isInstanceOf ( Cls ) ( null ) , false ) ;
212+ assertEquals ( isInstanceOf ( Cls ) ( undefined ) , false ) ;
213+ } ) ;
214+ await t . step ( "returns proper type predicate" , ( ) => {
215+ class Cls { }
216+ const a : unknown = new Cls ( ) ;
217+ if ( isInstanceOf ( Cls ) ( a ) ) {
218+ const _ : Cls = a ;
219+ }
220+
221+ const b : unknown = new Date ( ) ;
222+ if ( isInstanceOf ( Date ) ( b ) ) {
223+ const _ : Date = b ;
224+ }
225+
226+ const c : unknown = new Promise ( ( ) => { } ) ;
227+ if ( isInstanceOf ( Promise ) ( c ) ) {
228+ const _ : Promise < unknown > = c ;
229+ }
230+ } ) ;
231+ } ) ;
232+
183233Deno . test ( "isNull" , async ( t ) => {
184234 await testWithExamples ( t , isNull , [ "null" ] ) ;
185235} ) ;
@@ -192,6 +242,10 @@ Deno.test("isNullish", async (t) => {
192242 await testWithExamples ( t , isNullish , [ "null" , "undefined" ] ) ;
193243} ) ;
194244
245+ Deno . test ( "isSymbol" , async ( t ) => {
246+ await testWithExamples ( t , isSymbol , [ "symbol" ] ) ;
247+ } ) ;
248+
195249Deno . test ( "isOneOf<T>" , async ( t ) => {
196250 await t . step ( "returns proper type predicate" , ( ) => {
197251 const preds = [ isNumber , isString , isBoolean ] ;
0 commit comments