https://github.com/umstek/sampler
Generate elaborate random data instantly.
https://github.com/umstek/sampler
data faker javascript json sample
Last synced: 3 months ago
JSON representation
Generate elaborate random data instantly.
- Host: GitHub
- URL: https://github.com/umstek/sampler
- Owner: umstek
- License: mit
- Created: 2017-09-09T18:48:30.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2025-07-05T07:47:14.000Z (3 months ago)
- Last Synced: 2025-07-05T08:37:32.102Z (3 months ago)
- Topics: data, faker, javascript, json, sample
- Language: TypeScript
- Homepage: http://www.umstek.tk/sampler
- Size: 583 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 34
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# SamplerJS
Generate elaborate random data instantly.


[](https://codecov.io/gh/umstek/sampler)## How to use
### Try it online
View [demo](https://runkit.com/umstek/samplerjs-demo) or POST a JSON in correct format to https://samplerjs-demo-rqwiegzvqqfn.runkit.sh to get random data. (This is achieved with the help of RunKit and is rate-limited.)
### Install
Run:
`npm install samplerjs`
or,
`yarn add samplerjs`
if you're using yarn.**Use it on your project:**
```js
const samplerjs = require("samplerjs");
const parser = samplerjs.Parser.chanceParser;
const result = parser.parse({
user: {
firstName: {
$type: "first",
nationality: "us"
},
lastName: "last",
tel: "phone"
},
description: "paragraph"
});
```## Currently supported data types
Everything supported by the excellent `chance`js library except,
- Helper functions
- `hidden`
- `dice`
- `n`
- `unique`
- `weighted`These are to-be implemented in a "sampler-native" way in the future.
## Object Format
```js
const fillThisObject = {
someKey: "typeThatDoesNotNeedArgs",
otherKey: {
$type: "typeThatNeedsArgs",
arg1: "someSimpleArg",
arg2: {
// Argument that needs pre-processing
$type: "type",
arg1: "arg"
},
$process: ["arg2"] // Ask to preprocess arg2 as if it was anothe node in this object tree
}
};
```