@zod4-mock/locale-core 0.2.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/dist/index.d.ts +177 -0
- package/dist/index.js +19 -0
- package/package.json +23 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @zod4-mock/locale-core
|
|
3
|
+
* Shared locale types and the `extend()` utility. Consumed by the main
|
|
4
|
+
* `zod4-mock` package and every `@zod4-mock/locale-*` package.
|
|
5
|
+
*/
|
|
6
|
+
/** Seeded pseudo-random number generator. Implemented in the main `zod4-mock` package. */
|
|
7
|
+
interface Prng {
|
|
8
|
+
readonly seed: number;
|
|
9
|
+
random(): number;
|
|
10
|
+
int(min: number, max: number): number;
|
|
11
|
+
pick<T>(items: readonly [T, ...T[]]): T;
|
|
12
|
+
fork(key: string): Prng;
|
|
13
|
+
bytes(n: number): Uint8Array;
|
|
14
|
+
}
|
|
15
|
+
interface MarkovModel {
|
|
16
|
+
/** n-gram order (2 = bigram context). */
|
|
17
|
+
order: number;
|
|
18
|
+
/** Dirichlet smoothing weight (e.g. 0.01). */
|
|
19
|
+
prior: number;
|
|
20
|
+
/** Alphabet used by this model, including the "$" end-of-word sentinel. */
|
|
21
|
+
chars: string;
|
|
22
|
+
/** n-gram state → cumulative distribution function (length === chars.length). */
|
|
23
|
+
table: Record<string, number[]>;
|
|
24
|
+
}
|
|
25
|
+
/** A cultural-origin model paired with its relative sampling weight. */
|
|
26
|
+
interface NameOriginSet {
|
|
27
|
+
model: MarkovModel;
|
|
28
|
+
/** Relative probability weight — does not need to sum to 100. */
|
|
29
|
+
weight: number;
|
|
30
|
+
}
|
|
31
|
+
/** A surname prefix (tussenvoegsel) with its relative sampling weight. */
|
|
32
|
+
interface LastNamePrefix {
|
|
33
|
+
prefix: string;
|
|
34
|
+
weight: number;
|
|
35
|
+
}
|
|
36
|
+
interface Currency {
|
|
37
|
+
code: string;
|
|
38
|
+
name: string;
|
|
39
|
+
symbol: string;
|
|
40
|
+
numeric: string;
|
|
41
|
+
}
|
|
42
|
+
interface LocaleData {
|
|
43
|
+
id: string;
|
|
44
|
+
person: {
|
|
45
|
+
/**
|
|
46
|
+
* Weighted cultural-origin Markov models for male first names.
|
|
47
|
+
* When present, takes priority over `simpleFirstNamesMale`.
|
|
48
|
+
*/
|
|
49
|
+
firstNamesMale?: readonly NameOriginSet[];
|
|
50
|
+
firstNamesFemale?: readonly NameOriginSet[];
|
|
51
|
+
lastNames?: readonly NameOriginSet[];
|
|
52
|
+
/** Plain array fallback for first/last names — used when no Markov model is supplied. */
|
|
53
|
+
simpleFirstNamesMale?: readonly string[];
|
|
54
|
+
simpleFirstNamesFemale?: readonly string[];
|
|
55
|
+
simpleLastNames?: readonly string[];
|
|
56
|
+
/** Optional surname prefixes (e.g. Dutch tussenvoegsels like "de", "van der"). */
|
|
57
|
+
lastNamePrefixes?: readonly LastNamePrefix[];
|
|
58
|
+
prefixes: {
|
|
59
|
+
male: readonly string[];
|
|
60
|
+
female: readonly string[];
|
|
61
|
+
neutral: readonly string[];
|
|
62
|
+
};
|
|
63
|
+
suffixes: readonly string[];
|
|
64
|
+
genders: readonly string[];
|
|
65
|
+
jobTitles: readonly string[];
|
|
66
|
+
jobAreas: readonly string[];
|
|
67
|
+
jobTypes: readonly string[];
|
|
68
|
+
jobDescriptors: readonly string[];
|
|
69
|
+
formatFullName: (first: string, last: string) => string;
|
|
70
|
+
/** Returns a bio sentence using a locale-specific template. */
|
|
71
|
+
formatBio: (prng: Prng, parts: {
|
|
72
|
+
jobTitle: string;
|
|
73
|
+
jobArea: string;
|
|
74
|
+
jobType: string;
|
|
75
|
+
}) => string;
|
|
76
|
+
};
|
|
77
|
+
address: {
|
|
78
|
+
cities: readonly string[];
|
|
79
|
+
states: readonly string[];
|
|
80
|
+
countries: readonly string[];
|
|
81
|
+
countryCodes: readonly string[];
|
|
82
|
+
continents: readonly string[];
|
|
83
|
+
languages: readonly string[];
|
|
84
|
+
streetNames: readonly string[];
|
|
85
|
+
streetSuffixes: readonly string[];
|
|
86
|
+
cityPrefixes: readonly string[];
|
|
87
|
+
cityCores: readonly string[];
|
|
88
|
+
buildingNumberSuffixes: readonly string[];
|
|
89
|
+
timeZones: readonly string[];
|
|
90
|
+
directions: readonly string[];
|
|
91
|
+
cardinalDirections: readonly string[];
|
|
92
|
+
ordinalDirections: readonly string[];
|
|
93
|
+
streetFormats: ReadonlyArray<(number: string, name: string) => string>;
|
|
94
|
+
zipFormat: (prng: Prng) => string;
|
|
95
|
+
/** Returns a secondary-address line (e.g. "Apt 5", "Appartement 5"). */
|
|
96
|
+
secondaryAddressFormat: (n: number) => string;
|
|
97
|
+
phonePrefix: string;
|
|
98
|
+
ibanPrefix: string;
|
|
99
|
+
countryCode: string;
|
|
100
|
+
};
|
|
101
|
+
commerce: {
|
|
102
|
+
departments: readonly string[];
|
|
103
|
+
materials: readonly string[];
|
|
104
|
+
productAdjectives: readonly string[];
|
|
105
|
+
currencyCode: string;
|
|
106
|
+
formatPrice: (amount: number) => string;
|
|
107
|
+
formatProductName: (adjective: string, material: string, noun: string) => string;
|
|
108
|
+
formatProductDescription: (parts: {
|
|
109
|
+
productName: string;
|
|
110
|
+
adjective: string;
|
|
111
|
+
noun: string;
|
|
112
|
+
department: string;
|
|
113
|
+
}) => string;
|
|
114
|
+
};
|
|
115
|
+
company: {
|
|
116
|
+
prefixes: readonly string[];
|
|
117
|
+
suffixes: readonly string[];
|
|
118
|
+
buzzAdjectives: readonly string[];
|
|
119
|
+
buzzNouns: readonly string[];
|
|
120
|
+
buzzVerbLemmas: readonly string[];
|
|
121
|
+
catchPhraseAdjectives: readonly string[];
|
|
122
|
+
catchPhraseDescriptors: readonly string[];
|
|
123
|
+
catchPhraseNouns: readonly string[];
|
|
124
|
+
formatBuzzPhrase: (verb: string, adj: string, noun: string) => string;
|
|
125
|
+
};
|
|
126
|
+
word: {
|
|
127
|
+
/** Markov model for open-class nouns. When present, takes priority over `nouns`. */
|
|
128
|
+
nounModel?: MarkovModel;
|
|
129
|
+
adjectiveModel?: MarkovModel;
|
|
130
|
+
/** Plain array fallback — used when no Markov model is supplied. */
|
|
131
|
+
nouns?: readonly string[];
|
|
132
|
+
adjectives?: readonly string[];
|
|
133
|
+
articles: readonly string[];
|
|
134
|
+
prepositions: readonly string[];
|
|
135
|
+
conjunctions: readonly string[];
|
|
136
|
+
pronouns: readonly string[];
|
|
137
|
+
verbs: readonly string[];
|
|
138
|
+
verbsPlural: readonly string[];
|
|
139
|
+
adverbs: readonly string[];
|
|
140
|
+
interjections: readonly string[];
|
|
141
|
+
};
|
|
142
|
+
finance: {
|
|
143
|
+
bankCodes: readonly string[];
|
|
144
|
+
bicLocations: readonly string[];
|
|
145
|
+
currencies: readonly Currency[];
|
|
146
|
+
accountNames: readonly string[];
|
|
147
|
+
transactionTypes: readonly string[];
|
|
148
|
+
transactionDescriptions: readonly string[];
|
|
149
|
+
formatIban: (prng: Prng, bankCode: string) => string;
|
|
150
|
+
};
|
|
151
|
+
date: {
|
|
152
|
+
months: readonly string[];
|
|
153
|
+
monthsShort: readonly string[];
|
|
154
|
+
weekdays: readonly string[];
|
|
155
|
+
weekdaysShort: readonly string[];
|
|
156
|
+
timeZones: readonly string[];
|
|
157
|
+
};
|
|
158
|
+
color: {
|
|
159
|
+
names: readonly string[];
|
|
160
|
+
};
|
|
161
|
+
phone: {
|
|
162
|
+
mobilePrefix: string;
|
|
163
|
+
landlinePrefixes: readonly string[];
|
|
164
|
+
formatMobile: (prng: Prng) => string;
|
|
165
|
+
formatLandline: (prng: Prng) => string;
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
type LocaleOverrides = {
|
|
170
|
+
[K in keyof LocaleData]?: Partial<LocaleData[K]>;
|
|
171
|
+
} & {
|
|
172
|
+
id?: string;
|
|
173
|
+
};
|
|
174
|
+
/** Shallow-per-section merge: creates a new locale by overriding individual sections. */
|
|
175
|
+
declare function extend(base: LocaleData, overrides: LocaleOverrides): LocaleData;
|
|
176
|
+
|
|
177
|
+
export { type Currency, type LastNamePrefix, type LocaleData, type MarkovModel, type NameOriginSet, type Prng, extend };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/extend.ts
|
|
2
|
+
function extend(base, overrides) {
|
|
3
|
+
return {
|
|
4
|
+
...base,
|
|
5
|
+
...overrides,
|
|
6
|
+
person: { ...base.person, ...overrides.person },
|
|
7
|
+
address: { ...base.address, ...overrides.address },
|
|
8
|
+
commerce: { ...base.commerce, ...overrides.commerce },
|
|
9
|
+
company: { ...base.company, ...overrides.company },
|
|
10
|
+
word: { ...base.word, ...overrides.word },
|
|
11
|
+
finance: { ...base.finance, ...overrides.finance },
|
|
12
|
+
date: { ...base.date, ...overrides.date },
|
|
13
|
+
color: { ...base.color, ...overrides.color },
|
|
14
|
+
phone: { ...base.phone, ...overrides.phone }
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
extend
|
|
19
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zod4-mock/locale-core",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Shared locale types and the extend() utility for zod4-mock locales",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"typescript": "^6.0.3"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsup"
|
|
22
|
+
}
|
|
23
|
+
}
|