npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jsarbit

v0.0.1

Published

Random property generator.

Downloads

5

Readme

jsarbit

TODO: Write a project description

Installation

npm install jsarbit

Usage

Example

gen

gen is set of helper functions to create Arbitrary.

  • gen.of(value: any)

    • Asis value generator.
  • int(min: number, max: number)

  • float(min: number, max: number)

  • posNum()

  • posNum(max: number)

  • negNum()

  • negNum(min: number)

    • Generator of numbers in range.
  • array(element: Arbitrary or any value, sizeMin: number, sizeMax: number)

  • array(element: Arbitrary or any value, sizeMax: number)

    • Generator of array.
    • Example:
      var dogOrCatArray = gen.array(choose('dog', 'cat'), 10);
      var someOfPizza = gen.array('pizza', 1, 10);
  • array(element: Arbitrary or any value, sizeMin: number, sizeMax: number)

  • array(element: Arbitrary or any value, sizeMax: number)

    • Generator of array.
  • arrayOfN(size: number, arb: Arbitrary or value)

    • Generator of array which has size number of elements generated by arb (or arb value if arb is not Arbitrary).
  • obj(propArbitrary: object)

    • Generator of object.
    • propArbitrary is object which property takes Arbitrary.
    • Example:
      var arb = gen.obj({
        name: gen.oneOf("Alice", "Bob"),
        address: {
          country: "Japan",      // No Arbitrary property
          zip: gen.numericStr(3)
        },
      });
      
      var sample = arb.sample();
      /* {
        name: "Alice",
        address: {
          country: "Japan"    // as it is.
          zip: "491"
        }
      } */
  • choose(min: number, max: number)

    • Generator of arbitrary number in range.
  • oneOf(ary: array)

    • Generator which choose a element of ary randomly.
  • bool()

    • Generator of boolean.
  • alphaLowerChar()

  • alphaUpperChar()

  • alphaChar()

  • numericChar()

  • alphaNumericChar()

    • Generator of a char.
  • charSeqOf(arb: Arbitrary which generates of char, minLen, maxLen)

  • charSeqOf(arb: Arbitrary, minLen)

    • Generator of string consisted of arb's sample.
  • numericStr(minLen, maxLen)

  • numericStr(maxLen)

  • identifier(minLen, maxLen)

  • identifier(maxLen)

    • Generator of string.
  • frequency(freq: array)

    • Chooses one of the given generators with a weighted random distribution.
    • Example
      var arb = gen.frequency([
        [1, gen.oneOf(['a', 'b', 'c'])],
        [9, gen.choose(1,10)]
      ]);
      
      forAll(arb, function (value) {
        console.log(value); // char generated 10% of all.
      });

Arbitrary

Arbitrary is an arbitrary value generator class.

  • new Arbitrary(sampleFunc: function)
    • Creates new instance which has sample() function as sampleFunc.
  • Arbitrary.sample()
    • Generates arbitrary value.
  • Arbitrary.map(func: function)
    • Returns new Arbitrary which sample() applied func to this.sample()'s return value.
  • Arbitrary.flatMap(func: function)
    • Returns new Arbitrary which returned by func applied with this.sample()'s return value.

forAll

function to generate with Arbitrary.

  • forAll(arb: Arbitrary, func: function, count=100)
    • Call func number of count times with arbitrary value generated by arb.
    • Example
      forAll(choose(0, 50), function(num) {
        assert(num >= 0 && num <= 50);
      });

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Credits

TODO: Write credits

License

MIT