simpleObjectobjectWithKeysfromListsubListlistOfstringwordsentenceparagraphintegerfloatbooleanurlemaildatesimpleObjectProduces a simple object with a random number of key/value pairs. Each key is a random word, and each value is a random string
any.simpleObject();
// { ahe: 'pPwLKrme*OU4@AR1)*^', lel: '6ExqUAyD!', fegcim: 'j03do)OUDhvJ', ucalu: 'L#)zHg5@AV9#vD5O' }
objectWithKeysProduces a simple object with the keys defined from the provided list of keys
objectWithKeys parameterskeys (required): list of keys to be used for the produced object’s keysoptions: object to provide configuration options
factory: factory function to be used to create each of the values for the
produced object
string, if not providedobjectWithKeys examplesany.objectWithKeys(['foo', 'bar', 'baz']);
// { foo: 'eUnRumYAyoS@YVj', bar: 'GvdfJH%]OhNCSDe', baz: 'ozLo2]R' }
any.objectWithKeys(['foo', 'bar', 'baz'], {factory: any.url});
// { foo: 'http://hopap.lr/dupro', bar: 'http://kolore.np/cozmavje', baz: 'http://udegowum.cd/ohobasmo' }
any.objectWithKeys(['foo', 'bar', 'baz'], {factory: id => ({...any.simpleObject(), id})});
/*
{
foo: {
ipsawiw: '$McveM',
comgahra: ']TORpXOYqKQz&G]h',
ranimedo: 'Q^Y)ga2FG^jPzs](',
owabopmom: 'YQz[MoIEVHLbVG',
jebaru: 'qd&TpwaMEp8Vz#al8C',
zuwbedil: 'LC&c3$gPxI',
id: 'foo'
},
bar: {
jahaluz: '#HD0Zqs$QLxAC@Lrb*',
ekofesi: 'uhAOs',
veuhotuh: 'ob1K2TDc5Q',
zuufciw: 'L&hqNtx@',
riptutru: 'mYSXLZh#OmWvaJC2',
obebetmi: '[E@yC^xTBia*]kdvfC',
hugmoug: 'DfV8Qs9f8O433etJ',
zusurare: '0I0!xzrxEN$f4',
gonefo: 'YkLh9Sg&f7o%K)VDT',
watbihli: '3F2]ofS',
elaecave: 'iY@uTDWy@J',
id: 'bar'
},
baz: {
zehitek: '7$GlW8N',
upagpu: '9^UDxLQKp',
aniheiju: '9$lJPW6$eXhPf$GFa',
ekaradcun: ')nD1)rC&c^',
molilji: 'qvr7dW$Ve0uR3fkZ]',
jebowibuf: '0G6vTn)71NsXWsr]ypd',
wednotso: '2hHmqvDlw&&!^ycJ0',
arewibvuf: '*N^&UXo$c&eAiF^',
gutuet: '^JHXnzETi*VSuUy(3b',
molwadi: 'x!dAw',
fuglekpe: 'WqDOaU2[LdAvHm',
ireakiuso: '@VG9BF$)F',
id: 'baz'
}
}
*/
const qux = ['a', 'b', 'c'];
any.objectWithKeys(['foo', 'bar', 'baz'], {factory: (id, index) => ({id, letter: qux[index]})});
/*
{
foo: { id: 'foo', letter: 'a' },
bar: { id: 'bar', letter: 'b' },
baz: { id: 'baz', letter: 'c' }
}
*/
fromListDirect usage of pickone() from chance.js.
fromList parameterslist (required): list of items to choose fromfromList exampleany.fromList(['foo', 'bar', 'baz']);
// bar
subListAn almost direct usage of pickset() from chance.js.
subList parameterslist (required): list of items to choose fromoptions: (required) object to provide configuration options
size: (required) length of sub-list that should be produced by choosing
unique items from the provided listsubList exampleany.subList(['foo', 'bar', 'baz'], {size: 2});
// ['bar', 'foo']
listOfProduces a list of random items from the provided factory function
listOf parametersfactory (required): the factory function for producing the items for the
list.
options: object to provide configuration options
size: length of list that should be produced
1 and 20, if not provideduniqueOn: property on the produced objects that needs to be unique within
the resulting listlistOf examplesany.listOf(any.string);
// [ 'iQw2[CgBJ1FF8', '58jp*w', 'G]5MoXnKe#F43H3#1', 'oO*a7tY^gbY', 'f$AFjgd$Gg2' ]
any.listOf(any.string, {size: 2});
// [ 'wDPGiMtH]fg6o8QxMS', 'OYElY9vO9k4' ]
any.listOf(() => ({ id: any.integer(), foo: any.string() }), {uniqueOn: 'id'});
// [ { id: 173289733357568, foo: 'T8XCg*!Q((*Z5@BUFO' }, { id: 8233254624690176, foo: 'ziY]4e%cDoR07g)IhA' } ]
stringDirect usage of string() from chance.js.
Options are passed directly to the chance method so refer to its documentation
for what is available.
Be aware that string() can include special characters that may not be suitable
for some use cases. If they would cause issues, you may prefer word()
instead.
string exampleany.string();
// 1%BU8#64p%Z
wordDirect usage of word() from chance.js.
Options are passed directly to the chance method so refer to its documentation
for what is available.
word exampleany.word();
// nitte
sentenceDirect usage of sentence() from chance.js.
Options are passed directly to the chance method so refer to its documentation
for what is available.
sentence exampleany.sentence();
// 'Witpevze mappos isoletu fo res bi geow pofin mu rupoho revzi utva ne.'
paragraphDirect usage of paragraph() from chance.js.
Options are passed directly to the chance method so refer to its documentation
for what is available.
paragraph exampleany.paragraph();
// 'Lel fi huepe jupu akse zej ire vesik kojvulom zon is biwuwkef pa. Uv hokivej voh ebu
// numdogi akolo hik uwlez ta vacev ofdaimi acunetum suvet uhdab ir soglazo ju pafbeb. Pub
// cezeh fuc kebamnul he ok luumoabi rawkig me fov pin zup biv risugra. Ralpunad apkomgib
// alnirciw akel wa lus wahfum burog buol vecotihe abadahoj ugolo wovki ucojal fec.'
integerProduces a random integer >= 0. Direct usage of
natural() from chance.js.
Options are passed directly to the chance method so refer to its
documentation for what is available.
integer exampleany.integer();
// 8526341888540672
floatDirect usage of floating() from chance.js.
Options are passed directly to the chance method so refer to its documentation
for what is available.
float exampleany.float();
// -114981703621.0176
booleanProduces a random boolean value (true or false).
Options are passed directly to the chance method so refer to its documentation
for what is available.
boolean exampleany.boolean();
// true
urlDirect usage of url() from chance.js.
Options are passed directly to the chance method so refer to its
documentation for what is available.
url exampleany.url();
// http://vek.fo/derpu
emailDirect usage of email() from chance.js.
Options are passed directly to the chance method so refer to its documentation
for what is available.
email exampleany.email();
// itcobiv@iwo.gq
dateAn almost direct usage of date() from chance.js,
but {string: true} is passed so the default behavior is to generate a date
string by default.
Options are appended to the default of {string: true} when calling the chance
method, so refer to its documentation for what is available.
Pass {string: false} in order to return Date
objects instead of date strings.
date exampleany.date();
// 10/24/2028