mimic-data 1.2.0 → 1.2.1
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 +201 -274
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
# mimic-data
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/mimic-data)
|
|
4
|
+
[](https://www.npmjs.com/package/mimic-data)
|
|
5
|
+
[](https://opensourceimic-data.svg.org/licenses/MIT)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
|
|
3
8
|
Library TypeScript ringan tanpa dependency eksternal untuk menghasilkan data dummy yang realistis dengan dukungan lokalisasi yang kuat.
|
|
4
9
|
|
|
5
10
|
## ✨ Fitur
|
|
6
11
|
|
|
7
|
-
- 🌍 **
|
|
8
|
-
- 🪶 **Ringan** - Zero runtime dependencies
|
|
12
|
+
- 🌍 **101 Locale** - Coverage global yang sangat luas
|
|
13
|
+
- 🪶 **Ringan** - Zero runtime dependencies (~15KB minified)
|
|
9
14
|
- 📦 **Tree-shakeable** - Hanya bundle yang Anda gunakan
|
|
10
15
|
- 🔧 **TypeScript Native** - Full type safety
|
|
11
16
|
- 🎯 **Mudah Digunakan** - API yang sederhana dan intuitif
|
|
@@ -20,9 +25,7 @@ yarn add mimic-data
|
|
|
20
25
|
pnpm add mimic-data
|
|
21
26
|
```
|
|
22
27
|
|
|
23
|
-
## 🚀
|
|
24
|
-
|
|
25
|
-
### Metode 1: Factory Function (Rekomendasi)
|
|
28
|
+
## 🚀 Quick Start
|
|
26
29
|
|
|
27
30
|
```typescript
|
|
28
31
|
import { createMimic } from 'mimic-data';
|
|
@@ -38,20 +41,73 @@ console.log(mimic.location.fullAddress());
|
|
|
38
41
|
// Output: "Jl. Merdeka No. 123, RT 5/RW 3, Jakarta, DKI Jakarta 12345"
|
|
39
42
|
```
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
import { Mimic, locales } from 'mimic-data';
|
|
45
|
-
|
|
46
|
-
const mimic = new Mimic(locales.ja_JP);
|
|
44
|
+
## 📚 API Overview
|
|
47
45
|
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
### `createMimic(locale?: string): Mimic`
|
|
47
|
+
Buat instance Mimic dengan locale tertentu. Default: `en_US`
|
|
50
48
|
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
```typescript
|
|
50
|
+
const mimic = createMimic('ja_JP');
|
|
51
|
+
const mimicDefault = createMimic(); // menggunakan en_US
|
|
53
52
|
```
|
|
54
53
|
|
|
54
|
+
### Module Exports
|
|
55
|
+
|
|
56
|
+
| Export | Deskripsi |
|
|
57
|
+
|--------|-----------|
|
|
58
|
+
| `createMimic` | Factory function untuk membuat instance Mimic |
|
|
59
|
+
| `Mimic` | Class utama untuk generate data |
|
|
60
|
+
| `locales` | Object semua locale definitions |
|
|
61
|
+
| `Random` | Utility untuk random generation |
|
|
62
|
+
| `localeRegistry` | Registry untuk manage locales |
|
|
63
|
+
| `getAvailableLocales()` | Get semua locale codes utama |
|
|
64
|
+
| `getAllLocaleCodes()` | Get semua locale codes + aliases |
|
|
65
|
+
|
|
66
|
+
### Mimic Methods
|
|
67
|
+
|
|
68
|
+
| Module | Method | Deskripsi |
|
|
69
|
+
|--------|--------|-----------|
|
|
70
|
+
| `identity` | `firstName(gender?)` | Nama depan (male/female/random) |
|
|
71
|
+
| | `lastName()` | Nama belakang |
|
|
72
|
+
| | `fullName(gender?)` | Nama lengkap (format budaya) |
|
|
73
|
+
| | `gender()` | Gender (male/female) |
|
|
74
|
+
| | `age(range?)` | Umur (default 18-65) |
|
|
75
|
+
| | `dateOfBirth(range?)` | Tanggal lahir |
|
|
76
|
+
| | `person(gender?, range?)` | Semua data person |
|
|
77
|
+
| | `persons(count, gender?, range?)` | Generate multiple persons |
|
|
78
|
+
| | `uniquePersons(count, gender?, range?)` | Generate unique persons |
|
|
79
|
+
| `location` | `street()` | Nama jalan |
|
|
80
|
+
| | `city()` | Kota |
|
|
81
|
+
| | `state()` | Provinsi/State |
|
|
82
|
+
| | `zipCode()` | Kode pos |
|
|
83
|
+
| | `fullAddress()` | Alamat lengkap |
|
|
84
|
+
| | `address()` | Semua data address |
|
|
85
|
+
| | `addresses(count)` | Generate multiple addresses |
|
|
86
|
+
| | `uniqueAddresses(count)` | Generate unique addresses |
|
|
87
|
+
| `physical` | `height()` | Tinggi badan |
|
|
88
|
+
| | `weight()` | Berat badan |
|
|
89
|
+
| | `data()` | Semua data fisik |
|
|
90
|
+
| | `datas(count)` | Generate multiple physical data |
|
|
91
|
+
| `work` | `jobTitle()` | Judul pekerjaan |
|
|
92
|
+
| | `department()` | Departemen |
|
|
93
|
+
| | `data()` | Semua data pekerjaan |
|
|
94
|
+
| | `datas(count)` | Generate multiple work data |
|
|
95
|
+
| | `uniqueJobTitles(count)` | Unique job titles |
|
|
96
|
+
| | `uniqueDepartments(count)` | Unique departments |
|
|
97
|
+
| `contact` | `email(firstName?, lastName?)` | Email address |
|
|
98
|
+
| | `phone()` | Nomor telepon |
|
|
99
|
+
| | `website(name?)` | Website URL |
|
|
100
|
+
| | `data(firstName?, lastName?)` | Semua data kontak |
|
|
101
|
+
| | `datas(count)` | Generate multiple contact data |
|
|
102
|
+
| `company` | `name()` | Nama perusahaan |
|
|
103
|
+
| | `industry()` | Industri |
|
|
104
|
+
| | `catchPhrase()` | Tagline perusahaan |
|
|
105
|
+
| | `data()` | Semua data perusahaan |
|
|
106
|
+
| | `datas(count)` | Generate multiple company data |
|
|
107
|
+
| `Mimic` | `setLocale(locale)` | Ganti locale |
|
|
108
|
+
| | `generateMockEntities(count, options?)` | Generate complete entities |
|
|
109
|
+
| | `generateUniqueMockEntities(count, options?)` | Generate unique entities |
|
|
110
|
+
|
|
55
111
|
## 🌏 Locale yang Tersedia (101 Locale!)
|
|
56
112
|
|
|
57
113
|
### Americas 🌎 (17)
|
|
@@ -165,290 +221,80 @@ console.log(mimic.location.fullAddress());
|
|
|
165
221
|
|
|
166
222
|
**Total: 101 Locale dengan 250+ Aliases!**
|
|
167
223
|
|
|
168
|
-
##
|
|
224
|
+
## 💻 Contoh Penggunaan
|
|
169
225
|
|
|
170
|
-
###
|
|
226
|
+
### Penggunaan Dasar
|
|
171
227
|
|
|
172
228
|
```typescript
|
|
173
|
-
|
|
174
|
-
mimic.identity.firstName('male'); // "Takashi"
|
|
175
|
-
mimic.identity.firstName('female'); // "Yuki"
|
|
176
|
-
mimic.identity.firstName(); // Random gender
|
|
177
|
-
|
|
178
|
-
// Nama belakang
|
|
179
|
-
mimic.identity.lastName(); // "Tanaka"
|
|
180
|
-
|
|
181
|
-
// Nama lengkap (format sesuai budaya)
|
|
182
|
-
mimic.identity.fullName('male'); // Japan: "Tanaka Takashi"
|
|
183
|
-
// US: "John Smith"
|
|
184
|
-
// ID: "Budi Santoso"
|
|
185
|
-
|
|
186
|
-
// Gender
|
|
187
|
-
mimic.identity.gender(); // "male" | "female"
|
|
188
|
-
|
|
189
|
-
// Umur dengan range
|
|
190
|
-
mimic.identity.age(); // 18-65 (default)
|
|
191
|
-
mimic.identity.age({ min: 25, max: 40 }); // Custom range
|
|
192
|
-
|
|
193
|
-
// Tanggal lahir
|
|
194
|
-
mimic.identity.dateOfBirth();
|
|
195
|
-
mimic.identity.dateOfBirth({ min: 30, max: 50 });
|
|
196
|
-
|
|
197
|
-
// Generate semua data person sekaligus
|
|
198
|
-
const person = mimic.identity.person('female', { min: 25, max: 35 });
|
|
199
|
-
// {
|
|
200
|
-
// firstName: "Yuki",
|
|
201
|
-
// lastName: "Tanaka",
|
|
202
|
-
// fullName: "Tanaka Yuki",
|
|
203
|
-
// gender: "female",
|
|
204
|
-
// age: 28,
|
|
205
|
-
// dateOfBirth: Date
|
|
206
|
-
// }
|
|
207
|
-
|
|
208
|
-
// 🚀 NEW: Generate multiple persons at once
|
|
209
|
-
const persons = mimic.identity.persons(10); // Array of 10 persons
|
|
210
|
-
|
|
211
|
-
// 🚀 NEW: Generate unique persons (no duplicate full names)
|
|
212
|
-
const uniquePersons = mimic.identity.uniquePersons(5);
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
### Location (Lokasi)
|
|
216
|
-
|
|
217
|
-
```typescript
|
|
218
|
-
// Komponen alamat individual
|
|
219
|
-
mimic.location.street(); // "Chuo-dori"
|
|
220
|
-
mimic.location.city(); // "Tokyo"
|
|
221
|
-
mimic.location.state(); // "Kanagawa"
|
|
222
|
-
mimic.location.zipCode(); // "123-4567" (Japan format)
|
|
223
|
-
|
|
224
|
-
// Alamat lengkap (format sesuai negara)
|
|
225
|
-
mimic.location.fullAddress();
|
|
226
|
-
// Japan: "〒123-4567 Tokyo, Yokohama, Chuo-dori 2-5-10"
|
|
227
|
-
// US: "1234 Main Street, New York, California 12345"
|
|
228
|
-
// ID: "Jl. Merdeka No. 123, RT 5/RW 3, Jakarta, DKI Jakarta 12345"
|
|
229
|
-
|
|
230
|
-
// Generate semua data address sekaligus
|
|
231
|
-
const address = mimic.location.address();
|
|
232
|
-
// {
|
|
233
|
-
// street: "Chuo-dori",
|
|
234
|
-
// city: "Tokyo",
|
|
235
|
-
// state: "Kanagawa",
|
|
236
|
-
// zipCode: "123-4567",
|
|
237
|
-
// fullAddress: "〒123-4567 Tokyo, Yokohama, Chuo-dori 2-5-10"
|
|
238
|
-
// }
|
|
239
|
-
|
|
240
|
-
// 🚀 NEW: Generate multiple addresses at once
|
|
241
|
-
const addresses = mimic.location.addresses(10); // Array of 10 addresses
|
|
242
|
-
|
|
243
|
-
// 🚀 NEW: Generate unique addresses (no duplicate full addresses)
|
|
244
|
-
const uniqueAddresses = mimic.location.uniqueAddresses(5);
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
### Physical (Data Fisik)
|
|
248
|
-
|
|
249
|
-
```typescript
|
|
250
|
-
// Tinggi (unit sesuai locale)
|
|
251
|
-
mimic.physical.height();
|
|
252
|
-
// Metric: { height: 175, weight: 0, heightUnit: 'cm', weightUnit: 'kg' }
|
|
253
|
-
// Imperial: { height: 5.9, weight: 0, heightUnit: 'ft', weightUnit: 'lb' }
|
|
254
|
-
|
|
255
|
-
// Berat (unit sesuai locale)
|
|
256
|
-
mimic.physical.weight();
|
|
257
|
-
// Metric: { height: 0, weight: 70, heightUnit: 'cm', weightUnit: 'kg' }
|
|
258
|
-
// Imperial: { height: 0, weight: 154, heightUnit: 'ft', weightUnit: 'lb' }
|
|
259
|
-
|
|
260
|
-
// Generate semua data physical sekaligus
|
|
261
|
-
const physical = mimic.physical.data();
|
|
262
|
-
// Metric: { height: 175, weight: 70, heightUnit: 'cm', weightUnit: 'kg' }
|
|
263
|
-
// Imperial: { height: 5.9, weight: 154, heightUnit: 'ft', weightUnit: 'lb' }
|
|
264
|
-
|
|
265
|
-
// 🚀 NEW: Generate multiple physical data at once
|
|
266
|
-
const physicals = mimic.physical.datas(10); // Array of 10 physical data
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
### Work (Data Pekerjaan)
|
|
270
|
-
|
|
271
|
-
```typescript
|
|
272
|
-
mimic.work.jobTitle(); // "Software Engineer"
|
|
273
|
-
mimic.work.department(); // "Engineering"
|
|
274
|
-
|
|
275
|
-
// Generate semua data work sekaligus
|
|
276
|
-
const work = mimic.work.data();
|
|
277
|
-
// {
|
|
278
|
-
// jobTitle: "Software Engineer",
|
|
279
|
-
// department: "Engineering"
|
|
280
|
-
// }
|
|
281
|
-
|
|
282
|
-
// 🚀 NEW: Generate multiple work data at once
|
|
283
|
-
const works = mimic.work.datas(10); // Array of 10 work data
|
|
284
|
-
|
|
285
|
-
// 🚀 NEW: Generate unique job titles
|
|
286
|
-
const uniqueJobTitles = mimic.work.uniqueJobTitles(5);
|
|
287
|
-
|
|
288
|
-
// 🚀 NEW: Generate unique departments
|
|
289
|
-
const uniqueDepartments = mimic.work.uniqueDepartments(3);
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
### Contact (Kontak) - NEW! 📧
|
|
293
|
-
|
|
294
|
-
```typescript
|
|
295
|
-
// Generate email
|
|
296
|
-
mimic.contact.email('John', 'Doe'); // "john.doe123@gmail.com"
|
|
297
|
-
mimic.contact.email('Jane'); // "jane456@yahoo.com"
|
|
298
|
-
mimic.contact.email(); // "random789@outlook.com"
|
|
299
|
-
|
|
300
|
-
// Generate phone number (locale-specific format)
|
|
301
|
-
mimic.contact.phone(); // US: "+1 (555) 123-4567"
|
|
302
|
-
// ID: "+62 812-3456-7890"
|
|
303
|
-
|
|
304
|
-
// Generate website
|
|
305
|
-
mimic.contact.website(); // "www.acme-corp.com"
|
|
306
|
-
mimic.contact.website('Google');// "www.google.com"
|
|
307
|
-
|
|
308
|
-
// Generate complete contact data
|
|
309
|
-
const contact = mimic.contact.data('John', 'Doe');
|
|
310
|
-
// {
|
|
311
|
-
// email: "john.doe123@gmail.com",
|
|
312
|
-
// phone: "+1 (555) 123-4567",
|
|
313
|
-
// website: "www.john-doe.com"
|
|
314
|
-
// }
|
|
315
|
-
|
|
316
|
-
// 🚀 Generate multiple contact data
|
|
317
|
-
const contacts = mimic.contact.datas(10);
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
### Company (Perusahaan) - NEW! 🏢
|
|
321
|
-
|
|
322
|
-
```typescript
|
|
323
|
-
// Generate company name
|
|
324
|
-
mimic.company.name(); // "Techflow Solutions"
|
|
325
|
-
// "PT Telkom Indonesia" (id_ID)
|
|
326
|
-
|
|
327
|
-
// Generate industry
|
|
328
|
-
mimic.company.industry(); // "Technology"
|
|
329
|
-
// "Teknologi" (id_ID)
|
|
229
|
+
import { createMimic } from 'mimic-data';
|
|
330
230
|
|
|
331
|
-
|
|
332
|
-
mimic.company.catchPhrase(); // "Empower innovative solutions"
|
|
231
|
+
const mimic = createMimic('ja_JP');
|
|
333
232
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
// {
|
|
337
|
-
// name: "Quantumspark Labs",
|
|
338
|
-
// industry: "Technology",
|
|
339
|
-
// catchPhrase: "Transform cutting-edge experiences"
|
|
340
|
-
// }
|
|
233
|
+
console.log(mimic.identity.fullName());
|
|
234
|
+
// Output: "Tanaka Kenji"
|
|
341
235
|
|
|
342
|
-
|
|
343
|
-
|
|
236
|
+
console.log(mimic.location.fullAddress());
|
|
237
|
+
// Output: "〒123-4567 Tokyo, Yokohama, Chuo-dori 2-5-10"
|
|
344
238
|
```
|
|
345
239
|
|
|
346
|
-
###
|
|
240
|
+
### Dengan Class Langsung
|
|
347
241
|
|
|
348
242
|
```typescript
|
|
349
|
-
|
|
350
|
-
console.log(mimic.identity.fullName()); // "John Smith"
|
|
243
|
+
import { Mimic, locales } from 'mimic-data';
|
|
351
244
|
|
|
352
|
-
mimic
|
|
353
|
-
console.log(mimic.identity.fullName());
|
|
245
|
+
const mimic = new Mimic(locales.de_DE);
|
|
246
|
+
console.log(mimic.identity.fullName('female'));
|
|
247
|
+
// Output: "Maria Müller"
|
|
354
248
|
```
|
|
355
249
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
### 🔁 Seeded Random (Reproducible Data)
|
|
359
|
-
|
|
360
|
-
Generate data yang sama secara konsisten untuk testing:
|
|
250
|
+
### Seeded Random (Reproducible Data)
|
|
361
251
|
|
|
362
252
|
```typescript
|
|
363
253
|
import { createMimic, Random } from 'mimic-data';
|
|
364
254
|
|
|
365
|
-
// Set seed untuk reproducible randomness
|
|
366
255
|
Random.seed(12345);
|
|
367
256
|
|
|
368
257
|
const mimic = createMimic('en_US');
|
|
369
258
|
const person1 = mimic.identity.person('male', { min: 25, max: 35 });
|
|
370
259
|
|
|
371
|
-
// Reset seed yang sama
|
|
372
260
|
Random.seed(12345);
|
|
373
261
|
const person2 = mimic.identity.person('male', { min: 25, max: 35 });
|
|
374
262
|
|
|
375
|
-
// person1 dan person2 akan IDENTIK!
|
|
376
263
|
console.log(person1.fullName === person2.fullName); // true
|
|
377
|
-
console.log(person1.age === person2.age); // true
|
|
378
264
|
|
|
379
|
-
// Reset ke random non-deterministik
|
|
380
265
|
Random.unseed();
|
|
381
266
|
```
|
|
382
267
|
|
|
383
|
-
###
|
|
384
|
-
|
|
385
|
-
Generate banyak data sekaligus dengan performa optimal:
|
|
268
|
+
### Bulk Generation
|
|
386
269
|
|
|
387
270
|
```typescript
|
|
388
271
|
import { createMimic } from 'mimic-data';
|
|
389
272
|
|
|
390
273
|
const mimic = createMimic('id_ID');
|
|
391
274
|
|
|
392
|
-
// Generate 100 persons sekaligus
|
|
393
275
|
const persons = mimic.identity.persons(100);
|
|
394
|
-
|
|
395
|
-
// Generate 50 unique addresses (no duplicates)
|
|
396
276
|
const addresses = mimic.location.uniqueAddresses(50);
|
|
397
277
|
|
|
398
|
-
|
|
399
|
-
const entities = mimic.generateMockEntities(200, {
|
|
278
|
+
const employees = mimic.generateMockEntities(200, {
|
|
400
279
|
gender: 'female',
|
|
401
280
|
ageRange: { min: 20, max: 40 }
|
|
402
281
|
});
|
|
403
|
-
|
|
404
|
-
// Generate unique mock entities
|
|
405
|
-
const uniqueEntities = mimic.generateUniqueMockEntities(100);
|
|
406
|
-
```
|
|
407
|
-
|
|
408
|
-
### 🎯 Random Utilities
|
|
409
|
-
|
|
410
|
-
```typescript
|
|
411
|
-
import { Random } from 'mimic-data';
|
|
412
|
-
|
|
413
|
-
// Generate multiple values
|
|
414
|
-
const numbers = Random.multiple(() => Random.int(1, 100), 10);
|
|
415
|
-
|
|
416
|
-
// Generate unique values (no duplicates)
|
|
417
|
-
const uniqueNumbers = Random.unique(() => Random.int(1, 1000), 20);
|
|
418
|
-
|
|
419
|
-
// Shuffle array
|
|
420
|
-
const shuffled = Random.shuffle([1, 2, 3, 4, 5]);
|
|
421
|
-
|
|
422
|
-
// Pick random element
|
|
423
|
-
const randomItem = Random.pick(['apple', 'banana', 'cherry']);
|
|
424
|
-
```
|
|
425
|
-
|
|
426
|
-
### ⚡ Performance Improvements
|
|
427
|
-
|
|
428
|
-
- **Caching**: Generator methods di-cache untuk performa lebih cepat
|
|
429
|
-
- **Bulk Operations**: Generate banyak data dalam satu panggilan
|
|
430
|
-
- **Optimized Getters**: Tidak ada recreation pada setiap akses
|
|
431
|
-
|
|
432
|
-
```typescript
|
|
433
|
-
// Getter methods sekarang di-cache (lebih cepat)
|
|
434
|
-
const identity1 = mimic.identity;
|
|
435
|
-
const identity2 = mimic.identity;
|
|
436
|
-
console.log(identity1 === identity2); // true (same cached instance)
|
|
437
282
|
```
|
|
438
283
|
|
|
439
|
-
|
|
284
|
+
### Complete Employee Data
|
|
440
285
|
|
|
441
286
|
```typescript
|
|
442
287
|
import { createMimic } from 'mimic-data';
|
|
443
288
|
|
|
444
|
-
// Generate data karyawan Indonesia
|
|
445
289
|
const mimic = createMimic('id_ID');
|
|
446
290
|
|
|
447
291
|
const employee = {
|
|
448
292
|
...mimic.identity.person('male', { min: 25, max: 40 }),
|
|
449
293
|
...mimic.location.address(),
|
|
450
294
|
...mimic.physical.data(),
|
|
451
|
-
...mimic.work.data()
|
|
295
|
+
...mimic.work.data(),
|
|
296
|
+
...mimic.contact.data(),
|
|
297
|
+
...mimic.company.data()
|
|
452
298
|
};
|
|
453
299
|
|
|
454
300
|
console.log(employee);
|
|
@@ -469,10 +315,109 @@ console.log(employee);
|
|
|
469
315
|
// heightUnit: "cm",
|
|
470
316
|
// weightUnit: "kg",
|
|
471
317
|
// jobTitle: "Software Engineer",
|
|
472
|
-
// department: "Engineering"
|
|
318
|
+
// department: "Engineering",
|
|
319
|
+
// email: "budi.santoso123@gmail.com",
|
|
320
|
+
// phone: "+62 812-3456-7890",
|
|
321
|
+
// website: "www.budi-santoso.com",
|
|
322
|
+
// name: "Techflow Solutions",
|
|
323
|
+
// industry: "Technology",
|
|
324
|
+
// catchPhrase: "Empower innovative solutions"
|
|
473
325
|
// }
|
|
474
326
|
```
|
|
475
327
|
|
|
328
|
+
## 🔧 TypeScript Types
|
|
329
|
+
|
|
330
|
+
```typescript
|
|
331
|
+
import {
|
|
332
|
+
Gender,
|
|
333
|
+
MetricSystem,
|
|
334
|
+
PersonData,
|
|
335
|
+
AddressData,
|
|
336
|
+
PhysicalData,
|
|
337
|
+
WorkData,
|
|
338
|
+
ContactData,
|
|
339
|
+
CompanyData,
|
|
340
|
+
AgeRange,
|
|
341
|
+
LocaleDefinition
|
|
342
|
+
} from 'mimic-data';
|
|
343
|
+
|
|
344
|
+
const person: PersonData = mimic.identity.person('female', { min: 25, max: 35 });
|
|
345
|
+
const address: AddressData = mimic.location.address();
|
|
346
|
+
const physical: PhysicalData = mimic.physical.data();
|
|
347
|
+
const work: WorkData = mimic.work.data();
|
|
348
|
+
const contact: ContactData = mimic.contact.data();
|
|
349
|
+
const company: CompanyData = mimic.company.data();
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
### Type Definitions
|
|
353
|
+
|
|
354
|
+
```typescript
|
|
355
|
+
type Gender = 'male' | 'female';
|
|
356
|
+
type MetricSystem = 'metric' | 'imperial';
|
|
357
|
+
|
|
358
|
+
interface PersonData {
|
|
359
|
+
firstName: string;
|
|
360
|
+
lastName: string;
|
|
361
|
+
fullName: string;
|
|
362
|
+
gender: Gender;
|
|
363
|
+
age: number;
|
|
364
|
+
dateOfBirth: Date;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
interface AddressData {
|
|
368
|
+
street: string;
|
|
369
|
+
city: string;
|
|
370
|
+
state: string;
|
|
371
|
+
zipCode: string;
|
|
372
|
+
fullAddress: string;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
interface PhysicalData {
|
|
376
|
+
height: number;
|
|
377
|
+
weight: number;
|
|
378
|
+
heightUnit: 'cm' | 'ft';
|
|
379
|
+
weightUnit: 'kg' | 'lb';
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
interface WorkData {
|
|
383
|
+
jobTitle: string;
|
|
384
|
+
department: string;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
interface ContactData {
|
|
388
|
+
email: string;
|
|
389
|
+
phone: string;
|
|
390
|
+
website: string;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
interface CompanyData {
|
|
394
|
+
name: string;
|
|
395
|
+
industry: string;
|
|
396
|
+
catchPhrase: string;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
interface AgeRange {
|
|
400
|
+
min?: number;
|
|
401
|
+
max?: number;
|
|
402
|
+
}
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
## 🎲 Random Utilities
|
|
406
|
+
|
|
407
|
+
```typescript
|
|
408
|
+
import { Random } from 'mimic-data';
|
|
409
|
+
|
|
410
|
+
Random.seed(12345);
|
|
411
|
+
|
|
412
|
+
Random.int(1, 100);
|
|
413
|
+
Random.float(1.5, 10.5, 2);
|
|
414
|
+
Random.boolean();
|
|
415
|
+
Random.pick(['a', 'b', 'c']);
|
|
416
|
+
Random.shuffle([1, 2, 3, 4, 5]);
|
|
417
|
+
Random.multiple(() => Random.int(1, 100), 10);
|
|
418
|
+
Random.unique(() => Random.int(1, 1000), 20);
|
|
419
|
+
```
|
|
420
|
+
|
|
476
421
|
## 🛠️ Development
|
|
477
422
|
|
|
478
423
|
```bash
|
|
@@ -500,7 +445,7 @@ MIT
|
|
|
500
445
|
|
|
501
446
|
Kontribusi sangat diterima! Silakan buka issue atau pull request.
|
|
502
447
|
|
|
503
|
-
### Menambahkan Locale Baru
|
|
448
|
+
### Menambahkan Locale Baru
|
|
504
449
|
|
|
505
450
|
Dengan **Registry System**, menambah locale baru sangat mudah:
|
|
506
451
|
|
|
@@ -508,33 +453,28 @@ Dengan **Registry System**, menambah locale baru sangat mudah:
|
|
|
508
453
|
2. **Implement interface** `LocaleDefinition`
|
|
509
454
|
3. **Import dan register** di `src/index.ts`
|
|
510
455
|
|
|
511
|
-
**Contoh: Menambahkan locale Spanyol**
|
|
512
|
-
|
|
513
456
|
```typescript
|
|
514
457
|
// 1. Buat file: src/locales/es_ES.ts
|
|
515
458
|
import { LocaleDefinition } from '../types';
|
|
516
459
|
import { Random } from '../core/random';
|
|
517
460
|
|
|
518
461
|
export const es_ES: LocaleDefinition = {
|
|
519
|
-
firstNamesMale: ['Carlos', 'José', 'Antonio'
|
|
520
|
-
firstNamesFemale: ['María', 'Carmen', 'Ana'
|
|
521
|
-
lastNames: ['García', 'Fernández', 'López'
|
|
522
|
-
streets: ['Calle Mayor', 'Avenida Castellana'
|
|
523
|
-
cities: ['Madrid', 'Barcelona', 'Valencia'
|
|
524
|
-
states: ['Madrid', 'Cataluña', 'Andalucía'
|
|
462
|
+
firstNamesMale: ['Carlos', 'José', 'Antonio'],
|
|
463
|
+
firstNamesFemale: ['María', 'Carmen', 'Ana'],
|
|
464
|
+
lastNames: ['García', 'Fernández', 'López'],
|
|
465
|
+
streets: ['Calle Mayor', 'Avenida Castellana'],
|
|
466
|
+
cities: ['Madrid', 'Barcelona', 'Valencia'],
|
|
467
|
+
states: ['Madrid', 'Cataluña', 'Andalucía'],
|
|
525
468
|
zipCodePattern: '#####',
|
|
526
|
-
jobTitles: ['Ingeniero de Software'
|
|
527
|
-
departments: ['Ingeniería', 'Marketing'
|
|
469
|
+
jobTitles: ['Ingeniero de Software'],
|
|
470
|
+
departments: ['Ingeniería', 'Marketing'],
|
|
528
471
|
metricSystem: 'metric',
|
|
529
|
-
|
|
530
472
|
formatFullName(firstName, lastName) {
|
|
531
473
|
return `${firstName} ${lastName}`;
|
|
532
474
|
},
|
|
533
|
-
|
|
534
475
|
formatAddress(street, city, state, zipCode) {
|
|
535
476
|
return `${street} ${Random.int(1, 200)}, ${zipCode} ${city}`;
|
|
536
477
|
},
|
|
537
|
-
|
|
538
478
|
generateZipCode() {
|
|
539
479
|
return String(Random.int(10000, 99999));
|
|
540
480
|
}
|
|
@@ -543,19 +483,6 @@ export const es_ES: LocaleDefinition = {
|
|
|
543
483
|
// 2. Register di src/index.ts
|
|
544
484
|
import { es_ES } from './locales/es_ES';
|
|
545
485
|
localeRegistry.register('es_ES', es_ES, ['es', 'spain', 'españa']);
|
|
546
|
-
|
|
547
|
-
// 3. Export (opsional, untuk advanced usage)
|
|
548
|
-
export const locales = {
|
|
549
|
-
// ... existing locales
|
|
550
|
-
es_ES
|
|
551
|
-
};
|
|
552
|
-
```
|
|
553
|
-
|
|
554
|
-
**Selesai!** Locale baru Anda langsung tersedia:
|
|
555
|
-
|
|
556
|
-
```typescript
|
|
557
|
-
const mimic = createMimic('es'); // atau 'es_ES' atau 'spain'
|
|
558
|
-
console.log(mimic.identity.fullName()); // "Carlos García"
|
|
559
486
|
```
|
|
560
487
|
|
|
561
488
|
## 🙏 Acknowledgments
|
|
@@ -564,4 +491,4 @@ Terinspirasi oleh library seperti Faker.js, namun dengan fokus pada:
|
|
|
564
491
|
- Zero runtime dependencies
|
|
565
492
|
- Lokalisasi yang lebih akurat
|
|
566
493
|
- Bundle size yang lebih kecil
|
|
567
|
-
- TypeScript-first approach
|
|
494
|
+
- TypeScript-first approach
|
package/package.json
CHANGED