consistent-fake-data 0.0.0-stage → 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 +161 -2
- package/fakedata-core.js +681 -0
- package/package.json +40 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DataSwitch Pro (https://dataswitchpro.com)
|
|
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
CHANGED
|
@@ -1,3 +1,162 @@
|
|
|
1
|
-
#
|
|
1
|
+
# test-data-generator
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/consistent-fake-data) [](https://github.com/caminillov10/test-data-generator/actions/workflows/test.yml) [](LICENSE)
|
|
4
|
+
|
|
5
|
+
**Realistic, consistent fake test data — names, emails, addresses, dates, prices — as CSV, JSON or SQL INSERTs.**
|
|
6
|
+
One JavaScript file, no dependencies. Runs in Node, in the browser and in a Web Worker.
|
|
7
|
+
|
|
8
|
+
▶ **Live demo (no install, no sign-up):** [dataswitchpro.com/test-data-generator](https://dataswitchpro.com/test-data-generator/)
|
|
9
|
+
Up to 1,000,000 rows, CSV / JSON / SQL / Excel download, templates, and an editor for every column.
|
|
10
|
+
|
|
11
|
+
```text
|
|
12
|
+
id,first_name,last_name,email,phone,city,created_at,last_login,is_active
|
|
13
|
+
1,Jacob,Carter,jacobcarter91@example.org,(212) 555-0172,New York,2025-01-07 00:21:42,2025-02-16 14:55:02,true
|
|
14
|
+
2,Andrew,Morgan,andrew.morgan@example.org,(617) 555-0107,Boston,2025-02-01 02:12:11,2025-04-22 15:05:39,true
|
|
15
|
+
3,Dylan,Watson,dylanwatson75@example.net,(919) 555-0148,Raleigh,2025-03-28 15:47:07,2025-05-01 00:13:43,true
|
|
16
|
+
```
|
|
17
|
+
<sub>Output of [`examples/node.js`](examples/node.js) (seed `example`).</sub>
|
|
18
|
+
|
|
19
|
+
## Why another fake data generator?
|
|
20
|
+
|
|
21
|
+
Most generators fill every column on its own. That gives you rows that could never exist, and tests that pass on data your app will never see. This engine was built around the complaints people actually have:
|
|
22
|
+
|
|
23
|
+
| Problem | What this does |
|
|
24
|
+
|---|---|
|
|
25
|
+
| The email has nothing to do with the name | Each row is one person: the email and username come from the name, the gender matches the first name, the age matches the date of birth, and the street, city, region, postcode, phone, country and coordinates belong together. |
|
|
26
|
+
| Orders shipped before they were placed | The `after` type puts a date N–M days after another column (shipped after ordered, last login after sign-up). If the earlier date is blank, the later one is blank too. |
|
|
27
|
+
| Duplicates in a “unique” column | `unique: true` guarantees distinct values. An impossible request (500 unique values from 1–100) is reported **before** generating. |
|
|
28
|
+
| The SQL breaks on `O'Brien` | Quotes are escaped for each database (and backslashes for MySQL), identifiers are quoted, SQL Server gets `N'…'`, rows go into batched multi-row INSERTs inside a transaction, and an optional `CREATE TABLE` gets types, `PRIMARY KEY`, `NOT NULL` and `UNIQUE`. |
|
|
29
|
+
| Different data on every run | A **seed** makes output reproducible on any machine. Adding or removing a column does not change the values in the other columns. |
|
|
30
|
+
| Test emails reach real people | Emails use the reserved `example.com/.net/.org` domains by default (RFC 2606). Phone numbers use the ranges set aside for fiction where they exist (US 555-0100–0199, UK 07700 900xxx, France 06 39 98 xx xx). |
|
|
31
|
+
| Uniform numbers look fake | `amount` is skewed like real prices (many small, a few large, often ending in .99), lists take weights (`delivered:60, cancelled:10`), and any column can have a percentage of NULLs. |
|
|
32
|
+
| Accents and Arabic break | CSV can carry a UTF-8 BOM for Excel, MySQL output sets `utf8mb4`, and SQL Server columns are `NVARCHAR`. |
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install consistent-fake-data
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
It is a single file with no dependencies, so you can also copy `fakedata-core.js` into your project, or load it from a CDN:
|
|
41
|
+
|
|
42
|
+
```html
|
|
43
|
+
<script src="https://cdn.jsdelivr.net/npm/consistent-fake-data@1/fakedata-core.js"></script>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
### Node
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
const F = require('consistent-fake-data');
|
|
52
|
+
|
|
53
|
+
const schema = [
|
|
54
|
+
{ name: 'id', type: 'id' },
|
|
55
|
+
{ name: 'first_name', type: 'first_name' },
|
|
56
|
+
{ name: 'last_name', type: 'last_name' },
|
|
57
|
+
{ name: 'email', type: 'email', unique: true },
|
|
58
|
+
{ name: 'city', type: 'city' },
|
|
59
|
+
{ name: 'created_at', type: 'datetime', p: { from: '-2y', to: 'today' } },
|
|
60
|
+
{ name: 'last_login', type: 'after', p: { col: 'created_at', min: 0, max: 90 }, blank: 10 },
|
|
61
|
+
{ name: 'status', type: 'list', p: { values: 'active:70, pending:20, banned:10' } },
|
|
62
|
+
{ name: 'total', type: 'amount', p: { min: 5, max: 900 } }
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
const out = F.produce(schema, { rows: 1000, format: 'sql', dialect: 'postgres', table: 'users', seed: 'demo' });
|
|
66
|
+
if (out.errors) throw new Error(out.errors.join('\n'));
|
|
67
|
+
require('fs').writeFileSync('users.sql', out.chunks.join(''));
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Browser
|
|
71
|
+
|
|
72
|
+
```html
|
|
73
|
+
<script src="fakedata-core.js"></script>
|
|
74
|
+
<script>
|
|
75
|
+
const out = FakeData.produce(schema, { rows: 100, format: 'json', seed: 'abc' });
|
|
76
|
+
console.log(out.chunks.join(''));
|
|
77
|
+
</script>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Web Worker (large files without freezing the page)
|
|
81
|
+
|
|
82
|
+
The same file is also a worker. It answers `{ id, schema, opts }` messages with progress updates and the finished result:
|
|
83
|
+
|
|
84
|
+
```js
|
|
85
|
+
const worker = new Worker('fakedata-core.js');
|
|
86
|
+
worker.onmessage = (e) => {
|
|
87
|
+
if (e.data.progress !== undefined) return console.log(Math.round(e.data.progress * 100) + '%');
|
|
88
|
+
const blob = new Blob(e.data.chunks, { type: e.data.mime });
|
|
89
|
+
// download or upload the blob
|
|
90
|
+
};
|
|
91
|
+
worker.postMessage({ id: 1, schema, opts: { rows: 500000, format: 'csv', seed: 'big' } });
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Row by row
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
const g = new F.Generator(schema, { rows: 10, seed: 'x', locale: 'fr_FR' });
|
|
98
|
+
if (g.errs.length) throw new Error(g.errs.join('\n'));
|
|
99
|
+
for (let i = 0; i < 10; i++) console.log(g.row(i)); // array of values in schema order
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Options
|
|
103
|
+
|
|
104
|
+
| Option | Default | Description |
|
|
105
|
+
|---|---|---|
|
|
106
|
+
| `rows` | `0` | Number of rows. |
|
|
107
|
+
| `format` | `'csv'` | `csv`, `tsv`, `json`, `jsonl`, `sql`, or `rows` (raw arrays). |
|
|
108
|
+
| `seed` | `'1'` | Same seed and columns give the same rows. |
|
|
109
|
+
| `locale` | `'en_US'` | `en_US`, `en_GB`, `fr_FR`, `de_DE`, `es_ES`, `fr_MA` (Morocco, Latin script), `ar` (Arabic script), or `mix`. |
|
|
110
|
+
| `today` | current UTC day | Base for relative dates and ages (milliseconds, UTC). Fix it in tests. |
|
|
111
|
+
| `delim` | `','` | CSV delimiter, for example `';'` for Excel set to a decimal comma. |
|
|
112
|
+
| `header` | `true` | Include the header row (CSV/TSV). |
|
|
113
|
+
| `dates` | `'iso'` | Date style in CSV/TSV: `iso` (2026-03-31), `us` (03/31/2026), `eu` (31/03/2026). |
|
|
114
|
+
| `bom` | `true` | Prepend a UTF-8 BOM to CSV (returned as `bom: true`, so you add `'\ufeff'` yourself). |
|
|
115
|
+
| `dialect` | `'mysql'` | SQL: `mysql`, `postgres`, `sqlite`, `mssql`. |
|
|
116
|
+
| `table` | `'test_data'` | SQL table name. |
|
|
117
|
+
| `create` / `drop` | `true` / `false` | Add `CREATE TABLE` / `DROP TABLE IF EXISTS`. |
|
|
118
|
+
| `batch` | `500` | Rows per INSERT (SQL Server is capped at 1,000). |
|
|
119
|
+
| `tx` | `true` | Wrap the INSERTs in a transaction. |
|
|
120
|
+
|
|
121
|
+
`produce()` returns `{ chunks, mime, ext, bom }`, or `{ errors: [...] }` when the schema cannot work (duplicate column names, a min above its max, impossible uniqueness, an `after` column without a date to follow…).
|
|
122
|
+
|
|
123
|
+
## Columns
|
|
124
|
+
|
|
125
|
+
Each column is `{ name, type, p, blank, unique }`: `p` holds the type's options, `blank` is the percentage of NULLs (0–100), and `unique` forbids repeats.
|
|
126
|
+
|
|
127
|
+
| Group | Types |
|
|
128
|
+
|---|---|
|
|
129
|
+
| Keys | `id` (start, step), `uuid`, `fk` (min, max), `pattern` (`ORD-{row:6}`, `SKU-????-###`) |
|
|
130
|
+
| Person | `first_name`, `last_name`, `full_name`, `gender`, `email`, `username`, `phone`, `birth_date` (min/max age), `age`, `job_title`, `department`, `company` |
|
|
131
|
+
| Address | `street`, `city`, `region`, `postcode`, `country`, `country_code`, `latitude`, `longitude` |
|
|
132
|
+
| Numbers | `int` (min, max), `decimal` (min, max, dec), `amount` (min, max, dec, dist), `boolean` (pct) |
|
|
133
|
+
| Dates | `date`, `datetime`, `timestamp` (from, to), `time`, `after` (col, min, max days) |
|
|
134
|
+
| Text | `list` (weighted values), `word`, `sentence`, `paragraph`, `product`, `category`, `currency` |
|
|
135
|
+
| Internet | `url`, `domain`, `ipv4`, `ipv6`, `mac`, `color` |
|
|
136
|
+
|
|
137
|
+
**Patterns:** `#` digit, `?` capital letter, `*` letter or digit, `{row}` / `{row:6}` row number (padded), `\#` a literal `#`.
|
|
138
|
+
**Dates:** a date (`2025-01-31`) or relative to today: `today`, `-30d`, `-6m`, `-2y`, `+1y`.
|
|
139
|
+
**Lists:** comma-separated values; a number after `:` is the weight.
|
|
140
|
+
|
|
141
|
+
`F.guessType('customer_email')` → `{ type: 'email', p: {} }` guesses a type from a column name, which is handy for turning an existing header row or `CREATE TABLE` into a schema.
|
|
142
|
+
|
|
143
|
+
## Related tables
|
|
144
|
+
|
|
145
|
+
Generate the parent first, for example 100 customers with `{ type: 'id' }`. Then give the child table a foreign key over the same range: `{ name: 'customer_id', type: 'fk', p: { min: 1, max: 100 } }`. Every `customer_id` then points to a customer that exists.
|
|
146
|
+
|
|
147
|
+
## Tests
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
npm test
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
The generated SQL has been run in PostgreSQL and SQLite. MySQL and SQL Server output follows each database's documented quoting and escaping rules.
|
|
154
|
+
|
|
155
|
+
## Notes
|
|
156
|
+
|
|
157
|
+
- The data is made up from lists of common first names, surnames, streets and cities. It does not come from real people.
|
|
158
|
+
- Fictional phone ranges exist only for the US, UK and France. Numbers for the other locales follow the right format, so they can match a real number.
|
|
159
|
+
|
|
160
|
+
## License
|
|
161
|
+
|
|
162
|
+
[MIT](LICENSE). The online version, with a column editor, templates and Excel export, is at **[dataswitchpro.com/test-data-generator](https://dataswitchpro.com/test-data-generator/)**, alongside free in-browser converters for CSV, JSON, SQL, Excel, XML and YAML at [dataswitchpro.com](https://dataswitchpro.com/).
|
package/fakedata-core.js
ADDED
|
@@ -0,0 +1,681 @@
|
|
|
1
|
+
/*! test-data-generator — https://github.com/caminillov10/test-data-generator
|
|
2
|
+
* Live tool: https://dataswitchpro.com/test-data-generator/ · MIT License © 2026 DataSwitch Pro
|
|
3
|
+
*
|
|
4
|
+
* Seeded, reproducible fake rows whose fields agree with each other (the email is built from the name,
|
|
5
|
+
* the city matches the postcode, phone and country, an order date can follow a sign-up date), written as
|
|
6
|
+
* CSV, TSV, JSON, JSON Lines or SQL INSERTs for MySQL, PostgreSQL, SQLite and SQL Server.
|
|
7
|
+
* One file, no dependencies. Works in Node, in the browser and as a Web Worker. */
|
|
8
|
+
(function (root) {
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
/* ================= seeded random numbers ================= */
|
|
12
|
+
function seedHash(s) {
|
|
13
|
+
var h = 1779033703 ^ s.length;
|
|
14
|
+
for (var i = 0; i < s.length; i++) { h = Math.imul(h ^ s.charCodeAt(i), 3432918353); h = h << 13 | h >>> 19; }
|
|
15
|
+
h = Math.imul(h ^ h >>> 16, 2246822507); h = Math.imul(h ^ h >>> 13, 3266489909);
|
|
16
|
+
return (h ^ h >>> 16) >>> 0;
|
|
17
|
+
}
|
|
18
|
+
function rng(seed) {
|
|
19
|
+
var a = seedHash(String(seed));
|
|
20
|
+
function f() { a |= 0; a = a + 0x6D2B79F5 | 0; var t = Math.imul(a ^ a >>> 15, 1 | a); t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t; return ((t ^ t >>> 14) >>> 0) / 4294967296; }
|
|
21
|
+
return {
|
|
22
|
+
f: f,
|
|
23
|
+
int: function (lo, hi) { return lo + Math.floor(f() * (hi - lo + 1)); },
|
|
24
|
+
pick: function (arr) { return arr[Math.floor(f() * arr.length)]; },
|
|
25
|
+
chance: function (p) { return f() < p; },
|
|
26
|
+
normal: function () { var u = 0, v = 0; while (!u) u = f(); while (!v) v = f(); return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v); },
|
|
27
|
+
digits: function (n) { var s = ''; for (var i = 0; i < n; i++) s += Math.floor(f() * 10); return s; }
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/* ================= locale data ================= */
|
|
32
|
+
function W(s) { return s.split(' ').map(function (x) { return x.replace(/_/g, ' '); }); }
|
|
33
|
+
// city rows: name | region | postcode prefix | lat | lon | phone area code (when it matters)
|
|
34
|
+
function C(s) { return s.split(';').map(function (r) { var p = r.split('|'); return { city: p[0], region: p[1], pc: p[2], lat: +p[3], lon: +p[4], area: p[5] || '', country: p[6] || '', cc: p[7] || '' }; }); }
|
|
35
|
+
|
|
36
|
+
var LOC = {
|
|
37
|
+
en_US: {
|
|
38
|
+
label: 'English (United States)', country: 'United States', cc: 'US', currency: 'USD',
|
|
39
|
+
male: W('James John Robert Michael William David Richard Joseph Thomas Charles Christopher Daniel Matthew Anthony Mark Donald Steven Paul Andrew Joshua Kevin Brian George Timothy Ronald Jason Edward Jeffrey Ryan Jacob Gary Nicholas Eric Jonathan Stephen Larry Justin Scott Brandon Benjamin Samuel Gregory Alexander Patrick Frank Raymond Jack Dennis Tyler Aaron Jose Adam Nathan Henry Zachary Douglas Peter Kyle Noah Ethan Jeremy Christian Keith Sean Carl Dylan Arthur Jordan Jesse Bryan Gabriel Logan Alan Juan Elijah Vincent Mason Russell Philip Luis Carlos'),
|
|
40
|
+
female: W('Mary Patricia Jennifer Linda Elizabeth Barbara Susan Jessica Sarah Karen Lisa Nancy Betty Sandra Margaret Ashley Kimberly Emily Donna Michelle Carol Amanda Melissa Deborah Stephanie Rebecca Sharon Laura Cynthia Amy Kathleen Angela Brenda Emma Anna Pamela Nicole Samantha Katherine Christine Helen Rachel Carolyn Janet Maria Catherine Heather Diane Olivia Julie Joyce Victoria Lauren Kelly Christina Joan Evelyn Andrea Hannah Megan Jacqueline Martha Madison Teresa Gloria Sara Abigail Sophia Alice Isabella Julia Grace Amber Danielle Charlotte Natalie Diana Brittany Kayla Alexis Chloe Ava Mia'),
|
|
41
|
+
last: W("Smith Johnson Williams Brown Jones Garcia Miller Davis Rodriguez Martinez Hernandez Lopez Gonzalez Wilson Anderson Thomas Taylor Moore Jackson Martin Lee Perez Thompson White Harris Sanchez Clark Ramirez Lewis Robinson Walker Young Allen King Wright Scott Torres Nguyen Hill Flores Green Adams Nelson Baker Hall Rivera Campbell Mitchell Carter Roberts Gomez Phillips Evans Turner Diaz Parker Cruz Edwards Collins Reyes Stewart Morris Morales Murphy Cook Rogers Ortiz Morgan Cooper Peterson Bailey Reed Kelly Howard Ramos Kim Cox Ward Richardson Watson Brooks Chavez Wood James Bennett Gray Mendoza Hughes Price Patel Myers Long Ross Foster O'Brien O'Connor"),
|
|
42
|
+
cities: C('New York|NY|100|40.7128|-74.006|212;Los Angeles|CA|900|34.0522|-118.2437|213;Chicago|IL|606|41.8781|-87.6298|312;Houston|TX|770|29.7604|-95.3698|713;Phoenix|AZ|850|33.4484|-112.074|602;Philadelphia|PA|191|39.9526|-75.1652|215;San Antonio|TX|782|29.4241|-98.4936|210;San Diego|CA|921|32.7157|-117.1611|619;Dallas|TX|752|32.7767|-96.797|214;Austin|TX|787|30.2672|-97.7431|512;Jacksonville|FL|322|30.3322|-81.6557|904;Columbus|OH|432|39.9612|-82.9988|614;Charlotte|NC|282|35.2271|-80.8431|704;Indianapolis|IN|462|39.7684|-86.1581|317;Seattle|WA|981|47.6062|-122.3321|206;Denver|CO|802|39.7392|-104.9903|303;Boston|MA|021|42.3601|-71.0589|617;Nashville|TN|372|36.1627|-86.7816|615;Portland|OR|972|45.5152|-122.6784|503;Las Vegas|NV|891|36.1699|-115.1398|702;Detroit|MI|482|42.3314|-83.0458|313;Atlanta|GA|303|33.749|-84.388|404;Miami|FL|331|25.7617|-80.1918|305;Minneapolis|MN|554|44.9778|-93.265|612;Kansas City|MO|641|39.0997|-94.5786|816;Raleigh|NC|276|35.7796|-78.6382|919;Salt Lake City|UT|841|40.7608|-111.891|801;Pittsburgh|PA|152|40.4406|-79.9959|412;Cincinnati|OH|452|39.1031|-84.512|513;Orlando|FL|328|28.5383|-81.3792|407'),
|
|
43
|
+
streets: W('Main Oak Pine Maple Cedar Elm Washington Lake Hill Park Sunset Lincoln Jackson Church Highland Ridge Forest Spring River Meadow Willow Franklin Madison Walnut Chestnut'),
|
|
44
|
+
sfx: W('St Ave Rd Blvd Ln Dr Ct Way Pl'),
|
|
45
|
+
street: function (r, c) { return r.int(10, 9899) + ' ' + r.pick(this.streets) + ' ' + r.pick(this.sfx); },
|
|
46
|
+
postcode: function (r, c) { return c.pc + r.digits(2); },
|
|
47
|
+
phone: function (r, c) { var d = r.digits(2); return ['(' + c.area + ') 555-01' + d, '+1 ' + c.area + '-555-01' + d]; },
|
|
48
|
+
mail: W('gmail.com yahoo.com outlook.com hotmail.com icloud.com aol.com proton.me')
|
|
49
|
+
},
|
|
50
|
+
en_GB: {
|
|
51
|
+
label: 'English (United Kingdom)', country: 'United Kingdom', cc: 'GB', currency: 'GBP',
|
|
52
|
+
male: W('Oliver George Harry Jack Jacob Noah Charlie Thomas Oscar William James Leo Alfie Henry Joshua Freddie Archie Ethan Isaac Alexander Joseph Edward Samuel Max Daniel Arthur Lucas Mohammed Logan Theo Harrison Benjamin Mason Sebastian Finley Adam Dylan Zachary Riley Teddy Callum Rhys Owen Lewis'),
|
|
53
|
+
female: W('Olivia Amelia Isla Ava Emily Isabella Mia Poppy Ella Lily Evie Sophia Grace Sophie Freya Charlotte Florence Daisy Alice Jessica Phoebe Sienna Ruby Matilda Evelyn Chloe Ivy Rosie Harper Millie Lucy Elsie Erin Eva Holly Imogen Willow Maisie Lola Hannah Megan Bethan Niamh'),
|
|
54
|
+
last: W('Smith Jones Williams Taylor Brown Davies Evans Wilson Thomas Johnson Roberts Robinson Thompson Wright Walker White Edwards Hughes Green Hall Lewis Harris Clarke Patel Jackson Wood Turner Martin Cooper Hill Ward Morris Moore Clark Lee King Baker Harrison Morgan Allen James Scott Phillips Watson Davis Parker Price Bennett Young Griffiths Mitchell Kelly Cook Carter Richardson Bailey Collins Bell Shaw Murphy Campbell Stewart MacDonald'),
|
|
55
|
+
cities: C('London|England|E SW N W NW SE EC WC|51.5074|-0.1278;Birmingham|England|B|52.4862|-1.8904;Manchester|England|M|53.4808|-2.2426;Leeds|England|LS|53.8008|-1.5491;Glasgow|Scotland|G|55.8642|-4.2518;Liverpool|England|L|53.4084|-2.9916;Bristol|England|BS|51.4545|-2.5879;Sheffield|England|S|53.3811|-1.4701;Edinburgh|Scotland|EH|55.9533|-3.1883;Cardiff|Wales|CF|51.4816|-3.1791;Leicester|England|LE|52.6369|-1.1398;Nottingham|England|NG|52.9548|-1.1581;Newcastle upon Tyne|England|NE|54.9783|-1.6178;Brighton|England|BN|50.8225|-0.1372;Southampton|England|SO|50.9097|-1.4044;Oxford|England|OX|51.752|-1.2577;Cambridge|England|CB|52.2053|0.1218;York|England|YO|53.959|-1.0815;Belfast|Northern Ireland|BT|54.5973|-5.9301;Aberdeen|Scotland|AB|57.1497|-2.0943;Swansea|Wales|SA|51.6214|-3.9436'),
|
|
56
|
+
streets: W('High_Street Station_Road Church_Lane Victoria_Road Green_Lane Manor_Road Park_Road Queens_Road Kings_Road Mill_Lane School_Lane The_Avenue Grange_Road Albert_Road London_Road Church_Street Springfield_Road York_Road Windsor_Road Highfield_Road'),
|
|
57
|
+
street: function (r) { return r.int(1, 240) + ' ' + r.pick(this.streets); },
|
|
58
|
+
postcode: function (r, c) { var L = 'ABDEFGHJLNPQRSTUWXYZ'; return r.pick(c.pc.split(' ')) + r.int(1, 20) + ' ' + r.int(1, 9) + L[r.int(0, 19)] + L[r.int(0, 19)]; },
|
|
59
|
+
phone: function (r) { var n = r.digits(3); return ['07700 900' + n, '+44 7700 900' + n]; },
|
|
60
|
+
mail: W('gmail.com outlook.com hotmail.co.uk yahoo.co.uk btinternet.com icloud.com sky.com')
|
|
61
|
+
},
|
|
62
|
+
fr_FR: {
|
|
63
|
+
label: 'Français (France)', country: 'France', cc: 'FR', currency: 'EUR',
|
|
64
|
+
male: W('Lucas Hugo Louis Gabriel Arthur Jules Adam Raphaël Léo Nathan Thomas Paul Mathis Théo Maxime Antoine Alexandre Julien Nicolas Pierre Baptiste Clément Romain Quentin Victor Sacha Noah Mohamed Enzo Tom Ethan Benjamin Simon Martin Valentin François Olivier Laurent Philippe Mathieu'),
|
|
65
|
+
female: W('Emma Jade Louise Alice Chloé Léa Manon Inès Lina Camille Sarah Léna Zoé Juliette Anna Clara Mila Ambre Lucie Marie Pauline Laura Julie Mathilde Charlotte Margaux Élise Océane Anaïs Sophie Claire Céline Amélie Nina Isabelle Nathalie Sandrine Aurélie Émilie'),
|
|
66
|
+
last: W('Martin Bernard Thomas Petit Robert Richard Durand Dubois Moreau Laurent Simon Michel Lefebvre Leroy Roux David Bertrand Morel Fournier Girard Bonnet Dupont Lambert Fontaine Rousseau Vincent Muller Lefèvre Faure André Mercier Blanc Guérin Boyer Garnier Chevalier François Legrand Gauthier Garcia Perrin Robin Clément Morin Nicolas Henry Roussel Mathieu Gautier Masson'),
|
|
67
|
+
cities: C("Paris|Île-de-France|750|48.8566|2.3522;Marseille|Provence-Alpes-Côte d'Azur|130|43.2965|5.3698;Lyon|Auvergne-Rhône-Alpes|690|45.764|4.8357;Toulouse|Occitanie|310|43.6047|1.4442;Nice|Provence-Alpes-Côte d'Azur|060|43.7102|7.262;Nantes|Pays de la Loire|440|47.2184|-1.5536;Strasbourg|Grand Est|670|48.5734|7.7521;Montpellier|Occitanie|340|43.6108|3.8767;Bordeaux|Nouvelle-Aquitaine|330|44.8378|-0.5792;Lille|Hauts-de-France|590|50.6292|3.0573;Rennes|Bretagne|350|48.1173|-1.6778;Reims|Grand Est|511|49.2583|4.0317;Le Havre|Normandie|766|49.4944|0.1079;Toulon|Provence-Alpes-Côte d'Azur|830|43.1242|5.928;Grenoble|Auvergne-Rhône-Alpes|380|45.1885|5.7245;Dijon|Bourgogne-Franche-Comté|210|47.322|5.0415;Angers|Pays de la Loire|490|47.4784|-0.5632;Nîmes|Occitanie|300|43.8367|4.3601;Clermont-Ferrand|Auvergne-Rhône-Alpes|630|45.7772|3.087;Tours|Centre-Val de Loire|370|47.3941|0.6848"),
|
|
68
|
+
streets: W("rue_de_la_République rue_Victor_Hugo avenue_Jean_Jaurès rue_de_la_Paix boulevard_Gambetta rue_Pasteur place_de_la_Mairie rue_du_Moulin rue_Nationale rue_de_l'Église allée_des_Tilleuls rue_des_Écoles avenue_de_la_Gare rue_du_Château chemin_des_Vignes"),
|
|
69
|
+
street: function (r) { return r.int(1, 180) + ' ' + r.pick(this.streets); },
|
|
70
|
+
postcode: function (r, c) { return c.pc + r.digits(2); },
|
|
71
|
+
phone: function (r) { var n = r.digits(2) + ' ' + r.digits(2); return ['06 39 98 ' + n, '+33 6 39 98 ' + n]; },
|
|
72
|
+
mail: W('gmail.com orange.fr free.fr laposte.net hotmail.fr outlook.fr yahoo.fr sfr.fr')
|
|
73
|
+
},
|
|
74
|
+
de_DE: {
|
|
75
|
+
label: 'Deutsch (Deutschland)', country: 'Germany', cc: 'DE', currency: 'EUR',
|
|
76
|
+
male: W('Lukas Leon Finn Jonas Paul Luis Felix Noah Elias Ben Maximilian Henry Emil Julian Moritz Alexander David Tim Jan Niklas Tobias Florian Sebastian Michael Thomas Andreas Stefan Markus Christian Daniel Matthias Jürgen Uwe Frank Klaus'),
|
|
77
|
+
female: W('Mia Emma Hannah Sofia Anna Emilia Lina Marie Lea Lena Clara Leonie Ella Amelie Laura Lara Johanna Sophie Julia Katharina Sarah Lisa Nina Sandra Anja Petra Sabine Claudia Melanie Jana Ursula Monika Birgit Jessica Franziska'),
|
|
78
|
+
last: W('Müller Schmidt Schneider Fischer Weber Meyer Wagner Becker Schulz Hoffmann Schäfer Koch Bauer Richter Klein Wolf Schröder Neumann Schwarz Zimmermann Braun Krüger Hofmann Hartmann Lange Schmitt Werner Schmitz Krause Meier Lehmann Schmid Schulze Maier Köhler Herrmann König Walter Mayer Huber Kaiser Fuchs Peters Lang Scholz Möller Weiß Jung Hahn'),
|
|
79
|
+
cities: C('Berlin|Berlin|10|52.52|13.405|030;Hamburg|Hamburg|20|53.5511|9.9937|040;München|Bayern|80|48.1351|11.582|089;Köln|Nordrhein-Westfalen|50|50.9375|6.9603|0221;Frankfurt am Main|Hessen|60|50.1109|8.6821|069;Stuttgart|Baden-Württemberg|70|48.7758|9.1829|0711;Düsseldorf|Nordrhein-Westfalen|40|51.2277|6.7735|0211;Leipzig|Sachsen|04|51.3397|12.3731|0341;Dortmund|Nordrhein-Westfalen|44|51.5136|7.4653|0231;Essen|Nordrhein-Westfalen|45|51.4556|7.0116|0201;Bremen|Bremen|28|53.0793|8.8017|0421;Dresden|Sachsen|01|51.0504|13.7373|0351;Hannover|Niedersachsen|30|52.3759|9.732|0511;Nürnberg|Bayern|90|49.4521|11.0767|0911;Bonn|Nordrhein-Westfalen|53|50.7374|7.0982|0228'),
|
|
80
|
+
streets: W('Hauptstraße Schulstraße Gartenstraße Bahnhofstraße Dorfstraße Bergstraße Birkenweg Lindenstraße Kirchstraße Waldstraße Ringstraße Schillerstraße Goethestraße Am_Markt Mozartstraße Wiesenweg'),
|
|
81
|
+
street: function (r) { return r.pick(this.streets) + ' ' + r.int(1, 120); },
|
|
82
|
+
postcode: function (r, c) { return c.pc + r.digits(3); },
|
|
83
|
+
phone: function (r, c) { var n = r.digits(3) + ' ' + r.digits(4); return [c.area + ' ' + n, '+49 ' + c.area.slice(1) + ' ' + n]; },
|
|
84
|
+
mail: W('gmail.com gmx.de web.de t-online.de outlook.de yahoo.de freenet.de')
|
|
85
|
+
},
|
|
86
|
+
es_ES: {
|
|
87
|
+
label: 'Español (España)', country: 'Spain', cc: 'ES', currency: 'EUR', twoSurnames: true,
|
|
88
|
+
male: W('Hugo Martín Lucas Mateo Leo Daniel Alejandro Pablo Manuel Álvaro Adrián David Mario Diego Javier José Antonio Carlos Francisco Juan Miguel Sergio Jorge Luis Rafael Fernando Raúl Iván Rubén Óscar'),
|
|
89
|
+
female: W('Lucía Sofía Martina María Julia Paula Valeria Emma Daniela Carla Alba Noa Sara Carmen Ana Laura Isabel Elena Cristina Marta Pilar Rosa Teresa Beatriz Raquel Silvia Patricia Nuria Irene Andrea'),
|
|
90
|
+
last: W('García Rodríguez González Fernández López Martínez Sánchez Pérez Gómez Martín Jiménez Ruiz Hernández Díaz Moreno Muñoz Álvarez Romero Alonso Gutiérrez Navarro Torres Domínguez Vázquez Ramos Gil Ramírez Serrano Blanco Molina Morales Suárez Ortega Delgado Castro Ortiz Rubio Marín Sanz Iglesias'),
|
|
91
|
+
cities: C('Madrid|Comunidad de Madrid|28|40.4168|-3.7038|91;Barcelona|Cataluña|08|41.3874|2.1686|93;Valencia|Comunidad Valenciana|46|39.4699|-0.3763|96;Sevilla|Andalucía|41|37.3891|-5.9845|95;Zaragoza|Aragón|50|41.6488|-0.8891|976;Málaga|Andalucía|29|36.7213|-4.4214|95;Murcia|Región de Murcia|30|37.9922|-1.1307|968;Palma|Islas Baleares|07|39.5696|2.6502|971;Las Palmas de Gran Canaria|Canarias|35|28.1235|-15.4363|928;Bilbao|País Vasco|48|43.263|-2.935|94;Alicante|Comunidad Valenciana|03|38.3452|-0.481|96;Córdoba|Andalucía|14|37.8882|-4.7794|957;Valladolid|Castilla y León|47|41.6523|-4.7245|983;Vigo|Galicia|36|42.2406|-8.7207|986;Granada|Andalucía|18|37.1773|-3.5986|958'),
|
|
92
|
+
streets: W('Calle_Mayor Calle_Real Avenida_de_la_Constitución Calle_Nueva Plaza_de_España Calle_del_Sol Calle_de_la_Iglesia Avenida_de_Andalucía Calle_San_José Gran_Vía Calle_del_Carmen Paseo_de_la_Castellana Calle_Alcalá'),
|
|
93
|
+
street: function (r) { return r.pick(this.streets) + ', ' + r.int(1, 150); },
|
|
94
|
+
postcode: function (r, c) { return c.pc + r.digits(3); },
|
|
95
|
+
phone: function (r) { var n = '6' + r.digits(2) + ' ' + r.digits(3) + ' ' + r.digits(3); return [n, '+34 ' + n]; },
|
|
96
|
+
mail: W('gmail.com hotmail.com hotmail.es yahoo.es outlook.es telefonica.net')
|
|
97
|
+
},
|
|
98
|
+
fr_MA: {
|
|
99
|
+
label: 'Morocco (Latin script)', country: 'Morocco', cc: 'MA', currency: 'MAD',
|
|
100
|
+
male: W('Mohamed Youssef Ahmed Omar Hamza Adam Amine Mehdi Karim Rachid Said Hassan Khalid Yassine Anas Ayoub Ilyas Othmane Zakaria Abdellah Hicham Nabil Reda Soufiane Imad Ismail Badr Walid Tarik Mustapha Driss Brahim Nourdine Aziz Jamal'),
|
|
101
|
+
female: W('Fatima Khadija Aicha Salma Imane Meryem Sara Nora Hiba Yasmine Zineb Amina Hajar Sanaa Houda Laila Malak Rania Asmae Ghizlane Kawtar Nadia Siham Wafae Loubna Souad Hanane Ikram Chaimae Oumaima Najat Btissam Hind Latifa Samira'),
|
|
102
|
+
last: W('Alaoui Benali El_Amrani Bennani Tazi Idrissi Berrada Cherkaoui El_Fassi Lahlou Chraibi Benjelloun Ouazzani Kettani Sqalli El_Mansouri Bouzid Haddad Mansouri Ziani Naciri Filali Belkadi El_Idrissi Amrani Saadi Rami Hajji Bakkali Toumi Benkirane Sebti Lamrani Guessous Skalli'),
|
|
103
|
+
cities: C("Casablanca|Casablanca-Settat|20|33.5731|-7.5898;Rabat|Rabat-Salé-Kénitra|10|34.0209|-6.8416;Marrakech|Marrakech-Safi|40|31.6295|-7.9811;Fès|Fès-Meknès|30|34.0331|-5.0003;Tanger|Tanger-Tétouan-Al Hoceïma|90|35.7595|-5.834;Agadir|Souss-Massa|80|30.4278|-9.5981;Meknès|Fès-Meknès|50|33.8935|-5.5473;Oujda|Oriental|60|34.6814|-1.9086;Kénitra|Rabat-Salé-Kénitra|14|34.261|-6.5802;Tétouan|Tanger-Tétouan-Al Hoceïma|93|35.5785|-5.3684;Salé|Rabat-Salé-Kénitra|11|34.0531|-6.7985;El Jadida|Casablanca-Settat|24|33.2316|-8.5007"),
|
|
104
|
+
streets: W('Rue_Ibn_Battouta Avenue_Mohammed_V Boulevard_Zerktouni Rue_Allal_Ben_Abdellah Avenue_Hassan_II Rue_Oued_Sebou Boulevard_Anfa Rue_Ibn_Sina Avenue_des_FAR Rue_Moulay_Youssef Boulevard_Abdelmoumen'),
|
|
105
|
+
street: function (r) { return r.int(1, 300) + ', ' + r.pick(this.streets); },
|
|
106
|
+
postcode: function (r, c) { return c.pc + r.digits(3); },
|
|
107
|
+
phone: function (r) { var d = r.pick(['6', '7']), n = r.digits(2) + ' ' + r.digits(2) + ' ' + r.digits(2) + ' ' + r.digits(2); return ['0' + d + ' ' + n, '+212 ' + d + ' ' + n]; },
|
|
108
|
+
mail: W('gmail.com hotmail.com hotmail.fr yahoo.fr outlook.com menara.ma')
|
|
109
|
+
},
|
|
110
|
+
ar: {
|
|
111
|
+
label: 'العربية (Arabic script)', rtl: true, currency: '',
|
|
112
|
+
// "Arabic name:latin" — the Latin part builds emails and usernames
|
|
113
|
+
male: W('محمد:mohamed أحمد:ahmed علي:ali عمر:omar يوسف:youssef خالد:khaled حسن:hassan إبراهيم:ibrahim عبدالله:abdullah مصطفى:mostafa سعيد:saeed كريم:karim طارق:tarek ياسر:yasser وليد:walid سامي:sami فهد:fahad ماجد:majed هشام:hisham نبيل:nabil زياد:ziad رامي:rami بلال:bilal أنس:anas حمزة:hamza سلطان:sultan فيصل:faisal'),
|
|
114
|
+
female: W('فاطمة:fatima مريم:maryam عائشة:aisha سارة:sara نور:nour ليلى:laila هدى:huda أمينة:amina زينب:zainab خديجة:khadija سلمى:salma ياسمين:yasmine ريم:reem رنا:rana دينا:dina هبة:heba منى:mona سعاد:souad نادية:nadia لمى:lama جنى:jana رهف:rahaf آية:aya ملك:malak نوف:nouf'),
|
|
115
|
+
last: W('العلي:alali الأحمد:alahmad المنصوري:almansouri الشمري:alshammari القحطاني:alqahtani العتيبي:alotaibi الحربي:alharbi الزهراني:alzahrani الغامدي:alghamdi الدوسري:aldosari المصري:almasri الحسيني:alhusseini الخطيب:alkhatib النجار:alnajjar الحداد:alhaddad الصالح:alsaleh العمري:alomari الهاشمي:alhashimi التميمي:altamimi السعدي:alsaadi الرفاعي:alrifai الكعبي:alkaabi البلوشي:albalushi'),
|
|
116
|
+
cities: C('الرياض|منطقة الرياض||24.7136|46.6753|966|السعودية|SA;جدة|منطقة مكة المكرمة||21.4858|39.1925|966|السعودية|SA;الدمام|المنطقة الشرقية||26.4207|50.0888|966|السعودية|SA;دبي|إمارة دبي||25.2048|55.2708|971|الإمارات|AE;أبوظبي|إمارة أبوظبي||24.4539|54.3773|971|الإمارات|AE;القاهرة|محافظة القاهرة||30.0444|31.2357|20|مصر|EG;الإسكندرية|محافظة الإسكندرية||31.2001|29.9187|20|مصر|EG;عمّان|محافظة العاصمة||31.9454|35.9284|962|الأردن|JO;الدار البيضاء|جهة الدار البيضاء سطات||33.5731|-7.5898|212|المغرب|MA;الكويت|محافظة العاصمة||29.3759|47.9774|965|الكويت|KW;الدوحة|بلدية الدوحة||25.2854|51.531|974|قطر|QA;مسقط|محافظة مسقط||23.588|58.3829|968|عُمان|OM;بيروت|محافظة بيروت||33.8938|35.5018|961|لبنان|LB;تونس|ولاية تونس||36.8065|10.1815|216|تونس|TN;المنامة|محافظة العاصمة||26.2285|50.586|973|البحرين|BH'),
|
|
117
|
+
streets: W('شارع_الملك_فهد شارع_التحلية شارع_الجامعة شارع_النيل شارع_الحرية شارع_السلام شارع_الاستقلال شارع_الملك_عبدالعزيز شارع_الكورنيش شارع_المدينة_المنورة'),
|
|
118
|
+
street: function (r) { return r.pick(this.streets) + '، مبنى ' + r.int(1, 400); },
|
|
119
|
+
postcode: function (r) { return r.digits(5); },
|
|
120
|
+
phone: function (r, c) { var n = (c.area === '20' ? '1' : '5') + r.digits(8); return ['0' + n, '+' + c.area + ' ' + n]; },
|
|
121
|
+
mail: W('gmail.com hotmail.com outlook.com yahoo.com icloud.com'),
|
|
122
|
+
cur: { SA: 'SAR', AE: 'AED', EG: 'EGP', JO: 'JOD', MA: 'MAD', KW: 'KWD', QA: 'QAR', OM: 'OMR', LB: 'LBP', TN: 'TND', BH: 'BHD' }
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var MIX = ['en_US', 'en_US', 'en_GB', 'fr_FR', 'de_DE', 'es_ES', 'fr_MA'];
|
|
126
|
+
var SAFE_MAIL = ['example.com', 'example.net', 'example.org'];
|
|
127
|
+
|
|
128
|
+
var JOBS = W('Software_Engineer Data_Analyst Product_Manager Project_Manager Sales_Manager Account_Executive Marketing_Specialist Graphic_Designer UX_Designer HR_Manager Recruiter Accountant Financial_Analyst Customer_Support_Agent Operations_Manager Business_Analyst DevOps_Engineer QA_Engineer Content_Writer Office_Manager Nurse Teacher Pharmacist Electrician Mechanical_Engineer Civil_Engineer Architect Consultant Lawyer Paralegal Chef Logistics_Coordinator Warehouse_Supervisor Data_Scientist Systems_Administrator Security_Analyst Social_Media_Manager Executive_Assistant Copywriter Research_Scientist');
|
|
129
|
+
var DEPTS = W('Engineering Sales Marketing Finance Human_Resources Operations Customer_Support Legal Product Design IT Research Logistics Procurement Administration');
|
|
130
|
+
var CO_SFX = W('Group Ltd Inc Solutions Systems Labs Partners Holdings Technologies Consulting Industries Logistics');
|
|
131
|
+
var CO_A = W('Blue North Bright Silver Green Summit Pioneer Harbor Atlas Nova Apex Cedar Quantum Golden River Vertex Horizon Crescent Evergreen Liberty');
|
|
132
|
+
var CO_B = W('Stone Field Bridge Wave Point Peak Gate Line Path Works Forge Leaf Rock Light');
|
|
133
|
+
var DOM_A = W('blue river north pixel cloud data green swift bright peak nova zen urban smart fresh prime open solid clear rapid');
|
|
134
|
+
var DOM_B = W('labs works hub base forge nest wave stack point grid craft lane');
|
|
135
|
+
var TLD = W('com com com net io org co');
|
|
136
|
+
var ADJ = W('Ergonomic Rustic Sleek Compact Wireless Premium Classic Smart Portable Durable Lightweight Modern Vintage Organic Handmade Foldable Waterproof');
|
|
137
|
+
var MAT = W('Steel Wooden Cotton Leather Ceramic Glass Bamboo Aluminum Wool Granite Rubber Linen Marble Silicone');
|
|
138
|
+
var NOUN = W('Chair Table Lamp Backpack Mug Keyboard Headphones Watch Bottle Jacket Shoes Desk Speaker Notebook Wallet Sunglasses Blender Pillow Mouse Charger Kettle Shelf');
|
|
139
|
+
var CATS = W('Electronics Home_&_Kitchen Clothing Books Sports Beauty Toys Garden Automotive Office_Supplies Health Grocery Pet_Supplies Jewelry Music');
|
|
140
|
+
var LOREM = W('lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua enim ad minim veniam quis nostrud exercitation ullamco laboris nisi aliquip ex ea commodo consequat duis aute irure in reprehenderit voluptate velit esse cillum fugiat nulla pariatur excepteur sint occaecat cupidatat non proident sunt culpa qui officia deserunt mollit anim id est laborum');
|
|
141
|
+
|
|
142
|
+
/* ================= field types ================= */
|
|
143
|
+
// kind: how the value is stored and written — int, dec, bool, date, datetime, time, text, uuid
|
|
144
|
+
var P = {
|
|
145
|
+
min: function (d, l) { return { k: 'min', l: l || 'Min', t: 'num', d: d }; },
|
|
146
|
+
max: function (d, l) { return { k: 'max', l: l || 'Max', t: 'num', d: d }; },
|
|
147
|
+
dec: function (d) { return { k: 'dec', l: 'Decimals', t: 'num', d: d, min: 0, max: 8 }; },
|
|
148
|
+
from: function (d) { return { k: 'from', l: 'From', t: 'date', d: d }; },
|
|
149
|
+
to: function (d) { return { k: 'to', l: 'To', t: 'date', d: d }; }
|
|
150
|
+
};
|
|
151
|
+
var TYPES = {
|
|
152
|
+
id: { g: 'Keys', l: 'Row number (ID)', kind: 'int', p: [{ k: 'start', l: 'Start', t: 'num', d: 1 }, { k: 'step', l: 'Step', t: 'num', d: 1 }] },
|
|
153
|
+
uuid: { g: 'Keys', l: 'UUID', kind: 'uuid', p: [] },
|
|
154
|
+
fk: { g: 'Keys', l: 'Foreign key (ID 1…N)', kind: 'int', p: [P.min(1, 'From ID'), P.max(100, 'To ID')] },
|
|
155
|
+
pattern: { g: 'Keys', l: 'Pattern (ORD-{row:6})', kind: 'text', p: [{ k: 'pattern', l: 'Pattern', t: 'text', d: 'ORD-{row:6}', w: 1 }] },
|
|
156
|
+
first_name: { g: 'Person', l: 'First name', kind: 'text', p: [] },
|
|
157
|
+
last_name: { g: 'Person', l: 'Last name', kind: 'text', p: [] },
|
|
158
|
+
full_name: { g: 'Person', l: 'Full name', kind: 'text', p: [{ k: 'fmt', l: 'Format', t: 'sel', d: 'fl', o: [['fl', 'First Last'], ['lf', 'Last, First'], ['tfl', 'Mr./Ms. First Last']] }] },
|
|
159
|
+
gender: { g: 'Person', l: 'Gender', kind: 'text', p: [{ k: 'fmt', l: 'Values', t: 'sel', d: 'Male/Female', o: [['Male/Female', 'Male / Female'], ['M/F', 'M / F'], ['male/female', 'male / female']] }] },
|
|
160
|
+
email: { g: 'Person', l: 'Email (from the name)', kind: 'text', p: [{ k: 'dom', l: 'Domains', t: 'sel', d: 'safe', o: [['safe', 'example.com (safe)'], ['real', 'gmail.com, outlook.com…'], ['custom', 'My domains']] }, { k: 'domains', l: 'My domains', t: 'text', d: 'acme.test, shop.test', w: 1, when: ['dom', 'custom'] }] },
|
|
161
|
+
username: { g: 'Person', l: 'Username', kind: 'text', p: [] },
|
|
162
|
+
phone: { g: 'Person', l: 'Phone', kind: 'text', p: [{ k: 'fmt', l: 'Format', t: 'sel', d: 'nat', o: [['nat', 'National'], ['intl', 'International (+)']] }] },
|
|
163
|
+
birth_date: { g: 'Person', l: 'Date of birth', kind: 'date', p: [P.min(18, 'Min age'), P.max(80, 'Max age')] },
|
|
164
|
+
age: { g: 'Person', l: 'Age (matches birth date)', kind: 'int', p: [] },
|
|
165
|
+
job_title: { g: 'Person', l: 'Job title', kind: 'text', p: [] },
|
|
166
|
+
department: { g: 'Person', l: 'Department', kind: 'text', p: [] },
|
|
167
|
+
company: { g: 'Person', l: 'Company', kind: 'text', p: [] },
|
|
168
|
+
street: { g: 'Address', l: 'Street address', kind: 'text', p: [] },
|
|
169
|
+
city: { g: 'Address', l: 'City', kind: 'text', p: [] },
|
|
170
|
+
region: { g: 'Address', l: 'State / region', kind: 'text', p: [] },
|
|
171
|
+
postcode: { g: 'Address', l: 'Postcode / ZIP', kind: 'text', p: [] },
|
|
172
|
+
country: { g: 'Address', l: 'Country', kind: 'text', p: [] },
|
|
173
|
+
country_code: { g: 'Address', l: 'Country code (ISO)', kind: 'text', p: [] },
|
|
174
|
+
latitude: { g: 'Address', l: 'Latitude', kind: 'dec', p: [] },
|
|
175
|
+
longitude: { g: 'Address', l: 'Longitude', kind: 'dec', p: [] },
|
|
176
|
+
int: { g: 'Numbers', l: 'Whole number', kind: 'int', p: [P.min(1), P.max(100)] },
|
|
177
|
+
decimal: { g: 'Numbers', l: 'Decimal number', kind: 'dec', p: [P.min(0), P.max(100), P.dec(2)] },
|
|
178
|
+
amount: { g: 'Numbers', l: 'Price / amount', kind: 'dec', p: [P.min(5), P.max(500), P.dec(2), { k: 'dist', l: 'Spread', t: 'sel', d: 'skew', o: [['skew', 'Realistic (many small)'], ['flat', 'Even']] }] },
|
|
179
|
+
boolean: { g: 'Numbers', l: 'True / false', kind: 'bool', p: [{ k: 'pct', l: '% true', t: 'num', d: 50, min: 0, max: 100 }, { k: 'fmt', l: 'CSV as', t: 'sel', d: 'true/false', o: [['true/false', 'true / false'], ['1/0', '1 / 0'], ['yes/no', 'yes / no'], ['Y/N', 'Y / N']] }] },
|
|
180
|
+
date: { g: 'Dates', l: 'Date', kind: 'date', p: [P.from('-2y'), P.to('today')] },
|
|
181
|
+
datetime: { g: 'Dates', l: 'Date and time', kind: 'datetime', p: [P.from('-2y'), P.to('today')] },
|
|
182
|
+
time: { g: 'Dates', l: 'Time', kind: 'time', p: [{ k: 'from', l: 'From', t: 'text', d: '00:00' }, { k: 'to', l: 'To', t: 'text', d: '23:59' }] },
|
|
183
|
+
timestamp: { g: 'Dates', l: 'Unix timestamp', kind: 'int', p: [P.from('-2y'), P.to('today')] },
|
|
184
|
+
after: { g: 'Dates', l: 'Date after another column', kind: 'datetime', p: [{ k: 'col', l: 'After', t: 'col', d: '' }, P.min(0, 'Min days'), P.max(30, 'Max days'), { k: 'time', l: 'Type', t: 'sel', d: 'dt', o: [['dt', 'Date and time'], ['d', 'Date only']] }] },
|
|
185
|
+
list: { g: 'Text', l: 'Pick from a list', kind: 'text', p: [{ k: 'values', l: 'Values (weight after :)', t: 'text', d: 'active:70, inactive:20, banned:10', w: 1 }] },
|
|
186
|
+
word: { g: 'Text', l: 'Word', kind: 'text', p: [] },
|
|
187
|
+
sentence: { g: 'Text', l: 'Sentence', kind: 'text', p: [] },
|
|
188
|
+
paragraph: { g: 'Text', l: 'Paragraph', kind: 'text', p: [] },
|
|
189
|
+
product: { g: 'Text', l: 'Product name', kind: 'text', p: [] },
|
|
190
|
+
category: { g: 'Text', l: 'Product category', kind: 'text', p: [] },
|
|
191
|
+
currency: { g: 'Text', l: 'Currency code', kind: 'text', p: [] },
|
|
192
|
+
url: { g: 'Internet', l: 'URL', kind: 'text', p: [] },
|
|
193
|
+
domain: { g: 'Internet', l: 'Domain name', kind: 'text', p: [] },
|
|
194
|
+
ipv4: { g: 'Internet', l: 'IPv4 address', kind: 'text', p: [{ k: 'scope', l: 'Range', t: 'sel', d: 'any', o: [['any', 'Any'], ['private', 'Private (192.168…, 10…)']] }] },
|
|
195
|
+
ipv6: { g: 'Internet', l: 'IPv6 address', kind: 'text', p: [] },
|
|
196
|
+
mac: { g: 'Internet', l: 'MAC address', kind: 'text', p: [] },
|
|
197
|
+
color: { g: 'Internet', l: 'Hex colour', kind: 'text', p: [] }
|
|
198
|
+
};
|
|
199
|
+
function kindOf(col) {
|
|
200
|
+
if (col.type === 'after') return col.p && col.p.time === 'd' ? 'date' : 'datetime';
|
|
201
|
+
return TYPES[col.type] ? TYPES[col.type].kind : 'text';
|
|
202
|
+
}
|
|
203
|
+
function param(col, k) {
|
|
204
|
+
var v = col.p && col.p[k] !== undefined && col.p[k] !== '' ? col.p[k] : undefined;
|
|
205
|
+
if (v !== undefined) return v;
|
|
206
|
+
var t = TYPES[col.type]; if (!t) return undefined;
|
|
207
|
+
for (var i = 0; i < t.p.length; i++) if (t.p[i].k === k) return t.p[i].d;
|
|
208
|
+
}
|
|
209
|
+
function num(col, k) { var v = Number(param(col, k)); return isFinite(v) ? v : Number(TYPES[col.type].p.filter(function (x) { return x.k === k; })[0].d); }
|
|
210
|
+
|
|
211
|
+
/* ================= dates (UTC) ================= */
|
|
212
|
+
var DAY = 864e5;
|
|
213
|
+
function pad(n, w) { n = String(n); while (n.length < (w || 2)) n = '0' + n; return n; }
|
|
214
|
+
function fmtDate(ms) { var d = new Date(ms); return d.getUTCFullYear() + '-' + pad(d.getUTCMonth() + 1) + '-' + pad(d.getUTCDate()); }
|
|
215
|
+
function fmtDT(ms) { var d = new Date(ms); return fmtDate(ms) + ' ' + pad(d.getUTCHours()) + ':' + pad(d.getUTCMinutes()) + ':' + pad(d.getUTCSeconds()); }
|
|
216
|
+
function parseISO(s) {
|
|
217
|
+
var m = /^(\d{4})-(\d{2})-(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?/.exec(String(s || '')); if (!m) return NaN;
|
|
218
|
+
return Date.UTC(+m[1], +m[2] - 1, +m[3], +(m[4] || 0), +(m[5] || 0), +(m[6] || 0));
|
|
219
|
+
}
|
|
220
|
+
// "today", "-2y", "+30d", "-6m" or YYYY-MM-DD
|
|
221
|
+
function resolveDate(s, today) {
|
|
222
|
+
s = String(s || '').trim().toLowerCase();
|
|
223
|
+
if (!s || s === 'today' || s === 'now') return today;
|
|
224
|
+
var m = /^([+-]?\d+)\s*([dwmy])$/.exec(s);
|
|
225
|
+
if (m) {
|
|
226
|
+
var n = +m[1], d = new Date(today);
|
|
227
|
+
if (m[2] === 'd') return today + n * DAY;
|
|
228
|
+
if (m[2] === 'w') return today + n * 7 * DAY;
|
|
229
|
+
if (m[2] === 'm') { d.setUTCMonth(d.getUTCMonth() + n); return d.getTime(); }
|
|
230
|
+
d.setUTCFullYear(d.getUTCFullYear() + n); return d.getTime();
|
|
231
|
+
}
|
|
232
|
+
var t = parseISO(s); return isNaN(t) ? NaN : t;
|
|
233
|
+
}
|
|
234
|
+
function parseTime(s, dflt) { var m = /^(\d{1,2}):(\d{2})(?::(\d{2}))?$/.exec(String(s || '').trim()); return m ? (+m[1]) * 3600 + (+m[2]) * 60 + (+(m[3] || 0)) : dflt; }
|
|
235
|
+
|
|
236
|
+
/* ================= helpers ================= */
|
|
237
|
+
function ascii(s) { return String(s).normalize('NFD').replace(/[̀-ͯ]/g, '').replace(/ß/g, 'ss').replace(/æ/g, 'ae').replace(/ø/g, 'o').toLowerCase().replace(/[^a-z]/g, ''); }
|
|
238
|
+
function splitName(x) { var i = x.indexOf(':'); return i < 0 ? { s: x, a: ascii(x) } : { s: x.slice(0, i), a: x.slice(i + 1) }; }
|
|
239
|
+
function hex(r, n) { var s = ''; for (var i = 0; i < n; i++) s += '0123456789abcdef'[Math.floor(r.f() * 16)]; return s; }
|
|
240
|
+
function cap(s) { return s.charAt(0).toUpperCase() + s.slice(1); }
|
|
241
|
+
function parseList(text) {
|
|
242
|
+
var out = [], total = 0;
|
|
243
|
+
String(text || '').split(/\r?\n|,/).forEach(function (raw) {
|
|
244
|
+
var s = raw.trim(); if (!s) return;
|
|
245
|
+
var m = /^(.*?)\s*:\s*(\d+(?:\.\d+)?)$/.exec(s), w = 1;
|
|
246
|
+
if (m && m[1]) { s = m[1]; w = +m[2]; }
|
|
247
|
+
if (w > 0) { total += w; out.push({ v: s, w: total }); }
|
|
248
|
+
});
|
|
249
|
+
return { items: out, total: total };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/* ================= column order and checks ================= */
|
|
253
|
+
function prepare(schema, n) {
|
|
254
|
+
var errs = [], names = {};
|
|
255
|
+
schema.forEach(function (c, i) {
|
|
256
|
+
c.name = String(c.name || '').trim() || 'column_' + (i + 1);
|
|
257
|
+
var low = c.name.toLowerCase();
|
|
258
|
+
if (names[low]) errs.push('Two columns are called “' + c.name + '”. Give each column its own name.');
|
|
259
|
+
names[low] = c;
|
|
260
|
+
if (!TYPES[c.type]) errs.push('Unknown type for “' + c.name + '”.');
|
|
261
|
+
});
|
|
262
|
+
schema.forEach(function (c) {
|
|
263
|
+
if (c.type === 'after') {
|
|
264
|
+
var ref = names[String(param(c, 'col') || '').toLowerCase()];
|
|
265
|
+
if (!ref) errs.push('“' + c.name + '” must come after a date column — pick one in its options.');
|
|
266
|
+
else if (['date', 'datetime', 'after', 'birth_date', 'timestamp'].indexOf(ref.type) < 0) errs.push('“' + c.name + '” must follow a date column, but “' + ref.name + '” is not one.');
|
|
267
|
+
else if (ref === c) errs.push('“' + c.name + '” cannot follow itself.');
|
|
268
|
+
c._ref = ref;
|
|
269
|
+
}
|
|
270
|
+
if (['int', 'fk', 'decimal', 'amount'].indexOf(c.type) >= 0 && num(c, 'min') > num(c, 'max')) errs.push('“' + c.name + '”: Min is larger than Max.');
|
|
271
|
+
if (c.type === 'list' && !parseList(param(c, 'values')).items.length) errs.push('“' + c.name + '”: add at least one value to the list.');
|
|
272
|
+
if (c.unique && !(c.blank > 0)) {
|
|
273
|
+
var cap = capacity(c);
|
|
274
|
+
if (cap < n) errs.push('“' + c.name + '” can only have ' + cap.toLocaleString('en-US') + ' different values, so ' + n.toLocaleString('en-US') + ' unique rows are impossible. Widen the range or untick Unique.');
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
// generate referenced columns first
|
|
278
|
+
var order = [], seen = {}, busy = {};
|
|
279
|
+
function visit(c) {
|
|
280
|
+
if (seen[c.name]) return; if (busy[c.name]) { errs.push('Date columns refer to each other in a loop (' + c.name + ').'); return; }
|
|
281
|
+
busy[c.name] = 1; if (c._ref) visit(c._ref); busy[c.name] = 0; seen[c.name] = 1; order.push(c);
|
|
282
|
+
}
|
|
283
|
+
schema.forEach(visit);
|
|
284
|
+
return { errs: errs, order: order };
|
|
285
|
+
}
|
|
286
|
+
function capacity(c) {
|
|
287
|
+
switch (c.type) {
|
|
288
|
+
case 'int': case 'fk': return Math.max(0, Math.floor(num(c, 'max')) - Math.ceil(num(c, 'min')) + 1);
|
|
289
|
+
case 'decimal': case 'amount': return Math.max(0, Math.floor((num(c, 'max') - num(c, 'min')) * Math.pow(10, num(c, 'dec'))) + 1);
|
|
290
|
+
case 'boolean': return 2;
|
|
291
|
+
case 'gender': return 2;
|
|
292
|
+
case 'list': return parseList(param(c, 'values')).items.length;
|
|
293
|
+
case 'age': return 100;
|
|
294
|
+
default: return Infinity;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/* ================= the generator ================= */
|
|
299
|
+
function Generator(schema, opts) {
|
|
300
|
+
opts = opts || {};
|
|
301
|
+
var seed = String(opts.seed || '1');
|
|
302
|
+
var today = opts.today != null ? opts.today : (function () { var d = new Date(); return Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate()); })();
|
|
303
|
+
var locale = opts.locale || 'en_US';
|
|
304
|
+
var prep = prepare(schema, opts.rows || 0);
|
|
305
|
+
this.errs = prep.errs; this.schema = schema; this.today = today;
|
|
306
|
+
if (prep.errs.length) return;
|
|
307
|
+
var order = prep.order;
|
|
308
|
+
var R = { row: rng(seed + '|person'), place: rng(seed + '|place'), loc: rng(seed + '|locale') };
|
|
309
|
+
var birthCol = schema.filter(function (c) { return c.type === 'birth_date'; })[0];
|
|
310
|
+
var minAge = birthCol ? num(birthCol, 'min') : 18, maxAge = birthCol ? num(birthCol, 'max') : 80;
|
|
311
|
+
if (minAge > maxAge) { var t = minAge; minAge = maxAge; maxAge = t; }
|
|
312
|
+
var cols = order.map(function (c) {
|
|
313
|
+
var x = { c: c, r: rng(seed + '|' + c.name.toLowerCase() + '|' + c.type), nr: rng(seed + '|' + c.name.toLowerCase() + '|blank'), blank: Math.max(0, Math.min(100, +c.blank || 0)) / 100, uniq: c.unique ? new Set() : null, kind: kindOf(c) };
|
|
314
|
+
if (c.type === 'list') x.list = parseList(param(c, 'values'));
|
|
315
|
+
if (/^(date|datetime|timestamp)$/.test(c.type)) {
|
|
316
|
+
x.from = resolveDate(param(c, 'from'), today); x.to = resolveDate(param(c, 'to'), today);
|
|
317
|
+
if (isNaN(x.from)) x.from = resolveDate('-2y', today); if (isNaN(x.to)) x.to = today;
|
|
318
|
+
if (x.from > x.to) { var s = x.from; x.from = x.to; x.to = s; }
|
|
319
|
+
if (c.type !== 'date') x.to += DAY - 1000;
|
|
320
|
+
}
|
|
321
|
+
if (c.type === 'time') { x.t0 = parseTime(param(c, 'from'), 0); x.t1 = parseTime(param(c, 'to'), 86340); if (x.t0 > x.t1) { var u = x.t0; x.t0 = x.t1; x.t1 = u; } }
|
|
322
|
+
if (c.type === 'email') x.doms = param(c, 'dom') === 'custom' ? String(param(c, 'domains') || '').split(/[\s,;]+/).map(function (d) { return d.replace(/^@/, '').trim(); }).filter(Boolean) : null;
|
|
323
|
+
return x;
|
|
324
|
+
});
|
|
325
|
+
this.cols = cols;
|
|
326
|
+
var personNeeded = schema.some(function (c) { return TYPES[c.type].g === 'Person'; });
|
|
327
|
+
var placeNeeded = schema.some(function (c) { return TYPES[c.type].g === 'Address' || c.type === 'phone' || c.type === 'currency'; });
|
|
328
|
+
|
|
329
|
+
this.row = function (i) {
|
|
330
|
+
var lk = locale === 'mix' ? R.loc.pick(MIX) : locale, L = LOC[lk] || LOC.en_US;
|
|
331
|
+
var ctx = { i: i, L: L, lk: lk, v: {} };
|
|
332
|
+
if (personNeeded) {
|
|
333
|
+
var r = R.row, male = r.f() < 0.5, fn = splitName(r.pick(male ? L.male : L.female)), ln = splitName(r.pick(L.last));
|
|
334
|
+
if (L.twoSurnames) ln = { s: ln.s + ' ' + splitName(r.pick(L.last)).s, a: ln.a };
|
|
335
|
+
var span = (maxAge - minAge + 1) * 365.25 * DAY, birth = today - minAge * 365.25 * DAY - Math.floor(r.f() * span);
|
|
336
|
+
ctx.p = { male: male, first: fn.s, last: ln.s, fa: fn.a, la: ln.a, birth: Math.floor(birth / DAY) * DAY, style: r.int(0, 9), num: r.int(1, 99), year: r.int(0, 1), mail: r.f(), job: r.pick(JOBS), dept: r.pick(DEPTS), co: r.f() };
|
|
337
|
+
}
|
|
338
|
+
if (placeNeeded) {
|
|
339
|
+
var q = R.place, city = q.pick(L.cities);
|
|
340
|
+
var ph = L.phone(q, city);
|
|
341
|
+
ctx.a = { city: city, street: L.street(q, city), pc: L.postcode(q, city), lat: city.lat + (q.f() - 0.5) * 0.12, lon: city.lon + (q.f() - 0.5) * 0.12, ph: ph[0], phi: ph[1] };
|
|
342
|
+
}
|
|
343
|
+
var out = new Array(schema.length);
|
|
344
|
+
for (var k = 0; k < cols.length; k++) {
|
|
345
|
+
var x = cols[k], c = x.c, v;
|
|
346
|
+
if (x.blank && x.nr.f() < x.blank) v = null;
|
|
347
|
+
else {
|
|
348
|
+
v = value(x, ctx, 0);
|
|
349
|
+
if (x.uniq) {
|
|
350
|
+
var tries = 0;
|
|
351
|
+
while (x.uniq.has(v) && tries < 40) { tries++; v = value(x, ctx, tries); }
|
|
352
|
+
if (x.uniq.has(v)) v = makeUnique(x, v);
|
|
353
|
+
x.uniq.add(v);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
ctx.v[c.name] = v;
|
|
357
|
+
out[schema.indexOf(c)] = v;
|
|
358
|
+
}
|
|
359
|
+
return out;
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
function value(x, ctx, attempt) {
|
|
363
|
+
var c = x.c, r = x.r, p = ctx.p, a = ctx.a, L = ctx.L;
|
|
364
|
+
switch (c.type) {
|
|
365
|
+
case 'id': return num(c, 'start') + ctx.i * num(c, 'step');
|
|
366
|
+
case 'uuid': var h = hex(r, 32); return h.slice(0, 8) + '-' + h.slice(8, 12) + '-4' + h.slice(13, 16) + '-' + '89ab'[r.int(0, 3)] + h.slice(17, 20) + '-' + h.slice(20);
|
|
367
|
+
case 'fk': case 'int': return r.int(Math.ceil(num(c, 'min')), Math.floor(num(c, 'max')));
|
|
368
|
+
case 'pattern': return pattern(String(param(c, 'pattern')), r, ctx.i);
|
|
369
|
+
case 'first_name': return attempt ? fresh(ctx, r).first : p.first;
|
|
370
|
+
case 'last_name': return attempt ? fresh(ctx, r).last : p.last;
|
|
371
|
+
case 'full_name':
|
|
372
|
+
var pp = attempt ? fresh(ctx, r) : p, f = param(c, 'fmt');
|
|
373
|
+
if (f === 'lf') return pp.last + ', ' + pp.first;
|
|
374
|
+
if (f === 'tfl') return (L.rtl ? '' : pp.male ? 'Mr. ' : r.pick(['Ms. ', 'Mrs. ', 'Ms. '])) + pp.first + ' ' + pp.last;
|
|
375
|
+
return pp.first + ' ' + pp.last;
|
|
376
|
+
case 'gender': var g = String(param(c, 'fmt')).split('/'); return p.male ? g[0] : g[1];
|
|
377
|
+
case 'email': return email(x, ctx, attempt);
|
|
378
|
+
case 'username': return username(p, attempt ? r.int(1, 9999) : 0, r);
|
|
379
|
+
case 'phone': return param(c, 'fmt') === 'intl' ? a.phi : a.ph;
|
|
380
|
+
case 'birth_date': return fmtDate(p.birth);
|
|
381
|
+
case 'age': var b = new Date(p.birth), t = new Date(today), age = t.getUTCFullYear() - b.getUTCFullYear();
|
|
382
|
+
if (t.getUTCMonth() < b.getUTCMonth() || (t.getUTCMonth() === b.getUTCMonth() && t.getUTCDate() < b.getUTCDate())) age--; return age;
|
|
383
|
+
case 'job_title': return attempt ? r.pick(JOBS) : p.job;
|
|
384
|
+
case 'department': return attempt ? r.pick(DEPTS) : p.dept;
|
|
385
|
+
case 'company': return company(attempt ? r.f() : p.co, p, r);
|
|
386
|
+
case 'street': return attempt ? L.street(r, a.city) : a.street;
|
|
387
|
+
case 'city': return a.city.city;
|
|
388
|
+
case 'region': return a.city.region;
|
|
389
|
+
case 'postcode': return attempt ? L.postcode(r, a.city) : a.pc;
|
|
390
|
+
case 'country': return a.city.country || L.country;
|
|
391
|
+
case 'country_code': return a.city.cc || L.cc;
|
|
392
|
+
case 'latitude': return round(attempt ? a.city.lat + (r.f() - 0.5) * 0.12 : a.lat, 6);
|
|
393
|
+
case 'longitude': return round(attempt ? a.city.lon + (r.f() - 0.5) * 0.12 : a.lon, 6);
|
|
394
|
+
case 'decimal': return round(num(c, 'min') + r.f() * (num(c, 'max') - num(c, 'min')), num(c, 'dec'));
|
|
395
|
+
case 'amount': return amount(c, r);
|
|
396
|
+
case 'boolean': return r.f() * 100 < num(c, 'pct');
|
|
397
|
+
case 'date': return fmtDate(x.from + Math.floor(r.f() * (Math.floor((x.to - x.from) / DAY) + 1)) * DAY);
|
|
398
|
+
case 'datetime': return fmtDT(x.from + Math.floor(r.f() * ((x.to - x.from) / 1000 + 1)) * 1000);
|
|
399
|
+
case 'timestamp': return Math.floor((x.from + r.f() * (x.to - x.from)) / 1000);
|
|
400
|
+
case 'time': var s = x.t0 + Math.floor(r.f() * (x.t1 - x.t0 + 1)); return pad(Math.floor(s / 3600)) + ':' + pad(Math.floor(s / 60) % 60) + ':' + pad(s % 60);
|
|
401
|
+
case 'after':
|
|
402
|
+
var ref = ctx.v[c._ref.name], base = c._ref.type === 'timestamp' ? (ref == null ? NaN : ref * 1000) : parseISO(ref);
|
|
403
|
+
if (isNaN(base)) return null; // nothing to follow when the earlier date is blank
|
|
404
|
+
var lo = Math.max(0, num(c, 'min')), hi = Math.max(lo, num(c, 'max'));
|
|
405
|
+
var ms = base + lo * DAY + Math.floor(r.f() * ((hi - lo) * DAY / 1000 + 1)) * 1000;
|
|
406
|
+
if (param(c, 'time') === 'd') return fmtDate(Math.floor(ms / DAY) * DAY);
|
|
407
|
+
if (/^(date|birth_date)$/.test(c._ref.type) || (c._ref.type === 'after' && param(c._ref, 'time') === 'd')) ms += r.int(8 * 3600, 20 * 3600) * 1000;
|
|
408
|
+
return fmtDT(ms);
|
|
409
|
+
case 'list': var w = r.f() * x.list.total, it = x.list.items; for (var j = 0; j < it.length; j++) if (w < it[j].w) return it[j].v; return it[it.length - 1].v;
|
|
410
|
+
case 'word': return r.pick(LOREM);
|
|
411
|
+
case 'sentence': return sentence(r);
|
|
412
|
+
case 'paragraph': var n = r.int(3, 6), ps = []; for (var k = 0; k < n; k++) ps.push(sentence(r)); return ps.join(' ');
|
|
413
|
+
case 'product': return r.pick(ADJ) + ' ' + r.pick(MAT) + ' ' + r.pick(NOUN);
|
|
414
|
+
case 'category': return r.pick(CATS);
|
|
415
|
+
case 'currency': return L.cur ? L.cur[a.city.cc] : L.currency;
|
|
416
|
+
case 'url': return 'https://www.' + r.pick(DOM_A) + r.pick(DOM_B) + '.' + r.pick(TLD) + (r.chance(0.5) ? '/' + r.pick(LOREM) + (r.chance(0.5) ? '/' + r.pick(LOREM) : '') : '');
|
|
417
|
+
case 'domain': return r.pick(DOM_A) + r.pick(DOM_B) + '.' + r.pick(TLD);
|
|
418
|
+
case 'ipv4':
|
|
419
|
+
if (param(c, 'scope') === 'private') return r.chance(0.6) ? '192.168.' + r.int(0, 255) + '.' + r.int(1, 254) : '10.' + r.int(0, 255) + '.' + r.int(0, 255) + '.' + r.int(1, 254);
|
|
420
|
+
var o1; do { o1 = r.int(1, 223); } while (o1 === 10 || o1 === 127); return o1 + '.' + r.int(0, 255) + '.' + r.int(0, 255) + '.' + r.int(1, 254);
|
|
421
|
+
case 'ipv6': var gs = []; for (var z = 0; z < 8; z++) gs.push(hex(r, 4).replace(/^0+(?=.)/, '')); return gs.join(':');
|
|
422
|
+
case 'mac': var ms2 = []; for (var y = 0; y < 6; y++) ms2.push(hex(r, 2).toUpperCase()); return ms2.join(':');
|
|
423
|
+
case 'color': return '#' + hex(r, 6);
|
|
424
|
+
}
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
function fresh(ctx, r) {
|
|
428
|
+
var L = ctx.L, male = ctx.p.male, fn = splitName(r.pick(male ? L.male : L.female)), ln = splitName(r.pick(L.last));
|
|
429
|
+
return { male: male, first: fn.s, last: ln.s };
|
|
430
|
+
}
|
|
431
|
+
function company(f, p, r) {
|
|
432
|
+
var L = LOC.en_US;
|
|
433
|
+
if (f < 0.45) return splitName(r.pick(L.last)).s.replace(/'/g, '') + ' ' + r.pick(CO_SFX);
|
|
434
|
+
if (f < 0.8) return r.pick(CO_A) + r.pick(CO_B) + ' ' + r.pick(CO_SFX);
|
|
435
|
+
return splitName(r.pick(L.last)).s + ' & ' + splitName(r.pick(L.last)).s;
|
|
436
|
+
}
|
|
437
|
+
function email(x, ctx, attempt) {
|
|
438
|
+
var p = ctx.p, r = x.r, L = ctx.L, mode = param(x.c, 'dom');
|
|
439
|
+
var dom = mode === 'custom' && x.doms && x.doms.length ? x.doms[Math.floor(p.mail * x.doms.length)] : mode === 'real' ? L.mail[Math.floor(Math.pow(p.mail, 1.6) * L.mail.length)] : SAFE_MAIL[Math.floor(p.mail * 3)];
|
|
440
|
+
if (attempt) dom = mode === 'custom' && x.doms && x.doms.length ? r.pick(x.doms) : mode === 'real' ? r.pick(L.mail) : r.pick(SAFE_MAIL);
|
|
441
|
+
var local = localPart(p, attempt ? r.int(0, 9) : p.style, attempt ? r.int(1, 999) : p.num);
|
|
442
|
+
return local + '@' + dom;
|
|
443
|
+
}
|
|
444
|
+
function localPart(p, style, n) {
|
|
445
|
+
var f = p.fa || 'user', l = p.la || 'mail', yr = String(new Date(p.birth).getUTCFullYear());
|
|
446
|
+
switch (style) {
|
|
447
|
+
case 0: case 1: case 2: return f + '.' + l;
|
|
448
|
+
case 3: return f + l;
|
|
449
|
+
case 4: return f.charAt(0) + '.' + l;
|
|
450
|
+
case 5: return f + '_' + l;
|
|
451
|
+
case 6: return f + '.' + l + n;
|
|
452
|
+
case 7: return f + l + yr.slice(2);
|
|
453
|
+
case 8: return l + '.' + f;
|
|
454
|
+
default: return f.charAt(0) + l + n;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
function username(p, extra, r) {
|
|
458
|
+
var f = p.fa || 'user', l = p.la || 'name', u;
|
|
459
|
+
switch (p.style % 5) { case 0: u = f + '.' + l; break; case 1: u = f + l + p.num; break; case 2: u = f.charAt(0) + l; break; case 3: u = f + '_' + l.slice(0, 1) + p.num; break; default: u = l + f.slice(0, 3) + p.num; }
|
|
460
|
+
return extra ? u + extra : u;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
function makeUnique(x, v) {
|
|
464
|
+
var n = 2, s = String(v), at = s.indexOf('@');
|
|
465
|
+
if (x.kind === 'int' || x.kind === 'dec' || x.kind === 'bool') {
|
|
466
|
+
// walk to the nearest free value inside the range
|
|
467
|
+
var c = x.c, lo = Math.ceil(num(c, 'min')), hi = Math.floor(num(c, 'max'));
|
|
468
|
+
if (x.kind === 'int') { for (var k = lo; k <= hi; k++) if (!x.uniq.has(k)) return k; }
|
|
469
|
+
return v;
|
|
470
|
+
}
|
|
471
|
+
var out;
|
|
472
|
+
do { out = at > 0 ? s.slice(0, at) + n + s.slice(at) : s + ' ' + n; n++; } while (x.uniq.has(out));
|
|
473
|
+
return out;
|
|
474
|
+
}
|
|
475
|
+
function round(v, d) { var f = Math.pow(10, d); return Math.round(v * f) / f; }
|
|
476
|
+
function amount(c, r) {
|
|
477
|
+
var lo = num(c, 'min'), hi = num(c, 'max'), d = num(c, 'dec');
|
|
478
|
+
if (param(c, 'dist') === 'flat' || lo < 0 || hi <= lo) return round(lo + r.f() * (hi - lo), d);
|
|
479
|
+
var a = Math.log(Math.max(lo, 0.01) + 1), b = Math.log(hi + 1), mu = a + (b - a) * 0.38, sd = (b - a) / 4.5, v;
|
|
480
|
+
do { v = Math.exp(mu + sd * r.normal()) - 1; } while (v < lo || v > hi);
|
|
481
|
+
var out = round(v, d);
|
|
482
|
+
// prices like 19.99 and 249.00 rather than 19.37
|
|
483
|
+
if (d === 2 && r.chance(0.55)) out = Math.max(lo, Math.min(hi, Math.floor(out) + (r.chance(0.6) ? 0.99 : 0.49)));
|
|
484
|
+
return round(out, d);
|
|
485
|
+
}
|
|
486
|
+
function sentence(r) { var n = r.int(6, 14), w = []; for (var i = 0; i < n; i++) w.push(r.pick(LOREM)); return cap(w.join(' ')) + '.'; }
|
|
487
|
+
// # digit · ? capital letter · * letter or digit · {row} / {row:6} row number · \# literal
|
|
488
|
+
function pattern(pt, r, i) {
|
|
489
|
+
var out = '', L = 'ABCDEFGHJKLMNPQRSTUVWXYZ', A = '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ';
|
|
490
|
+
for (var k = 0; k < pt.length; k++) {
|
|
491
|
+
var ch = pt[k];
|
|
492
|
+
if (ch === '\\' && k + 1 < pt.length) { out += pt[++k]; continue; }
|
|
493
|
+
if (ch === '{') { var m = /^\{row(?::(\d{1,2}))?\}/.exec(pt.slice(k)); if (m) { out += pad(i + 1, +(m[1] || 0)); k += m[0].length - 1; continue; } }
|
|
494
|
+
out += ch === '#' ? r.int(0, 9) : ch === '?' ? L[r.int(0, L.length - 1)] : ch === '*' ? A[r.int(0, A.length - 1)] : ch;
|
|
495
|
+
}
|
|
496
|
+
return out;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/* ================= writers ================= */
|
|
500
|
+
function dateOut(v, kind, f) {
|
|
501
|
+
if (v == null || f === 'iso' || !f) return v;
|
|
502
|
+
var m = /^(\d{4})-(\d{2})-(\d{2})(.*)$/.exec(v); if (!m) return v;
|
|
503
|
+
return (f === 'us' ? m[2] + '/' + m[3] + '/' + m[1] : m[3] + '/' + m[2] + '/' + m[1]) + m[4];
|
|
504
|
+
}
|
|
505
|
+
function fixed(c, v) { var d = c.type === 'latitude' || c.type === 'longitude' ? 6 : num(c, 'dec'); return v.toFixed(Math.max(0, Math.min(8, d))); }
|
|
506
|
+
|
|
507
|
+
function textCell(c, kind, v, o) {
|
|
508
|
+
if (v === null || v === undefined) return '';
|
|
509
|
+
if (kind === 'bool') { var f = String(param(c, 'fmt') || 'true/false').split('/'); return v ? f[0] : f[1]; }
|
|
510
|
+
if (kind === 'dec') return fixed(c, v);
|
|
511
|
+
if (kind === 'date' || kind === 'datetime') return dateOut(v, kind, o.dates);
|
|
512
|
+
return String(v);
|
|
513
|
+
}
|
|
514
|
+
function csvQuote(s, d) { return /["\r\n]/.test(s) || s.indexOf(d) >= 0 || /^\s|\s$/.test(s) ? '"' + s.replace(/"/g, '""') + '"' : s; }
|
|
515
|
+
|
|
516
|
+
var Q = {
|
|
517
|
+
mysql: function (s) { return '`' + s.replace(/`/g, '``') + '`'; },
|
|
518
|
+
postgres: function (s) { return '"' + s.replace(/"/g, '""') + '"'; },
|
|
519
|
+
sqlite: function (s) { return '"' + s.replace(/"/g, '""') + '"'; },
|
|
520
|
+
mssql: function (s) { return '[' + s.replace(/]/g, ']]') + ']'; }
|
|
521
|
+
};
|
|
522
|
+
function sqlStr(s, d) {
|
|
523
|
+
s = String(s).replace(/'/g, "''");
|
|
524
|
+
if (d === 'mysql') s = s.replace(/\\/g, '\\\\');
|
|
525
|
+
return (d === 'mssql' ? "N'" : "'") + s + "'";
|
|
526
|
+
}
|
|
527
|
+
function sqlVal(c, kind, v, d) {
|
|
528
|
+
if (v === null || v === undefined) return 'NULL';
|
|
529
|
+
if (kind === 'bool') return d === 'postgres' || d === 'mysql' ? (v ? 'TRUE' : 'FALSE') : (v ? '1' : '0');
|
|
530
|
+
if (kind === 'int') return String(v);
|
|
531
|
+
if (kind === 'dec') return fixed(c, v);
|
|
532
|
+
if (kind === 'uuid' && d === 'mssql') return "'" + v + "'";
|
|
533
|
+
return sqlStr(v, d);
|
|
534
|
+
}
|
|
535
|
+
function sqlType(c, kind, d, st) {
|
|
536
|
+
var len = st.len, P2 = st.prec;
|
|
537
|
+
switch (kind) {
|
|
538
|
+
case 'int': return c.type === 'timestamp' ? (d === 'sqlite' ? 'INTEGER' : 'BIGINT') : d === 'sqlite' ? 'INTEGER' : st.big ? 'BIGINT' : d === 'postgres' ? 'INTEGER' : 'INT';
|
|
539
|
+
case 'dec': return d === 'sqlite' ? 'REAL' : (d === 'postgres' ? 'NUMERIC(' : 'DECIMAL(') + P2[0] + ',' + P2[1] + ')';
|
|
540
|
+
case 'bool': return d === 'mssql' ? 'BIT' : d === 'sqlite' ? 'INTEGER' : 'BOOLEAN';
|
|
541
|
+
case 'date': return d === 'sqlite' ? 'TEXT' : 'DATE';
|
|
542
|
+
case 'datetime': return d === 'sqlite' ? 'TEXT' : d === 'postgres' ? 'TIMESTAMP' : d === 'mssql' ? 'DATETIME2(0)' : 'DATETIME';
|
|
543
|
+
case 'time': return d === 'sqlite' ? 'TEXT' : d === 'mssql' ? 'TIME(0)' : 'TIME';
|
|
544
|
+
case 'uuid': return d === 'postgres' ? 'UUID' : d === 'mssql' ? 'UNIQUEIDENTIFIER' : d === 'sqlite' ? 'TEXT' : 'CHAR(36)';
|
|
545
|
+
default:
|
|
546
|
+
if (d === 'sqlite') return 'TEXT';
|
|
547
|
+
var n = [50, 100, 255].filter(function (x) { return x >= Math.ceil(len * 1.25); })[0];
|
|
548
|
+
if (!n) return d === 'mssql' ? 'NVARCHAR(MAX)' : 'TEXT';
|
|
549
|
+
return (d === 'mssql' ? 'NVARCHAR(' : 'VARCHAR(') + n + ')';
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/* Produce the file as string chunks. onRow(i) is called every 2,000 rows for progress. */
|
|
554
|
+
function produce(schema, opts, onProgress) {
|
|
555
|
+
var n = Math.max(0, Math.floor(opts.rows || 0)), fmt = opts.format || 'csv';
|
|
556
|
+
var g = new Generator(schema, opts);
|
|
557
|
+
if (g.errs.length) return { errors: g.errs };
|
|
558
|
+
var kinds = schema.map(kindOf), chunks = [], buf = [], i;
|
|
559
|
+
var flush = function () { if (buf.length) { chunks.push(buf.join('')); buf = []; } };
|
|
560
|
+
var names = schema.map(function (c) { return c.name; });
|
|
561
|
+
|
|
562
|
+
if (fmt === 'csv' || fmt === 'tsv') {
|
|
563
|
+
var d = fmt === 'tsv' ? '\t' : opts.delim || ',', q = function (s) { return fmt === 'tsv' ? s.replace(/[\t\r\n]+/g, ' ') : csvQuote(s, d); };
|
|
564
|
+
if (opts.header !== false) buf.push(names.map(q).join(d) + '\r\n');
|
|
565
|
+
for (i = 0; i < n; i++) {
|
|
566
|
+
var row = g.row(i), cells = new Array(row.length);
|
|
567
|
+
for (var k = 0; k < row.length; k++) cells[k] = q(textCell(schema[k], kinds[k], row[k], opts));
|
|
568
|
+
buf.push(cells.join(d) + '\r\n');
|
|
569
|
+
if (buf.length >= 2000) { flush(); if (onProgress) onProgress(i + 1, n); }
|
|
570
|
+
}
|
|
571
|
+
flush();
|
|
572
|
+
return { chunks: chunks, mime: fmt === 'tsv' ? 'text/tab-separated-values' : 'text/csv', ext: fmt, bom: opts.bom !== false && fmt === 'csv' };
|
|
573
|
+
}
|
|
574
|
+
if (fmt === 'json' || fmt === 'jsonl') {
|
|
575
|
+
var keys = names.map(function (s) { return JSON.stringify(s); });
|
|
576
|
+
if (fmt === 'json') buf.push('[\n');
|
|
577
|
+
for (i = 0; i < n; i++) {
|
|
578
|
+
var r2 = g.row(i), parts = new Array(r2.length);
|
|
579
|
+
for (var j = 0; j < r2.length; j++) {
|
|
580
|
+
var v = r2[j], kd = kinds[j];
|
|
581
|
+
parts[j] = keys[j] + (fmt === 'json' ? ': ' : ':') + (v === null ? 'null' : kd === 'dec' ? String(Number(fixed(schema[j], v))) : kd === 'int' || kd === 'bool' ? String(v) : JSON.stringify(String(v)));
|
|
582
|
+
}
|
|
583
|
+
buf.push(fmt === 'json' ? ' {' + parts.join(', ') + '}' + (i < n - 1 ? ',\n' : '\n') : '{' + parts.join(',') + '}\n');
|
|
584
|
+
if (buf.length >= 2000) { flush(); if (onProgress) onProgress(i + 1, n); }
|
|
585
|
+
}
|
|
586
|
+
if (fmt === 'json') buf.push(']\n');
|
|
587
|
+
flush();
|
|
588
|
+
return { chunks: chunks, mime: fmt === 'json' ? 'application/json' : 'application/x-ndjson', ext: fmt };
|
|
589
|
+
}
|
|
590
|
+
if (fmt === 'sql') {
|
|
591
|
+
var dl = opts.dialect || 'mysql', qi = Q[dl] || Q.mysql, table = String(opts.table || 'test_data').trim() || 'test_data';
|
|
592
|
+
var batch = Math.max(1, Math.min(dl === 'mssql' ? 1000 : 5000, Math.floor(opts.batch || 500)));
|
|
593
|
+
var head = 'INSERT INTO ' + qi(table) + ' (' + names.map(qi).join(', ') + ') VALUES\n';
|
|
594
|
+
var st = schema.map(function () { return { len: 1, big: false, int: 1, frac: 0 }; });
|
|
595
|
+
for (i = 0; i < n; i++) {
|
|
596
|
+
var r3 = g.row(i), vals = new Array(r3.length);
|
|
597
|
+
for (var m = 0; m < r3.length; m++) {
|
|
598
|
+
var val = r3[m], s3 = st[m], kk = kinds[m];
|
|
599
|
+
if (val !== null) {
|
|
600
|
+
if (kk === 'text' && String(val).length > s3.len) s3.len = String(val).length;
|
|
601
|
+
else if (kk === 'int' && Math.abs(val) > 2147483647) s3.big = true;
|
|
602
|
+
else if (kk === 'dec') { var ip = String(Math.floor(Math.abs(val))).length; if (ip > s3.int) s3.int = ip; }
|
|
603
|
+
}
|
|
604
|
+
vals[m] = sqlVal(schema[m], kk, val, dl);
|
|
605
|
+
}
|
|
606
|
+
buf.push((i % batch === 0 ? head : '') + ' (' + vals.join(', ') + ')' + ((i + 1) % batch === 0 || i === n - 1 ? ';\n' : ',\n'));
|
|
607
|
+
if (buf.length >= 2000) { flush(); if (onProgress) onProgress(i + 1, n); }
|
|
608
|
+
}
|
|
609
|
+
flush();
|
|
610
|
+
var pre = [];
|
|
611
|
+
if (dl === 'mysql') pre.push('SET NAMES utf8mb4;\n');
|
|
612
|
+
if (opts.create !== false) {
|
|
613
|
+
if (opts.drop) pre.push('DROP TABLE IF EXISTS ' + qi(table) + ';\n');
|
|
614
|
+
var pk = schema.filter(function (c) { return c.type === 'id'; })[0];
|
|
615
|
+
var defs = schema.map(function (c, k) {
|
|
616
|
+
var s4 = st[k], dd = c.type === 'latitude' || c.type === 'longitude' ? 6 : kinds[k] === 'dec' ? num(c, 'dec') : 0;
|
|
617
|
+
s4.prec = [Math.min(38, Math.max(10, s4.int + dd + 1)), dd];
|
|
618
|
+
var line = ' ' + qi(c.name) + ' ' + sqlType(c, kinds[k], dl, s4);
|
|
619
|
+
if (c === pk) line += ' PRIMARY KEY';
|
|
620
|
+
else { if (!(c.blank > 0)) line += ' NOT NULL'; if (c.unique) line += ' UNIQUE'; }
|
|
621
|
+
return line;
|
|
622
|
+
});
|
|
623
|
+
pre.push('CREATE TABLE ' + (opts.drop ? '' : dl === 'mssql' ? '' : 'IF NOT EXISTS ') + qi(table) + ' (\n' + defs.join(',\n') + '\n)' + (dl === 'mysql' ? ' DEFAULT CHARSET=utf8mb4' : '') + ';\n\n');
|
|
624
|
+
}
|
|
625
|
+
if (opts.tx !== false && n) pre.push(dl === 'mssql' ? 'BEGIN TRANSACTION;\n' : dl === 'mysql' ? 'START TRANSACTION;\n' : 'BEGIN;\n');
|
|
626
|
+
chunks.unshift(pre.join(''));
|
|
627
|
+
if (opts.tx !== false && n) chunks.push('COMMIT;\n');
|
|
628
|
+
return { chunks: chunks, mime: 'application/sql', ext: 'sql' };
|
|
629
|
+
}
|
|
630
|
+
if (fmt === 'rows') {
|
|
631
|
+
var rows = []; for (i = 0; i < n; i++) { rows.push(g.row(i)); if (onProgress && i % 2000 === 1999) onProgress(i + 1, n); }
|
|
632
|
+
return { rows: rows, kinds: kinds };
|
|
633
|
+
}
|
|
634
|
+
return { errors: ['Unknown format'] };
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/* ================= guessing a type from a column name ================= */
|
|
638
|
+
var GUESS = [
|
|
639
|
+
[/^(id|row_id|rowid|pk|#|no|number)$/, 'id'], [/(^|_)(uuid|guid)$/, 'uuid'], [/_id$|_fk$/, 'fk'], [/^(is|has|can|should)_|_(verified|enabled|active|deleted|confirmed|subscribed|opt_?in)$/, 'boolean'],
|
|
640
|
+
[/first_?name|given_?name|forename|prenom/, 'first_name'], [/last_?name|surname|family_?name|^nom$/, 'last_name'],
|
|
641
|
+
[/e_?mail/, 'email'], [/user_?name|^login$|handle|nickname/, 'username'], [/phone|mobile|^tel|_tel|cell/, 'phone'],
|
|
642
|
+
[/gender|^sex$/, 'gender'], [/birth|dob/, 'birth_date'], [/^age$/, 'age'],
|
|
643
|
+
[/job|title|position/, 'job_title'], [/^dep(ar)?t/, 'department'], [/company|employer|organi[sz]ation|business|supplier|vendor/, 'company'],
|
|
644
|
+
[/street|address/, 'street'], [/city|town/, 'city'], [/^state$|region|province|county/, 'region'], [/zip|post_?code|postal/, 'postcode'],
|
|
645
|
+
[/country_?code|^iso/, 'country_code'], [/country|nation/, 'country'], [/^lat/, 'latitude'], [/^(lon|lng)/, 'longitude'],
|
|
646
|
+
[/url|website|link|homepage/, 'url'], [/domain|host/, 'domain'], [/ipv6/, 'ipv6'], [/^ip|ip_?addr/, 'ipv4'], [/^mac/, 'mac'], [/colou?r/, 'color'],
|
|
647
|
+
[/price|amount|total|cost|salary|revenue|balance|fee|spend|income|payment/, 'amount'],
|
|
648
|
+
[/qty|quantity|count|stock|units|number_of|^num/, 'int', { min: 0, max: 100 }], [/rating|stars/, 'int', { min: 1, max: 5 }], [/score/, 'int', { min: 0, max: 100 }],
|
|
649
|
+
[/percent|pct|discount|rate$|ratio/, 'decimal', { min: 0, max: 100, dec: 1 }],
|
|
650
|
+
[/^(is|has|can|should)_|active|enabled|verified|deleted|subscribed|^paid$|flag/, 'boolean'],
|
|
651
|
+
[/datetime|timestamp|_at$|_ts$/, 'datetime'], [/(^|_)date($|_)|_on$|^day$/, 'date'],
|
|
652
|
+
[/created|updated|modified|signup|last_login|logged/, 'datetime'], [/(^|_)time$/, 'time'],
|
|
653
|
+
[/status|stage/, 'list', { values: 'active:70, pending:15, inactive:10, banned:5' }], [/priority/, 'list', { values: 'low:40, medium:40, high:20' }],
|
|
654
|
+
[/^(full_?)?name$|customer|contact|client|author|employee|owner|person|manager/, 'full_name'],
|
|
655
|
+
[/description|notes?$|comment|bio|summary|message|body|review/, 'sentence'], [/product|item/, 'product'], [/category|genre|segment/, 'category'],
|
|
656
|
+
[/currency/, 'currency'], [/sku|code|ref|reference|serial|invoice/, 'pattern', { pattern: '???-#####' }], [/tag|keyword|word|label/, 'word']
|
|
657
|
+
];
|
|
658
|
+
function guessType(name) {
|
|
659
|
+
var n = String(name).trim().replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase().replace(/[\s\-.]+/g, '_');
|
|
660
|
+
for (var i = 0; i < GUESS.length; i++) {
|
|
661
|
+
if (GUESS[i][0].test(n)) return { type: GUESS[i][1], p: GUESS[i][2] ? JSON.parse(JSON.stringify(GUESS[i][2])) : {} };
|
|
662
|
+
}
|
|
663
|
+
return { type: 'word', p: {} };
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
var API = { TYPES: TYPES, LOC: LOC, produce: produce, Generator: Generator, guessType: guessType, kindOf: kindOf, param: param, textCell: textCell, resolveDate: resolveDate, parseList: parseList, rng: rng };
|
|
667
|
+
if (typeof module !== 'undefined' && module.exports) module.exports = API;
|
|
668
|
+
root.FakeData = API;
|
|
669
|
+
|
|
670
|
+
/* ================= worker entry ================= */
|
|
671
|
+
if (typeof document === 'undefined' && typeof self !== 'undefined' && typeof postMessage === 'function' && typeof module === 'undefined') {
|
|
672
|
+
self.onmessage = function (e) {
|
|
673
|
+
var m = e.data, t0 = Date.now(), last = 0;
|
|
674
|
+
try {
|
|
675
|
+
var res = produce(m.schema, m.opts, function (i, n) { var now = Date.now(); if (now - last > 120) { last = now; postMessage({ id: m.id, progress: i / n }); } });
|
|
676
|
+
res.id = m.id; res.ms = Date.now() - t0;
|
|
677
|
+
postMessage(res);
|
|
678
|
+
} catch (err) { postMessage({ id: m.id, errors: [String(err && err.message || err)] }); }
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
})(typeof self !== 'undefined' ? self : this);
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "consistent-fake-data",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Realistic, consistent fake test data (names, emails, addresses, dates, prices) as CSV, JSON or SQL INSERTs. One file, no dependencies.",
|
|
5
|
+
"main": "fakedata-core.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"fakedata-core.js",
|
|
8
|
+
"README.md",
|
|
9
|
+
"LICENSE"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"test": "node --test",
|
|
13
|
+
"example": "node examples/node.js"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"test-data",
|
|
17
|
+
"test-data-generator",
|
|
18
|
+
"fake-data",
|
|
19
|
+
"mock-data",
|
|
20
|
+
"faker",
|
|
21
|
+
"csv",
|
|
22
|
+
"json",
|
|
23
|
+
"sql",
|
|
24
|
+
"sql-insert",
|
|
25
|
+
"seed",
|
|
26
|
+
"generator",
|
|
27
|
+
"mockaroo-alternative"
|
|
28
|
+
],
|
|
29
|
+
"author": "DataSwitch Pro (https://dataswitchpro.com)",
|
|
30
|
+
"homepage": "https://dataswitchpro.com/test-data-generator/",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/caminillov10/test-data-generator.git"
|
|
34
|
+
},
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/caminillov10/test-data-generator/issues"
|
|
37
|
+
},
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=18"
|
|
41
|
+
}
|
|
42
|
+
}
|