@venn-lang/data 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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +143 -0
  3. package/dist/index.d.ts +152 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +1941 -0
  6. package/dist/index.js.map +1 -0
  7. package/package.json +54 -0
  8. package/src/actions/faker-actions.ts +22 -0
  9. package/src/actions/index.ts +7 -0
  10. package/src/actions/parse-actions.ts +31 -0
  11. package/src/actions/random-actions.ts +51 -0
  12. package/src/csv/csv.types.ts +2 -0
  13. package/src/csv/index.ts +2 -0
  14. package/src/csv/parse-csv.ts +30 -0
  15. package/src/faker/address.ts +70 -0
  16. package/src/faker/all-specs.ts +25 -0
  17. package/src/faker/brazil-documents.ts +46 -0
  18. package/src/faker/brazil.ts +75 -0
  19. package/src/faker/check-digits.ts +56 -0
  20. package/src/faker/commerce.ts +59 -0
  21. package/src/faker/company.ts +41 -0
  22. package/src/faker/data/business.ts +80 -0
  23. package/src/faker/data/commerce.ts +73 -0
  24. package/src/faker/data/index.ts +36 -0
  25. package/src/faker/data/names.ts +93 -0
  26. package/src/faker/data/places.ts +109 -0
  27. package/src/faker/data/web.ts +45 -0
  28. package/src/faker/data/words.ts +104 -0
  29. package/src/faker/datetime.ts +102 -0
  30. package/src/faker/faker.types.ts +24 -0
  31. package/src/faker/finance.ts +86 -0
  32. package/src/faker/ids.ts +80 -0
  33. package/src/faker/index.ts +8 -0
  34. package/src/faker/internet.ts +100 -0
  35. package/src/faker/person.ts +88 -0
  36. package/src/faker/primitives.ts +77 -0
  37. package/src/faker/text.ts +56 -0
  38. package/src/index.ts +8 -0
  39. package/src/plugin.ts +17 -0
  40. package/src/rng/index.ts +4 -0
  41. package/src/rng/mulberry32.ts +18 -0
  42. package/src/rng/rng.types.ts +2 -0
  43. package/src/rng/shared-rng.ts +15 -0
  44. package/src/rng/shuffle.ts +17 -0
  45. package/src/types.ts +14 -0
@@ -0,0 +1,15 @@
1
+ import { mulberry32 } from "./mulberry32.js";
2
+ import type { Rng } from "./rng.types.js";
3
+
4
+ /** The fixed seed. A constant seed is what makes every generated value reproducible. */
5
+ const SEED = 1;
6
+
7
+ let shared: Rng = mulberry32(SEED);
8
+
9
+ /** The module-level deterministic PRNG shared by every generator in this package. */
10
+ export const rng: Rng = () => shared();
11
+
12
+ /** Reset the shared PRNG to its seed so the same stream can be drawn again. Used by tests. */
13
+ export function resetRng(): void {
14
+ shared = mulberry32(SEED);
15
+ }
@@ -0,0 +1,17 @@
1
+ import type { Rng } from "./rng.types.js";
2
+
3
+ /**
4
+ * Fisher-Yates shuffle driven by the given PRNG.
5
+ *
6
+ * @returns A new array holding the same elements in a new order. `items` is untouched.
7
+ */
8
+ export function shuffleWith(items: readonly unknown[], rng: Rng): unknown[] {
9
+ const out = [...items];
10
+ for (let i = out.length - 1; i > 0; i -= 1) {
11
+ const j = Math.floor(rng() * (i + 1));
12
+ const tmp = out[i];
13
+ out[i] = out[j];
14
+ out[j] = tmp;
15
+ }
16
+ return out;
17
+ }
package/src/types.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { type TypeSpec, t } from "@venn-lang/types";
2
+
3
+ /**
4
+ * The named types `@venn-lang/data` publishes to scripts, keyed by their bare name.
5
+ *
6
+ * Hand-mirrored from `csv/csv.types.ts`: the two must agree, so change them together.
7
+ */
8
+ export const dataTypeDefs: Readonly<Record<string, TypeSpec>> = {
9
+ /**
10
+ * One parsed CSV record. The keys come from the file's header line, so they
11
+ * cannot be named here. Only the cell type is knowable, and it is always a string.
12
+ */
13
+ Row: t.map(t.string),
14
+ };