@stacksjs/faker 0.70.88 → 0.70.91

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.
@@ -0,0 +1,258 @@
1
+ import type { Faker as BaseFaker } from '@stacksjs/ts-faker';
2
+ /**
3
+ * Compatibility layer for @faker-js/faker API
4
+ * @stacksjs/ts-faker uses different module names, so we create aliases
5
+ * @defaultValue `{ array<T>: () => unknown }`
6
+ */
7
+ declare const datatype: {
8
+ boolean: () => boolean;
9
+ number: (options?: { min?: number; max?: number }) => number;
10
+ float: (options?: { min?: number; max?: number; precision?: number }) => number;
11
+ uuid: () => string;
12
+ string: (length?: number) => string;
13
+ array<T>: (generator: () => T, length?: number) => T[]
14
+ };
15
+ // location module (alias to address for @faker-js/faker compatibility)
16
+ declare const location: {
17
+ street: () => string;
18
+ streetAddress: (useFullAddress?: boolean) => string;
19
+ city: () => string;
20
+ state: () => string;
21
+ stateAbbr: () => string;
22
+ country: () => string;
23
+ countryCode: () => string;
24
+ zipCode: () => string;
25
+ latitude: (options?: { min?: number; max?: number; precision?: number }) => number;
26
+ longitude: (options?: { min?: number; max?: number; precision?: number }) => number;
27
+ direction: () => string;
28
+ buildingNumber: () => string
29
+ };
30
+ /**
31
+ * company module enhancements
32
+ * @defaultValue
33
+ * ```ts
34
+ * {
35
+ * ...baseFaker.company,
36
+ * catchPhrase: () => string {
37
+ * const co = baseFaker.company as { buzzPhrase?: (),
38
+ * buzzPhrase: () => string {
39
+ * const co = baseFaker.company as { buzzPhrase?: ()
40
+ * }
41
+ * ```
42
+ */
43
+ declare const company: Omit<typeof baseFaker.company, keyof {
44
+ name: () => string;
45
+ catchPhrase: () => string;
46
+ buzzPhrase: () => string
47
+ }> & {
48
+ name: () => string;
49
+ catchPhrase: () => string;
50
+ buzzPhrase: () => string
51
+ };
52
+ /**
53
+ * vehicle module enhancements
54
+ * @defaultValue `{ ...baseFaker.vehicle }`
55
+ */
56
+ declare const vehicle: Omit<typeof baseFaker.vehicle, keyof {
57
+ vrm: () => string;
58
+ vehicle: () => string;
59
+ type: () => string;
60
+ manufacturer: () => string;
61
+ model: () => string;
62
+ fuel: () => string;
63
+ vin: () => string;
64
+ color: () => string
65
+ }> & {
66
+ vrm: () => string;
67
+ vehicle: () => string;
68
+ type: () => string;
69
+ manufacturer: () => string;
70
+ model: () => string;
71
+ fuel: () => string;
72
+ vin: () => string;
73
+ color: () => string
74
+ };
75
+ /**
76
+ * helpers module enhancements for @faker-js/faker compatibility
77
+ * @defaultValue `{ ...baseFaker.helpers }`
78
+ */
79
+ declare const helpers: Omit<typeof baseFaker.helpers, keyof {
80
+ arrayElement<T>: (array: T[]) => T;
81
+ arrayElements<T>: (array: T[], count?: number) => T[];
82
+ /**
83
+ * Fisher-Yates shuffle. Returns a new array; the input is not mutated.
84
+ *
85
+ * Why not `[...array].sort(() => Math.random() - 0.5)`: that idiom is
86
+ * heavily biased — V8 / JSC's stable sort calls the comparator a
87
+ * variable number of times depending on input length, which means
88
+ * elements near the start are ~3x more likely to remain near the start
89
+ * than elements in the middle. Real Fisher-Yates is unbiased.
90
+ */
91
+ shuffle<T>(array: T[]): T[] {
92
+ const a = [...array]
93
+ for (let i = a.length - 1; i > 0; i--) {
94
+ const j = Math.floor(Math.random() * (i + 1))
95
+ const ai = a[i] as T
96
+ const aj = a[j] as T
97
+ a[i] = aj
98
+ a[j] = ai
99
+ }
100
+ return a
101
+ },
102
+ maybe<T>(callback: () => T, options?: { probability?: number }): T | undefined {
103
+ const probability = options?.probability ?? 0.5
104
+ return Math.random() < probability ? callback() : undefined
105
+ },
106
+ objectKey<T extends object>(obj: T): keyof T {
107
+ const keys = Object.keys(obj) as (keyof T)[]
108
+ if (keys.length === 0) throw new Error('objectKey: unknown
109
+ }> & {
110
+ arrayElement<T>: (array: T[]) => T;
111
+ arrayElements<T>: (array: T[], count?: number) => T[];
112
+ /**
113
+ * Fisher-Yates shuffle. Returns a new array; the input is not mutated.
114
+ *
115
+ * Why not `[...array].sort(() => Math.random() - 0.5)`: that idiom is
116
+ * heavily biased — V8 / JSC's stable sort calls the comparator a
117
+ * variable number of times depending on input length, which means
118
+ * elements near the start are ~3x more likely to remain near the start
119
+ * than elements in the middle. Real Fisher-Yates is unbiased.
120
+ */
121
+ shuffle<T>(array: T[]): T[] {
122
+ const a = [...array]
123
+ for (let i = a.length - 1; i > 0; i--) {
124
+ const j = Math.floor(Math.random() * (i + 1))
125
+ const ai = a[i] as T
126
+ const aj = a[j] as T
127
+ a[i] = aj
128
+ a[j] = ai
129
+ }
130
+ return a
131
+ },
132
+ maybe<T>(callback: () => T, options?: { probability?: number }): T | undefined {
133
+ const probability = options?.probability ?? 0.5
134
+ return Math.random() < probability ? callback() : undefined
135
+ },
136
+ objectKey<T extends object>(obj: T): keyof T {
137
+ const keys = Object.keys(obj) as (keyof T)[]
138
+ if (keys.length === 0) throw new Error('objectKey: unknown
139
+ };
140
+ /**
141
+ * Enhanced lorem module with better API
142
+ * @defaultValue `{ ...baseFaker.lorem }`
143
+ */
144
+ declare const enhancedLorem: Omit<typeof baseFaker.lorem, keyof {
145
+ /**
146
+ * Generate a random word
147
+ */
148
+ word: () => string;
149
+ /**
150
+ * Generate random words
151
+ * @param count - Number of words (default: 3)
152
+ */
153
+ words: (count?: number) => string;
154
+ /**
155
+ * Generate a sentence with random words
156
+ * @param maxWords - Maximum number of words in the sentence (default: random 3-10)
157
+ */
158
+ sentence: (maxWords?: number) => string;
159
+ /**
160
+ * Generate multiple sentences
161
+ * @param count - Number of sentences (default: 3)
162
+ * @param separator - Separator between sentences (default: ' ')
163
+ */
164
+ sentences: (count?: number, separator?: string) => string;
165
+ /**
166
+ * Generate a paragraph
167
+ * @param sentenceCount - Number of sentences in the paragraph
168
+ */
169
+ paragraph: (sentenceCount?: number) => string;
170
+ /**
171
+ * Generate multiple paragraphs
172
+ * @param count - Number of paragraphs (default: 3)
173
+ * @param separator - Separator between paragraphs (default: '\n\n')
174
+ */
175
+ paragraphs: (count?: number, separator?: string) => string;
176
+ /**
177
+ * Generate lorem text of specified length
178
+ * @param length - Target character length (default: 200)
179
+ */
180
+ text: (length?: number) => string;
181
+ /**
182
+ * Generate a slug from lorem words
183
+ * @param wordCount - Number of words in the slug (default: 3)
184
+ */
185
+ slug: (wordCount?: number) => string;
186
+ /**
187
+ * Generate multiple lines of sentences
188
+ * @param count - Number of lines (default: 3)
189
+ */
190
+ lines: (count?: number) => string
191
+ }> & {
192
+ /**
193
+ * Generate a random word
194
+ */
195
+ word: () => string;
196
+ /**
197
+ * Generate random words
198
+ * @param count - Number of words (default: 3)
199
+ */
200
+ words: (count?: number) => string;
201
+ /**
202
+ * Generate a sentence with random words
203
+ * @param maxWords - Maximum number of words in the sentence (default: random 3-10)
204
+ */
205
+ sentence: (maxWords?: number) => string;
206
+ /**
207
+ * Generate multiple sentences
208
+ * @param count - Number of sentences (default: 3)
209
+ * @param separator - Separator between sentences (default: ' ')
210
+ */
211
+ sentences: (count?: number, separator?: string) => string;
212
+ /**
213
+ * Generate a paragraph
214
+ * @param sentenceCount - Number of sentences in the paragraph
215
+ */
216
+ paragraph: (sentenceCount?: number) => string;
217
+ /**
218
+ * Generate multiple paragraphs
219
+ * @param count - Number of paragraphs (default: 3)
220
+ * @param separator - Separator between paragraphs (default: '\n\n')
221
+ */
222
+ paragraphs: (count?: number, separator?: string) => string;
223
+ /**
224
+ * Generate lorem text of specified length
225
+ * @param length - Target character length (default: 200)
226
+ */
227
+ text: (length?: number) => string;
228
+ /**
229
+ * Generate a slug from lorem words
230
+ * @param wordCount - Number of words in the slug (default: 3)
231
+ */
232
+ slug: (wordCount?: number) => string;
233
+ /**
234
+ * Generate multiple lines of sentences
235
+ * @param count - Number of lines (default: 3)
236
+ */
237
+ lines: (count?: number) => string
238
+ };
239
+ /**
240
+ * Enhanced faker instance with improved lorem API and @faker-js/faker compatibility
241
+ * @defaultValue `{ ...baseFaker }`
242
+ */
243
+ export declare const faker: Omit<typeof baseFaker, keyof {
244
+ lorem: unknown;
245
+ datatype: typeof datatype;
246
+ location: typeof location;
247
+ company: typeof company;
248
+ vehicle: typeof vehicle;
249
+ helpers: typeof helpers
250
+ }> & {
251
+ lorem: unknown;
252
+ datatype: typeof datatype;
253
+ location: typeof location;
254
+ company: typeof company;
255
+ vehicle: typeof vehicle;
256
+ helpers: typeof helpers
257
+ };
258
+ export type Faker = BaseFaker;
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ // @bun
2
+ import{faker as z}from"@stacksjs/ts-faker";var M={boolean(){return z.random.boolean()},number(q){return z.number.int({min:q?.min??0,max:q?.max??100})},float(q){return z.number.float({min:q?.min??0,max:q?.max??1,precision:q?.precision??2})},uuid(){return z.string.uuid()},string(q){return z.string.alphanumeric({length:q??10})},array(q,B){let D=[],G=B??z.number.int({min:1,max:10});for(let H=0;H<G;H++)D.push(q());return D}},N={street(){return z.address.street()},streetAddress(q){return z.address.streetAddress({useFullAddress:q})},city(){return z.address.city()},state(){return z.address.state()},stateAbbr(){return z.address.stateAbbr()},country(){return z.address.country()},countryCode(){return z.address.countryCode()},zipCode(){return z.address.zipCode()},latitude(q){return z.address.latitude(q)},longitude(q){return z.address.longitude(q)},direction(){return z.address.direction()},buildingNumber(){return z.address.buildingNumber()}},O={...z.company,name(){return z.company.name()},catchPhrase(){let q=z.company;return q.buzzPhrase?.()??q.catchphrase?.()??`${z.word.adjective()} ${z.word.noun()}`},buzzPhrase(){return z.company.buzzPhrase?.()??z.lorem.sentence(3)}},Q={...z.vehicle,vrm(){return`${"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[Math.floor(Math.random()*26)]}${"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[Math.floor(Math.random()*26)]}${"0123456789"[Math.floor(Math.random()*10)]}${"0123456789"[Math.floor(Math.random()*10)]} ${"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[Math.floor(Math.random()*26)]}${"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[Math.floor(Math.random()*26)]}${"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[Math.floor(Math.random()*26)]}`},vehicle(){let q=["Toyota","Honda","Ford","Chevrolet","BMW","Mercedes","Audi","Tesla","Nissan","Hyundai"],B=["Sedan","SUV","Truck","Coupe","Hatchback","Wagon","Van","Crossover"];return`${q[Math.floor(Math.random()*q.length)]} ${B[Math.floor(Math.random()*B.length)]}`},type(){let q=["Sedan","SUV","Truck","Van","Coupe","Convertible","Wagon","Hatchback"];return q[Math.floor(Math.random()*q.length)]??"Sedan"},manufacturer(){let q=["Toyota","Honda","Ford","Chevrolet","BMW","Mercedes-Benz","Audi","Tesla","Nissan","Hyundai","Kia","Volkswagen"];return q[Math.floor(Math.random()*q.length)]??"Toyota"},model(){let q=["Camry","Accord","F-150","Silverado","3 Series","C-Class","A4","Model 3","Altima","Elantra"];return q[Math.floor(Math.random()*q.length)]??"Camry"},fuel(){let q=["Gasoline","Diesel","Electric","Hybrid","Plug-in Hybrid"];return q[Math.floor(Math.random()*q.length)]??"Gasoline"},vin(){let B="";for(let D=0;D<17;D++)B+="0123456789ABCDEFGHJKLMNPRSTUVWXYZ"[Math.floor(Math.random()*33)];return B},color(){let q=["Black","White","Silver","Gray","Red","Blue","Green","Brown","Orange","Yellow"];return q[Math.floor(Math.random()*q.length)]??"Black"}},J={...z.helpers,arrayElement(q){if(q.length===0)throw Error("arrayElement: cannot pick from an empty array");return q[Math.floor(Math.random()*q.length)]},arrayElements(q,B){let D=B??Math.floor(Math.random()*q.length)+1;return J.shuffle(q).slice(0,Math.min(D,q.length))},shuffle(q){let B=[...q];for(let D=B.length-1;D>0;D--){let G=Math.floor(Math.random()*(D+1)),H=B[D],K=B[G];B[D]=K,B[G]=H}return B},maybe(q,B){let D=B?.probability??0.5;return Math.random()<D?q():void 0},objectKey(q){let B=Object.keys(q);if(B.length===0)throw Error("objectKey: object has no keys");return B[Math.floor(Math.random()*B.length)]},objectValue(q){let B=Object.values(q);if(B.length===0)throw Error("objectValue: object has no values");return B[Math.floor(Math.random()*B.length)]}},R={...z.lorem,word(){return z.lorem.word()},words(q){return z.lorem.words(q??3)},sentence(q){if(q!==void 0){let B=Math.min(3,q),D=Math.floor(Math.random()*(q-B+1))+B;return z.lorem.sentence(D)}return z.lorem.sentence()},sentences(q,B){return z.lorem.sentences(q??3,B??" ")},paragraph(q){return z.lorem.paragraph(q)},paragraphs(q,B){return z.lorem.paragraphs(q??3,B??`
3
+
4
+ `)},text(q){return z.lorem.text(q)},slug(q){return z.lorem.slug(q??3)},lines(q){return z.lorem.lines(q??3)}},T={...z,lorem:R,datatype:M,location:N,company:O,vehicle:Q,helpers:J};export{T as faker};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/faker",
3
3
  "type": "module",
4
- "version": "0.70.88",
4
+ "version": "0.70.91",
5
5
  "description": "Faker functions.",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": [
@@ -53,8 +53,8 @@
53
53
  "prepublishOnly": "bun run build"
54
54
  },
55
55
  "devDependencies": {
56
- "@stacksjs/cli": "0.70.88",
57
- "@stacksjs/config": "0.70.88",
56
+ "@stacksjs/cli": "0.70.91",
57
+ "@stacksjs/config": "0.70.91",
58
58
  "better-dx": "^0.2.16",
59
59
  "@stacksjs/ts-faker": "^0.1.7"
60
60
  },