Deterministic random data generator for mocks, seeds, demos, and tests.
npm install @mirawision/imagineDeterministic random data generator for mocks, seeds, demos, and tests.
ESM-first, TypeScript-typed, fully deterministic via global or local seeds. Pragmatic faker-style API plus SVG helpers for avatars and patterns.
- Deterministic: Global seed(value) and per-call { seed }
- Typed: Full TypeScript definitions
- Tree-shakable: ESM modules and scoped imports
- Rich domains: number, boolean, id, string, person, location, date, internet, color, game, util, images (SVG)
``bash`
npm install @mirawision/imagine
or
`bash`
yarn add @mirawision/imagine
`ts
import imagine, { seed, number, string, person, images } from 'imagine';
seed(123);
const n = number.int(10, 20);
const sku = string.pattern('AAA-####-!!');
const name = person.fullName();
const avatar = images.avatar({ seed: name, style: 'identicon', as: 'string' });
// via default object
const hex = imagine.color.hex();
`
`ts
import { number } from 'imagine/number';
import { avatar } from 'imagine/images';
const id = number.int(1, 100);
const svg = avatar({ seed: id, as: 'string' });
`
`ts
import { seed, string } from 'imagine';
seed(2024); // global seed for deterministic runs
const a = string.word(); // uses global seed
const b = string.word({ seed: 'test' }); // independent local seed
`
`ts
import { location } from 'imagine';
const countryName = location.country(); // e.g. "Poland"
const countryCode = location.countryCode(); // e.g. "PL"
const tz = location.timezone(); // e.g. "Europe/Warsaw"
`
`ts
import { images } from 'imagine';
const svgStr = images.placeholder({ width: 320, height: 180, text: 'Hello' });
const dataUrl = images.pattern({ seed: 1, type: 'hex', as: 'dataUrl' }) as string;
`
- seed(value): set global seed
- number: int, float, sequencebool(probability)
- boolean: uuid
- id: , hash, slugchar
- string: , string, word, sentence, paragraph, patternfirstName
- person: , lastName, fullName, username, email, password, avatar, phonecountry
- location: , countryCode, city, address, zip, coordinates, timezone, languagedate
- date: , time, timestamp, year, month, day, dayOfTheWeekip
- internet: , ipv6, domain, url, mac, userAgenthex
- color: , hexa, rgb/rgba, hsl/hsla, hsv, cmykdice
- game: , card, coinarray
- util: , object, objectMany, autoavatar
- images: , pattern, placeholder, initials, shapeSet
All generators accept an optional { seed?: number | string } to isolate randomness per call without affecting the global sequence. Use seed(value) at app/test start for predictable, repeatable results.
- ESM-only outputs with .d.ts typesimport { number } from 'imagine/number'`)
- Node.js 18+ and modern browsers supported
- Prefer scoped imports for best tree-shaking (
Contributions are always welcome! Feel free to open issues or submit pull requests.
This project is licensed under the MIT License.