0.0.7 • Published 1 year ago

tseudo v0.0.7

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
1 year ago

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

tseudo

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 tseudo
# or
$ yarn add tseudo

Examples

Using Generators

Generators are individual functions that return pseudo random data.

Example 1: Create a random address

import { address } from 'tseudo';
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 'tseudo';

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

NameDescriptionType
rngIntrandom integernumber
rngfloatrandom floating pointnumber
normalDistrandom float with a normal distributionnumber
percentrandom float between 0 and 1number
percentStringpercent but as a string eg: '45%'string

String Util

NameDescriptionType
fromFormatrandom string from format (ZZ99-99)string

Array Util

NameDescriptionType
rngFromArraypick a random element from an arrayelementType

Geographic

NameDescriptionType
postcodepostcode or zipcodestring
citythe citystring
countythe countystring
streetthe streetstring
houseNameNumberthe house name or numberstring
addressfull address in object formatIAddress
addressStringfull address represented as a stringstring

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

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
0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago