Skip to main content

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 keys
  • valueArb — arbitrary instance responsible to generate values
  • minKeys? — 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: false — only generate objects based on the Object-prototype, do not generate any object with null-prototype
  • depthIdentifier? — default: undefined — share the depth between instances using the same depthIdentifier

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 values
  • minLength? — default: 0 — minimal size (included)
  • maxLength? — default: 0x7fffffff more — maximal size (included)
  • size? — default: undefined more — 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 and will more likely generate entries having the minimal accepted length as the depth increases

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 keys
  • valueArb — arbitrary instance responsible to generate values
  • minKeys? — default: 0 — minimal number of entries in the generated instances (included)
  • maxKeys? — default: 0x7fffffff more — maximal number of entries in the generated instances (included)
  • size? — default: undefined more — how large should the generated values be?
  • depthIdentifier? — default: undefined — share the depth between instances using the same depthIdentifier

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 instance
  • requiredKeys? — default: [all keys of recordModel] — list of keys that should never be deleted
  • noNullPrototype? — 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?, stringUnit?, values?})

with:

  • key? — default: fc.string() — arbitrary responsible to generate keys used for instances of objects
  • depthSize? — 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 — enable bigint - eg.: 1n
  • withBoxedValues? — default: false — enable boxed values - eg.: new Number(5)
  • withDate? — default: false — enable Date - eg.: new Date('2020-10-14T16:52:36.736Z')
  • withMap? — default: false — enable Map - 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 — enable Set - 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]
  • stringUnit? — default: undefined — customize the set of characters being used by the string arbitrary
  • values? — 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,[]],"g|":{"UK{":1.638245012303011e-165,"9h=<":false},"-)}N%d":{"kD":-5.1806779758120815e-48,"wpV+j":"\"!2@U,p","$j3":null,"Oq":[],"+v":true}}
// • {"]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}
// • {"(TjI84":{"!ax5yBXr#":1.7962464671949172e+244,"H3C1OZ-CE`":undefined,"bB^5Yz!cI":[],"yrL*Wn,'m":{}}}
// • {"\\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":[[[]],[],[]],"c":{"c":"M?","b":{},"a":"-"},"a":"jRQ!kA"}
// • {"c":[null,true,-5103135698626634,true,8.640826035376584e+129,"BQxVJft(?",-1.5564132973251761e-224,-8751473183072760]}
// • {"a":null,"c":":M2(J"}
// • {"b":[],"c":true,"a":{"b":false,"a":{},"c":false}}
// • …

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,
stringUnit: 'binary',
});
// Examples of generated values:
// • {__proto__:null,"𰻱𑶤𺪑󃥪񊿈󶅉􈹾򹓡򆁟":new Set([new Number(-4.539245569755607e+78),true,new Date("-062662-10-13T03:47:43.925Z"),new String("􍩥񮃗񁅷􇷻󭛁"),1.0886235696968947e+240,null,new String("󧴻𩬶􀜘􀫋𮟩"),new Number(5260756349353269)])}
// • {"𾃍󊿀򩵤󶭌":Uint32Array.from([3525331117]),"񂽪򌪟":{"󢔨𡇔𣍼󘏏":-4.581115131551448e+198,"𽞞򮵥򱥺􇔛󨣆򨓉񰁞":new Date("+072439-12-15T04:41:53.558Z"),"􊖇􈋂񡏂󄩄񉱫󓧈񺺑󕎤":false,"\"񽍢󡩍𛅙\"":new Map([]),"󽧫򴟲񿺷󕥆񱞃򦕃󮁹嗂":null,"󫢅񎞥񦅷񠩎򰉑":[true,null,-47176364463675964841238719861465503407680120771862815279408271999183036017209n,"󩉫򧎾􆡓",new String("󽏹񨰿󻉸򏩸𬲹򇵪󧺩񞫗𿏎𵽣"),new Boolean(true)]}}
// • {__proto__:null,"valueOf":[905015983362557,"􊹅􄮀",Uint32Array.from([2179536137,16689176,1491003272,2263339788,3344434292,446240506,127364256,278108951,952474616,2126694980]),new Number(4991892160223293)],"񶦍򐐥󑠕󭂧񲴀򁜫󇏼ҕ񻤩":Int16Array.from([]),"𱲤򋝤􉅟񽬜𾫕󅾧":false,"恕阒":[2.4688589287798766e-167,8110989220561255,{},null,-4.505195455753882e-273],"񳒐\u0005򩙤\u0001󑵗𑊆񱱫񖌷󎍳":[new Number(13),-39075725674097423291782190797854690559182113260431387720985451121064733036268n,new Date("-132915-08-06T03:13:07.628Z"),null,-57896044618658097711785492504343953926634992332820282019728792003956564819928n,new Number(-7.4e-323),"񌍖\u0014񾫊\u0014󪍙\n",undefined,"Ṇ򧩖򼊮񳱼䒙","\r񼲐\n\u0006񴦔󻥚򑱣􏿱"],"":[false,,,Uint16Array.from([58410,13922]),,,,,,,,,,,,,,,,,,,,,,"\"[,,,,,,,,,,,,,,,,,,,,,,,,,,,]\""],"l":new Set([new Number(-4324877024762989),new String("ꥁ񡖪뛷"),"󯔬󟌸񿧎򻗵󒔂򷟺񳋡󞝪匂",undefined,-41061354347769021590585168711417922438300178603139828034513456683961995412447n,new Number(9.860336635010953e-61),new String("񱴝􉥊򁼤"),true,new Boolean(false)]),"\u0014\u0014\u0014\b":{"򥹪\u0010𤱨\u0000𥗏":[],"key":[new Date("+227125-02-22T06:42:48.648Z"),new Map([]),new Set([])]},"name":new Map([[-1.7976931348623125e+308,[]],["1.7976931348623153e+308","[]"],[{},[]]])}
// • {__proto__:null,"󺜿򷸉󃰁򞾖󺔵":[,,,,,,,,,,,,,,,,],"󙗏򩸄񯬼𱰨򄞧􆅋񃳐𘌽":Uint16Array.from([3913,11691,14366,64582,22368,123,4015,34065]),"򤌿򸅇":["塍񝱦򠭅",new Number(1.7976931348623157e+308),new Number(-8998827767507172),new Boolean(true),new Number(-1.524376890020046e-237),new Number(-1.6338651267943743e+251),new Boolean(true),-1.1089019914669168e+174]}
// • {__proto__:null,"󋼔򆩕򧣖󲹜󆌾":new Map([["𽕪򩏊󒉏􊅼򿜈𶥝󱯠",{}],["྿񡀻",null],["",undefined],["񌒉􀸿𔼩񡍓󷯘񳜈񄣖𬐗𦚴󾵪",[]]])}
// • …

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":[[{},550159071652803,-6.43168939689525e-308,{},"zO)!dhS[T"],-2031183643501032,[true,{},true,null,[]]],"~M*b":{"mCQ":{},"":8.940058015250812e-271,"qAHv?":"P:w<OcJP","Q4ZF|M":108779479352173.86,"!)!UV~9":false,"I3<aagCu9":-590557752051460.5,"y":false}}
// • {"<6Fmm`4}Bu":[{},{},-1.4822190691647479e+184,[],[]],"G)`-# cLY":[undefined,",<]u[K6BWe",{},false,{},"xlSjDQL",[]],"Ni9!&AMFHC":undefined}
// • {"QP~oe^k":{"":-6.297226029379872e-90,"nTBQxV":["j&JgF",{},null,"j}M\"-yx1",3907173995380043],"{tna_":[undefined,[]]}}
// • {"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":"Fg","":5370699505275749,"R":5.485514714171935e+139,"aMSxw":-2.1796191484530992e-215,"?\\engU$T":"","N.P/N":false},"\\EZq71Vg^g":-7351123399757278,"N.F!HH+u%":[],"]{\\s~Bq":{":=u^*,k<e":{},"Z":-2.943842010162528e-293,"QB":["J&t,cwb","",1373338100409305,-2.9862025771594276e+75,"7C=CjiJ",false]},"SLcswYd":"e0PlrD"}
// • …

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?, stringUnit?, values?})

with:

  • key? — default: fc.string() — arbitrary responsible to generate keys used for instances of objects
  • depthSize? — 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 — enable bigint - eg.: 1n
  • withBoxedValues? — default: false — enable boxed values - eg.: new Number(5)
  • withDate? — default: false — enable Date - eg.: new Date('2020-10-14T16:52:36.736Z')
  • withMap? — default: false — enable Map - 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 — enable Set - 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]
  • stringUnit? — default: undefined — customize the set of characters being used by the string arbitrary
  • 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'","":[],"<":"/|iF","Y":"x\"","YP$;D_Cs":-2.406148264784688e+274}
// • {"3O":[],"ojL*":"","HR*;xj)W":"yle"}
// • "ref"
// • null
// • {"key":{},"#A0 >51#Pz":{}}
// • …

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":{}}
// • ""
// • "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,
stringUnit: 'binary',
});
// Examples of generated values:
// • "Uint16Array.from([53182,0,4,6,25929,65528,18436,59190])"
// • {__proto__:null,"񆘫󯻕𓲓":"-0","toString":new Set([])}
// • ""
// • {__proto__:null,"name\fppl":-6941269085696329146163175412746620343296644761384769470252449906252644935385n,"񌚬󽿡񁺊𙯸񀙨椇򵔤":new Number(74711227181270.42),"󢫬􄜄":new Set([]),"𵍃񎪓򦍛򁄼򹔊":new Date("1969-12-31T23:59:59.969Z"),"":{__proto__:null}}
// • [,,-1.7976931348623135e+308,,new Number(9007199254740976),,undefined,,,,,,,,,,,,,,,,,,,new Number(-4.052584823476833e-249),,{},,]
// • …

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":{"W71^)":[],"q\"Z5Ql>b":2.3156928974722997e+102,"m!ONO'":{},"e{o3":"P"}}
// • ""
// • "Y}q^/9i*"
// • 3467734424335213
// • …

Resources: API reference.
Available since 0.0.7.