@vielzeug/illusionist 2.3.2 → 26.10.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/README.md +2 -50
- package/dist/_helpers/boolean.cjs +1 -1
- package/dist/_helpers/boolean.cjs.map +1 -1
- package/dist/_helpers/boolean.d.ts +1 -1
- package/dist/_helpers/boolean.d.ts.map +1 -1
- package/dist/_helpers/boolean.js +1 -8
- package/dist/_helpers/boolean.js.map +1 -1
- package/dist/_helpers/float.cjs +1 -1
- package/dist/_helpers/float.cjs.map +1 -1
- package/dist/_helpers/float.d.ts +1 -1
- package/dist/_helpers/float.d.ts.map +1 -1
- package/dist/_helpers/float.js +1 -12
- package/dist/_helpers/float.js.map +1 -1
- package/dist/_helpers/int.cjs +1 -1
- package/dist/_helpers/int.cjs.map +1 -1
- package/dist/_helpers/int.d.ts +1 -1
- package/dist/_helpers/int.d.ts.map +1 -1
- package/dist/_helpers/int.js +1 -8
- package/dist/_helpers/int.js.map +1 -1
- package/dist/_helpers/next-float.d.ts +1 -3
- package/dist/_helpers/next-float.d.ts.map +1 -1
- package/dist/_helpers/next-float.js +1 -8
- package/dist/_helpers/string.cjs +1 -1
- package/dist/_helpers/string.cjs.map +1 -1
- package/dist/_helpers/string.d.ts +1 -1
- package/dist/_helpers/string.d.ts.map +1 -1
- package/dist/_helpers/string.js +1 -28
- package/dist/_helpers/string.js.map +1 -1
- package/dist/_virtual/_rolldown/runtime.cjs +1 -1
- package/dist/_virtual/_rolldown/runtime.js +1 -11
- package/dist/commerce/commerce.cjs +1 -1
- package/dist/commerce/commerce.cjs.map +1 -1
- package/dist/commerce/commerce.js +1 -50
- package/dist/commerce/commerce.js.map +1 -1
- package/dist/commerce/data.js +1 -82
- package/dist/commerce/data.js.map +1 -1
- package/dist/date/date.cjs +1 -1
- package/dist/date/date.cjs.map +1 -1
- package/dist/date/date.d.ts.map +1 -1
- package/dist/date/date.js +1 -92
- package/dist/date/date.js.map +1 -1
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.js +1 -9
- package/dist/errors.js.map +1 -1
- package/dist/factory.cjs +1 -1
- package/dist/factory.cjs.map +1 -1
- package/dist/factory.d.ts +0 -5
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +1 -45
- package/dist/factory.js.map +1 -1
- package/dist/finance/data.js +1 -59
- package/dist/finance/data.js.map +1 -1
- package/dist/finance/finance.cjs +1 -1
- package/dist/finance/finance.cjs.map +1 -1
- package/dist/finance/finance.js +1 -89
- package/dist/finance/finance.js.map +1 -1
- package/dist/illusionist.cjs +3 -3
- package/dist/illusionist.cjs.map +1 -1
- package/dist/illusionist.iife.js +3 -3
- package/dist/illusionist.iife.js.map +1 -1
- package/dist/illusionist.js +3 -3
- package/dist/illusionist.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -12
- package/dist/internet/data.js +1 -83
- package/dist/internet/data.js.map +1 -1
- package/dist/internet/internet.cjs +1 -1
- package/dist/internet/internet.cjs.map +1 -1
- package/dist/internet/internet.js +1 -120
- package/dist/internet/internet.js.map +1 -1
- package/dist/locales/de.js +1 -11
- package/dist/locales/de.js.map +1 -1
- package/dist/locales/en.js +1 -11
- package/dist/locales/en.js.map +1 -1
- package/dist/locales/index.js +1 -3
- package/dist/location/data/de.js +1 -81
- package/dist/location/data/de.js.map +1 -1
- package/dist/location/data/en.js +1 -64
- package/dist/location/data/en.js.map +1 -1
- package/dist/location/location.cjs +1 -1
- package/dist/location/location.cjs.map +1 -1
- package/dist/location/location.js +1 -56
- package/dist/location/location.js.map +1 -1
- package/dist/lorem/data.js +1 -5
- package/dist/lorem/data.js.map +1 -1
- package/dist/lorem/lorem.cjs +3 -3
- package/dist/lorem/lorem.cjs.map +1 -1
- package/dist/lorem/lorem.js +3 -53
- package/dist/lorem/lorem.js.map +1 -1
- package/dist/person/data/de.js +1 -61
- package/dist/person/data/de.js.map +1 -1
- package/dist/person/data/en.js +1 -69
- package/dist/person/data/en.js.map +1 -1
- package/dist/person/person.cjs +1 -1
- package/dist/person/person.cjs.map +1 -1
- package/dist/person/person.js +1 -43
- package/dist/person/person.js.map +1 -1
- package/dist/seed/create-seed.cjs +1 -1
- package/dist/seed/create-seed.cjs.map +1 -1
- package/dist/seed/create-seed.d.ts +2 -2
- package/dist/seed/create-seed.d.ts.map +1 -1
- package/dist/seed/create-seed.js +1 -22
- package/dist/seed/create-seed.js.map +1 -1
- package/dist/seed/mulberry32.cjs +1 -1
- package/dist/seed/mulberry32.cjs.map +1 -1
- package/dist/seed/mulberry32.d.ts +1 -1
- package/dist/seed/mulberry32.d.ts.map +1 -1
- package/dist/seed/mulberry32.js +1 -12
- package/dist/seed/mulberry32.js.map +1 -1
- package/dist/system/data.js +1 -75
- package/dist/system/data.js.map +1 -1
- package/dist/system/system.cjs +1 -1
- package/dist/system/system.cjs.map +1 -1
- package/dist/system/system.d.ts.map +1 -1
- package/dist/system/system.js +1 -69
- package/dist/system/system.js.map +1 -1
- package/dist/types.d.ts +2 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +10 -82
- package/dist/_helpers/next-float.cjs +0 -2
- package/dist/_helpers/next-float.cjs.map +0 -1
- package/dist/_helpers/next-float.js.map +0 -1
- package/dist/commerce/index.cjs +0 -1
- package/dist/commerce/index.d.ts +0 -2
- package/dist/commerce/index.d.ts.map +0 -1
- package/dist/commerce/index.js +0 -2
- package/dist/date/index.cjs +0 -1
- package/dist/date/index.d.ts +0 -2
- package/dist/date/index.d.ts.map +0 -1
- package/dist/date/index.js +0 -2
- package/dist/finance/index.cjs +0 -1
- package/dist/finance/index.d.ts +0 -2
- package/dist/finance/index.d.ts.map +0 -1
- package/dist/finance/index.js +0 -2
- package/dist/internet/index.cjs +0 -1
- package/dist/internet/index.d.ts +0 -2
- package/dist/internet/index.d.ts.map +0 -1
- package/dist/internet/index.js +0 -2
- package/dist/location/index.cjs +0 -1
- package/dist/location/index.d.ts +0 -2
- package/dist/location/index.d.ts.map +0 -1
- package/dist/location/index.js +0 -2
- package/dist/lorem/index.cjs +0 -1
- package/dist/lorem/index.d.ts +0 -2
- package/dist/lorem/index.d.ts.map +0 -1
- package/dist/lorem/index.js +0 -2
- package/dist/person/index.cjs +0 -1
- package/dist/person/index.d.ts +0 -2
- package/dist/person/index.d.ts.map +0 -1
- package/dist/person/index.js +0 -2
- package/dist/seed/index.cjs +0 -1
- package/dist/seed/index.d.ts +0 -3
- package/dist/seed/index.d.ts.map +0 -1
- package/dist/seed/index.js +0 -3
- package/dist/system/index.cjs +0 -1
- package/dist/system/index.d.ts +0 -2
- package/dist/system/index.d.ts.map +0 -1
- package/dist/system/index.js +0 -2
package/dist/date/date.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.cjs","names":[],"sources":["../../src/date/date.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"date.cjs","names":[],"sources":["../../src/date/date.ts"],"sourcesContent":["import { Temporal } from '@vielzeug/tempo';\n\nimport { int } from '../_helpers/int';\nimport type { IllusionistContext } from '../types';\n\ntype DateOptions = {\n years?: number;\n ref?: Temporal.ZonedDateTime;\n};\n\nfunction resolveRef(ref?: Temporal.ZonedDateTime): Temporal.ZonedDateTime {\n return ref ?? Temporal.Now.zonedDateTimeISO('UTC');\n}\n\n/**\n * Generates a past date within the given number of years from `ref` (default: now).\n */\nexport function past(ctx: IllusionistContext, options?: DateOptions): Temporal.ZonedDateTime {\n const ref = resolveRef(options?.ref);\n const years = options?.years ?? 1;\n const maxSeconds = years * 365 * 24 * 60 * 60;\n const minSeconds = 1;\n\n return ref.add({ seconds: -int(minSeconds, maxSeconds, ctx.source) });\n}\n\n/**\n * Generates a future date within the given number of years from `ref` (default: now).\n */\nexport function future(ctx: IllusionistContext, options?: DateOptions): Temporal.ZonedDateTime {\n const ref = resolveRef(options?.ref);\n const years = options?.years ?? 1;\n const maxSeconds = years * 365 * 24 * 60 * 60;\n\n return ref.add({ seconds: int(1, maxSeconds, ctx.source) });\n}\n\n/**\n * Generates a recent date within the given number of days from `ref` (default: now).\n */\nexport function recent(\n ctx: IllusionistContext,\n options?: { days?: number; ref?: Temporal.ZonedDateTime },\n): Temporal.ZonedDateTime {\n const ref = resolveRef(options?.ref);\n const days = options?.days ?? 1;\n const maxSeconds = days * 24 * 60 * 60;\n\n return ref.add({ seconds: -int(1, maxSeconds, ctx.source) });\n}\n\n/**\n * Generates a date between `from` and `to`.\n */\nexport function between(\n ctx: IllusionistContext,\n from: Temporal.ZonedDateTime,\n to: Temporal.ZonedDateTime,\n): Temporal.ZonedDateTime {\n const fromNs = from.toInstant().epochNanoseconds;\n const toNs = to.toInstant().epochNanoseconds;\n\n if (fromNs > toNs) {\n return from;\n }\n\n const spanNs = toNs - fromNs;\n const spanSeconds = Number(spanNs / 1_000_000_000n);\n const offsetSeconds = Math.floor(ctx.source.next() * spanSeconds);\n\n return from.add({ seconds: offsetSeconds });\n}\n\n/**\n * Generates a random birthday — a date with a random year (default 18-80 years ago) and random month/day.\n */\nexport function birthday(\n ctx: IllusionistContext,\n options?: { minAge?: number; maxAge?: number; ref?: Temporal.ZonedDateTime },\n): Temporal.PlainDate {\n const ref = resolveRef(options?.ref);\n const minAge = options?.minAge ?? 18;\n const maxAge = options?.maxAge ?? 80;\n const age = int(minAge, maxAge, ctx.source);\n const month = int(1, 12, ctx.source);\n const day = int(1, 28, ctx.source);\n\n return ref.toPlainDate().subtract({ years: age }).with({ day, month });\n}\n\n/**\n * Returns a random weekday name.\n */\nexport function weekday(ctx: IllusionistContext, locale?: string): string {\n const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];\n const loc = locale ?? ctx.locale.code;\n const localized =\n loc === 'de' ? ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag'] : days;\n\n return localized[int(0, 6, ctx.source)]!;\n}\n\n/**\n * Returns a random month name.\n */\nexport function month(ctx: IllusionistContext, locale?: string): string {\n const months = [\n 'January',\n 'February',\n 'March',\n 'April',\n 'May',\n 'June',\n 'July',\n 'August',\n 'September',\n 'October',\n 'November',\n 'December',\n ];\n const loc = locale ?? ctx.locale.code;\n const localized =\n loc === 'de'\n ? [\n 'Januar',\n 'Februar',\n 'März',\n 'April',\n 'Mai',\n 'Juni',\n 'Juli',\n 'August',\n 'September',\n 'Oktober',\n 'November',\n 'Dezember',\n ]\n : months;\n\n return localized[int(0, 11, ctx.source)]!;\n}\n"],"mappings":"8QAUA,SAAS,WAAW,EAAsD,CACxE,OAAO,GAAO,EAAA,SAAS,IAAI,iBAAiB,KAAK,CACnD,CAKA,SAAgB,KAAK,EAAyB,EAA+C,CAC3F,IAAM,EAAM,WAAW,GAAS,GAAG,EAE7B,GADQ,GAAS,OAAS,GACL,IAAM,GAAK,GAAK,GAG3C,OAAO,EAAI,IAAI,CAAE,QAAS,CAAC,EAAA,IAAI,EAAY,EAAY,EAAI,MAAM,CAAE,CAAC,CACtE,CAKA,SAAgB,OAAO,EAAyB,EAA+C,CAC7F,IAAM,EAAM,WAAW,GAAS,GAAG,EAE7B,GADQ,GAAS,OAAS,GACL,IAAM,GAAK,GAAK,GAE3C,OAAO,EAAI,IAAI,CAAE,QAAS,EAAA,IAAI,EAAG,EAAY,EAAI,MAAM,CAAE,CAAC,CAC5D,CAKA,SAAgB,OACd,EACA,EACwB,CACxB,IAAM,EAAM,WAAW,GAAS,GAAG,EAE7B,GADO,GAAS,MAAQ,GACJ,GAAK,GAAK,GAEpC,OAAO,EAAI,IAAI,CAAE,QAAS,CAAC,EAAA,IAAI,EAAG,EAAY,EAAI,MAAM,CAAE,CAAC,CAC7D,CAKA,SAAgB,QACd,EACA,EACA,EACwB,CACxB,IAAM,EAAS,EAAK,UAAU,CAAC,CAAC,iBAC1B,EAAO,EAAG,UAAU,CAAC,CAAC,iBAE5B,GAAI,EAAS,EACX,OAAO,EAGT,IAAM,EAAS,EAAO,EAChB,EAAc,OAAO,EAAS,WAAc,EAC5C,EAAgB,KAAK,MAAM,EAAI,OAAO,KAAK,EAAI,CAAW,EAEhE,OAAO,EAAK,IAAI,CAAE,QAAS,CAAc,CAAC,CAC5C,CAKA,SAAgB,SACd,EACA,EACoB,CACpB,IAAM,EAAM,WAAW,GAAS,GAAG,EAC7B,EAAS,GAAS,QAAU,GAC5B,EAAS,GAAS,QAAU,GAC5B,EAAM,EAAA,IAAI,EAAQ,EAAQ,EAAI,MAAM,EACpC,EAAQ,EAAA,IAAI,EAAG,GAAI,EAAI,MAAM,EAC7B,EAAM,EAAA,IAAI,EAAG,GAAI,EAAI,MAAM,EAEjC,OAAO,EAAI,YAAY,CAAC,CAAC,SAAS,CAAE,MAAO,CAAI,CAAC,CAAC,CAAC,KAAK,CAAE,MAAK,OAAM,CAAC,CACvE,CAKA,SAAgB,QAAQ,EAAyB,EAAyB,CAMxE,QAJY,GAAU,EAAI,OAAO,QAEvB,KAAO,CAAC,SAAU,WAAY,WAAY,aAAc,UAAW,UAAW,SAAS,EAAI,CAHvF,SAAU,UAAW,YAAa,WAAY,SAAU,WAAY,QAGmB,EAAA,CAEpF,EAAA,IAAI,EAAG,EAAG,EAAI,MAAM,EACvC,CAKA,SAAgB,MAAM,EAAyB,EAAyB,CAkCtE,QAnBY,GAAU,EAAI,OAAO,QAEvB,KACJ,CACE,SACA,UACA,OACA,QACA,MACA,OACA,OACA,SACA,YACA,UACA,WACA,UACF,EACA,CA9BJ,UACA,WACA,QACA,QACA,MACA,OACA,OACA,SACA,YACA,UACA,WACA,UAmBI,EAAA,CAEW,EAAA,IAAI,EAAG,GAAI,EAAI,MAAM,EACxC"}
|
package/dist/date/date.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/date/date.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/date/date.ts"],"names":[],"mappings":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C,GAAG,EAAE,kBAAkB,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAmCtE"}
|
package/dist/date/date.js
CHANGED
|
@@ -1,93 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { int as t } from "../_helpers/int.js";
|
|
3
|
-
import { Temporal as n, shift as r } from "@vielzeug/tempo";
|
|
4
|
-
//#region src/date/date.ts
|
|
5
|
-
var i = /* @__PURE__ */ e({
|
|
6
|
-
between: () => l,
|
|
7
|
-
birthday: () => u,
|
|
8
|
-
future: () => s,
|
|
9
|
-
month: () => f,
|
|
10
|
-
past: () => o,
|
|
11
|
-
recent: () => c,
|
|
12
|
-
weekday: () => d
|
|
13
|
-
});
|
|
14
|
-
function a(e) {
|
|
15
|
-
return e ?? n.Now.zonedDateTimeISO("UTC");
|
|
16
|
-
}
|
|
17
|
-
function o(e, n) {
|
|
18
|
-
let i = a(n?.ref), o = (n?.years ?? 1) * 365 * 24 * 60 * 60;
|
|
19
|
-
return r(i, { seconds: -t(1, o, e.source) });
|
|
20
|
-
}
|
|
21
|
-
function s(e, n) {
|
|
22
|
-
let i = a(n?.ref), o = (n?.years ?? 1) * 365 * 24 * 60 * 60;
|
|
23
|
-
return r(i, { seconds: t(1, o, e.source) });
|
|
24
|
-
}
|
|
25
|
-
function c(e, n) {
|
|
26
|
-
let i = a(n?.ref), o = (n?.days ?? 1) * 24 * 60 * 60;
|
|
27
|
-
return r(i, { seconds: -t(1, o, e.source) });
|
|
28
|
-
}
|
|
29
|
-
function l(e, t, n) {
|
|
30
|
-
let r = t.toInstant().epochNanoseconds, i = n.toInstant().epochNanoseconds;
|
|
31
|
-
if (r > i) return t;
|
|
32
|
-
let a = i - r, o = Number(a / 1000000000n), s = Math.floor(e.source.next() * o);
|
|
33
|
-
return t.add({ seconds: s });
|
|
34
|
-
}
|
|
35
|
-
function u(e, n) {
|
|
36
|
-
let r = a(n?.ref), i = n?.minAge ?? 18, o = n?.maxAge ?? 80, s = t(i, o, e.source), c = t(1, 12, e.source), l = t(1, 28, e.source);
|
|
37
|
-
return r.toPlainDate().subtract({ years: s }).with({
|
|
38
|
-
day: l,
|
|
39
|
-
month: c
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
function d(e, n) {
|
|
43
|
-
return ((n ?? e.locale.code) === "de" ? [
|
|
44
|
-
"Montag",
|
|
45
|
-
"Dienstag",
|
|
46
|
-
"Mittwoch",
|
|
47
|
-
"Donnerstag",
|
|
48
|
-
"Freitag",
|
|
49
|
-
"Samstag",
|
|
50
|
-
"Sonntag"
|
|
51
|
-
] : [
|
|
52
|
-
"Monday",
|
|
53
|
-
"Tuesday",
|
|
54
|
-
"Wednesday",
|
|
55
|
-
"Thursday",
|
|
56
|
-
"Friday",
|
|
57
|
-
"Saturday",
|
|
58
|
-
"Sunday"
|
|
59
|
-
])[t(0, 6, e.source)];
|
|
60
|
-
}
|
|
61
|
-
function f(e, n) {
|
|
62
|
-
return ((n ?? e.locale.code) === "de" ? [
|
|
63
|
-
"Januar",
|
|
64
|
-
"Februar",
|
|
65
|
-
"März",
|
|
66
|
-
"April",
|
|
67
|
-
"Mai",
|
|
68
|
-
"Juni",
|
|
69
|
-
"Juli",
|
|
70
|
-
"August",
|
|
71
|
-
"September",
|
|
72
|
-
"Oktober",
|
|
73
|
-
"November",
|
|
74
|
-
"Dezember"
|
|
75
|
-
] : [
|
|
76
|
-
"January",
|
|
77
|
-
"February",
|
|
78
|
-
"March",
|
|
79
|
-
"April",
|
|
80
|
-
"May",
|
|
81
|
-
"June",
|
|
82
|
-
"July",
|
|
83
|
-
"August",
|
|
84
|
-
"September",
|
|
85
|
-
"October",
|
|
86
|
-
"November",
|
|
87
|
-
"December"
|
|
88
|
-
])[t(0, 11, e.source)];
|
|
89
|
-
}
|
|
90
|
-
//#endregion
|
|
91
|
-
export { l as between, u as birthday, i as date_exports, s as future, f as month, o as past, c as recent, d as weekday };
|
|
92
|
-
|
|
1
|
+
import{__exportAll as e}from"../_virtual/_rolldown/runtime.js";import{int as t}from"../_helpers/int.js";import{Temporal as n}from"@vielzeug/tempo";var r=e({between:()=>between,birthday:()=>birthday,future:()=>future,month:()=>month,past:()=>past,recent:()=>recent,weekday:()=>weekday});function resolveRef(e){return e??n.Now.zonedDateTimeISO(`UTC`)}function past(e,n){let r=resolveRef(n?.ref),i=(n?.years??1)*365*24*60*60;return r.add({seconds:-t(1,i,e.source)})}function future(e,n){let r=resolveRef(n?.ref),i=(n?.years??1)*365*24*60*60;return r.add({seconds:t(1,i,e.source)})}function recent(e,n){let r=resolveRef(n?.ref),i=(n?.days??1)*24*60*60;return r.add({seconds:-t(1,i,e.source)})}function between(e,t,n){let r=t.toInstant().epochNanoseconds,i=n.toInstant().epochNanoseconds;if(r>i)return t;let a=i-r,o=Number(a/1000000000n),s=Math.floor(e.source.next()*o);return t.add({seconds:s})}function birthday(e,n){let r=resolveRef(n?.ref),i=n?.minAge??18,a=n?.maxAge??80,o=t(i,a,e.source),s=t(1,12,e.source),c=t(1,28,e.source);return r.toPlainDate().subtract({years:o}).with({day:c,month:s})}function weekday(e,n){return((n??e.locale.code)===`de`?[`Montag`,`Dienstag`,`Mittwoch`,`Donnerstag`,`Freitag`,`Samstag`,`Sonntag`]:[`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`,`Sunday`])[t(0,6,e.source)]}function month(e,n){return((n??e.locale.code)===`de`?[`Januar`,`Februar`,`März`,`April`,`Mai`,`Juni`,`Juli`,`August`,`September`,`Oktober`,`November`,`Dezember`]:[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`])[t(0,11,e.source)]}export{between,birthday,r as date_exports,future,month,past,recent,weekday};
|
|
93
2
|
//# sourceMappingURL=date.js.map
|
package/dist/date/date.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.js","names":[],"sources":["../../src/date/date.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"date.js","names":[],"sources":["../../src/date/date.ts"],"sourcesContent":["import { Temporal } from '@vielzeug/tempo';\n\nimport { int } from '../_helpers/int';\nimport type { IllusionistContext } from '../types';\n\ntype DateOptions = {\n years?: number;\n ref?: Temporal.ZonedDateTime;\n};\n\nfunction resolveRef(ref?: Temporal.ZonedDateTime): Temporal.ZonedDateTime {\n return ref ?? Temporal.Now.zonedDateTimeISO('UTC');\n}\n\n/**\n * Generates a past date within the given number of years from `ref` (default: now).\n */\nexport function past(ctx: IllusionistContext, options?: DateOptions): Temporal.ZonedDateTime {\n const ref = resolveRef(options?.ref);\n const years = options?.years ?? 1;\n const maxSeconds = years * 365 * 24 * 60 * 60;\n const minSeconds = 1;\n\n return ref.add({ seconds: -int(minSeconds, maxSeconds, ctx.source) });\n}\n\n/**\n * Generates a future date within the given number of years from `ref` (default: now).\n */\nexport function future(ctx: IllusionistContext, options?: DateOptions): Temporal.ZonedDateTime {\n const ref = resolveRef(options?.ref);\n const years = options?.years ?? 1;\n const maxSeconds = years * 365 * 24 * 60 * 60;\n\n return ref.add({ seconds: int(1, maxSeconds, ctx.source) });\n}\n\n/**\n * Generates a recent date within the given number of days from `ref` (default: now).\n */\nexport function recent(\n ctx: IllusionistContext,\n options?: { days?: number; ref?: Temporal.ZonedDateTime },\n): Temporal.ZonedDateTime {\n const ref = resolveRef(options?.ref);\n const days = options?.days ?? 1;\n const maxSeconds = days * 24 * 60 * 60;\n\n return ref.add({ seconds: -int(1, maxSeconds, ctx.source) });\n}\n\n/**\n * Generates a date between `from` and `to`.\n */\nexport function between(\n ctx: IllusionistContext,\n from: Temporal.ZonedDateTime,\n to: Temporal.ZonedDateTime,\n): Temporal.ZonedDateTime {\n const fromNs = from.toInstant().epochNanoseconds;\n const toNs = to.toInstant().epochNanoseconds;\n\n if (fromNs > toNs) {\n return from;\n }\n\n const spanNs = toNs - fromNs;\n const spanSeconds = Number(spanNs / 1_000_000_000n);\n const offsetSeconds = Math.floor(ctx.source.next() * spanSeconds);\n\n return from.add({ seconds: offsetSeconds });\n}\n\n/**\n * Generates a random birthday — a date with a random year (default 18-80 years ago) and random month/day.\n */\nexport function birthday(\n ctx: IllusionistContext,\n options?: { minAge?: number; maxAge?: number; ref?: Temporal.ZonedDateTime },\n): Temporal.PlainDate {\n const ref = resolveRef(options?.ref);\n const minAge = options?.minAge ?? 18;\n const maxAge = options?.maxAge ?? 80;\n const age = int(minAge, maxAge, ctx.source);\n const month = int(1, 12, ctx.source);\n const day = int(1, 28, ctx.source);\n\n return ref.toPlainDate().subtract({ years: age }).with({ day, month });\n}\n\n/**\n * Returns a random weekday name.\n */\nexport function weekday(ctx: IllusionistContext, locale?: string): string {\n const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];\n const loc = locale ?? ctx.locale.code;\n const localized =\n loc === 'de' ? ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag'] : days;\n\n return localized[int(0, 6, ctx.source)]!;\n}\n\n/**\n * Returns a random month name.\n */\nexport function month(ctx: IllusionistContext, locale?: string): string {\n const months = [\n 'January',\n 'February',\n 'March',\n 'April',\n 'May',\n 'June',\n 'July',\n 'August',\n 'September',\n 'October',\n 'November',\n 'December',\n ];\n const loc = locale ?? ctx.locale.code;\n const localized =\n loc === 'de'\n ? [\n 'Januar',\n 'Februar',\n 'März',\n 'April',\n 'Mai',\n 'Juni',\n 'Juli',\n 'August',\n 'September',\n 'Oktober',\n 'November',\n 'Dezember',\n ]\n : months;\n\n return localized[int(0, 11, ctx.source)]!;\n}\n"],"mappings":"8RAUA,SAAS,WAAW,EAAsD,CACxE,OAAO,GAAO,EAAS,IAAI,iBAAiB,KAAK,CACnD,CAKA,SAAgB,KAAK,EAAyB,EAA+C,CAC3F,IAAM,EAAM,WAAW,GAAS,GAAG,EAE7B,GADQ,GAAS,OAAS,GACL,IAAM,GAAK,GAAK,GAG3C,OAAO,EAAI,IAAI,CAAE,QAAS,CAAC,EAAI,EAAY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AW,UAAW,SAAS,EAAI,CAHvF,SAAU,UAAW,YAAa,WAAY,SAAU,WAAY,QAGmB,EAAA,CAEpF,EAAI,EAAG,EAAG,EAAI,MAAM,EACvC,CAKA,SAAgB,MAAM,EAAyB,EAAyB,CAkCtE,QAnBY,GAAU,EAAI,OAAO,QAEvB,KACJ,CACE,SACA,UACA,OACA,QACA,MACA,OACA,OACA,SACA,YACA,UACA,WACA,UACF,EACA,CA9BJ,UACA,WACA,QACA,QACA,MACA,OACA,OACA,SACA,YACA,UACA,WACA,UAmBI,EAAA,CAEW,EAAI,EAAG,GAAI,EAAI,MAAM,EACxC"}
|
package/dist/errors.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var IllusionistError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},IllusionistSeedError=class extends IllusionistError{};exports.IllusionistError=IllusionistError,exports.IllusionistSeedError=IllusionistSeedError;
|
|
2
2
|
//# sourceMappingURL=errors.cjs.map
|
package/dist/errors.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all illusionist errors. Use `instanceof IllusionistError` to catch any illusionist-originated error. */\nexport class IllusionistError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when the seeded random source produces an invalid value. */\nexport class IllusionistSeedError extends IllusionistError {}\n"],"mappings":"AACA,IAAa,
|
|
1
|
+
{"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all illusionist errors. Use `instanceof IllusionistError` to catch any illusionist-originated error. */\nexport class IllusionistError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when the seeded random source produces an invalid value. */\nexport class IllusionistSeedError extends IllusionistError {}\n"],"mappings":"AACA,IAAa,iBAAb,cAAsC,KAAM,CAC1C,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,qBAAb,cAA0C,gBAAiB,CAAC"}
|
package/dist/errors.js
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
var e = class extends Error {
|
|
3
|
-
constructor(e, t) {
|
|
4
|
-
super(e, t), this.name = new.target.name, Object.setPrototypeOf(this, new.target.prototype);
|
|
5
|
-
}
|
|
6
|
-
}, t = class extends e {};
|
|
7
|
-
//#endregion
|
|
8
|
-
export { e as IllusionistError, t as IllusionistSeedError };
|
|
9
|
-
|
|
1
|
+
var IllusionistError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},IllusionistSeedError=class extends IllusionistError{};export{IllusionistError,IllusionistSeedError};
|
|
10
2
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all illusionist errors. Use `instanceof IllusionistError` to catch any illusionist-originated error. */\nexport class IllusionistError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when the seeded random source produces an invalid value. */\nexport class IllusionistSeedError extends IllusionistError {}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all illusionist errors. Use `instanceof IllusionistError` to catch any illusionist-originated error. */\nexport class IllusionistError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when the seeded random source produces an invalid value. */\nexport class IllusionistSeedError extends IllusionistError {}\n"],"mappings":"AACA,IAAa,iBAAb,cAAsC,KAAM,CAC1C,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,qBAAb,cAA0C,gBAAiB,CAAC"}
|
package/dist/factory.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./commerce/commerce.cjs"),t=require("./date/date.cjs"),n=require("./finance/finance.cjs"),r=require("./internet/internet.cjs"),i=require("./location/location.cjs"),a=require("./lorem/lorem.cjs"),o=require("./person/person.cjs"),s=require("./seed/create-seed.cjs"),c=require("./system/system.cjs");function
|
|
1
|
+
const e=require("./commerce/commerce.cjs"),t=require("./date/date.cjs"),n=require("./finance/finance.cjs"),r=require("./internet/internet.cjs"),i=require("./location/location.cjs"),a=require("./lorem/lorem.cjs"),o=require("./person/person.cjs"),s=require("./seed/create-seed.cjs"),c=require("./system/system.cjs");function createIllusion(l){let{locale:u,seed:d}=l,f={locale:u,source:s.createSeed(d)},bind=e=>{let t={};for(let[n,r]of Object.entries(e))typeof r==`function`&&(t[n]=(...e)=>r(f,...e));return t};return{commerce:bind(e.commerce_exports),date:bind(t.date_exports),finance:bind(n.finance_exports),internet:bind(r.internet_exports),locale:u,location:bind(i.location_exports),lorem:bind(a.lorem_exports),person:bind(o.person_exports),seed:d,system:bind(c.system_exports)}}exports.createIllusion=createIllusion;
|
|
2
2
|
//# sourceMappingURL=factory.cjs.map
|
package/dist/factory.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.cjs","names":[],"sources":["../src/factory.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"factory.cjs","names":[],"sources":["../src/factory.ts"],"sourcesContent":["import * as commerceApi from './commerce/commerce';\nimport * as dateApi from './date/date';\nimport * as financeApi from './finance/finance';\nimport * as internetApi from './internet/internet';\nimport * as locationApi from './location/location';\nimport * as loremApi from './lorem/lorem';\nimport * as personApi from './person/person';\nimport { createSeed } from './seed/create-seed';\nimport * as systemApi from './system/system';\nimport type { IllusionistContext, IllusionistLocale, IllusionistOptions, RandomSource } from './types';\n\nexport type { IllusionistOptions } from './types';\n\n/** Strips the leading `IllusionistContext` parameter from a function type. */\ntype Bound<F> = F extends (ctx: IllusionistContext, ...args: infer A) => infer R ? (...args: A) => R : F;\n\n/** Maps a module of `(ctx, ...args) => R` functions to `(...args) => R`. */\ntype BoundApi<T> = { readonly [K in keyof T]: Bound<T[K]> };\n\nexport type Illusionist = {\n readonly person: BoundApi<typeof personApi>;\n readonly internet: BoundApi<typeof internetApi>;\n readonly commerce: BoundApi<typeof commerceApi>;\n readonly date: BoundApi<typeof dateApi>;\n readonly finance: BoundApi<typeof financeApi>;\n readonly location: BoundApi<typeof locationApi>;\n readonly lorem: BoundApi<typeof loremApi>;\n readonly system: BoundApi<typeof systemApi>;\n\n /** The seed used to initialize this instance, or `undefined` for cryptographic randomness. */\n readonly seed: number | string | undefined;\n /** The active locale data. */\n readonly locale: IllusionistLocale;\n};\n\n/**\n * Creates a bound illusionist instance with all categories sharing a single seeded\n * random source and locale.\n *\n * @example\n * ```ts\n * import { en } from '@vielzeug/illusionist/locales';\n *\n * const illusion = createIllusion({ seed: 12345, locale: en });\n *\n * illusion.person.fullName(); // deterministic — same seed → same result\n * illusion.internet.email();\n * illusion.commerce.price();\n * ```\n */\nexport function createIllusion(options: IllusionistOptions): Illusionist {\n const { locale, seed } = options;\n const source: RandomSource = createSeed(seed);\n\n const ctx: IllusionistContext = { locale, source };\n\n const bind = <T extends Record<string, (ctx: IllusionistContext, ...args: never[]) => unknown>>(\n api: T,\n ): BoundApi<T> => {\n const bound = {} as Record<string, (...args: never[]) => unknown>;\n\n for (const [key, fn] of Object.entries(api)) {\n if (typeof fn === 'function') {\n bound[key] = (...args: never[]) => (fn as (ctx: IllusionistContext, ...args: never[]) => unknown)(ctx, ...args);\n }\n }\n\n return bound as unknown as BoundApi<T>;\n };\n\n return {\n commerce: bind(commerceApi),\n date: bind(dateApi),\n finance: bind(financeApi),\n internet: bind(internetApi),\n locale,\n location: bind(locationApi),\n lorem: bind(loremApi),\n person: bind(personApi),\n seed,\n system: bind(systemApi),\n };\n}\n"],"mappings":"0TAkDA,SAAgB,eAAe,EAA0C,CACvE,GAAM,CAAE,SAAQ,QAAS,EAGnB,EAA0B,CAAE,SAAQ,OAFb,EAAA,WAAW,CAEE,CAAO,EAE3C,KACJ,GACgB,CAChB,IAAM,EAAQ,CAAC,EAEf,IAAK,GAAM,CAAC,EAAK,KAAO,OAAO,QAAQ,CAAG,EACpC,OAAO,GAAO,aAChB,EAAM,IAAQ,GAAG,IAAmB,EAA8D,EAAK,GAAG,CAAI,GAIlH,OAAO,CACT,EAEA,MAAO,CACL,SAAU,KAAK,EAAA,gBAAW,EAC1B,KAAM,KAAK,EAAA,YAAO,EAClB,QAAS,KAAK,EAAA,eAAU,EACxB,SAAU,KAAK,EAAA,gBAAW,EAC1B,SACA,SAAU,KAAK,EAAA,gBAAW,EAC1B,MAAO,KAAK,EAAA,aAAQ,EACpB,OAAQ,KAAK,EAAA,cAAS,EACtB,OACA,OAAQ,KAAK,EAAA,cAAS,CACxB,CACF"}
|
package/dist/factory.d.ts
CHANGED
|
@@ -27,10 +27,6 @@ export type Illusionist = {
|
|
|
27
27
|
readonly seed: number | string | undefined;
|
|
28
28
|
/** The active locale data. */
|
|
29
29
|
readonly locale: IllusionistLocale;
|
|
30
|
-
dispose(): void;
|
|
31
|
-
readonly disposed: boolean;
|
|
32
|
-
readonly disposalSignal: AbortSignal;
|
|
33
|
-
[Symbol.dispose](): void;
|
|
34
30
|
};
|
|
35
31
|
/**
|
|
36
32
|
* Creates a bound illusionist instance with all categories sharing a single seeded
|
|
@@ -45,7 +41,6 @@ export type Illusionist = {
|
|
|
45
41
|
* illusion.person.fullName(); // deterministic — same seed → same result
|
|
46
42
|
* illusion.internet.email();
|
|
47
43
|
* illusion.commerce.price();
|
|
48
|
-
* illusion.dispose(); // [Symbol.dispose]() also works
|
|
49
44
|
* ```
|
|
50
45
|
*/
|
|
51
46
|
export declare function createIllusion(options: IllusionistOptions): Illusionist;
|
package/dist/factory.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,OAAO,MAAM,aAAa,CAAC;AACvC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,WAAW,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,WAAW,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAE7C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,kBAAkB,EAAgB,MAAM,SAAS,CAAC;AAEvG,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,8EAA8E;AAC9E,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,kBAAkB,EAAE,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAEzG,4EAA4E;AAC5E,KAAK,QAAQ,CAAC,CAAC,IAAI;IAAE,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC;AAE5D,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,OAAO,SAAS,CAAC,CAAC;IAC5C,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,OAAO,WAAW,CAAC,CAAC;IAChD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,OAAO,WAAW,CAAC,CAAC;IAChD,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,OAAO,OAAO,CAAC,CAAC;IACxC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,UAAU,CAAC,CAAC;IAC9C,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,OAAO,WAAW,CAAC,CAAC;IAChD,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,OAAO,QAAQ,CAAC,CAAC;IAC1C,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,OAAO,SAAS,CAAC,CAAC;IAE5C,8FAA8F;IAC9F,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAC3C,8BAA8B;IAC9B,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;CACpC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,CAgCvE"}
|
package/dist/factory.js
CHANGED
|
@@ -1,46 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { date_exports as t } from "./date/date.js";
|
|
3
|
-
import { finance_exports as n } from "./finance/finance.js";
|
|
4
|
-
import { internet_exports as r } from "./internet/internet.js";
|
|
5
|
-
import { location_exports as i } from "./location/location.js";
|
|
6
|
-
import { lorem_exports as a } from "./lorem/lorem.js";
|
|
7
|
-
import { person_exports as o } from "./person/person.js";
|
|
8
|
-
import { createSeed as s } from "./seed/create-seed.js";
|
|
9
|
-
import { system_exports as c } from "./system/system.js";
|
|
10
|
-
//#region src/factory.ts
|
|
11
|
-
function l(l) {
|
|
12
|
-
let { locale: u, seed: d } = l, f = s(d), p = new AbortController(), m = !1, h = {
|
|
13
|
-
locale: u,
|
|
14
|
-
source: f
|
|
15
|
-
}, g = (e) => {
|
|
16
|
-
let t = {};
|
|
17
|
-
for (let [n, r] of Object.entries(e)) typeof r == "function" && (t[n] = (...e) => r(h, ...e));
|
|
18
|
-
return t;
|
|
19
|
-
}, _ = () => {
|
|
20
|
-
m || (m = !0, p.abort());
|
|
21
|
-
};
|
|
22
|
-
return {
|
|
23
|
-
commerce: g(e),
|
|
24
|
-
date: g(t),
|
|
25
|
-
get disposalSignal() {
|
|
26
|
-
return p.signal;
|
|
27
|
-
},
|
|
28
|
-
dispose: _,
|
|
29
|
-
get disposed() {
|
|
30
|
-
return m;
|
|
31
|
-
},
|
|
32
|
-
finance: g(n),
|
|
33
|
-
internet: g(r),
|
|
34
|
-
locale: u,
|
|
35
|
-
location: g(i),
|
|
36
|
-
lorem: g(a),
|
|
37
|
-
person: g(o),
|
|
38
|
-
seed: d,
|
|
39
|
-
system: g(c),
|
|
40
|
-
[Symbol.dispose]: _
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
//#endregion
|
|
44
|
-
export { l as createIllusion };
|
|
45
|
-
|
|
1
|
+
import{commerce_exports as e}from"./commerce/commerce.js";import{date_exports as t}from"./date/date.js";import{finance_exports as n}from"./finance/finance.js";import{internet_exports as r}from"./internet/internet.js";import{location_exports as i}from"./location/location.js";import{lorem_exports as a}from"./lorem/lorem.js";import{person_exports as o}from"./person/person.js";import{createSeed as s}from"./seed/create-seed.js";import{system_exports as c}from"./system/system.js";function createIllusion(l){let{locale:u,seed:d}=l,f={locale:u,source:s(d)},bind=e=>{let t={};for(let[n,r]of Object.entries(e))typeof r==`function`&&(t[n]=(...e)=>r(f,...e));return t};return{commerce:bind(e),date:bind(t),finance:bind(n),internet:bind(r),locale:u,location:bind(i),lorem:bind(a),person:bind(o),seed:d,system:bind(c)}}export{createIllusion};
|
|
46
2
|
//# sourceMappingURL=factory.js.map
|
package/dist/factory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","names":[],"sources":["../src/factory.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"factory.js","names":[],"sources":["../src/factory.ts"],"sourcesContent":["import * as commerceApi from './commerce/commerce';\nimport * as dateApi from './date/date';\nimport * as financeApi from './finance/finance';\nimport * as internetApi from './internet/internet';\nimport * as locationApi from './location/location';\nimport * as loremApi from './lorem/lorem';\nimport * as personApi from './person/person';\nimport { createSeed } from './seed/create-seed';\nimport * as systemApi from './system/system';\nimport type { IllusionistContext, IllusionistLocale, IllusionistOptions, RandomSource } from './types';\n\nexport type { IllusionistOptions } from './types';\n\n/** Strips the leading `IllusionistContext` parameter from a function type. */\ntype Bound<F> = F extends (ctx: IllusionistContext, ...args: infer A) => infer R ? (...args: A) => R : F;\n\n/** Maps a module of `(ctx, ...args) => R` functions to `(...args) => R`. */\ntype BoundApi<T> = { readonly [K in keyof T]: Bound<T[K]> };\n\nexport type Illusionist = {\n readonly person: BoundApi<typeof personApi>;\n readonly internet: BoundApi<typeof internetApi>;\n readonly commerce: BoundApi<typeof commerceApi>;\n readonly date: BoundApi<typeof dateApi>;\n readonly finance: BoundApi<typeof financeApi>;\n readonly location: BoundApi<typeof locationApi>;\n readonly lorem: BoundApi<typeof loremApi>;\n readonly system: BoundApi<typeof systemApi>;\n\n /** The seed used to initialize this instance, or `undefined` for cryptographic randomness. */\n readonly seed: number | string | undefined;\n /** The active locale data. */\n readonly locale: IllusionistLocale;\n};\n\n/**\n * Creates a bound illusionist instance with all categories sharing a single seeded\n * random source and locale.\n *\n * @example\n * ```ts\n * import { en } from '@vielzeug/illusionist/locales';\n *\n * const illusion = createIllusion({ seed: 12345, locale: en });\n *\n * illusion.person.fullName(); // deterministic — same seed → same result\n * illusion.internet.email();\n * illusion.commerce.price();\n * ```\n */\nexport function createIllusion(options: IllusionistOptions): Illusionist {\n const { locale, seed } = options;\n const source: RandomSource = createSeed(seed);\n\n const ctx: IllusionistContext = { locale, source };\n\n const bind = <T extends Record<string, (ctx: IllusionistContext, ...args: never[]) => unknown>>(\n api: T,\n ): BoundApi<T> => {\n const bound = {} as Record<string, (...args: never[]) => unknown>;\n\n for (const [key, fn] of Object.entries(api)) {\n if (typeof fn === 'function') {\n bound[key] = (...args: never[]) => (fn as (ctx: IllusionistContext, ...args: never[]) => unknown)(ctx, ...args);\n }\n }\n\n return bound as unknown as BoundApi<T>;\n };\n\n return {\n commerce: bind(commerceApi),\n date: bind(dateApi),\n finance: bind(financeApi),\n internet: bind(internetApi),\n locale,\n location: bind(locationApi),\n lorem: bind(loremApi),\n person: bind(personApi),\n seed,\n system: bind(systemApi),\n };\n}\n"],"mappings":"+dAkDA,SAAgB,eAAe,EAA0C,CACvE,GAAM,CAAE,SAAQ,QAAS,EAGnB,EAA0B,CAAE,SAAQ,OAFb,EAAW,CAEE,CAAO,EAE3C,KACJ,GACgB,CAChB,IAAM,EAAQ,CAAC,EAEf,IAAK,GAAM,CAAC,EAAK,KAAO,OAAO,QAAQ,CAAG,EACpC,OAAO,GAAO,aAChB,EAAM,IAAQ,GAAG,IAAmB,EAA8D,EAAK,GAAG,CAAI,GAIlH,OAAO,CACT,EAEA,MAAO,CACL,SAAU,KAAK,CAAW,EAC1B,KAAM,KAAK,CAAO,EAClB,QAAS,KAAK,CAAU,EACxB,SAAU,KAAK,CAAW,EAC1B,SACA,SAAU,KAAK,CAAW,EAC1B,MAAO,KAAK,CAAQ,EACpB,OAAQ,KAAK,CAAS,EACtB,OACA,OAAQ,KAAK,CAAS,CACxB,CACF"}
|
package/dist/finance/data.js
CHANGED
|
@@ -1,60 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
var e = {
|
|
3
|
-
banks: [
|
|
4
|
-
"Deutsche Bank",
|
|
5
|
-
"Commerzbank",
|
|
6
|
-
"Sparkasse",
|
|
7
|
-
"Barclays",
|
|
8
|
-
"HSBC",
|
|
9
|
-
"BNP Paribas",
|
|
10
|
-
"Santander",
|
|
11
|
-
"ING",
|
|
12
|
-
"UniCredit",
|
|
13
|
-
"UBS"
|
|
14
|
-
],
|
|
15
|
-
creditCardIins: {
|
|
16
|
-
amex: ["34", "37"],
|
|
17
|
-
mastercard: [
|
|
18
|
-
"51",
|
|
19
|
-
"52",
|
|
20
|
-
"53",
|
|
21
|
-
"54",
|
|
22
|
-
"55"
|
|
23
|
-
],
|
|
24
|
-
visa: ["4"]
|
|
25
|
-
},
|
|
26
|
-
ibanCountryCodes: {
|
|
27
|
-
AT: "AT",
|
|
28
|
-
BE: "BE",
|
|
29
|
-
CH: "CH",
|
|
30
|
-
DE: "DE",
|
|
31
|
-
ES: "ES",
|
|
32
|
-
FR: "FR",
|
|
33
|
-
GB: "GB",
|
|
34
|
-
IT: "IT",
|
|
35
|
-
NL: "NL"
|
|
36
|
-
},
|
|
37
|
-
ibanLengths: {
|
|
38
|
-
AT: 20,
|
|
39
|
-
BE: 16,
|
|
40
|
-
CH: 21,
|
|
41
|
-
DE: 22,
|
|
42
|
-
ES: 24,
|
|
43
|
-
FR: 27,
|
|
44
|
-
GB: 22,
|
|
45
|
-
IT: 27,
|
|
46
|
-
NL: 18
|
|
47
|
-
},
|
|
48
|
-
transactionTypes: [
|
|
49
|
-
"payment",
|
|
50
|
-
"transfer",
|
|
51
|
-
"deposit",
|
|
52
|
-
"withdrawal",
|
|
53
|
-
"refund",
|
|
54
|
-
"fee"
|
|
55
|
-
]
|
|
56
|
-
};
|
|
57
|
-
//#endregion
|
|
58
|
-
export { e as FINANCE_DATA };
|
|
59
|
-
|
|
1
|
+
var e={banks:[`Deutsche Bank`,`Commerzbank`,`Sparkasse`,`Barclays`,`HSBC`,`BNP Paribas`,`Santander`,`ING`,`UniCredit`,`UBS`],creditCardIins:{amex:[`34`,`37`],mastercard:[`51`,`52`,`53`,`54`,`55`],visa:[`4`]},ibanCountryCodes:{AT:`AT`,BE:`BE`,CH:`CH`,DE:`DE`,ES:`ES`,FR:`FR`,GB:`GB`,IT:`IT`,NL:`NL`},ibanLengths:{AT:20,BE:16,CH:21,DE:22,ES:24,FR:27,GB:22,IT:27,NL:18},transactionTypes:[`payment`,`transfer`,`deposit`,`withdrawal`,`refund`,`fee`]};export{e as FINANCE_DATA};
|
|
60
2
|
//# sourceMappingURL=data.js.map
|
package/dist/finance/data.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.js","names":[],"sources":["../../src/finance/data.ts"],"sourcesContent":["export const FINANCE_DATA = {\n banks: [\n 'Deutsche Bank',\n 'Commerzbank',\n 'Sparkasse',\n 'Barclays',\n 'HSBC',\n 'BNP Paribas',\n 'Santander',\n 'ING',\n 'UniCredit',\n 'UBS',\n ],\n creditCardIins: { amex: ['34', '37'], mastercard: ['51', '52', '53', '54', '55'], visa: ['4'] },\n ibanCountryCodes: { AT: 'AT', BE: 'BE', CH: 'CH', DE: 'DE', ES: 'ES', FR: 'FR', GB: 'GB', IT: 'IT', NL: 'NL' },\n ibanLengths: { AT: 20, BE: 16, CH: 21, DE: 22, ES: 24, FR: 27, GB: 22, IT: 27, NL: 18 },\n transactionTypes: ['payment', 'transfer', 'deposit', 'withdrawal', 'refund', 'fee'],\n} as const;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"data.js","names":[],"sources":["../../src/finance/data.ts"],"sourcesContent":["export const FINANCE_DATA = {\n banks: [\n 'Deutsche Bank',\n 'Commerzbank',\n 'Sparkasse',\n 'Barclays',\n 'HSBC',\n 'BNP Paribas',\n 'Santander',\n 'ING',\n 'UniCredit',\n 'UBS',\n ],\n creditCardIins: { amex: ['34', '37'], mastercard: ['51', '52', '53', '54', '55'], visa: ['4'] },\n ibanCountryCodes: { AT: 'AT', BE: 'BE', CH: 'CH', DE: 'DE', ES: 'ES', FR: 'FR', GB: 'GB', IT: 'IT', NL: 'NL' },\n ibanLengths: { AT: 20, BE: 16, CH: 21, DE: 22, ES: 24, FR: 27, GB: 22, IT: 27, NL: 18 },\n transactionTypes: ['payment', 'transfer', 'deposit', 'withdrawal', 'refund', 'fee'],\n} as const;\n"],"mappings":"AAAA,IAAa,EAAe,CAC1B,MAAO,CACL,gBACA,cACA,YACA,WACA,OACA,cACA,YACA,MACA,YACA,KACF,EACA,eAAgB,CAAE,KAAM,CAAC,KAAM,IAAI,EAAG,WAAY,CAAC,KAAM,KAAM,KAAM,KAAM,IAAI,EAAG,KAAM,CAAC,GAAG,CAAE,EAC9F,iBAAkB,CAAE,GAAI,KAAM,GAAI,KAAM,GAAI,KAAM,GAAI,KAAM,GAAI,KAAM,GAAI,KAAM,GAAI,KAAM,GAAI,KAAM,GAAI,IAAK,EAC7G,YAAa,CAAE,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,EAAG,EACtF,iBAAkB,CAAC,UAAW,WAAY,UAAW,aAAc,SAAU,KAAK,CACpF"}
|
package/dist/finance/finance.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../_virtual/_rolldown/runtime.cjs"),t=require("../_helpers/float.cjs"),n=require("../_helpers/int.cjs"),r=require("../_helpers/string.cjs"),i=require("./data.cjs");let a=require("@vielzeug/coins");var o=e.__exportAll({amount:()=>
|
|
1
|
+
const e=require("../_virtual/_rolldown/runtime.cjs"),t=require("../_helpers/float.cjs"),n=require("../_helpers/int.cjs"),r=require("../_helpers/string.cjs"),i=require("./data.cjs");let a=require("@vielzeug/coins");var o=e.__exportAll({amount:()=>amount,bank:()=>bank,bic:()=>bic,bitcoinAddress:()=>bitcoinAddress,creditCardCVV:()=>creditCardCVV,creditCardNumber:()=>creditCardNumber,ethereumAddress:()=>ethereumAddress,iban:()=>iban,transactionType:()=>transactionType}),s={EUR:a.EUR,GBP:a.GBP,USD:a.USD},c=[`visa`,`mastercard`,`amex`],l=Object.keys(i.FINANCE_DATA.ibanCountryCodes),u=`ABCDEFGHIJKLMNOPQRSTUVWXYZ`.split(``);function letters(e,t){let n=[];for(let i=0;i<e;i++)n.push(r.pick(u,t.source));return n.join(``)}function mod97(e){let t=0;for(let n of e)t=(t*10+Number(n))%97;return t}function ibanCheckDigits(e,t){return(98-mod97(`${t}${e}00`.replace(/[A-Z]/g,e=>String(e.charCodeAt(0)-55)))).toString().padStart(2,`0`)}function luhnCheckDigit(e){let t=e.split(``).map(Number),n=0,r=!0;for(let e=t.length-1;e>=0;e--){let i=t[e];r&&(i*=2,i>9&&(i-=9)),n+=i,r=!r}let i=(10-n%10)%10;return String(i)}function amount(e,n={}){let r=n.min??100,i=n.max??1e4,o=n.currency??`USD`,c=t.floatFixed(r,i,2,e.source);return(0,a.money)(c.toFixed(2),s[o])}function iban(e,t){let n=t??r.pick(l,e.source);if(!(n in i.FINANCE_DATA.ibanLengths))throw RangeError(`iban: unsupported country code "${t}". Supported: ${l.join(`, `)}`);let a=i.FINANCE_DATA.ibanLengths[n]-4,o=r.numericString(a,e.source);return`${n}${ibanCheckDigits(n,o)}${o}`}function bic(e){return`${letters(4,e)}${letters(2,e)}${r.alphanumeric(2,e.source).toUpperCase()}${n.int(0,1,e.source)===1?r.alphanumeric(3,e.source).toUpperCase():``}`}function creditCardNumber(e,t){let n=t??r.pick(c,e.source),a=r.pick(i.FINANCE_DATA.creditCardIins[n],e.source),o=a+r.numericString((n===`amex`?15:16)-a.length-1,e.source);return`${o}${luhnCheckDigit(o)}`}function creditCardCVV(e,t){let n=(t??r.pick(c,e.source))===`amex`?4:3;return r.numericString(n,e.source)}function bitcoinAddress(e){let t=r.pick([`1`,`3`,`bc1`],e.source),i=n.int(25,34,e.source);return`${t}${r.base58String(i,e.source)}`}function ethereumAddress(e){return`0x${r.hexString(40,e.source)}`}function transactionType(e){return r.pick(i.FINANCE_DATA.transactionTypes,e.source)}function bank(e){return r.pick(i.FINANCE_DATA.banks,e.source)}exports.amount=amount,exports.bank=bank,exports.bic=bic,exports.bitcoinAddress=bitcoinAddress,exports.creditCardCVV=creditCardCVV,exports.creditCardNumber=creditCardNumber,exports.ethereumAddress=ethereumAddress,Object.defineProperty(exports,"finance_exports",{enumerable:!0,get:function(){return o}}),exports.iban=iban,exports.transactionType=transactionType;
|
|
2
2
|
//# sourceMappingURL=finance.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"finance.cjs","names":[],"sources":["../../src/finance/finance.ts"],"sourcesContent":["import { type Currency, EUR, GBP, type Money, money, USD } from '@vielzeug/coins';\n\nimport { floatFixed } from '../_helpers/float';\nimport { int } from '../_helpers/int';\nimport { alphanumeric, base58String, hexString, numericString, pick } from '../_helpers/string';\nimport type { IllusionistContext } from '../types';\nimport { FINANCE_DATA } from './data';\n\nconst CURRENCIES: Record<'USD' | 'EUR' | 'GBP', Currency> = { EUR, GBP, USD };\n\nconst CREDIT_CARD_TYPES = ['visa', 'mastercard', 'amex'] as const;\ntype CreditCardType = (typeof CREDIT_CARD_TYPES)[number];\n\nconst IBAN_COUNTRIES = Object.keys(FINANCE_DATA.ibanCountryCodes) as (keyof typeof FINANCE_DATA.ibanCountryCodes)[];\n\nconst LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');\n\nfunction letters(count: number, ctx: IllusionistContext): string {\n const out: string[] = [];\n\n for (let i = 0; i < count; i++) {\n out.push(pick(LETTERS, ctx.source)!);\n }\n\n return out.join('');\n}\n\n/** Computes `n mod 97` for an arbitrarily long numeric string. */\nfunction mod97(numeric: string): number {\n let remainder = 0;\n\n for (const ch of numeric) {\n remainder = (remainder * 10 + Number(ch)) % 97;\n }\n\n return remainder;\n}\n\n/** Computes the two IBAN check digits so the resulting IBAN passes the mod-97 validation. */\nfunction ibanCheckDigits(country: string, bban: string): string {\n const rearranged = `${bban}${country}00`;\n const numeric = rearranged.replace(/[A-Z]/g, (c) => String(c.charCodeAt(0) - 55));\n const check = 98 - mod97(numeric);\n\n return check.toString().padStart(2, '0');\n}\n\n/** Computes the Luhn check digit for a partial card number (the final digit is appended). */\nfunction luhnCheckDigit(partial: string): string {\n const digits = partial.split('').map(Number);\n let sum = 0;\n let double = true;\n\n for (let i = digits.length - 1; i >= 0; i--) {\n let d = digits[i]!;\n\n if (double) {\n d *= 2;\n if (d > 9) d -= 9;\n }\n\n sum += d;\n double = !double;\n }\n\n const check = (10 - (sum % 10)) % 10;\n\n return String(check);\n}\n\nexport type AmountOptions = {\n readonly min?: number;\n readonly max?: number;\n readonly currency?: 'USD' | 'EUR' | 'GBP';\n};\n\nexport function amount(ctx: IllusionistContext, opts: AmountOptions = {}): Money {\n const min = opts.min ?? 100;\n const max = opts.max ?? 10000;\n const code = opts.currency ?? 'USD';\n const value = floatFixed(min, max, 2, ctx.source);\n\n return money(value.toFixed(2), CURRENCIES[code]);\n}\n\nexport function iban(ctx: IllusionistContext, countryCode?: string): string {\n const country = (countryCode ?? pick(IBAN_COUNTRIES, ctx.source)!) as keyof typeof FINANCE_DATA.ibanLengths;\n\n if (!(country in FINANCE_DATA.ibanLengths)) {\n throw new RangeError(`iban: unsupported country code \"${countryCode}\". Supported: ${IBAN_COUNTRIES.join(', ')}`);\n }\n\n const totalLength = FINANCE_DATA.ibanLengths[country];\n const bbanLength = totalLength - 4;\n const bban = numericString(bbanLength, ctx.source);\n const checkDigits = ibanCheckDigits(country, bban);\n\n return `${country}${checkDigits}${bban}`;\n}\n\nexport function bic(ctx: IllusionistContext): string {\n const bankCode = letters(4, ctx);\n const country = letters(2, ctx);\n const location = alphanumeric(2, ctx.source).toUpperCase();\n const useBranch = int(0, 1, ctx.source) === 1;\n const branch = useBranch ? alphanumeric(3, ctx.source).toUpperCase() : '';\n\n return `${bankCode}${country}${location}${branch}`;\n}\n\nexport function creditCardNumber(ctx: IllusionistContext, type?: CreditCardType): string {\n const cardType = type ?? pick(CREDIT_CARD_TYPES, ctx.source)!;\n const iin = pick(FINANCE_DATA.creditCardIins[cardType], ctx.source)!;\n const totalLength = cardType === 'amex' ? 15 : 16;\n const partial = iin + numericString(totalLength - iin.length - 1, ctx.source);\n const checkDigit = luhnCheckDigit(partial);\n\n return `${partial}${checkDigit}`;\n}\n\nexport function creditCardCVV(ctx: IllusionistContext, type?: CreditCardType): string {\n const cardType = type ?? pick(CREDIT_CARD_TYPES, ctx.source)!;\n const length = cardType === 'amex' ? 4 : 3;\n\n return numericString(length, ctx.source);\n}\n\nexport function bitcoinAddress(ctx: IllusionistContext): string {\n const prefix = pick(['1', '3', 'bc1'], ctx.source)!;\n const suffixLength = int(25, 34, ctx.source);\n\n return `${prefix}${base58String(suffixLength, ctx.source)}`;\n}\n\nexport function ethereumAddress(ctx: IllusionistContext): string {\n return `0x${hexString(40, ctx.source)}`;\n}\n\nexport function transactionType(ctx: IllusionistContext): string {\n return pick(FINANCE_DATA.transactionTypes, ctx.source)!;\n}\n\nexport function bank(ctx: IllusionistContext): string {\n return pick(FINANCE_DATA.banks, ctx.source)!;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"finance.cjs","names":[],"sources":["../../src/finance/finance.ts"],"sourcesContent":["import { type Currency, EUR, GBP, type Money, money, USD } from '@vielzeug/coins';\n\nimport { floatFixed } from '../_helpers/float';\nimport { int } from '../_helpers/int';\nimport { alphanumeric, base58String, hexString, numericString, pick } from '../_helpers/string';\nimport type { IllusionistContext } from '../types';\nimport { FINANCE_DATA } from './data';\n\nconst CURRENCIES: Record<'USD' | 'EUR' | 'GBP', Currency> = { EUR, GBP, USD };\n\nconst CREDIT_CARD_TYPES = ['visa', 'mastercard', 'amex'] as const;\ntype CreditCardType = (typeof CREDIT_CARD_TYPES)[number];\n\nconst IBAN_COUNTRIES = Object.keys(FINANCE_DATA.ibanCountryCodes) as (keyof typeof FINANCE_DATA.ibanCountryCodes)[];\n\nconst LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');\n\nfunction letters(count: number, ctx: IllusionistContext): string {\n const out: string[] = [];\n\n for (let i = 0; i < count; i++) {\n out.push(pick(LETTERS, ctx.source)!);\n }\n\n return out.join('');\n}\n\n/** Computes `n mod 97` for an arbitrarily long numeric string. */\nfunction mod97(numeric: string): number {\n let remainder = 0;\n\n for (const ch of numeric) {\n remainder = (remainder * 10 + Number(ch)) % 97;\n }\n\n return remainder;\n}\n\n/** Computes the two IBAN check digits so the resulting IBAN passes the mod-97 validation. */\nfunction ibanCheckDigits(country: string, bban: string): string {\n const rearranged = `${bban}${country}00`;\n const numeric = rearranged.replace(/[A-Z]/g, (c) => String(c.charCodeAt(0) - 55));\n const check = 98 - mod97(numeric);\n\n return check.toString().padStart(2, '0');\n}\n\n/** Computes the Luhn check digit for a partial card number (the final digit is appended). */\nfunction luhnCheckDigit(partial: string): string {\n const digits = partial.split('').map(Number);\n let sum = 0;\n let double = true;\n\n for (let i = digits.length - 1; i >= 0; i--) {\n let d = digits[i]!;\n\n if (double) {\n d *= 2;\n if (d > 9) d -= 9;\n }\n\n sum += d;\n double = !double;\n }\n\n const check = (10 - (sum % 10)) % 10;\n\n return String(check);\n}\n\nexport type AmountOptions = {\n readonly min?: number;\n readonly max?: number;\n readonly currency?: 'USD' | 'EUR' | 'GBP';\n};\n\nexport function amount(ctx: IllusionistContext, opts: AmountOptions = {}): Money {\n const min = opts.min ?? 100;\n const max = opts.max ?? 10000;\n const code = opts.currency ?? 'USD';\n const value = floatFixed(min, max, 2, ctx.source);\n\n return money(value.toFixed(2), CURRENCIES[code]);\n}\n\nexport function iban(ctx: IllusionistContext, countryCode?: string): string {\n const country = (countryCode ?? pick(IBAN_COUNTRIES, ctx.source)!) as keyof typeof FINANCE_DATA.ibanLengths;\n\n if (!(country in FINANCE_DATA.ibanLengths)) {\n throw new RangeError(`iban: unsupported country code \"${countryCode}\". Supported: ${IBAN_COUNTRIES.join(', ')}`);\n }\n\n const totalLength = FINANCE_DATA.ibanLengths[country];\n const bbanLength = totalLength - 4;\n const bban = numericString(bbanLength, ctx.source);\n const checkDigits = ibanCheckDigits(country, bban);\n\n return `${country}${checkDigits}${bban}`;\n}\n\nexport function bic(ctx: IllusionistContext): string {\n const bankCode = letters(4, ctx);\n const country = letters(2, ctx);\n const location = alphanumeric(2, ctx.source).toUpperCase();\n const useBranch = int(0, 1, ctx.source) === 1;\n const branch = useBranch ? alphanumeric(3, ctx.source).toUpperCase() : '';\n\n return `${bankCode}${country}${location}${branch}`;\n}\n\nexport function creditCardNumber(ctx: IllusionistContext, type?: CreditCardType): string {\n const cardType = type ?? pick(CREDIT_CARD_TYPES, ctx.source)!;\n const iin = pick(FINANCE_DATA.creditCardIins[cardType], ctx.source)!;\n const totalLength = cardType === 'amex' ? 15 : 16;\n const partial = iin + numericString(totalLength - iin.length - 1, ctx.source);\n const checkDigit = luhnCheckDigit(partial);\n\n return `${partial}${checkDigit}`;\n}\n\nexport function creditCardCVV(ctx: IllusionistContext, type?: CreditCardType): string {\n const cardType = type ?? pick(CREDIT_CARD_TYPES, ctx.source)!;\n const length = cardType === 'amex' ? 4 : 3;\n\n return numericString(length, ctx.source);\n}\n\nexport function bitcoinAddress(ctx: IllusionistContext): string {\n const prefix = pick(['1', '3', 'bc1'], ctx.source)!;\n const suffixLength = int(25, 34, ctx.source);\n\n return `${prefix}${base58String(suffixLength, ctx.source)}`;\n}\n\nexport function ethereumAddress(ctx: IllusionistContext): string {\n return `0x${hexString(40, ctx.source)}`;\n}\n\nexport function transactionType(ctx: IllusionistContext): string {\n return pick(FINANCE_DATA.transactionTypes, ctx.source)!;\n}\n\nexport function bank(ctx: IllusionistContext): string {\n return pick(FINANCE_DATA.banks, ctx.source)!;\n}\n"],"mappings":"udAQM,EAAsD,CAAE,IAAA,EAAA,IAAK,IAAA,EAAA,IAAK,IAAA,EAAA,GAAI,EAEtE,EAAoB,CAAC,OAAQ,aAAc,MAAM,EAGjD,EAAiB,OAAO,KAAK,EAAA,aAAa,gBAAgB,EAE1D,EAAU,6BAA6B,MAAM,EAAE,EAErD,SA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AAgB,EAAiC,CAC/D,OAAO,EAAA,KAAK,EAAA,aAAa,iBAAkB,EAAI,MAAM,CACvD,CAEA,SAAgB,KAAK,EAAiC,CACpD,OAAO,EAAA,KAAK,EAAA,aAAa,MAAO,EAAI,MAAM,CAC5C"}
|
package/dist/finance/finance.js
CHANGED
|
@@ -1,90 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { floatFixed as t } from "../_helpers/float.js";
|
|
3
|
-
import { int as n } from "../_helpers/int.js";
|
|
4
|
-
import { alphanumeric as r, base58String as i, hexString as a, numericString as o, pick as s } from "../_helpers/string.js";
|
|
5
|
-
import { FINANCE_DATA as c } from "./data.js";
|
|
6
|
-
import { EUR as l, GBP as u, USD as d, money as f } from "@vielzeug/coins";
|
|
7
|
-
//#region src/finance/finance.ts
|
|
8
|
-
var p = /* @__PURE__ */ e({
|
|
9
|
-
amount: () => S,
|
|
10
|
-
bank: () => A,
|
|
11
|
-
bic: () => w,
|
|
12
|
-
bitcoinAddress: () => D,
|
|
13
|
-
creditCardCVV: () => E,
|
|
14
|
-
creditCardNumber: () => T,
|
|
15
|
-
ethereumAddress: () => O,
|
|
16
|
-
iban: () => C,
|
|
17
|
-
transactionType: () => k
|
|
18
|
-
}), m = {
|
|
19
|
-
EUR: l,
|
|
20
|
-
GBP: u,
|
|
21
|
-
USD: d
|
|
22
|
-
}, h = [
|
|
23
|
-
"visa",
|
|
24
|
-
"mastercard",
|
|
25
|
-
"amex"
|
|
26
|
-
], g = Object.keys(c.ibanCountryCodes), _ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
|
|
27
|
-
function v(e, t) {
|
|
28
|
-
let n = [];
|
|
29
|
-
for (let r = 0; r < e; r++) n.push(s(_, t.source));
|
|
30
|
-
return n.join("");
|
|
31
|
-
}
|
|
32
|
-
function y(e) {
|
|
33
|
-
let t = 0;
|
|
34
|
-
for (let n of e) t = (t * 10 + Number(n)) % 97;
|
|
35
|
-
return t;
|
|
36
|
-
}
|
|
37
|
-
function b(e, t) {
|
|
38
|
-
return (98 - y(`${t}${e}00`.replace(/[A-Z]/g, (e) => String(e.charCodeAt(0) - 55)))).toString().padStart(2, "0");
|
|
39
|
-
}
|
|
40
|
-
function x(e) {
|
|
41
|
-
let t = e.split("").map(Number), n = 0, r = !0;
|
|
42
|
-
for (let e = t.length - 1; e >= 0; e--) {
|
|
43
|
-
let i = t[e];
|
|
44
|
-
r && (i *= 2, i > 9 && (i -= 9)), n += i, r = !r;
|
|
45
|
-
}
|
|
46
|
-
let i = (10 - n % 10) % 10;
|
|
47
|
-
return String(i);
|
|
48
|
-
}
|
|
49
|
-
function S(e, n = {}) {
|
|
50
|
-
let r = n.min ?? 100, i = n.max ?? 1e4, a = n.currency ?? "USD", o = t(r, i, 2, e.source);
|
|
51
|
-
return f(o.toFixed(2), m[a]);
|
|
52
|
-
}
|
|
53
|
-
function C(e, t) {
|
|
54
|
-
let n = t ?? s(g, e.source);
|
|
55
|
-
if (!(n in c.ibanLengths)) throw RangeError(`iban: unsupported country code "${t}". Supported: ${g.join(", ")}`);
|
|
56
|
-
let r = c.ibanLengths[n] - 4, i = o(r, e.source);
|
|
57
|
-
return `${n}${b(n, i)}${i}`;
|
|
58
|
-
}
|
|
59
|
-
function w(e) {
|
|
60
|
-
return `${v(4, e)}${v(2, e)}${r(2, e.source).toUpperCase()}${n(0, 1, e.source) === 1 ? r(3, e.source).toUpperCase() : ""}`;
|
|
61
|
-
}
|
|
62
|
-
function T(e, t) {
|
|
63
|
-
let n = t ?? s(h, e.source), r = s(c.creditCardIins[n], e.source), i = r + o((n === "amex" ? 15 : 16) - r.length - 1, e.source);
|
|
64
|
-
return `${i}${x(i)}`;
|
|
65
|
-
}
|
|
66
|
-
function E(e, t) {
|
|
67
|
-
let n = (t ?? s(h, e.source)) === "amex" ? 4 : 3;
|
|
68
|
-
return o(n, e.source);
|
|
69
|
-
}
|
|
70
|
-
function D(e) {
|
|
71
|
-
let t = s([
|
|
72
|
-
"1",
|
|
73
|
-
"3",
|
|
74
|
-
"bc1"
|
|
75
|
-
], e.source), r = n(25, 34, e.source);
|
|
76
|
-
return `${t}${i(r, e.source)}`;
|
|
77
|
-
}
|
|
78
|
-
function O(e) {
|
|
79
|
-
return `0x${a(40, e.source)}`;
|
|
80
|
-
}
|
|
81
|
-
function k(e) {
|
|
82
|
-
return s(c.transactionTypes, e.source);
|
|
83
|
-
}
|
|
84
|
-
function A(e) {
|
|
85
|
-
return s(c.banks, e.source);
|
|
86
|
-
}
|
|
87
|
-
//#endregion
|
|
88
|
-
export { S as amount, A as bank, w as bic, D as bitcoinAddress, E as creditCardCVV, T as creditCardNumber, O as ethereumAddress, p as finance_exports, C as iban, k as transactionType };
|
|
89
|
-
|
|
1
|
+
import{__exportAll as e}from"../_virtual/_rolldown/runtime.js";import{floatFixed as t}from"../_helpers/float.js";import{int as n}from"../_helpers/int.js";import{alphanumeric as r,base58String as i,hexString as a,numericString as o,pick as s}from"../_helpers/string.js";import{FINANCE_DATA as c}from"./data.js";import{EUR as l,GBP as u,USD as d,money as f}from"@vielzeug/coins";var p=e({amount:()=>amount,bank:()=>bank,bic:()=>bic,bitcoinAddress:()=>bitcoinAddress,creditCardCVV:()=>creditCardCVV,creditCardNumber:()=>creditCardNumber,ethereumAddress:()=>ethereumAddress,iban:()=>iban,transactionType:()=>transactionType}),m={EUR:l,GBP:u,USD:d},h=[`visa`,`mastercard`,`amex`],g=Object.keys(c.ibanCountryCodes),_=`ABCDEFGHIJKLMNOPQRSTUVWXYZ`.split(``);function letters(e,t){let n=[];for(let r=0;r<e;r++)n.push(s(_,t.source));return n.join(``)}function mod97(e){let t=0;for(let n of e)t=(t*10+Number(n))%97;return t}function ibanCheckDigits(e,t){return(98-mod97(`${t}${e}00`.replace(/[A-Z]/g,e=>String(e.charCodeAt(0)-55)))).toString().padStart(2,`0`)}function luhnCheckDigit(e){let t=e.split(``).map(Number),n=0,r=!0;for(let e=t.length-1;e>=0;e--){let i=t[e];r&&(i*=2,i>9&&(i-=9)),n+=i,r=!r}let i=(10-n%10)%10;return String(i)}function amount(e,n={}){let r=n.min??100,i=n.max??1e4,a=n.currency??`USD`,o=t(r,i,2,e.source);return f(o.toFixed(2),m[a])}function iban(e,t){let n=t??s(g,e.source);if(!(n in c.ibanLengths))throw RangeError(`iban: unsupported country code "${t}". Supported: ${g.join(`, `)}`);let r=c.ibanLengths[n]-4,i=o(r,e.source);return`${n}${ibanCheckDigits(n,i)}${i}`}function bic(e){return`${letters(4,e)}${letters(2,e)}${r(2,e.source).toUpperCase()}${n(0,1,e.source)===1?r(3,e.source).toUpperCase():``}`}function creditCardNumber(e,t){let n=t??s(h,e.source),r=s(c.creditCardIins[n],e.source),i=r+o((n===`amex`?15:16)-r.length-1,e.source);return`${i}${luhnCheckDigit(i)}`}function creditCardCVV(e,t){let n=(t??s(h,e.source))===`amex`?4:3;return o(n,e.source)}function bitcoinAddress(e){let t=s([`1`,`3`,`bc1`],e.source),r=n(25,34,e.source);return`${t}${i(r,e.source)}`}function ethereumAddress(e){return`0x${a(40,e.source)}`}function transactionType(e){return s(c.transactionTypes,e.source)}function bank(e){return s(c.banks,e.source)}export{amount,bank,bic,bitcoinAddress,creditCardCVV,creditCardNumber,ethereumAddress,p as finance_exports,iban,transactionType};
|
|
90
2
|
//# sourceMappingURL=finance.js.map
|