@@ -29,6 +29,8 @@ import is, {
2929 isReadonlyUniformTupleOf ,
3030 isRecord ,
3131 isRecordOf ,
32+ isSet ,
33+ isSetOf ,
3234 isString ,
3335 isSymbol ,
3436 isSyncFunction ,
@@ -56,6 +58,7 @@ const examples = {
5658 bigint : [ 0n , 1234567890n ] ,
5759 boolean : [ true , false ] ,
5860 array : [ [ ] , [ 0 , 1 , 2 ] , [ "a" , "b" , "c" ] , [ 0 , "a" , true ] ] ,
61+ set : [ new Set ( ) , new Set ( [ 0 , 1 , 2 ] ) , new Set ( [ "a" , "b" , "c" ] ) ] ,
5962 record : [ { } , { a : 0 , b : 1 , c : 2 } , { a : "a" , b : "b" , c : "c" } ] ,
6063 syncFunction : [ function a ( ) { } , ( ) => { } ] ,
6164 asyncFunction : [ async function b ( ) { } , async ( ) => { } ] ,
@@ -130,6 +133,7 @@ Deno.test("isAny", async (t) => {
130133 "bigint" ,
131134 "boolean" ,
132135 "array" ,
136+ "set" ,
133137 "record" ,
134138 "syncFunction" ,
135139 "asyncFunction" ,
@@ -150,6 +154,7 @@ Deno.test("isUnknown", async (t) => {
150154 "bigint" ,
151155 "boolean" ,
152156 "array" ,
157+ "set" ,
153158 "record" ,
154159 "syncFunction" ,
155160 "asyncFunction" ,
@@ -208,6 +213,36 @@ Deno.test("isArrayOf<T>", async (t) => {
208213 } ) ;
209214} ) ;
210215
216+ Deno . test ( "isSet" , async ( t ) => {
217+ await testWithExamples ( t , isSet , { validExamples : [ "set" ] } ) ;
218+ } ) ;
219+
220+ Deno . test ( "isSetOf<T>" , async ( t ) => {
221+ await t . step ( "returns properly named function" , async ( t ) => {
222+ await assertSnapshot ( t , isSetOf ( isNumber ) . name ) ;
223+ await assertSnapshot ( t , isSetOf ( ( _x ) : _x is string => false ) . name ) ;
224+ } ) ;
225+ await t . step ( "returns proper type predicate" , ( ) => {
226+ const a : unknown = new Set ( [ 0 , 1 , 2 ] ) ;
227+ if ( isSetOf ( isNumber ) ( a ) ) {
228+ assertType < Equal < typeof a , Set < number > > > ( true ) ;
229+ }
230+ } ) ;
231+ await t . step ( "returns true on T set" , ( ) => {
232+ assertEquals ( isSetOf ( isNumber ) ( new Set ( [ 0 , 1 , 2 ] ) ) , true ) ;
233+ assertEquals ( isSetOf ( isString ) ( new Set ( [ "a" , "b" , "c" ] ) ) , true ) ;
234+ assertEquals ( isSetOf ( isBoolean ) ( new Set ( [ true , false , true ] ) ) , true ) ;
235+ } ) ;
236+ await t . step ( "returns false on non T set" , ( ) => {
237+ assertEquals ( isSetOf ( isString ) ( new Set ( [ 0 , 1 , 2 ] ) ) , false ) ;
238+ assertEquals ( isSetOf ( isNumber ) ( new Set ( [ "a" , "b" , "c" ] ) ) , false ) ;
239+ assertEquals ( isSetOf ( isString ) ( new Set ( [ true , false , true ] ) ) , false ) ;
240+ } ) ;
241+ await testWithExamples ( t , isSetOf ( ( _ : unknown ) : _ is unknown => true ) , {
242+ excludeExamples : [ "set" ] ,
243+ } ) ;
244+ } ) ;
245+
211246Deno . test ( "TupleOf<T>" , ( ) => {
212247 assertType <
213248 Equal <
@@ -1048,6 +1083,11 @@ Deno.test("isOptionalOf<T>", async (t) => {
10481083 validExamples : [ "array" , "undefined" ] ,
10491084 } ) ;
10501085 } ) ;
1086+ await t . step ( "with isSet" , async ( t ) => {
1087+ await testWithExamples ( t , isOptionalOf ( isSet ) , {
1088+ validExamples : [ "set" , "undefined" ] ,
1089+ } ) ;
1090+ } ) ;
10511091 await t . step ( "with isRecord" , async ( t ) => {
10521092 await testWithExamples ( t , isOptionalOf ( isRecord ) , {
10531093 validExamples : [ "record" , "date" , "promise" , "undefined" ] ,
0 commit comments