Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cagen

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cagen

Number of Cases Generator

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
79
decreased by-4.82%
Maintainers
1
Weekly downloads
 
Created
Source

Cagen

GitHub license npm version Downloads Build Status

Number of Case Generator for TypeScript.

SymbolClass
A x B x ... x ZCartesianProduct
n!Factorial
nPrPermutation
nrRepeatedPermutation
nHrRepeatedCombination
nCrCombination

Usage

Installation

npm install --save cagen

Common Features

namespace cagen.base
{
    export interface IForwardGenerator
    {
        // FREQUENCE ACCESSORS
        size(): number;
        begin(): Iterator;
        end(): Iterator;

        // ES2015, THEN FOR-OF ITERATION IS ALSO POSSIBLE
        [Symbol.iterator]: IterableIterator<number[]>;
    }

    export interface Iterator
    {
        readonly value: number[];

        next(): Iterator;
        equals(obj: Iterator): boolean;
    }
}
import { CartesianProduct } from "cagen";

function main(): void
{
    let generator = new CartesianProduct(5, 4); // 5C4
    console.log("n(5C4) =", generator.size());

    for (let it = generator.begin(); !it.equals(generator.end()); it = it.next())
    {
        let aCase: number[] = it.value;
        console.log("  -", aCase);
    }
}
main();
for (let aCase of generator)
    console.log("  -", aCase);

Random Accessor

namespace cagen.base
{
    export abstract class ArrayGenerator
        implements IForwardGenerator<Iterator>
    {
        at(index: number): Array<number>;
    }
}

Most of Case Generator classes, except combination classes, provide a random accessor at(). By that method at(), you can access to a specific case through not full iteration, but the special index number.

  • Permutation
  • Factorial
  • RepeatedPermutation
  • CartesianProduct
  • Combination
  • RepeatedCombination
import { Permutation } from "cagen";

function main(): void
{
    let generator = new Permutation(7, 3);

    console.log( generator.at(13) );
    console.log( generator.at(31) );
    console.log( generator.at(9999) ); // throw an std.OutOfRange error.
}
main();

Keywords

FAQs

Package last updated on 22 Sep 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc