fakeforge 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +107 -0
- package/index.js +210 -0
- package/package.json +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 [Your Name]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# fakeforge
|
|
2
|
+
|
|
3
|
+
Zero-dependency, **seedable** fake data generator for tests, demos, and prototypes. Generate names, emails, phone numbers, addresses, and full person records — with the option to make output fully reproducible.
|
|
4
|
+
|
|
5
|
+
## Why another fake-data library?
|
|
6
|
+
|
|
7
|
+
- **Zero dependencies** — nothing to audit, tiny install.
|
|
8
|
+
- **Seedable** — pass a seed and you get the *same* data every run, so your test snapshots don't break.
|
|
9
|
+
- **Simple API** — one class, intuitive methods.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install fakeforge
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick start
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
const FakeForge = require('fakeforge');
|
|
21
|
+
|
|
22
|
+
const fake = new FakeForge();
|
|
23
|
+
|
|
24
|
+
fake.fullName(); // "Sofia Martinez"
|
|
25
|
+
fake.email(); // "p.nguyen@gmail.com"
|
|
26
|
+
fake.phone(); // "(415) 892-3310"
|
|
27
|
+
fake.address(); // { street, city, state, stateAbbr, zip }
|
|
28
|
+
fake.person(); // full record (see below)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Or grab the ready-made default instance:
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
const { fake } = require('fakeforge');
|
|
35
|
+
fake.fullName();
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Reproducible data with seeds
|
|
39
|
+
|
|
40
|
+
Pass a number or string seed. The same seed always produces the same sequence — ideal for deterministic tests.
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
const a = new FakeForge('my-seed');
|
|
44
|
+
const b = new FakeForge('my-seed');
|
|
45
|
+
|
|
46
|
+
a.fullName() === b.fullName(); // true
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## API
|
|
50
|
+
|
|
51
|
+
| Method | Returns |
|
|
52
|
+
| --- | --- |
|
|
53
|
+
| `firstName()` | First name |
|
|
54
|
+
| `lastName()` | Last name |
|
|
55
|
+
| `fullName()` | "First Last" |
|
|
56
|
+
| `email(first?, last?)` | Email, derived from a name if given |
|
|
57
|
+
| `phone(format?)` | Phone; `format` uses `#` as a digit placeholder |
|
|
58
|
+
| `streetAddress()` | "123 Maple St" |
|
|
59
|
+
| `city()` / `state(abbr?)` / `zip()` | Address parts |
|
|
60
|
+
| `address()` | `{ street, city, state, stateAbbr, zip }` |
|
|
61
|
+
| `number(min?, max?)` | Integer in range |
|
|
62
|
+
| `bool(probability?)` | Boolean |
|
|
63
|
+
| `pick(array)` | Random item from your array |
|
|
64
|
+
| `uuid()` | v4-style UUID |
|
|
65
|
+
| `date(start?, end?)` | Date in range |
|
|
66
|
+
| `words(n?)` | n words of lorem ipsum |
|
|
67
|
+
| `person()` | Full person record |
|
|
68
|
+
| `array(method, n, ...args)` | Array of n results from a method |
|
|
69
|
+
|
|
70
|
+
### Custom phone formats
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
fake.phone('+1-###-###-####'); // "+1-415-892-3310"
|
|
74
|
+
fake.phone('###.###.####'); // "415.892.3310"
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Generating many records
|
|
78
|
+
|
|
79
|
+
```js
|
|
80
|
+
const users = new FakeForge('users').array('person', 100);
|
|
81
|
+
// 100 deterministic person objects
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Example person record
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"id": "a4e3c9e8-96c5-49ae-aa78-50692d103f9f",
|
|
89
|
+
"firstName": "Diego",
|
|
90
|
+
"lastName": "Davis",
|
|
91
|
+
"fullName": "Diego Davis",
|
|
92
|
+
"email": "ddavis@yahoo.com",
|
|
93
|
+
"phone": "(352) 762-6744",
|
|
94
|
+
"address": {
|
|
95
|
+
"street": "3432 Cedar Way",
|
|
96
|
+
"city": "Salem",
|
|
97
|
+
"state": "Georgia",
|
|
98
|
+
"stateAbbr": "GA",
|
|
99
|
+
"zip": "55495"
|
|
100
|
+
},
|
|
101
|
+
"birthDate": "1999-09-24"
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
MIT
|
package/index.js
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/* ============================================================
|
|
4
|
+
* fakeforge — zero-dependency, seedable fake data generator
|
|
5
|
+
* Single-file build. No subfolders, nothing to misplace.
|
|
6
|
+
* ============================================================ */
|
|
7
|
+
|
|
8
|
+
/* ---- Seedable PRNG (mulberry32) ---- */
|
|
9
|
+
|
|
10
|
+
function mulberry32(seed) {
|
|
11
|
+
let a = seed >>> 0;
|
|
12
|
+
return function () {
|
|
13
|
+
a |= 0;
|
|
14
|
+
a = (a + 0x6d2b79f5) | 0;
|
|
15
|
+
let t = Math.imul(a ^ (a >>> 15), 1 | a);
|
|
16
|
+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
17
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function hashSeed(str) {
|
|
22
|
+
let h = 1779033703 ^ str.length;
|
|
23
|
+
for (let i = 0; i < str.length; i++) {
|
|
24
|
+
h = Math.imul(h ^ str.charCodeAt(i), 3432918353);
|
|
25
|
+
h = (h << 13) | (h >>> 19);
|
|
26
|
+
}
|
|
27
|
+
return h >>> 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
class Random {
|
|
31
|
+
constructor(seed) {
|
|
32
|
+
if (seed === undefined || seed === null) {
|
|
33
|
+
this._next = Math.random;
|
|
34
|
+
} else if (typeof seed === 'string') {
|
|
35
|
+
this._next = mulberry32(hashSeed(seed));
|
|
36
|
+
} else {
|
|
37
|
+
this._next = mulberry32(Number(seed) >>> 0);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
float() { return this._next(); }
|
|
41
|
+
int(min, max) { return Math.floor(this._next() * (max - min + 1)) + min; }
|
|
42
|
+
pick(arr) { return arr[Math.floor(this._next() * arr.length)]; }
|
|
43
|
+
sample(arr, n) {
|
|
44
|
+
const copy = arr.slice();
|
|
45
|
+
const out = [];
|
|
46
|
+
n = Math.min(n, copy.length);
|
|
47
|
+
for (let i = 0; i < n; i++) {
|
|
48
|
+
const idx = Math.floor(this._next() * copy.length);
|
|
49
|
+
out.push(copy.splice(idx, 1)[0]);
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
bool(probability = 0.5) { return this._next() < probability; }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* ---- Data pools ---- */
|
|
57
|
+
|
|
58
|
+
const firstNames = [
|
|
59
|
+
'James', 'Mary', 'Robert', 'Patricia', 'John', 'Jennifer', 'Michael', 'Linda',
|
|
60
|
+
'David', 'Elizabeth', 'William', 'Barbara', 'Richard', 'Susan', 'Joseph', 'Jessica',
|
|
61
|
+
'Thomas', 'Sarah', 'Charles', 'Karen', 'Christopher', 'Nancy', 'Daniel', 'Lisa',
|
|
62
|
+
'Matthew', 'Margaret', 'Anthony', 'Betty', 'Mark', 'Sandra', 'Aisha', 'Wei',
|
|
63
|
+
'Mateo', 'Sofia', 'Omar', 'Priya', 'Liam', 'Olivia', 'Noah', 'Emma',
|
|
64
|
+
'Yuki', 'Chen', 'Amara', 'Diego', 'Fatima', 'Ravi', 'Ingrid', 'Tomas'
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
const lastNames = [
|
|
68
|
+
'Smith', 'Johnson', 'Williams', 'Brown', 'Jones', 'Garcia', 'Miller', 'Davis',
|
|
69
|
+
'Rodriguez', 'Martinez', 'Hernandez', 'Lopez', 'Gonzalez', 'Wilson', 'Anderson',
|
|
70
|
+
'Thomas', 'Taylor', 'Moore', 'Jackson', 'Martin', 'Lee', 'Perez', 'Thompson',
|
|
71
|
+
'White', 'Harris', 'Sanchez', 'Clark', 'Ramirez', 'Lewis', 'Robinson', 'Walker',
|
|
72
|
+
'Nguyen', 'Kim', 'Patel', 'Khan', 'Singh', 'Chen', 'Wang', 'Ali',
|
|
73
|
+
'Okafor', 'Silva', 'Costa', 'Rossi', 'Muller', 'Schmidt', 'Novak', 'Ivanov'
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
const emailDomains = [
|
|
77
|
+
'gmail.com', 'yahoo.com', 'outlook.com', 'hotmail.com', 'icloud.com',
|
|
78
|
+
'proton.me', 'example.com', 'mail.com'
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
const streetNames = [
|
|
82
|
+
'Maple', 'Oak', 'Pine', 'Cedar', 'Elm', 'Washington', 'Lake', 'Hill',
|
|
83
|
+
'Park', 'Sunset', 'River', 'Spring', 'Highland', 'Forest', 'Meadow', 'Ridge',
|
|
84
|
+
'Lincoln', 'Jefferson', 'Madison', 'Franklin', 'Church', 'Market', 'Union', 'Center'
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
const streetTypes = ['St', 'Ave', 'Blvd', 'Rd', 'Ln', 'Dr', 'Ct', 'Way', 'Pl'];
|
|
88
|
+
|
|
89
|
+
const cities = [
|
|
90
|
+
'Springfield', 'Riverside', 'Franklin', 'Greenville', 'Bristol', 'Clinton',
|
|
91
|
+
'Fairview', 'Salem', 'Madison', 'Georgetown', 'Arlington', 'Ashland',
|
|
92
|
+
'Burlington', 'Manchester', 'Oxford', 'Dover', 'Hudson', 'Kingston'
|
|
93
|
+
];
|
|
94
|
+
|
|
95
|
+
const states = [
|
|
96
|
+
{ name: 'California', abbr: 'CA' }, { name: 'Texas', abbr: 'TX' },
|
|
97
|
+
{ name: 'Florida', abbr: 'FL' }, { name: 'New York', abbr: 'NY' },
|
|
98
|
+
{ name: 'Illinois', abbr: 'IL' }, { name: 'Ohio', abbr: 'OH' },
|
|
99
|
+
{ name: 'Georgia', abbr: 'GA' }, { name: 'Washington', abbr: 'WA' },
|
|
100
|
+
{ name: 'Arizona', abbr: 'AZ' }, { name: 'Colorado', abbr: 'CO' }
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
const lorem = [
|
|
104
|
+
'lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit',
|
|
105
|
+
'sed', 'do', 'eiusmod', 'tempor', 'incididunt', 'ut', 'labore', 'et', 'dolore',
|
|
106
|
+
'magna', 'aliqua', 'enim', 'minim', 'veniam', 'quis', 'nostrud', 'exercitation'
|
|
107
|
+
];
|
|
108
|
+
|
|
109
|
+
/* ---- Main class ---- */
|
|
110
|
+
|
|
111
|
+
class FakeForge {
|
|
112
|
+
/** @param {number|string} [seed] Same seed => same data. */
|
|
113
|
+
constructor(seed) {
|
|
114
|
+
this.rng = new Random(seed);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
firstName() { return this.rng.pick(firstNames); }
|
|
118
|
+
lastName() { return this.rng.pick(lastNames); }
|
|
119
|
+
fullName() { return `${this.firstName()} ${this.lastName()}`; }
|
|
120
|
+
|
|
121
|
+
email(firstName, lastName) {
|
|
122
|
+
const first = (firstName || this.firstName()).toLowerCase();
|
|
123
|
+
const last = (lastName || this.lastName()).toLowerCase();
|
|
124
|
+
const domain = this.rng.pick(emailDomains);
|
|
125
|
+
const styles = [
|
|
126
|
+
`${first}.${last}`,
|
|
127
|
+
`${first}${last}`,
|
|
128
|
+
`${first}_${last}`,
|
|
129
|
+
`${first}${this.rng.int(1, 999)}`,
|
|
130
|
+
`${first[0]}${last}`
|
|
131
|
+
];
|
|
132
|
+
const local = this.rng.pick(styles).replace(/[^a-z0-9._]/g, '');
|
|
133
|
+
return `${local}@${domain}`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
phone(format = '(###) ###-####') {
|
|
137
|
+
let out = '';
|
|
138
|
+
for (const ch of format) out += ch === '#' ? this.rng.int(0, 9) : ch;
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
streetAddress() {
|
|
143
|
+
return `${this.rng.int(1, 9999)} ${this.rng.pick(streetNames)} ${this.rng.pick(streetTypes)}`;
|
|
144
|
+
}
|
|
145
|
+
city() { return this.rng.pick(cities); }
|
|
146
|
+
state(abbr = false) { const s = this.rng.pick(states); return abbr ? s.abbr : s.name; }
|
|
147
|
+
zip() { return String(this.rng.int(10000, 99999)); }
|
|
148
|
+
|
|
149
|
+
address() {
|
|
150
|
+
const s = this.rng.pick(states);
|
|
151
|
+
return {
|
|
152
|
+
street: this.streetAddress(),
|
|
153
|
+
city: this.city(),
|
|
154
|
+
state: s.name,
|
|
155
|
+
stateAbbr: s.abbr,
|
|
156
|
+
zip: String(this.rng.int(10000, 99999))
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
number(min = 0, max = 100) { return this.rng.int(min, max); }
|
|
161
|
+
bool(probability = 0.5) { return this.rng.bool(probability); }
|
|
162
|
+
pick(arr) { return this.rng.pick(arr); }
|
|
163
|
+
|
|
164
|
+
uuid() {
|
|
165
|
+
const hex = '0123456789abcdef';
|
|
166
|
+
let out = '';
|
|
167
|
+
for (let i = 0; i < 36; i++) {
|
|
168
|
+
if (i === 8 || i === 13 || i === 18 || i === 23) out += '-';
|
|
169
|
+
else if (i === 14) out += '4';
|
|
170
|
+
else if (i === 19) out += hex[(this.rng.int(0, 15) & 0x3) | 0x8];
|
|
171
|
+
else out += hex[this.rng.int(0, 15)];
|
|
172
|
+
}
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
date(start, end) {
|
|
177
|
+
const s = (start ? new Date(start) : new Date(Date.now() - 3.15e11)).getTime();
|
|
178
|
+
const e = (end ? new Date(end) : new Date()).getTime();
|
|
179
|
+
return new Date(s + this.rng.float() * (e - s));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
words(n = 3) { return this.rng.sample(lorem, Math.min(n, lorem.length)).join(' '); }
|
|
183
|
+
|
|
184
|
+
person() {
|
|
185
|
+
const first = this.firstName();
|
|
186
|
+
const last = this.lastName();
|
|
187
|
+
return {
|
|
188
|
+
id: this.uuid(),
|
|
189
|
+
firstName: first,
|
|
190
|
+
lastName: last,
|
|
191
|
+
fullName: `${first} ${last}`,
|
|
192
|
+
email: this.email(first, last),
|
|
193
|
+
phone: this.phone(),
|
|
194
|
+
address: this.address(),
|
|
195
|
+
birthDate: this.date('1950-01-01', '2005-12-31').toISOString().slice(0, 10)
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
array(method, n, ...args) {
|
|
200
|
+
const out = [];
|
|
201
|
+
for (let i = 0; i < n; i++) out.push(this[method](...args));
|
|
202
|
+
return out;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const defaultInstance = new FakeForge();
|
|
207
|
+
|
|
208
|
+
module.exports = FakeForge;
|
|
209
|
+
module.exports.FakeForge = FakeForge;
|
|
210
|
+
module.exports.fake = defaultInstance;
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fakeforge",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Zero-dependency, seedable fake data generator — names, emails, phones, addresses and full person records for testing and prototyping.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "node test.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"index.js"
|
|
12
|
+
],
|
|
13
|
+
"keywords": [
|
|
14
|
+
"fake",
|
|
15
|
+
"faker",
|
|
16
|
+
"mock",
|
|
17
|
+
"dummy-data",
|
|
18
|
+
"test-data",
|
|
19
|
+
"seed",
|
|
20
|
+
"seedable",
|
|
21
|
+
"random",
|
|
22
|
+
"generator",
|
|
23
|
+
"names",
|
|
24
|
+
"email",
|
|
25
|
+
"address"
|
|
26
|
+
],
|
|
27
|
+
"author": "mohen_96",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=14"
|
|
31
|
+
}
|
|
32
|
+
}
|