Nondeterministic Postrequisite Metaprotocol

    csnow
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.1 • Public • Published

    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.

    Install

    npm i csnow

    DownloadsWeekly Downloads

    2

    Version

    1.0.1

    License

    Unlicense

    Unpacked Size

    108 kB

    Total Files

    24

    Last publish

    Collaborators

    • jakehamtexas