Security News
UK Officials Consider Banning Ransomware Payments from Public Entities
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
chance-generators
Advanced tools
This module is thin wrapper around the excellent chance library for doing composable generators.
npm install --save chance-generators
var g = require('./lib/chance-generators')(42)
var emails = g.email({ domain: g.pick(['example.com', 'mail.me']) })
expect(emails(), 'to equal', 'hiapli@example.com')
expect(emails(), 'to equal', 'cuval@mail.me')
expect(emails(), 'to equal', 'ozi@example.com')
When you call any of the functions documented on www.chancejs.com with one of more arguments a new generator function is returned instead of just generating the result:
var positiveIntegers = g.integer({ min: 0 })
expect(positiveIntegers, 'to be a function')
expect(positiveIntegers(), 'to be a number')
If you call a generator without any arguments it will produce a new value.
expect(g.integer(), 'to be a number')
Any generators passed as parameters to other generators will be called to produce a random value:
var g = require('./lib/chance-generators')(42)
var smallStrings = g.string({ length: g.integer({ min: 3, max: 9 }) })
expect(smallStrings(), 'to equal', '(n25S')
expect(smallStrings(), 'to equal', 'GlheH#y')
expect(smallStrings(), 'to equal', '0Wbe)19')
The only exception to this rule is the n
and unique
functions, they don't
dereference the generator given as the first argument:
var g = require('./lib/chance-generators')(42)
var stringArrays = g.n(g.string, g.integer({ min: 0, max: 10 }))
expect(stringArrays(), 'to equal', [
'(n25SSlGlheH#ySk0', 'be)19*pan]nTwTM', 'FbvMT', 'kdv[BrHg6To'
])
expect(stringArrays(), 'to equal', [
'[RId@SYmHea(*', 'P7CwbhrYrGYjTK9cm^Ct', 'X3xFMpO', 'nc)!5H*D%&S1&y'
])
expect(stringArrays(), 'to equal', [])
Always generates the given value.
var g = require('./lib/chance-generators')(42)
expect(g.identity(42), 'when called', 'to equal', 42)
Same as n
but defaults to generate arrays between 0-50 items when no count is
supplied.
var g = require('./lib/chance-generators')(42)
expect(
chance.array(chance.natural({ max: 10 })),
'when called',
'to equal', [
8, 10, 2, 8, 8, 6, 6, 1, 4,
1, 1, 0, 5, 9, 3, 6, 1, 7, 7
]
)
Generates values of the given shape, if the structure contains generators they will be unwrapped.
expect(chance.shape({
constant: 42,
point: {
x: chance.integer,
y: chance.integer
}
}), 'when called', 'to satisfy', {
constant: 42,
point: {
x: expect.it('to be a number'),
y: expect.it('to be a number')
}
})
Copyright (c) 2016 Sune Simonsen sune@we-knowhow.dk
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Random generators based on changejs
The npm package chance-generators receives a total of 192 weekly downloads. As such, chance-generators popularity was classified as not popular.
We found that chance-generators demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.