@stacksjs/faker 0.70.91 → 0.70.92

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 (2) hide show
  1. package/dist/index.d.ts +66 -229
  2. package/package.json +3 -3
package/dist/index.d.ts CHANGED
@@ -1,17 +1,7 @@
1
+ import { faker as baseFaker } from '@stacksjs/ts-faker';
1
2
  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
- };
3
+ // datatype module for boolean, number generation (compatibility with @faker-js/faker)
4
+ declare const datatype: DatatypeCompatibility;
15
5
  // location module (alias to address for @faker-js/faker compatibility)
16
6
  declare const location: {
17
7
  street: () => string;
@@ -27,232 +17,79 @@ declare const location: {
27
17
  direction: () => string;
28
18
  buildingNumber: () => string
29
19
  };
20
+ declare const company: EnhancedCompany;
21
+ declare const vehicle: EnhancedVehicle;
22
+ // helpers module enhancements for @faker-js/faker compatibility
23
+ // Keep this annotation explicit. bun-plugin-dtsx cannot reliably infer a
24
+ // declaration for a spread object that also contains documented generic methods.
25
+ declare const helpers: EnhancedHelpers;
26
+ declare const enhancedLorem: EnhancedLorem;
27
+ export declare const faker: EnhancedFaker;
30
28
  /**
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
- * ```
29
+ * Compatibility layer for @faker-js/faker API
30
+ * @stacksjs/ts-faker uses different module names, so we create aliases
42
31
  */
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;
32
+ declare interface DatatypeCompatibility {
33
+ boolean: () => boolean
34
+ number: (options?: { min?: number; max?: number }) => number
35
+ float: (options?: { min?: number; max?: number; precision?: number }) => number
36
+ uuid: () => string
37
+ string: (length?: number) => string
38
+ array: <T>(generator: () => T, length?: number) => T[]
39
+ }
40
+ // company module enhancements
41
+ declare interface CompanyCompatibility {
42
+ name: () => string
43
+ catchPhrase: () => string
50
44
  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;
45
+ }
46
+ // vehicle module enhancements
47
+ declare interface VehicleCompatibility {
48
+ vrm: () => string
49
+ vehicle: () => string
50
+ type: () => string
51
+ manufacturer: () => string
52
+ model: () => string
53
+ fuel: () => string
54
+ vin: () => string
73
55
  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
- };
56
+ }
57
+ declare interface HelpersCompatibility {
58
+ arrayElement: <T>(array: T[]) => T
59
+ arrayElements: <T>(array: T[], count?: number) => T[]
60
+ shuffle: <T>(array: T[]) => T[]
61
+ maybe: <T>(callback: () => T, options?: { probability?: number }) => T | undefined
62
+ objectKey: <T extends object>(obj: T) => keyof T
63
+ objectValue: <T extends object>(obj: T) => T[keyof T]
64
+ }
140
65
  /**
141
66
  * Enhanced lorem module with better API
142
- * @defaultValue `{ ...baseFaker.lorem }`
143
67
  */
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
- */
68
+ declare interface LoremCompatibility {
69
+ word: () => string
70
+ words: (count?: number) => string
71
+ sentence: (maxWords?: number) => string
72
+ sentences: (count?: number, separator?: string) => string
73
+ paragraph: (sentenceCount?: number) => string
74
+ paragraphs: (count?: number, separator?: string) => string
75
+ text: (length?: number) => string
76
+ slug: (wordCount?: number) => string
237
77
  lines: (count?: number) => string
238
- };
78
+ }
239
79
  /**
240
80
  * Enhanced faker instance with improved lorem API and @faker-js/faker compatibility
241
- * @defaultValue `{ ...baseFaker }`
242
81
  */
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;
82
+ declare interface FakerCompatibility {
83
+ lorem: typeof enhancedLorem
84
+ datatype: typeof datatype
85
+ location: typeof location
86
+ company: typeof company
87
+ vehicle: typeof vehicle
249
88
  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
- };
89
+ }
90
+ declare type EnhancedCompany = Omit<typeof baseFaker.company, keyof CompanyCompatibility> & CompanyCompatibility;
91
+ declare type EnhancedVehicle = Omit<typeof baseFaker.vehicle, keyof VehicleCompatibility> & VehicleCompatibility;
92
+ declare type EnhancedHelpers = Omit<typeof baseFaker.helpers, keyof HelpersCompatibility> & HelpersCompatibility;
93
+ declare type EnhancedLorem = Omit<typeof baseFaker.lorem, keyof LoremCompatibility> & LoremCompatibility;
94
+ declare type EnhancedFaker = Omit<typeof baseFaker, keyof FakerCompatibility> & FakerCompatibility;
258
95
  export type Faker = BaseFaker;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/faker",
3
3
  "type": "module",
4
- "version": "0.70.91",
4
+ "version": "0.70.92",
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.91",
57
- "@stacksjs/config": "0.70.91",
56
+ "@stacksjs/cli": "0.70.92",
57
+ "@stacksjs/config": "0.70.92",
58
58
  "better-dx": "^0.2.16",
59
59
  "@stacksjs/ts-faker": "^0.1.7"
60
60
  },