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

@fauxjs/faux.js

v0.1.7

Published

Modern performant pseudo random data generator

Downloads

213

Readme

<typescript> <nicholasmordecai> <nicholasmordecai> code style: prettier npm Coverage Status

faux.js

Modern performant pseudo random data generator

Please note, this is still very early development and has not been tested in a production envirnoment!

Installing

$ npm i faux.js
# or
$ yarn add faux.js

Examples

Using Generators

Generators are individual functions that return pseudo random data.

Example 1: Create a random address

import { address } from 'faux.js';
const address = address();

/*
	{
	  country: 'United Kingdom',
	  county: 'Devon',
	  city: 'Birmingham',
	  street: 'Green Lane',
	  houseNumber: 'Red Stables',
	  postcode: 'VX53 8ZF'
	}
*/

For a full break down of all generators, click here.

Using Registers

Registers are kind of like factories. You can describe your object with built in, custom or inline functions to be group generators together for ease of use.

Example 1:

import { Register, address, rngInt } from  '../core/register';

const  user  = {
	address: address,
	age: () =>  rngInt({min: 18, max: 80})
};

const userRegister = new Register(user);

In order to generate a new user, you can call the build method on that register. Example 2a:

...
const newUser = userRegister.build();

/*
{
  address: {
    country: 'United Kingdom',
    county: 'Essex',
    city: 'Bristol',
    street: 'Kings Lane',
    houseNumber: 7,
    postcode: 'ET9 6WS'
  },
  age: 25
}
*/

Server

If you're developing on the frontend, or are performing API integrations then you may find it very useful to couple registers up with an API. It's a fast and east way to generate data and fetch it through a restful API.

Example 3.

import { Server } from 'faux.js';

const server = new Server();

// create registers
const userRegister = new Register(user);
const account = new Register(account);

// define routes
const routes = {
    '/user': userRegister,
	'/cart': cartRegister
};

server.run(routes);

Core Generators

Math

| Name | Description | Type | |--|--|--| | rngInt | random integer | number | | rngfloat | random floating point | number | | normalDist | random float with a normal distribution | number | | percent | random float between 0 and 1 | number | | percentString | percent but as a string eg: '45%' | string |

String Util

| Name | Description | Type | |--|--|--| | fromFormat | random string from format (ZZ99-99) | string |

Array Util

| Name | Description | Type | |--|--|--| | rngFromArray | pick a random element from an array | elementType |

Geographic

| Name | Description | Type | |--|--|--| | postcode | postcode or zipcode | string | | city | the city | string | | county | the county | string | | street | the street | string | | houseNameNumber | the house name or number | string | | address | full address in object format | IAddress | | addressString | full address represented as a string | string |

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

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

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Nicholas Mordecai

See also the list of contributors who participated in this project.

License

Apache 2.0 License © Nicholas Mordecai

=======

Notes To Self
  • If a nested structure is optional, a config should be set to allow that nested property to be or not to be generated
  • Remove uuid & MD5 packages so this package is without any dependencies (big bonus)

Need to write -

  1. an object can lookup the values of a parent object for conditional statements / branches
  2. you should be able to wrap any fn in a probability factor to determine one of multiple outcomes
  3. Override any value / property from a function generator