
Research
/Security News
Popular Tinycolor npm Package Compromised in Supply Chain Attack Affecting 40+ Packages
Malicious update to @ctrl/tinycolor on npm is part of a supply-chain attack hitting 40+ packages across maintainers
This module allows you to generate completely random variables, which is sometimes useful in testing. There are situations when you want to write a little property-based test, but you don't want to use a full framework for that.
This module allows you to generate completely random variables, which is sometimes useful in testing. There are situations when you want to write a little property-based test, but you don't want to use a full framework for that.
That's where Anything comes in.
Anything is a tiny, zero-dependency utility for generating random stuff.
Install it with yarn:
yarn add -D any-thing
Or, if you use npm:
npm install --save-dev any-thing
An example of usage with Jest:
import _ from 'lodash'
import { anything } from 'any-thing'
test('makeOkResponse', () => {
/* a tiny property-based test */
_.times(100, () => {
const thing = anything()
expect(makeOkResponse(thing)).toEqual({ status: "OK", payload: thing })
})
})
Anything includes 9 generators, which produce, respectively:
null
undefined
Arrays, functions and objects may also be nested.
anything(options = {})
Generates anything. You may provide options for each generator. Options is an object that contains options for all (or some) generators. The overall shape is:
{
array: { /* array options */ },
boolean: { /* boolean options */ },
function: { /* function options */ },
integer: { /* integer options */ },
/* and so on for other generators */
}
See also: Generator options.
anything.but(generators..., options = {})
Generates anything, but does not use specified generators. For example, anything.but(Array, Object)
will generate anything but an array or an object.
anything.except(generators..., options = {})
Alias for anything.but
.
anything.from(generators..., options = {})
Generates anything using a whitelist of generators. For example, anything.from(null, undefined)
will return either null
or undefined
.
There's also a function for each generator:
anyArray()
anyBoolean()
anyFunction()
anyInteger()
anyNumber()
anyObject()
anyString()
These functions accept options, which are specific for each generator.
minLength
: minimum length of the array. Default: 0maxLength
: maximum length of the array. Default: 10maxDepth
: maximum depth ("nestedness") of the array. Default: 3Example:
anyArray({ minLength: 1, maxLength: 2, maxDepth: 2 })
// => [ -923712 ]
This generator doesn't have any options.
Example:
anyBoolean()
// => true
maxDepth
: maximum depth of the function. Default: 3Example:
anyFunction({ maxDepth: 2 })
// => function () { return 23123 }
min
: minimum value. Default: -1,000,000max
: maximum value. Default: 1,000,000Example:
anyInteger({ min: 0, max: 42 })
// => 42
// i knew I'd get 42
// what else could it be
min
: minimum value. Default: -1,000,000max
: maximum value. Default: 1,000,000Example:
anyNumber({ min: 0, max: 42 })
// => 30.172931281536908
minLength
: minimum length. Default: 0maxLength
: maximum length. Default: 10alphabet
: characters to use when generating a stirng. May be a string or an array.
Default: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
Example:
anyString({ minLength: 10, maxLength: 30, alphabet: '(!*@#!@ )' })
// => '! @ !#*(!*@)('
minLength
: minimum object length (number of entries). Default: 0maxLength
: maximum object length. Default: 10maxDepth
: maximum object depth. Default: 3minStringLength
: minimum length of keys. Default: 1maxStringLength
: maximum length of keys. Default: 20alphabet
: alphabet to use when generating keys. Defaults to String generator's defaultExample:
anyObject({
minLength: 0,
maxLength: 2,
maxDepth: 1,
minStringLength: 1,
maxStringLength: 4,
alphabet: '!@#$%^'
})
// => {}
// of course that's what I get
// rng often seems like it's not random at all
FAQs
This module allows you to generate completely random variables, which is sometimes useful in testing. There are situations when you want to write a little property-based test, but you don't want to use a full framework for that.
We found that any-thing demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Malicious update to @ctrl/tinycolor on npm is part of a supply-chain attack hitting 40+ packages across maintainers
Security News
pnpm's new minimumReleaseAge setting delays package updates to prevent supply chain attacks, with other tools like Taze and NCU following suit.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.