lacspace-fake 0.1.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 ADDED
@@ -0,0 +1,51 @@
1
+ Lacspace Free Licence
2
+ Version 1.0, August 2026
3
+
4
+ Copyright (c) 2026 Lacspace
5
+
6
+ PREAMBLE
7
+
8
+ This software is published by Lacspace under the Lacspace Free Licence — a free,
9
+ permissive licence that lets you use this software for any purpose, including in
10
+ commercial products and services, at no cost. It grants the same freedoms as
11
+ common permissive open-source licences; the only condition is that this notice
12
+ travels with the software. The canonical, always-current text of this licence is
13
+ maintained at https://lacspace.com/licenses/lacspace-free-1.0
14
+
15
+ GRANT OF RIGHTS
16
+
17
+ Permission is hereby granted, free of charge, to any person or organisation
18
+ obtaining a copy of this software and its associated documentation and data files
19
+ (the "Software"), to deal in the Software without restriction, including without
20
+ limitation the rights to use, copy, modify, merge, publish, distribute,
21
+ sublicense, and/or sell copies of the Software, and to permit persons to whom the
22
+ Software is furnished to do so, subject to the conditions below. These rights are
23
+ granted for any purpose, personal or commercial, and are perpetual, worldwide,
24
+ non-exclusive, and royalty-free.
25
+
26
+ CONDITIONS
27
+
28
+ The above copyright notice, this permission notice, and the name of this licence
29
+ ("Lacspace Free Licence") shall be included in all copies or substantial portions
30
+ of the Software.
31
+
32
+ TRADEMARKS
33
+
34
+ This licence does not grant permission to use the trade names, trademarks, service
35
+ marks, logos, or product names of Lacspace, except as required to reproduce the
36
+ notice above or to describe the origin of the Software in a truthful manner.
37
+
38
+ DISCLAIMER OF WARRANTY AND LIMITATION OF LIABILITY
39
+
40
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
42
+ FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
43
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN
44
+ AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
45
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
46
+
47
+ ---
48
+
49
+ The Lacspace Free Licence is a source-available, permissive licence and is not (as
50
+ of this version) an OSI-approved licence. In substance it grants the same freedoms
51
+ as the MIT Licence. Learn more at https://lacspace.com/licenses
package/README.md ADDED
@@ -0,0 +1,193 @@
1
+ # lacspace-fake
2
+
3
+ **Keyless, deterministic fake / seed data — schema in, JSON · NDJSON · CSV · SQL out.**
4
+
5
+ Describe a schema, get realistic rows: names, emails, phones, addresses, prices,
6
+ timestamps, UUIDs and more. Reproducible with `--seed` (byte-identical output on
7
+ every machine), **Nepal-aware** with `--locale ne`, and it emits ready-to-run
8
+ `INSERT` statements so you can seed any database in one command.
9
+
10
+ ```bash
11
+ npx lacspace-fake --fields "id:autoincrement,name:fullName,email:email,age:int(18..65)" -n 5
12
+ ```
13
+
14
+ ## Why it exists
15
+
16
+ - **Free & keyless.** No API key, no account, no network calls, no telemetry — runs fully offline.
17
+ - **Deterministic.** Same `--seed` ⇒ same rows, forever. Perfect for reproducible test fixtures and CI.
18
+ - **Zero dependencies.** Pure Node built-ins. Tiny install, nothing to audit.
19
+ - **Schema-driven.** One inline string or a JSON schema file → N rows in the format you need.
20
+ - **Seeds databases directly.** `-f sql --table users` gives you escaped, injection-safe `INSERT`s. Pairs with `lacspace-sql`.
21
+ - **Nepal-aware.** Romanized Nepali names, districts/provinces, NPR, `+977` mobiles, PAN/VAT numbers.
22
+
23
+ ## Quick start
24
+
25
+ ```bash
26
+ # 5 users as pretty JSON
27
+ npx lacspace-fake --fields "id:autoincrement,name:fullName,email:email,age:int(18..65)" -n 5 --pretty
28
+
29
+ # 100 rows as SQL INSERTs, ready to pipe into a database
30
+ npx lacspace-fake --fields "id:autoincrement,name:fullName,role:oneOf(admin|user)" -n 100 -f sql --table users
31
+
32
+ # From a JSON schema, out to a CSV file
33
+ npx lacspace-fake --schema users.json -n 50 -f csv -o users.csv
34
+
35
+ # Nepal locale
36
+ npx lacspace-fake --fields "name:fullName,phone:phone,district:city" --locale ne -n 10
37
+
38
+ # Just five emails
39
+ npx lacspace-fake email -n 5 --seed 42
40
+
41
+ # Discover every generator
42
+ npx lacspace-fake list
43
+ ```
44
+
45
+ ## Examples with output
46
+
47
+ **Inline schema → JSON**
48
+
49
+ ```bash
50
+ $ npx lacspace-fake --fields "id:autoincrement,name:fullName,role:oneOf(admin|user)" -n 2 --seed 42 --pretty
51
+ [
52
+ { "id": 1, "name": "Charlotte Taylor", "role": "admin" },
53
+ { "id": 2, "name": "Michael Davis", "role": "user" }
54
+ ]
55
+ ```
56
+
57
+ **→ SQL (quotes escaped, injection-safe)**
58
+
59
+ ```bash
60
+ $ npx lacspace-fake --fields "id:autoincrement,name:fullName" -n 2 -f sql --table users --seed 1
61
+ INSERT INTO "users" ("id", "name") VALUES
62
+ (1, 'Mary Davis'),
63
+ (2, 'Nora Jones');
64
+ ```
65
+
66
+ **→ CSV**
67
+
68
+ ```bash
69
+ $ npx lacspace-fake --fields "name:fullName,email:email" -n 2 -f csv --seed 3
70
+ name,email
71
+ Mary Miller,noah.davis27@hotmail.com
72
+ Hannah Rodriguez,henryjones@outlook.com
73
+ ```
74
+
75
+ **Nepal locale → NDJSON**
76
+
77
+ ```bash
78
+ $ npx lacspace-fake --fields "name:fullName,phone:phone,province:state" --locale ne -n 2 --seed 7 -f ndjson
79
+ {"name":"Aayush Maharjan","phone":"+9779704425721","province":"Gandaki"}
80
+ {"name":"Anish Gurung","phone":"+9779710956696","province":"Karnali"}
81
+ ```
82
+
83
+ **JSON schema file** (`users.json`) with nested objects and arrays:
84
+
85
+ ```json
86
+ {
87
+ "id": "autoincrement",
88
+ "name": "fullName",
89
+ "email": "email",
90
+ "score": { "type": "int", "min": 1, "max": 100 },
91
+ "tags": { "type": "array", "of": "word", "count": 3 },
92
+ "address": { "type": "object", "properties": { "city": "city", "zip": "zip" } }
93
+ }
94
+ ```
95
+
96
+ ```bash
97
+ $ npx lacspace-fake --schema users.json -n 50 -f csv -o users.csv
98
+ ✓ wrote users.csv (csv)
99
+ ```
100
+
101
+ ## Field syntax
102
+
103
+ Inline `--fields` is a comma-separated list of `key:generator` (with optional args):
104
+
105
+ ```
106
+ key:generator name:fullName
107
+ key:generator(args) age:int(18..65) role:oneOf(admin|user)
108
+ ```
109
+
110
+ - Numeric ranges use `..` — `int(18..65)`, `price(10..999)`, `float(0..1)`
111
+ - Option lists use `|` — `oneOf(admin|user|guest)`
112
+ - Weighted picks use `value:weight` — `weighted(admin:1|user:9)`
113
+ - Date windows use `..` — `between(2020-01-01..2024-12-31)`
114
+
115
+ Fields evaluate in order, so a later field can derive from an earlier one:
116
+ `firstName:firstName,lastName:lastName,email:email` yields emails built from each row's name.
117
+
118
+ ## Generators
119
+
120
+ `firstName · lastName · fullName · gender · age · dateOfBirth · email · username ·
121
+ url · domain · ipv4 · ipv6 · mac · password · uuid · slug · phone · phoneLocal ·
122
+ street · city · state · country · countryCode · zip · address · latitude · longitude ·
123
+ latlng · company · catchphrase · jobTitle · department · productName · price · sku ·
124
+ currency · category · color · word · words · sentence · paragraph · lorem · past ·
125
+ future · recent · soon · between · timestamp · date · time · int · float · bool ·
126
+ oneOf · weighted · digit · autoincrement · nanoid · objectId · pan · vat`
127
+
128
+ Run `lacspace-fake list` for a live sample of each.
129
+
130
+ > **Foreign keys / relations:** model an FK column with an `int` range that points at
131
+ > your parent table's id space, e.g. `user_id:int(1..100)`. Deterministic seeds keep the
132
+ > references stable across regenerations.
133
+
134
+ ## CLI reference
135
+
136
+ | Flag | Purpose |
137
+ |------|---------|
138
+ | `[generator]` | Positional: generate N values of one generator (e.g. `email`, `int(1..100)`) |
139
+ | `list` | Print every generator with a sample value |
140
+ | `-n, --count <n>` | Number of rows/values (default 10) |
141
+ | `-f, --format <fmt>` | `json` (default), `ndjson`, `csv`, `sql` |
142
+ | `-t, --table <name>` | Table name for `-f sql` |
143
+ | `--fields <spec>` | Inline schema string |
144
+ | `--schema <file>` | JSON schema file (`-` for stdin) |
145
+ | `-s, --seed <str>` | Seed for reproducible output (number or any string) |
146
+ | `-l, --locale <loc>` | `en` (default) or `ne` (Nepal) |
147
+ | `--pretty` | Pretty-print JSON |
148
+ | `-o, --out <file>` | Write to a file instead of stdout |
149
+ | `-h, --help` / `-v, --version` | Help / version |
150
+
151
+ Respects `NO_COLOR`. Data is written to **stdout**; status/errors to **stderr**; exits **non-zero** on any error, so it composes cleanly in scripts and CI.
152
+
153
+ ## Library API
154
+
155
+ ```ts
156
+ import {
157
+ parseFields, parseJsonSchema, generateRows, generateValues, formatRows, RNG,
158
+ } from "lacspace-fake";
159
+
160
+ const fields = parseFields("id:autoincrement,name:fullName,email:email,age:int(18..65)");
161
+ const rows = generateRows(fields, { count: 3, seed: 42, locale: "en" });
162
+ formatRows(rows, { format: "sql", table: "users" });
163
+ ```
164
+
165
+ | Export | Signature |
166
+ |--------|-----------|
167
+ | `parseFields(spec)` | `(input: string) => Field[]` — compile an inline field string |
168
+ | `parseJsonSchema(obj)` | `(schema: unknown) => Field[]` — compile a JSON schema object |
169
+ | `generateRows(fields, opts)` | `(Field[], { count?, seed?, locale? }) => Record<string, unknown>[]` |
170
+ | `generateValues(spec, opts)` | `(specStr: string, { count?, seed?, locale? }) => unknown[]` |
171
+ | `formatRows(rows, opts)` | `(rows, { format, pretty?, table? }) => string` |
172
+ | `formatValues(values, col, opts)` | scalar-value formatter |
173
+ | `toCsv(rows)` / `toSql(rows, table)` | direct formatters |
174
+ | `sqlValue(v)` / `sqlIdent(name)` | SQL escaping primitives |
175
+ | `generators` / `callGen(name, ctx, args)` | the generator registry |
176
+ | `RNG` | the seeded mulberry32 PRNG (`int`, `float`, `bool`, `pick`, `weighted`, `uuid`, …) |
177
+ | `slugify(str)` | accent/punctuation-safe URL slug |
178
+
179
+ Types (`Field`, `Spec`, `Format`, `FormatOptions`, `GenContext`, `Locale`, …) are all exported. Ships dual **ESM + CJS** with `.d.ts`.
180
+
181
+ ## Limitations
182
+
183
+ - Data is **plausible, not real** — it's for tests and demos, never production identities.
184
+ - Locales are `en` and `ne` only; `en` is generic English/US-ish, not per-country.
185
+ - Relations are best-effort via `int()` id ranges — there is no cross-table referential engine.
186
+ - Determinism holds for a given package version; generator internals may evolve across minor versions.
187
+ - Time-based generators (`past`, `future`, `recent`) are anchored to the current clock, so their absolute instants shift day to day (still deterministic within a run given a seed).
188
+
189
+ ## Licence
190
+
191
+ Lacspace Free Licence v1.0 — see [LICENSE](./LICENSE). Free to use, keyless, offline.
192
+
193
+ Part of the [Lacspace developer tools](https://developer.lacspace.com/tools).