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:0x7fffffff
more — maximal number of keys in the generated instances (included)size?
— default:undefined
more — how large should the generated values be?noNullPrototype?
— default:true
— 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:
// • {"<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}"}
// • {"_":" y|","Yo+\"O@q+j":"cI{H","":"3#$}9{5!z","?^~k ":"w$defipro","[fa4c":"J"}
// • {"~":""}
// • {"lzproperty":"?"}
// • {"hOIY\"R q}":"W","l__defineG":"8x`:H0?T"}
// • …
fc.dictionary(fc.string(), fc.nat());
// Examples of generated values:
// • {"":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}
// • {"#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}
// • {"K":1498847755,"&cP<5:e(y\"":1430281549,"!\"2a":1631161561,"dY+g":1880545446,"M2+^,Yq7~t":1437539188}
// • {"NfXclS":815533370,"?":2060844890,"":1862140278,"R":618808229,"N|":25902062,"DGw00u?brK":348863633}
// • {" R~Own":2147483645,"~":16,"i$#D":1037390287}
// • {">YTN<Tt":1950414260,"I6":1505301756,"2;]'dH.i!":815067799,":kmC'":1948205418,"g|GTLPe-":2101264769}
// • …
fc.dictionary(fc.string(), fc.string(), { noNullPrototype: false });
// Note: Allow generated values to be objects with null prototype
// Examples of generated values:
// • {"|^!!\"+.\"%":"LB","]CQxQ":"0/uv","(JH(35e8":":"}
// • {",>a[":"f&EYz","VR 9JX":"/|hRyU","Nm20AgHq":"b","A1Gb{5nXM":"?B","W;>__":"","G5":"IS"}
// • {"3{59v":"Tf]hDL2","tj:,Kq9'2":"#o:WpR","":"[4h","e{":"j","!Ws@hZV_":"p1*44.<"}
// • Object.assign(Object.create(null),{"/\\v":"1ki#1'|#","L":"2o","chGEb'qmi":"hXXU"})
// • {"Q]8":"JQ=b<ea","@zz\\]oW(*":"uv","w":"\\","X*X":"/2{*wi=d","\"+;P\"tp3n":"LLZ-%}w"}
// • …
Resources: API reference.
Available since 1.0.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?})
fc.record(recordModel, {withDeletedKeys?, noNullPrototype?})
with:
recordModel
— structure of the resulting instancerequiredKeys?
— default:[all keys of recordModel]
— list of keys that should never be deleted, remark: cannot be used withwithDeletedKeys
withDeletedKeys?
— default:false
— when enabled, record might not generate all keys.withDeletedKeys: true
is equivalent torequiredKeys: []
, thus the two options cannot be used at the same timenoNullPrototype?
— default:true
— only generate records based on the Object-prototype, do not generate any record with null-prototype
Usages:
fc.record({
id: fc.uuidV(4),
age: fc.nat(99),
});
// Examples of generated values:
// • {"id":"0000001b-000b-4000-8000-0000ab45c359","age":1}
// • {"id":"9de2ca04-dc68-4c3f-87e4-e878407827d6","age":98}
// • {"id":"12bb661f-b57a-4d8c-8407-719100000002","age":99}
// • {"id":"ffffffe3-0013-4000-a7d5-d5734251f8d2","age":0}
// • {"id":"00000007-000a-4000-8000-00170000000e","age":5}
// • …
fc.record(
{
id: fc.uuidV(4),
age: fc.nat(99),
},
{ requiredKeys: [] },
);
// Note: Both id and age will be optional values
// Examples of generated values:
// • {"id":"00000004-27f6-48bb-8000-000a69064200","age":3}
// • {"id":"ffffffee-ffef-4fff-8000-0015f69788ee","age":21}
// • {"age":34}
// • {"id":"2db92e09-3fdc-49e6-8000-001b00000007","age":5}
// • {"id":"00000006-0007-4000-8397-86ea00000004"}
// • …
fc.record(
{
id: fc.uuidV(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:
// • {"id":"46045be9-0009-4000-8000-0008ffffffed","name":"Karen","age":11,"birthday":new Date("2100-12-31T23:59:59.996Z")}
// • {"id":"fffffffe-0015-4000-95a0-f8e9ffffffe7","name":"Karen","birthday":new Date("1970-01-01T00:00:00.018Z")}
// • {"id":"e2b066ec-000b-4000-bfff-ffe7ccb1828d","name":"Karen","age":17}
// • {"id":"43b7d8e5-d043-42ef-8000-001a00000005","age":16,"birthday":new Date("2004-10-16T22:01:09.416Z")}
// • {"id":"00000007-2008-452e-8000-00133ed36be7","name":"Karen","age":6,"birthday":new Date("2100-12-31T23:59:59.981Z")}
// • …
fc.record(
{
id: fc.uuidV(4),
age: fc.nat(99),
},
{ withDeletedKeys: true },
);
// Note: Both id and age will be optional values
// Examples of generated values:
// • {"id":"ffffffe1-582d-457d-899e-8084fffffff7","age":97}
// • {"age":96}
// • {"id":"00000012-bdc2-4b1c-8a2a-245900000006","age":6}
// • {"id":"8785297a-e305-43bc-bfff-fff1927a3512","age":30}
// • {"age":17}
// • …
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:undefined
more — 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:0x7fffffff
more — maximal number of keys in generated objects (Map and Set included into objects)size?
— default:undefined
more — how large should the generated values be?withBigInt?
— default:false
— enablebigint
- eg.:1n
withBoxedValues?
— 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 forkey
andvalues
so that they produce unicode strings with non-ascii characters — shadowed bystringUnit
stringUnit?
— default:undefined
— customize the set of characters being used by thestring
arbitraryvalues?
— 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.7976931348623111e+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,"!^!":-2.57e-322,":NCTp":-8325747361775351}," &HDDGxQP":["Mfwc!n",true," g\"",true,5924336580000517,-2.87e-322],":,":{"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":-1e-322}
// • …
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("𱚏")]),"#":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]])","'3#諸0,":Object.assign(Object.create(null),{". +𪲿4":new Number(8e-323),"𭩼𗿎臦":"","":23060781171921571898756243128383982884697443490579335692025690551060929342872n,"uoStr":new String(""),"":null,"𮏄":new Number(-1.3004479422180178e+247)})}
// • Object.assign(Object.create(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],"":Object.assign(Object.create(null),{"눡":2.152516341623135e-119,"":new Boolean(true),"쳟":-34792858776756117278644791631482107040200676854821362073707882618437886127898n,"𨻎":new Boolean(false),"𢙻":true,"":new Date("-126777-12-31T00:18:16.754Z"),"\"":-3.099084554742164e+111})},"⑄":Object.assign(Object.create(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)]])})
// • Object.assign(Object.create(null),{"":new Set([]),".𓍚":Int8Array.from([-46,-72,-12,-70,56,120,-31,124,52,-33]),"key":Object.assign(Object.create(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.77e-322,2.3e-322,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:undefined
more — 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:0x7fffffff
more — maximal number of keys in generated objects (Map and Set included into objects)size?
— default:undefined
more — how large should the generated values be?withBigInt?
— default:false
— enablebigint
- eg.:1n
withBoxedValues?
— 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 forkey
andvalues
so that they produce unicode strings with non-ascii charactersstringUnit?
— default:undefined
— customize the set of characters being used by thestring
arbitrary — shadowed bystringUnit
values?
— 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, 2.6e-322, -1.83e-322, 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.