Object
Generate object values.
dictionary
Generate dictionaries containing keys generated using keyArb and values generated by valueArb.
Signatures:
fc.dictionary(keyArb, valueArb)fc.dictionary(keyArb, valueArb, {minKeys?, maxKeys?, size?, noNullPrototype?, depthIdentifier?})
with:
keyArb— arbitrary instance responsible to generate keysvalueArb— arbitrary instance responsible to generate valuesminKeys?— default:0— minimal number of keys in the generated instances (included)maxKeys?— default:0x7fffffffmore — maximal number of keys in the generated instances (included)size?— default:undefinedmore — how large should the generated values be?noNullPrototype?— default:false— only generate objects based on the Object-prototype, do not generate any object with null-prototypedepthIdentifier?— default:undefined— share the depth between instances using the samedepthIdentifier
Usages:
fc.dictionary(fc.string(), fc.string());
// Examples of generated values:
// • {__proto__:null,"<H":"`D? &7A","T>X0Aa]tp>":":5+|","8{0.mI>8R,":"j._[Xi&.[","!83F]'E1_":"y[bB,G$_S}","NnY,!{":"6NZ4,G'}","Y&>Uj":"gg@eTi","e>QDNvD/gz":"Bt0&oV;","ULLW1":"F6i_","?&I":"lPd7}"}
// • {__proto__:null,"_":" y|","Yo+\"O@q+j":"cI{H","":"3#$}9{5!z","?^~k ":"w$defipro","[fa4c":"J"}
// • {__proto__:null,"~":""}
// • {"lzproperty":"?"}
// • {"hOIY\"R q}":"W","l__defineG":"8x`:H0?T"}
// • …
fc.dictionary(fc.string(), fc.nat());
// Examples of generated values:
// • {__proto__:null,"":11,".[hM+$+:?N":30,"%{":59342696,"|_":29,"E":670852246,"pl_":2147483639,">":2147483630,"M7cU?#9":1072636200,"ot":1627183273}
// • {"_G@>x":461241683,"@9c=&6H:c0":105089967,"c_)r66nwK":1355210745}
// • {__proto__:null,"#1O;mZ1":1005073225}
// • {}
// • {"6":144134225,".9":437743867,"tR?j$Hat3X":1920000943,"DQTd":324814916}
// • …
fc.dictionary(fc.string(), fc.nat(), { minKeys: 2 });
// Note: Generate instances with at least 2 keys
// Examples of generated values:
// • {"%{":11,"4cH":12,"ke":2147483622,"rqM~i'":485910780}
// • {__proto__:null,"K":1498847755,"&cP<5:e(y\"":1430281549,"!\"2a":1631161561,"dY+g":1880545446,"M2+^,Yq7~t":1437539188}
// • {__proto__:null,"NfXclS":815533370,"?":2060844890,"":1862140278,"R":618808229,"N|":25902062,"DGw00u?brK":348863633}
// • {" R~Own":2147483645,"~":16,"i$#D":1037390287}
// • {__proto__:null,">YTN<Tt":1950414260,"I6":1505301756,"2;]'dH.i!":815067799,":kmC'":1948205418,"g|GTLPe-":2101264769}
// • …
fc.dictionary(fc.string(), fc.string(), { noNullPrototype: true });
// Note: Do not generate any object with null prototype, always define them with Object prototype
// Examples of generated values:
// • {"~}P-T{^H`":"X~bd\"T","3Y,I8B\\*":"i;vLI(7R|","_":"o>|L~","RIUht":"x>?!**l:\\o","8oV?LkD@LD":"E%leQ*Q}4O"}
// • {}
// • {"zQD\"x!p":"V<GfsgU","q1RH0sG":"rXM>>","Eo3iTH4f":"","sU3":"FJ-"}
// • {"iY7s.{?":"&i>","V`x?~qpp4C":"3+u$","I!z{na":",0D^g/G5"}
// • {"Vo=AG":"0D%{Mv2c>w","_~dC3=@D":"f-","=":"vluzcJ"}
// • …
Resources: API reference.
Available since 1.0.0.
set
Set of random size containing unique values generated by arb.
All the values in the set are unique. Comparison of values relies on SameValueZero which is the same comparison algorithm used by JavaScript's native Set. This means that -0 and +0 are considered equal, and NaN is considered equal to itself.
Signatures:
fc.set(arb)fc.set(arb, {minLength?, maxLength?, size?, depthIdentifier?})
with:
arb— arbitrary instance responsible to generate valuesminLength?— default:0— minimal size (included)maxLength?— default:0x7fffffffmore — maximal size (included)size?— default:undefinedmore — how large should the generated values be?depthIdentifier?— default:undefined— when specified, the set will impact the depth attached to the identifier to avoid going too deep if it already generated lots of items for current level
Usages:
fc.set(fc.nat());
// Examples of generated values:
// • new Set([1681938411,278250656,2138206756])
// • new Set([28,1046862664])
// • new Set([1521748689,316610179,1601449343,1057761988,2088580527,1974557534,1618733983,882909472])
// • new Set([269035825,95461057,227736260])
// • new Set([755444117,555135045,511312424,1358336721,939579971])
// • …
fc.set(fc.nat(), { minLength: 3 });
// Examples of generated values:
// • new Set([602547610,112021681,83201570,693834807,2146945516,698558116,1101096089])
// • new Set([6,1430479569,702296885,894326742,2147483621])
// • new Set([1015331865,7,999206705,1519706408,514833092,961783345])
// • new Set([17,1694060249,16])
// • new Set([586174988,95340586,9582779,194927067,729188280,293838753,1487439988,689790741])
// • …
fc.set(fc.nat(), { maxLength: 3 });
// Examples of generated values: new Set([]), new Set([1015331865]), new Set([586174988]), new Set([90041247,2029142854]), new Set([2147483622,443201851])…
fc.set(fc.nat(), { minLength: 5, maxLength: 7 });
// Examples of generated values:
// • new Set([1759373912,1442115536,851584635,195490435,2138804991,584365960,105302036])
// • new Set([2011675117,1466574499,1048059617,1763350988,647054407,973683117])
// • new Set([2147483623,16,23,513953320,2016509989,11])
// • new Set([146428064,24,1830129633,18,8])
// • new Set([12,11,393990951,1986689091,1210840379,9])
// • …
fc.set(fc.record({ id: fc.nat(), name: fc.string() }));
// Note: Set comparison uses SameValueZero, so objects are compared by reference.
// The generated sets will contain unique object instances.
// Examples of generated values:
// • new Set([])
// • new Set([{"id":2147483643,"name":"fA#3;&"}])
// • new Set([{__proto__:null,"id":1,"name":"caller"},{__proto__:null,"id":2147483643,"name":"e"}])
// • new Set([{__proto__:null,"id":7,"name":"valueOf"},{__proto__:null,"id":6,"name":""},{"id":747148193,"name":"r6piZ_"}])
// • new Set([{"id":1197887885,"name":"|-y]y!A*y"},{"id":309672783,"name":"?%i]n6"},{"id":1074933601,"name":"~TF!9"},{"id":17,"name":"uy"},{"id":2147483625,"name":"me4"},{"id":17,"name":""}])
// • …
fc.set(fc.constantFrom(-0, 0, Number.NaN, 1, 2));
// Note: SameValueZero considers -0 and +0 as equal, and NaN as equal to itself.
// So generated sets will not contain both -0 and +0, but can contain NaN.
// Examples of generated values: new Set([Number.NaN,0,1,2]), new Set([0,2,1,Number.NaN]), new Set([2,1]), new Set([0,Number.NaN,2,1]), new Set([0])…
Resources: API reference.
Available since 4.4.0.
map
Generate Maps containing keys generated using keyArb and values generated by valueArb.
Signatures:
fc.map(keyArb, valueArb)fc.map(keyArb, valueArb, {minKeys?, maxKeys?, size?, depthIdentifier?})
with:
keyArb— arbitrary instance responsible to generate keysvalueArb— arbitrary instance responsible to generate valuesminKeys?— default:0— minimal number of entries in the generated instances (included)maxKeys?— default:0x7fffffffmore — maximal number of entries in the generated instances (included)size?— default:undefinedmore — how large should the generated values be?depthIdentifier?— default:undefined— share the depth between instances using the samedepthIdentifier
Usages:
fc.map(fc.string(), fc.string());
// Examples of generated values:
// • new Map([["n","\"Tw=j>E6"],["{!#o+% !","&&-~q\"!"],["$I","x-[xineSet"],["%JI>:","p(5y=m$"],["^A/ZU&i)","EdJV~<WD,"],["[0","refisPro"]])
// • new Map([["%a;4","D{XPQq9"],["dJ","M#VOL*]n"]])
// • new Map([["R<HD!ydUY","A%%0V'Ww"],["}mz","RUzlsB*`"],["f","A0!;h"],["O","173@]\"1o"],["Y)Z\\k/ZbFI","I$)"],["16`*-&s","-xorJg%7nW"]])
// • new Map([["$#","c@K{]z,V{-"],["y;!","t@>"],["xEaXPvf3H","."]])
// • new Map([["lv V!\"","?0Vb"],["d$x",""],[" x*l{13R$","$#z"],["t@:)&$^",""],["ref","?kU0cLA<"],["\"bind{n","LNK/{"],["","KXQOj1`i&"],["valueOf","6x!z%% 3A9"],["tB0hX",""]])
// • …
fc.map(fc.string(), fc.nat());
// Examples of generated values:
// • new Map([["k",1448733623],["#_",2147483645],["\"",2147483647],["TR6\"1Nb9>I",2012980671],["!de_",8],["{ylengthOw",512298650]])
// • new Map([["!nyXQ",1369741659],["?$",1836670181],["tI[wr*,M",1452610252],["W",1374903681],["f9Zs}Q ",1782516336],["jbxV`Ws",1400640368],[" <8#",828152769],[";",755286114],["yKF~R9w",336247456],["B8>E",1455651403]])
// • new Map([])
// • new Map([["g-O_X5",744471594],["{_x",1122673095],["tiQ8er",250166111],["uc2~2XP0",175685851]])
// • new Map([["xj",930769045],["+u&",1993658380],["#qxy",2147483629]])
// • …
fc.map(fc.string(), fc.nat(), { minKeys: 2 });
// Note: Generate instances with at least 2 entries
// Examples of generated values:
// • new Map([["a:m[nG+",341869735],["*N.~r6fZO4",1547378663],["E+\"2:vr!rD",740659417],["dPXo$V1+uW",1964026855],["b^\\a>,X&",1440918465],["W+G",862228200],["I?L!smo|",277564851],["4Q5%1\\@xv",1972355972],["\\v(o",415185085],[":wSh9@",501960005],["|V Wio9lO!",324642121],["",1878118961]])
// • new Map([["v+F5",1030950445],["Y",18],["#}v&.7",1883797433],["qJ@a8.3",4]])
// • new Map([["@o|g4}Cn",18],["Nz_",29],["",920403338],["+L",10],["i:",1392468760],[".",898880680],["!t",4],["!a",13],[" er",2147483630]])
// • new Map([["x=a",6],["S!>CQu",638476530],["yZ7%hru",2147483624],["@",713385500],["ia/(=Ozu95",61371014],[".|",21],["W-",1018807193],["}!z8#c$\"",25],["wSnk",1192769499],["X|:1P30VB",15],["",18],["[u!\"+yuzes",20],["x",1229270118],["<_m9=?AF",1091195456]])
// • new Map([[" Vx=",1782399021],["n$:P1|8?s",1357712747],["-9L^V#\"",2029749716],["/A",181643247],["(i~",1438095678]])
// • …
fc.map(fc.constantFrom('a', 'b', 'c'), fc.boolean(), { maxKeys: 3 });
// Note: Keys are always in ['a', 'b', 'c']. Setting maxKeys to 3 makes generation more efficient as it avoids attempting to generate Maps with more than 3 entries when only 3 unique keys are possible.
// Examples of generated values: new Map([]), new Map([["c",false]]), new Map([["c",true],["b",true]]), new Map([["b",true],["a",false]]), new Map([["a",true]])…
Resources: API reference.
Available since 4.4.0.
record
Generate records using the incoming arbitraries to generate its values.
It comes very useful when dealing with settings.
Signatures:
fc.record(recordModel)fc.record(recordModel, {requiredKeys?, noNullPrototype?})
with:
recordModel— structure of the resulting instancerequiredKeys?— default:[all keys of recordModel]— list of keys that should never be deletednoNullPrototype?— default:false— only generate records based on the Object-prototype, do not generate any record with null-prototype
Usages:
fc.record({
id: fc.uuid({ version: 4 }),
age: fc.nat(99),
});
// Examples of generated values:
// • {__proto__:null,"id":"0000001f-2a24-4215-b068-5798948c5f90","age":3}
// • {__proto__:null,"id":"acf6f6c5-fff4-4fff-bfff-fff0a2ca880f","age":18}
// • {__proto__:null,"id":"5682d7df-8023-4f9b-b7a7-19500000001a","age":5}
// • {"id":"0000000b-001a-4000-8000-0001c7ed6eaf","age":93}
// • {"id":"f4f0e509-dcc3-435a-8000-0007fffffffe","age":7}
// • …
fc.record(
{
id: fc.uuid({ version: 4 }),
age: fc.nat(99),
},
{ requiredKeys: [] },
);
// Note: Both id and age will be optional values
// Examples of generated values:
// • {__proto__:null,"id":"fffffffb-c066-4b8c-bfff-fff076fecf56","age":99}
// • {"age":4}
// • {__proto__:null,"age":4}
// • {"id":"79a18a26-7f2a-44ae-8000-001d24687e88"}
// • {__proto__:null,"id":"00000005-6a47-4c09-b343-053a0000000d","age":24}
// • …
fc.record(
{
id: fc.uuid({ version: 4 }),
name: fc.constantFrom('Paul', 'Luis', 'Jane', 'Karen'),
age: fc.nat(99),
birthday: fc.date({ min: new Date('1970-01-01T00:00:00.000Z'), max: new Date('2100-12-31T23:59:59.999Z') }),
},
{ requiredKeys: ['id'] },
);
// Note: All keys except 'id' will be optional values. id has been marked as required.
// Examples of generated values:
// • {__proto__:null,"id":"90ff29b1-56e2-408d-bf2a-4f6b0000001f","name":"Paul","age":66,"birthday":new Date("2050-04-17T15:35:56.134Z")}
// • {"id":"fffffff5-ffe5-4fff-8000-000b00000013","name":"Luis","age":3,"birthday":new Date("1970-01-01T00:00:00.025Z")}
// • {__proto__:null,"id":"687e2e0a-000e-4000-bfff-fff30000000a","name":"Karen","age":6,"birthday":new Date("1970-01-01T00:00:00.040Z")}
// • {"id":"f6967db5-3699-45bd-b9b6-4b300ca48a17","name":"Paul","age":94,"birthday":new Date("2031-12-18T04:14:25.874Z")}
// • {__proto__:null,"id":"00000009-377c-4856-8000-000d3b05e20d","age":79}
// • …
fc.record(
{
id: fc.uuid({ version: 4 }),
age: fc.nat(99),
},
{ requiredKeys: [] },
);
// Note: Both id and age will be optional values
// Examples of generated values:
// • {__proto__:null,"id":"fffffffb-c066-4b8c-bfff-fff076fecf56","age":99}
// • {"age":4}
// • {__proto__:null,"age":4}
// • {"id":"79a18a26-7f2a-44ae-8000-001d24687e88"}
// • {__proto__:null,"id":"00000005-6a47-4c09-b343-053a0000000d","age":24}
// • …
fc.record(
{
id: fc.uuid({ version: 4 }),
age: fc.nat(99),
},
{ noNullPrototype: true },
);
// Note: If you only want instances coming with the prototype of Object, you can toggle the flag noNullPrototype.
// The prototype of Object carry some extra functions with it: `generatedInstance.toString()` can be achieved on it, it "cannot" without a prototype if no toString was explicitely defined.
// Examples of generated values:
// • {"id":"f24af89b-fff1-4fff-9941-0ed3ffffffe4","age":5}
// • {"id":"00000001-860d-4216-ba28-48790000001a","age":35}
// • {"id":"fffffff8-9657-4e22-93a8-24ed21bdd338","age":3}
// • {"id":"937c1a2c-fffd-4fff-9c7d-d2d200000007","age":2}
// • {"id":"dabdc13e-4e5e-43ed-acf2-062100000014","age":96}
// • …
Resources: API reference.
Available since 0.0.12.
object
Generate objects (key/values).
Signatures:
fc.object()fc.object({key?, depthSize?, maxDepth?, maxKeys?, size?, withBigInt?, withBoxedValues?, withDate?, withMap?, withNullPrototype?, withObjectString?, withSet?, withTypedArray?, withSparseArray?, withUnicodeString?, stringUnit?, values?})
with:
key?— default:fc.string()— arbitrary responsible to generate keys used for instances of objectsdepthSize?— default:undefinedmore — how much we allow our recursive structures to be deep?maxDepth?— default:Number.POSITIVE_INFINITY— maximal depth for generated objects (Map and Set included into objects)maxKeys?— default:0x7fffffffmore — maximal number of keys in generated objects (Map and Set included into objects)size?— default:undefinedmore — how large should the generated values be?withBigInt?— default:false— enablebigint- eg.:1nwithBoxedValues?— default:false— enable boxed values - eg.:new Number(5)withDate?— default:false— enableDate- eg.:new Date('2020-10-14T16:52:36.736Z')withMap?— default:false— enableMap- eg.:new Map([['key', 'value']])withNullPrototype?— default:false— enable objects not defining any prototype - eg.:Object.create(null)withObjectString?— default:false— enable strings looking as string representations of JavaScript instances - eg.:"{}","new Set([1])"withSet?— default:false— enableSet- eg.:new Set([1, 2, 3])withTypedArray?— default:false— enable typed arrays for ints, uints and floats - eg.:Int8Array.from([1, 2, 3])withSparseArray?— default:false— enable sparse arrays - eg.:[1,,,3]withUnicodeString?— default:false— change the default forkeyandvaluesso that they produce unicode strings with non-ascii characters — shadowed bystringUnitstringUnit?— default:undefined— customize the set of characters being used by thestringarbitraryvalues?— default: booleans, numbers, strings, null and undefined — array of arbitraries producing the root* values - *non-object ones
Usages:
fc.object();
// Examples of generated values:
// • {"T>\"C9":false,"yHBAjk":{"<uc'a%TWVL":undefined},"\\7PeD/-o:":true,"PW'CFh3Pw":[-7.214519610151173e-299,false,true,null,2030234130078961,null,-8273957629958170,"",undefined,-8.179494320148384e-94],"2$1~":[-3282804867866377,false,4298380906242337,[[7564146043215021,"VYH","h","",false,"%ds7#kDfYS",3.578123265927531e-219,-354088372170986,-2613507181137057],"U,pa$"]],"3W":[-6.675234143629247e-99,"vV 'iQL3",[true,true],"",-5.0163002484267276e-251],"4A B6S":-8850782960808458}
// • {"]iD\"27;N":"Q2znA<",">|{G|F':f":[-3.4364134630258427e+167],"::n|?y1":false,"D#\"qgM":["{?Ug/mu`y",4099389896444517,2.8106429365287123e-290,"D0u7f\\wL4",true,"go\"+a'h~","4~SPYw","}5nUz@cu",false,2.653699048373951e+52],"A*]4kR#":[3.077678585699057e-191,":."],"<{zL{GS_df":{"Kr/`":{"-<":true,"{;L>~A?+b":{":flM\\Ds":-5869183493605743,"":"pH"}},"C8iO":false},"w;c[ifHPI":[null,-1832455907117025,"46q)#d^l1&","",-5.074102272041778e-260,3155691818471737,false,-2142427046048884,"$vG2"],"":2792379101188081}
// • {"(TjI84":{"!ax5yBXr#":1.7962464671949172e+244,"H3C1OZ-CE`":undefined,"bB^5Yz!cI":["*Wn,'",7.690509123279207e+227,undefined,5852017543054509,1.0974361021126729e-16],"1!Tq":"Y"}}
// • {"\\YeS$":true,"\\Cx>":[null,undefined,5667732388716951,"r:-4=`eKn",true,undefined,-1.0161624651353362e+89],"kwF$1q'lm\\":undefined,"":7427664738904881}
// • {}
// • …
fc.object({
key: fc.constantFrom('a', 'b', 'c'),
});
// Note: Keys in ['a', 'b', 'c']
// Examples of generated values:
// • {"a":5434039340410617,"c":"6C&YYy&I"}
// • {"b":[[undefined,null,undefined],["M?",-5580220830100695,"-",false,1.0406508739549715e-195,undefined,",<]u[K6BWe",7191393626793647,true],"xlSjDQL"],"a":[{"c":null,"b":-3.31044629414266e-203},[5.08501079708449e+64,true,"To7_sk",-7813867695183313,undefined,-2.6288856620187387e-300,true,"opc$","},.h%"],"_aa%]B"],"c":""}
// • {"c":[null,true,-5103135698626634,true,8.640826035376584e+129,"BQxVJft(?",-1.5564132973251761e-224,-8751473183072760]}
// • {"a":null,"c":":M2(J"}
// • {"b":[],"c":true,"a":{"c":undefined,"a":1.4812341361081706e-90,"b":3.0694085912031733e-265}}
// • …
fc.object({
maxDepth: 0,
});
// Examples of generated values:
// • {}
// • {"":-2661215485674034,"xc\" _":5.122556662839035e+30}
// • {"EjK.b?^O":"D1$L","zDJWs":"","s ":true}
// • {"":"","r ":"f96g[G4Ta","Lo":-9007199254740982,"y?D0":-4.029795204858185e-145,"{k\"":"4Eg!e$X&!","!#\"{;[r|":true,"ElpSy!":undefined,"N_/?":"3|OB->","Ur!\"":8.561972111917054e-150,"whbHaYv(9":undefined}
// • {"i<\":q":-2.6171334135337624e-291}
// • …
fc.object({
maxDepth: 1,
});
// Examples of generated values:
// • {}
// • {"":{"7xc\" ":"pU","`2ce{'@$":"rT0u2Fz","=\\MDU^x?F":-1634219774646683,"=C_`":":p","5r&":"UHG\"<N"},"9DK]":true}
// • {"EjK.b?^O":{},"D1$L":{"JWsn":" 9%Gp.m0N|"},"?8,E(":{"p7*8>":"O","d!R":"vUwQTwv","Jk<?]Q4kiz":"t9sE;","/a70Mu$":1.553810706514351e-293,"u?*":"};Q4%","":-1.6909038094436722e+50,"jlh42":-1.5681604359387257e+267,";\"OH=dAQ":true,"U<SYe":-6.243528612631655e+287,"_":"q\\b%5"}}
// • {"":{},"r ":{"f96g[G4Ta":3507520577650897,">":null,"-d%v":"YBz[cn","<0u\">P":"?D","1! oW":true,"\\7q5":false,"zx":-3977761363413685,"_":true,"@gK7^Ue YJ":false,"<T.o":-7480996801782140},"y$ );[":-1.7976931348623143e+308,"v&ElpSy!8":{"_/?==2^3|O":null,")[uv*IokV}":" rn(#c","A6[":undefined,"":-7486588236535470},"$1$#S?&Q":5675817337610269,"Z":{},",\"S":[],"F":{"10":-6578471272860074,"djr%&u9k":9007199254740988,"Q9$%":-9007199254740972,"_Ziwm4T":"$__prot","WgRxy<]":true,"?k@":null,"!^!":-3e-323,":NCTp":-8325747361775351}," &HDDGxQP":["Mfwc!n",true," g\"",true,5924336580000517,-7.4e-323],":,":{"nXS#E":false,"bi":-9007199254740972,"":"6","W#/":false,"Ls^d:;":-9007199254740954,"i~$s&":true,"key":2.1892316382848086e-97,"n":"Oc&z\"P0","8\"W{q":7287039842698893,"~Bl!":-3.7948918096071375e-76}}
// • {"i<\":q":9.4e-323}
// • …
fc.object({
withBigInt: true,
withBoxedValues: true,
withDate: true,
withMap: true,
withNullPrototype: true,
withObjectString: true,
withSet: true,
withTypedArray: true,
withSparseArray: true,
withUnicodeString: true,
});
// Examples of generated values:
// • {}
// • {"𐝥𥸕綖":{"𤻎":"new Number(5.458711183935786e+215)","\"\"":new Set([new Number(-168580940874959),false,new String("𱚏")]),"\u0003":new Map([["",new String("尢纍")],["𮕉ɠ𪲳",new Number(-3.915309186966617e-201)],["𬘃𨴓𦹎",false],["𣏓⢋𰌂",9.778144932315068e-292],["",new Boolean(true)],["",new Number(7263738133547713)],["𬲒","𪶟"],["",""],["𧘻",new String("")]])},"𤾿":Uint8ClampedArray.from([2,167,221,250,25,5,253,3,39]),"":new Set([null,-7554992422397568,-17220778063163852213518299424149709632540904753173033601881880719429971665504n,new String(""),new Boolean(true),undefined,-10556040980590440407765974154662897970048173654375365677184296697937171159766n]),"toString":{},"":[],"":Uint8ClampedArray.from([118,211,17]),"n":"new Map([[\"\",-3.847406447449319e-89]])","\u0007\u0013\u0003諸\u0010\f":{__proto__:null,"\u000e\u0000\u000b𪲿\u0014":new Number(-7.4e-323),"𭩼𗿎臦":"","":23060781171921571898756243128383982884697443490579335692025690551060929342872n,"uoStr":new String(""),"":null,"𮏄":new Number(-1.3004479422180178e+247)}}
// • {__proto__:null,"":Int32Array.from([]),"𐔕𗶅":{"\"\\\"[,,,new Number(-4.490174307177352e-198),,new Date(\\\\\\\"-106579-12-08T20:44:48.131Z\\\\\\\"),,,,undefined,undefined,,,,,new Boolean(true),1.9508140793094447e-78,,new Number(-5041235613012303)]\\\"\"":[undefined,30705958287062063809406821421480739232961490015468570116289856317966655176612n,new Number(7.67366369906868e+61),"",-14338777825638388738588125662519091098121465295520758561664196240746398148098n,"",undefined],"셎":[,,6140240271527813,,,,,,,,,,,false,,,-6137666721580411,,,new String(""),,,,,,,,null],"":{__proto__:null,"눡":2.152516341623135e-119,"":new Boolean(true),"쳟":-34792858776756117278644791631482107040200676854821362073707882618437886127898n,"𨻎":new Boolean(false),"𢙻":true,"":new Date("-126777-12-31T00:18:16.754Z"),"\u0002":-3.099084554742164e+111}},"⑄":{__proto__:null,"":true,"":new String(""),"":new Number(-472028172876604),"𓐑":new Date("+037493-02-01T23:18:48.960Z"),"":new Number(-2.3716909519897796e-150),"Ձ":3040157920756017,"𮁫":new String("𬡟ﰖ𔕫"),"𦱂":new Number(2532454634579329),"new Number(7798002711790977)":new String("𫏡੩")},"𨩟":"Int16Array.from([7658,22125,-26239])","":new Map([["",Uint8Array.from([])],["{\"𪫮\":34333408565281186912577278712210978660985153156897149000078193251081785567642n,\"≼\":-6668764753275173,\"new String(\\\"\\\")\":3.795018961460958e+53,\"⺠쌛𧡬\":-2839839446815476,\"\":true,\"\":-1671767290528202,\"\":{\"𮘒󠄵\":new Date(\"-182354-05-21T10:29:26.023Z\"),\"𨌰\":true,\"𰯬𪮾广\":new Number(4536131695635927),\"new Number(5.117983040436394e+69)\":-7686272122101106,\"\":new Date(\"+256755-02-25T04:42:50.620Z\"),\"\":new Date(\"-128815-01-15T07:27:05.561Z\"),\"\":new Number(1918554798446691),\"悵\":-7170578019637745722012682538451894114914867188472658657746570163170180233272n,\"\":null,\"\":undefined},\"囖\":new Number(-1.5469047808995759e-83)}",new Number(-1.6148448506765371e+22)],["",false],["",new Number(-5.826528261511027e+274)]])}
// • {__proto__:null,"":new Set([]),"\u000e𓍚":Int8Array.from([-46,-72,-12,-70,56,120,-31,124,52,-33]),"key":{__proto__:null,"new Map([[new Boolean(false),-1.441300349275421e+148]])":null,"𬇆":new Number(-9.77072430925001e+272),"𥝸":[,,,,,,,,,,,,,,,,,,,,,,,,,,,,Float64Array.from([2.4327003204327724e+59,-2.3055577399170182e+238,-1.220016394687611e+278,-1.748990183698356e+145,5.1394770441041245e+137,1.8234041126551352e-121,1.094040461150623e-206])],"𦪹𮯙":new Date("+193195-05-28T11:42:59.440Z"),"arguments":new Boolean(false)},"𗬩":"[48]"}
// • {"":new Map([]),"":Uint32Array.from([1826204194,2417112435,3273159995,841539727,2942351593,1381423026]),"𰂻":new Map([["",new Number(-6836057403391378)],["new Date(\"-258207-08-18T07:39:50.664Z\")",[,,,,new Number(-1735757222382761),,"",,,,,,,,6278459942747999807080033191647922344096494191174452342262690828457892656925n,,new Date("-214251-08-20T20:06:26.663Z"),"",,,,,-8.079750906287982e-78,,,,,,,-10369827297499097554212502537348689556523576568069581751719816193396600267713n]],["",new Number(-1.2812321053022621e+131)],["𥼄",new Boolean(false)]]),"":[,new Set([-2.788886288154636e-108,-23176574200426617453381026519592490931781297414960701128396696332593406842216n,new Number(2614490335475399)]),,new Number(1.3866106311527406e+165),,43453764951860924684879533858074278006216090104086631170894299857984787714606n,,,,,,"𦱓",,,,,,,,-40062093534296937501748016010257849709288299651944876442585854714003078112906n,,,,,,,new Date("+120633-04-04T13:13:22.144Z")],"綌𩕊":Uint8Array.from([187,25,149,37,145,210,143,27]),"フ𘚢":"\"new Date(\\\"-062403-09-14T13:14:48.775Z\\\")\"","":new Date("+252329-01-04T02:02:12.616Z")}
// • …
fc.object({
depthSize: 'medium',
maxDepth: 1000,
});
// Note: For the moment, we have to specify maxDepth to avoid falling back onto its default value
// Examples of generated values:
// • {"jlRI2'7":[[-3.6634432860547786e+51,{"7m=0":"&fz",")!":[undefined],"N":null,"I=u8m^VR":{"S29":undefined,"b:<?mCQkVd":8.940058015250812e-271,"qAHv?":"P:w<OcJP","Q4ZF|M":108779479352173.86,"!)!UV~9":false,"I3<aagCu9":-590557752051460.5,"y":false,"u<*Y#T@Y3":8165685034312269,"<W;Qzu8":"&%Xv","V":null}},-3.121430328628285e+162,undefined],["","phW",-1.9464950299309262e-17,-4.226362328068501e-212,3.1522566190934685e-186],{"4":1.3897601044135302e-295,"}nkw<.)":false,"8h9gD":true,"r<!":true,"]f/sR%^9Hj":"H&)","cHm kh":[-4.396365385982941e+29,8089452988759541],"wln.":{"Ahv<l]:|":undefined,"w*OEhL":-1.1354700894005589e-291,"W39)u&":true,"":true,"SX4e'Hj":false,"G\"yRzF":false,"\\,tcQ6$#j":"zCGHb]","yvRw":undefined},"":-3.8760248323787517e-97}],"{?F(":{"R\\94!x6Q":[[],{"i@iro5[fKd":{"Pq*;vr;c":3433121904518719,"E((9PS":"5|Tp","y/Jo0":false,"{\\F8{l":true,"3@9J1{9?b4":{"JqLj#8%IVM":-4.345111006146924e-119,"E#h ":-1.4458501693886183e-53,"Z":null,"ek":7.627014306073162e+35,"":5211735920391165,"b":"#T"},"Q.$%&J*hg1":true},"MWBjU":-5998627330219094},{"99\\QXu]D_":0.049788359044109755,"|< 0vgmqeG":",","":true,"r=QT":6.720558051229312e-144,"G++i!hk@":4647057243076279,"E&ng)(~G":-4.1051239898293556e-219,"JtBUMq":null,"q`kX22":""}],",0sD":[-2291925253002477,-3680809186684411],"d>}":{"WPP5*6Cr":{"\"1":null,"2)T":-8377951956507916,"9HF3{V8tEb":2280334561885641,"!$%Rey@}":2528584674341843,"d^!9":"8@$-sOGr",":-?}' ":"u@f","qP":-4245571069522892,"NFS,v8,3B":"~fdG,gkK3"},"/G;o":[null,-8242886212680521,-6105795529017969,2.4795920784861635e-58,true],"|W*45":"","@/:$YWe":true,"h[&":-7.300258930257669e-188,"zj=S68":697925372625389}}}
// • {"<6Fmm`4}Bu":[{"wimM?[D_l":"-"," cLYEh":undefined,"~M=,<]":undefined,"":{"+5V>":true,"x'xlSjDQL":[1802778402004233,-8616465840854132,true],"eG?2W":false,"y":undefined,">sMsRX 6y":-1.7189385776940326e-264,"SS%K~_":-1.0690658255104117e-299,"0WR\\L":false,"#}D{":""},".Df)X2<":-2202090815862342,"HZd+N":[undefined,{"C_H~4X4q":2709965599750143,"Qz2":null,"[*~=DXH":"yZi"},undefined,":L=\\O","5UeV}~.'",-3.31044629414266e-203,false,false],"*a@K.To":[false]},false,["Gmfz&O=K2o",-7.403319311837875e+241,[-3.0613655782090207e-27,true,"a%]B","","b9x}"],null,4179679971001965,{"~Ve#ZG6Mb":null,"i:SSd7":null,"Jf4P2mz":100760271.13220443,"W)k":"zI&n-d(wbC"},undefined,-7286446844918941,-4.039967891793219e+56,1906820233849569],296844346754593,{"S5rX+-":[-1.1392462164399509e-198,[-9.535024608921826e-271,"Gq;"],true,undefined,3.5981254940269306e+81,"T)c')v9r\"A","oO5oP+'",":M=m",-3.944166286120164e+33,-6205742952976482],"YTl":undefined,"I<,TFUmM":{"&A$":{"oKj$u2ew":-775022.3461122828,"fF^|`":"+8a:]/|E?","$/Mx":"`","U'SU4y9WL":{"DR(Vw":"sp^5@HyTyg","\"x":{},"=DrKR^41":":eTPKH{|","/Jw.":"4*2.d43","XX0jo":true,"8I+]uE,~f!":"KU","U#XUyT":null,"}]0G`S":false,"R":8685784240008809}},"":1.620440900490254e-107,"rD8XT^&[Z|":[],"gXifr1xy":[true,true,false,undefined,-2.6592975170538685e+219,-7514943573617259,4.4832607392026617e+86,4960815038961037,"W3=9"]}}],"_":[[],{"^B!_l":"/D[S5Z2zWA","jfZ":"F$uvKnq","Lguy)#r_IX":1.2359628335811745e-97,"1;":3821770058210129},-6.904446105243352e-71,-1.0297835727619694e-278,-3.5748966927106464e-37,"JVd6D|",347573441937437,-2.359579050814135e+229,false],"G2jJT":{" ":[2.951809015572984e+77,".H:K~5Wa",7.880546788741649e+254,"#I5H XXI",-256426800988548,"'U|*?Z{R","@xJ]",undefined],"o=P":{",lv,|":{"Qn":{"f\\bt0%":[],"4pdV~v":"tx8>?nX","m1<<":[false,undefined]},"zAzTM_<Pw":-5.140247429260173e+64,"p":{"iiQQ43":-3035959157448065,"o":true},"8IXbO":2.6967794816849864e+174},"R\\Jgqd":"","P5/1GS5P|r":"Hl~Qiu>"},"":{"":{"O<}lhD_VJ":"KRa",">ARE|":2.105709110120377e+291},"mt-5CHw":[7281056895309909,undefined,-1.0832106067775677e+83,"n",1.1148533710500072e-144,undefined,9.612492054183178e+254,{"w^7m1":"x","gAJ":1216468896413103,"3P.":undefined,"lH`PK3XT":true,"M":true,"V'$":1366229033719073,"":-5449296540214400,"dDV4":"aN-1$oz","o`6":"sf1J9i@[<","7IQ!VE)":"oRO6+-@-4"},-6617712369339759,false],"!J%w/m":true},"bM\"!Z":false,"9}/":{"U/N0":-8.797962526796922e-300,"Ians":"_<d"}}}
// • {"QP~oe^k":{"":-6.297226029379872e-90,"nTBQxV":["&JgF{Ts",-2.2023434094817895e+57,"}",{"J[G5),H":2896817514483901,"+;.1i@":"3_AK_j3Me","Wr":5040983497678121,"":null,"y":"T","(3w|Ctz":"m?(hO3U]U","7,-Dk":1.097665475704934e-37,",e'\"`":-1.3824131271867126e-137,"+":true,"sT{T U":"jrWM)PTK4"},"ShcW"],"Uy":[[-2.5e-323,6e-323,true,"*?C?",{"09gDr)":-6631066354524675,"abW0O`G7w":1.7975641982015258e-218,"24R2wI@m8":-1.4231998566419938e-152,"":"'(yHIDy8.","iJhH@CoZI":-9.306087735675537e-117,"[~Su5uc":true,"c2>U#O#":-2.554930250476925e+50}],9007199254740989,{"7":false,"1)eo[:ZLR":-1680458957018741}]}}
// • {"Qynb2&R:":"kprototy","S/zpO]":-6.610312155890988e+164}
// • {"gIkH":{"M5R7w_$C0":false,"":"2hHGwqBi]","4?NZ(<btD":" ","tb":null,"[tE~r,Tp":3272117996070697,"9% ;$":{},"gdZ7p.rOM":-1.8456309562500985e+216,"nnTx}3z+B":true},"8$":[{"@p3P":{"`%:j4)tY":"[/RpNyjA8","F;>I\"l0!1":"}1","-yFgaGXx":undefined,"O":false,"MSxw E&*":2053216282867765,"gU$Tvn:":6468393373138605,"N":false,"\\EZq71Vg^g":-7351123399757278},"N.F!HH+u%":[]}],"]{\\s~Bq":{":=u^*,k<e":{"Z":-2.943842010162528e-293,"QB":[undefined]},"kJ&t":[],"bJVUgr{%4_":-2229105556514824},"L":{},"CjiJ,/q;S":{"wYd/nde0":[-7641753278026031,-2.3215299537372015e-307,{"#VlxP":".o9D##","Xr1BGSJ":"\\\\sy]h"},8501134920229827,"e Ok` 1(",48256.5854714529,"J-"],"(n":undefined,"n+ABlR":"k ","q3":{"L}h]4*9>N@":8318651930088765,"UD+Lz6":" 4","":-5138984880950414,"i":true,"pL\\w":"<9","z3M6\"X -":1.3642276018956944e+61,"uqHu":9.837488911132902e+60},"v<=P0L":"b(an[(81","sCs`< ajc":true},"aq#; 4":[false,"zHdkS","u~SK","A$`ATe|+,",true,"/'",false,[2065404388717637,false,"fI58Jykr","6"],4.058136433038056e+268,"^z<Hm'"],".q^":null}
// • …
Resources: API reference.
Available since 0.0.7.
anything
Generate any kind of entities.
Signatures:
fc.anything()fc.anything({key?, depthSize?, maxDepth?, maxKeys?, size?, withBigInt?, withBoxedValues?, withDate?, withMap?, withNullPrototype?, withObjectString?, withSet?, withTypedArray?, withSparseArray?, withUnicodeString?, stringUnit?, values?})
with:
key?— default:fc.string()— arbitrary responsible to generate keys used for instances of objectsdepthSize?— default:undefinedmore — how much we allow our recursive structures to be deep?maxDepth?— default:Number.POSITIVE_INFINITY— maximal depth for generated objects (Map and Set included into objects)maxKeys?— default:0x7fffffffmore — maximal number of keys in generated objects (Map and Set included into objects)size?— default:undefinedmore — how large should the generated values be?withBigInt?— default:false— enablebigint- eg.:1nwithBoxedValues?— default:false— enable boxed values - eg.:new Number(5)withDate?— default:false— enableDate- eg.:new Date('2020-10-14T16:52:36.736Z')withMap?— default:false— enableMap- eg.:new Map([['key', 'value']])withNullPrototype?— default:false— enable objects not defining any prototype - eg.:Object.create(null)withObjectString?— default:false— enable strings looking as string representations of JavaScript instances - eg.:"{}","new Set([1])"withSet?— default:false— enableSet- eg.:new Set([1, 2, 3])withTypedArray?— default:false— enable typed arrays for ints, uints and floats - eg.:Int8Array.from([1, 2, 3])withSparseArray?— default:false— enable sparse arrays - eg.:[1,,,3]withUnicodeString?— default:false— change the default forkeyandvaluesso that they produce unicode strings with non-ascii charactersstringUnit?— default:undefined— customize the set of characters being used by thestringarbitrary — shadowed bystringUnitvalues?— default: booleans, numbers, strings, null and undefined — array of arbitraries producing the root* values - *non-object ones
Usages:
fc.anything();
// Examples of generated values:
// • {"iWE$U_3M":-1.1761153457907281e+64,"L8Yr[Em":false,"\":5S":false,"o*&t(b":"{e~\\gX0Ed","oZ":null,"1_0O9":"foL+as'","":[1.0463183151057806e-218,null,true,"`","/|iF"],"Y":"x\"","YP$;D_Cs":-2.406148264784688e+274,"c!lltdK:(_":"bD'arF"}
// • {"3O":[undefined,false,[true,-3.9051738307924134e-153,4.149228362205894e-119,false,false,true,false," D%}6m0",2.799370866495145e-203,-4.091042595321496e+221]],".J":[{"Og*S":"","I9?z([s":-1.1821534452382826e-198},1.7790896502987502e+276,true,-2.376179675473729e-295,true,true,undefined],"~MS":"key"}
// • "ref"
// • null
// • {"key":{},"MTvN8AE0gi":[3405288540635877,"P]z!2",true,-2.387521190971066e-60,null,-3698869638931618,";|s%~j+NA",-6.1815138747104425e-266,{}]}
// • …
fc.anything({
key: fc.constantFrom('a', 'b', 'c'),
});
// Note: Generated objects will come with keys in ['a', 'b', 'c']
// Examples of generated values:
// • [true,true,null,-5.6688453874368936e+48,false,2014694191684145,"LV$%~%",undefined,"_`qj6\"kX[",""]
// • {"b":{"c":6997371217031069,"b":8609382555061735,"a":5.120009133889531e-261}}
// • ""
// • "Y}q^/9i*"
// • 3467734424335213
// • …
fc.anything({
maxDepth: 0,
});
// Note: Only root values
// Examples of generated values: -8578863785414675, -4e-323, 5.4e-323, 1.9666983140272718e-262, -34…
fc.anything({
maxDepth: 1,
});
// Examples of generated values:
// • 1.1084525170506736e-156
// • ["&",-951559264941376,",M9|W?"]
// • [-2218061790593050,30]
// • [-8177572456165737,"5",undefined,-6845939437559701,false,"8erNtuc"]
// • -6827243000782837
// • …
fc.anything({
withBigInt: true,
withBoxedValues: true,
withDate: true,
withMap: true,
withNullPrototype: true,
withObjectString: true,
withSet: true,
withTypedArray: true,
withSparseArray: true,
withUnicodeString: true,
});
// Examples of generated values:
// • {}
// • Float32Array.from([])
// • ""
// • [,,,,,,,,,,,,"𧴘",,"𰭜𐺫",,-5.3675543270540993e-284,[new Number(1657701218649805)],,[new Date("+220046-10-23T23:52:55.336Z"),new Number(2.1773262360012777e-144)],null,,new Boolean(false),,,undefined]
// • [,,,false,new Number(-1.599410877348038e+79),,43191232019149202439704040983801711618185659722841871029570904665841503300146n,,,,,undefined,-464687703824889,,,,,,,,,,,new String(""),,,,false,-1.2182093470461338e-165]
// • …
fc.anything({
depthSize: 'medium',
maxDepth: 1000,
});
// Note: For the moment, we have to specify maxDepth to avoid falling back onto its default value
// Examples of generated values:
// • [true,true,null,-5.6688453874368936e+48,false,2014694191684145,"LV$%~%",undefined,"_`qj6\"kX[",""]
// • {"`?f\"vcr":{"XW71":{"zXAq\"Z5Q":true,"@qs0m!":[5.120009133889531e-261,{"o3i[OWP`=F":{"":4.068510532307745e+281}},2487404948730847],";TuQtZ&=7m":{"'($":null," bkaeV":{"":true,"Aw9+YG]!":-6.879800144762926e+244,"n?L!B#R)n":"g5","'mq.#%I":1.3221798495494814e-101,"}E==:3Bp^T":-7996608749108864,"m":2.6223863023846673e-44,"w|q":3.70106922442221e-186},"!-V+{4":"\\","jwvaZ8":{"zB!nm|":7757208992281711,"h":-4.149080249381332e+195,"aiDLh":"","(Hs)$P*P":1.190747970776708e+91,"%?nT~X[N~\\":undefined,"`.r,*R;I":true},"":[-6523958486123735,undefined,1.2305151888129762e-204,8115823674866317,null,false,4.434127565304523e-183]}},".sfPOsH*41":[-5.01979880119724e-255,"i",-1.4081703508890424e+232,{"m!?ZW`:":"Y{P?$jVp","zq$@`":"fP>v)%C","sE,":[undefined,2467017295150935,[false,1063781909072521],"/>V;[_hAQG","[q:F",1.7094514624379897e+303,"",4.022046823766959e-77,true,false]},undefined,null,-5117919068097772,-1.0529463229722598e-11]}}
// • ""
// • "Y}q^/9i*"
// • 3467734424335213
// • …
Resources: API reference.
Available since 0.0.7.