Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@no-day/fp-ts-generators
Advanced tools
Readme
Seeded pseudorandom generators for structured data.
fp-ts-generators
is a library that's only purpose is pseudo random data generation. It can be useful in many fields, e.g. in generative art, mocking APIs or as well as property based testing.
With combinators like
recordOf({ foo: int(), bar: boolean });
and a given seed, we can deterministically generate random looking data.
This library is not a testing library in the style of quick-check. However, a testing library can be built on top of this package.
Uses fp-ts
as a peer dependency.
npm install fp-ts @no-day/fp-ts-generators
import { Gen, generateSample, recordOf, boolean, string, int, mkSeed, arrayOf, float } from '@no-day/fp-ts-generators';
import * as assert from 'assert';
import { pipe } from 'fp-ts/function';
// Let's first of all define a type for which we want to generate some pseudo random data
type Person = {
name: string;
age: number;
hobbies: string[];
details: { active: boolean; trusted: boolean };
height: number;
};
// And let's define a specific generator for that type:
const genPerson: Gen<Person> = recordOf({
name: string(),
age: int({ min: 0, max: 100 }),
hobbies: arrayOf(string()),
height: float({ min: 0.0, max: 2.0 }),
details: recordOf({ active: boolean, trusted: boolean }),
});
assert.deepStrictEqual(
pipe(
genPerson,
// Here we generate 3 samples with the given seed `42`.
// The result will always be the same.
generateSample({ count: 3, seed: mkSeed(42), size: 5 })
),
[
{
age: 84,
details: {
active: false,
trusted: true,
},
height: 0.6403711704913259,
hobbies: [':noq0', 'h}I=', '<U', ';A', ''],
name: '}',
},
{
age: 9,
details: {
active: true,
trusted: true,
},
height: 1.988632641722106,
hobbies: [],
name: 'Y',
},
{
age: 80,
details: {
active: true,
trusted: false,
},
height: 0.16447428536086742,
hobbies: ['{@3 ', '=)nr', 'ue', 'oK[*', 'IC'],
name: ' (8',
},
]
);
See the examples
folder for more usage demos.
The library can be used in plain JavaScript as well, you'll find a demo in the examples folder, too.
Parts of this library are ported from purescript-quickcheck.
FAQs
Seeded pseudorandom generators for structured data.
The npm package @no-day/fp-ts-generators receives a total of 94 weekly downloads. As such, @no-day/fp-ts-generators popularity was classified as not popular.
We found that @no-day/fp-ts-generators 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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.