1.0.1 • Published 2 years ago

csnow v1.0.1

Weekly downloads
-
License
Unlicense
Repository
-
Last release
2 years ago

csnow

npm i -D csnow

csnow is a Cartesian/SNapshot Object Writer that calculates the Cartesian product of an object, which may be used for brute-force snapshot testing. csnow provides a declarative interface for controlling the production behavior by allowing properties of the object to be expressbable as Cartesian products or combinations.

The resulting construction may be expanded to an array.

import csnow from "csnow";

const subject = {
	foo: csnow.OneOf(["bar", "baz"]),
	bar: "foo",
	baz: csnow.KOf(2, ["foo", "bar", "baz"]),
};

const snapshots = [...csnow(subject).result];

/*
 * [
 *   { foo: "bar", bar: "foo", baz: ["foo", "bar"] },
 *   { foo: "baz", bar: "foo", baz: ["foo", "bar"] },
 *   { foo: "bar", bar: "foo", baz: ["foo", "baz"] },
 *   { foo: "baz", bar: "foo", baz: ["foo", "baz"] },
 *   { foo: "bar", bar: "foo", baz: ["bar", "baz"] },
 *   { foo: "baz", bar: "foo", baz: ["bar", "baz"] }
 * ]
 */

Calling csnow on a cartesian product Subject will return an { result: Iterator<object[]>; count: number }. You can iterate through the result it with a for..of loop, or use something like [...iterator] to expand it to an array. Due to the large size of the resultant array, it may be preferable to iterate through them lazily with for..of in some cases.

1.0.1

2 years ago

1.0.0

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago