faker-i18n 0.1.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/LICENCE +21 -0
- package/README.md +118 -0
- package/dist/core/random.d.ts +4 -0
- package/dist/core/random.js +13 -0
- package/dist/fields/internet.d.ts +11 -0
- package/dist/fields/internet.js +12 -0
- package/dist/fields/misc.d.ts +11 -0
- package/dist/fields/misc.js +12 -0
- package/dist/fields/person.d.ts +7 -0
- package/dist/fields/person.js +7 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +54 -0
- package/dist/locales/de.d.ts +7 -0
- package/dist/locales/de.js +7 -0
- package/dist/locales/en.d.ts +7 -0
- package/dist/locales/en.js +7 -0
- package/dist/locales/es.d.ts +7 -0
- package/dist/locales/es.js +7 -0
- package/dist/locales/fr.d.ts +7 -0
- package/dist/locales/fr.js +7 -0
- package/dist/locales/ja.d.ts +7 -0
- package/dist/locales/ja.js +7 -0
- package/dist/locales/pt.d.ts +7 -0
- package/dist/locales/pt.js +7 -0
- package/dist/locales/ru.d.ts +7 -0
- package/dist/locales/ru.js +7 -0
- package/dist/locales/tr.d.ts +7 -0
- package/dist/locales/tr.js +7 -0
- package/dist/locales/zh.d.ts +7 -0
- package/dist/locales/zh.js +7 -0
- package/dist/types/locale.d.ts +7 -0
- package/dist/types/locale.js +1 -0
- package/package.json +38 -0
package/LICENCE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 mikefox10
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# faker-i18n
|
|
2
|
+
|
|
3
|
+
✨ **faker-i18n** is a lightweight library for generating fake data in a simple, fast, and dependency-free way.
|
|
4
|
+
Perfect for **tests**, **seeders**, **mocking**, and **prototyping**.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
## 🌍 Supported Locales
|
|
8
|
+
|
|
9
|
+
Currently supported locales:
|
|
10
|
+
|
|
11
|
+
- EN – English (Default)
|
|
12
|
+
|
|
13
|
+
- ES – Spanish
|
|
14
|
+
|
|
15
|
+
- PT – Portuguese
|
|
16
|
+
|
|
17
|
+
- FR – French
|
|
18
|
+
|
|
19
|
+
- DE – German
|
|
20
|
+
|
|
21
|
+
- RU – Russian
|
|
22
|
+
|
|
23
|
+
- JA – Japanese
|
|
24
|
+
|
|
25
|
+
- ZH – Chinese
|
|
26
|
+
|
|
27
|
+
- TR – Turkish
|
|
28
|
+
|
|
29
|
+
## 📦 Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install faker-i18n
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Basic Usage
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
import { faker } from "faker-i18n";
|
|
39
|
+
|
|
40
|
+
const fake = faker("EN");
|
|
41
|
+
|
|
42
|
+
console.log(fake.firstName()); // Mike
|
|
43
|
+
console.log(fake.lastName()); // Taylor
|
|
44
|
+
console.log(fake.company()); // Soft Inc
|
|
45
|
+
console.log(fake.jobTitle()); // Designer
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Person
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
fake.firstName(); // Mike
|
|
52
|
+
fake.lastName(); // Taylor
|
|
53
|
+
fake.fullName(); // Mike Taylor
|
|
54
|
+
fake.company(); // Soft Inc
|
|
55
|
+
fake.jobTitle(); // Designer
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Internet
|
|
59
|
+
```bash
|
|
60
|
+
fake.email(); // vwvsqu@gmail.com
|
|
61
|
+
fake.username(); // user_irp593
|
|
62
|
+
fake.password(); // wriocxwhpxeb
|
|
63
|
+
fake.domain(); // gmail.com
|
|
64
|
+
fake.avatarUrl(); // https://i.pravatar.cc/131
|
|
65
|
+
fake.url(); // https://site966.com
|
|
66
|
+
fake.ip(); // 9.92.10.212
|
|
67
|
+
fake.mac(); // zn:pl:mt
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Location
|
|
71
|
+
```bash
|
|
72
|
+
fake.city(); // Texas
|
|
73
|
+
fake.zipCode(); // 88295
|
|
74
|
+
fake.phone(); // +3 63080859
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Utilities
|
|
78
|
+
```bash
|
|
79
|
+
fake.uuid(); // fe4e9431-4fe1-47d1-a16c-8b58ce10bf4e
|
|
80
|
+
fake.boolean(); // true
|
|
81
|
+
fake.currency(); // USD
|
|
82
|
+
fake.numberBetween(1, 4); // 3
|
|
83
|
+
fake.color(); // #823109
|
|
84
|
+
fake.lorem(); // Lorem ipsum dolor sit amet
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
## 🎯 Project Goals
|
|
91
|
+
|
|
92
|
+
🪶 Lightweight and fast
|
|
93
|
+
|
|
94
|
+
📦 No unnecessary dependencies
|
|
95
|
+
|
|
96
|
+
🌍 Multi-language support
|
|
97
|
+
|
|
98
|
+
🧪 Ideal for tests and mocks
|
|
99
|
+
|
|
100
|
+
💡 Simple and predictable API
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
## Contributions are welcome 🙌
|
|
105
|
+
Feel free to open issues or pull requests for:
|
|
106
|
+
|
|
107
|
+
- New locales
|
|
108
|
+
|
|
109
|
+
- New generators
|
|
110
|
+
|
|
111
|
+
- Performance improvements
|
|
112
|
+
|
|
113
|
+
- Bug fixes
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
### 📄 License
|
|
117
|
+
|
|
118
|
+
MIT © 2025
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function pick(items) {
|
|
2
|
+
return items[Math.floor(Math.random() * items.length)];
|
|
3
|
+
}
|
|
4
|
+
export function number(min = 0, max = 9999) {
|
|
5
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
6
|
+
}
|
|
7
|
+
export function bool() {
|
|
8
|
+
return Math.random() < 0.5;
|
|
9
|
+
}
|
|
10
|
+
export function alpha(length = 8) {
|
|
11
|
+
const chars = "abcdefghijklmnopqrstuvwxyz";
|
|
12
|
+
return Array.from({ length }, () => pick(chars.split(""))).join("");
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const internet: {
|
|
2
|
+
email: (l: any) => string;
|
|
3
|
+
username: () => string;
|
|
4
|
+
password: () => string;
|
|
5
|
+
domain: (l: any) => unknown;
|
|
6
|
+
url: () => string;
|
|
7
|
+
ip: () => string;
|
|
8
|
+
color: () => string;
|
|
9
|
+
avatarUrl: () => string;
|
|
10
|
+
mac: () => string;
|
|
11
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { pick, number, alpha } from "../core/random.js";
|
|
2
|
+
export const internet = {
|
|
3
|
+
email: (l) => `${alpha(6)}@${pick(l.domains)}`,
|
|
4
|
+
username: () => `user_${alpha(3)}${number(1, 999)}`,
|
|
5
|
+
password: () => alpha(12),
|
|
6
|
+
domain: (l) => pick(l.domains),
|
|
7
|
+
url: () => `https://site${number(1, 999)}.com`,
|
|
8
|
+
ip: () => `${number(1, 255)}.${number(1, 255)}.${number(1, 255)}.${number(1, 255)}`,
|
|
9
|
+
color: () => `#${number(100000, 999999)}`,
|
|
10
|
+
avatarUrl: () => `https://i.pravatar.cc/${number(100, 300)}`,
|
|
11
|
+
mac: () => `${alpha(2)}:${alpha(2)}:${alpha(2)}`
|
|
12
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const misc: {
|
|
2
|
+
city: (l: any) => unknown;
|
|
3
|
+
phone: () => string;
|
|
4
|
+
zipCode: () => string;
|
|
5
|
+
uuid: () => string;
|
|
6
|
+
boolean: () => boolean;
|
|
7
|
+
currency: () => string;
|
|
8
|
+
percentage: () => number;
|
|
9
|
+
numberBetween: (minNum: number, maxNum: number) => number;
|
|
10
|
+
lorem: () => string;
|
|
11
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { pick, number } from "../core/random.js";
|
|
2
|
+
export const misc = {
|
|
3
|
+
city: (l) => pick(l.cities),
|
|
4
|
+
phone: () => `+${number(1, 99)} ${number(60000000, 79999999)}`,
|
|
5
|
+
zipCode: () => number(10000, 99999).toString(),
|
|
6
|
+
uuid: () => crypto.randomUUID(),
|
|
7
|
+
boolean: () => Math.random() < 0.5,
|
|
8
|
+
currency: () => pick(["USD", "EUR", "BOB"]),
|
|
9
|
+
percentage: () => number(0, 100),
|
|
10
|
+
numberBetween: (minNum, maxNum) => number(minNum = 1, maxNum),
|
|
11
|
+
lorem: () => "Lorem ipsum dolor sit amet"
|
|
12
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
type Locale = "EN" | "ES" | "PT" | "FR" | "DE" | "RU" | "JA" | "ZH" | "TR";
|
|
2
|
+
declare function faker(initialLocale?: Locale): {
|
|
3
|
+
firstName: () => string;
|
|
4
|
+
lastName: () => string;
|
|
5
|
+
company: () => string;
|
|
6
|
+
jobTitle: () => string;
|
|
7
|
+
email: () => string;
|
|
8
|
+
username: () => string;
|
|
9
|
+
password: () => string;
|
|
10
|
+
domain: () => unknown;
|
|
11
|
+
avatarUrl: () => string;
|
|
12
|
+
url: () => string;
|
|
13
|
+
ip: () => string;
|
|
14
|
+
mac: () => string;
|
|
15
|
+
color: () => string;
|
|
16
|
+
city: () => unknown;
|
|
17
|
+
zipCode: () => string;
|
|
18
|
+
phone: () => string;
|
|
19
|
+
uuid: () => string;
|
|
20
|
+
boolean: () => boolean;
|
|
21
|
+
currency: () => string;
|
|
22
|
+
numberBetween: (minNum: number, maxNum: number) => number;
|
|
23
|
+
lorem: () => string;
|
|
24
|
+
setLocale(locale: Locale): {
|
|
25
|
+
setLocale(locale: Locale): any;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export { faker };
|
|
29
|
+
export default faker;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ES } from "./locales/es.js";
|
|
2
|
+
import { EN } from "./locales/en.js";
|
|
3
|
+
import { PT } from "./locales/pt.js";
|
|
4
|
+
import { FR } from "./locales/fr.js";
|
|
5
|
+
import { DE } from "./locales/de.js";
|
|
6
|
+
import { RU } from "./locales/ru.js";
|
|
7
|
+
import { JA } from "./locales/ja.js";
|
|
8
|
+
import { ZH } from "./locales/zh.js";
|
|
9
|
+
import { TR } from "./locales/tr.js";
|
|
10
|
+
import { person } from "./fields/person.js";
|
|
11
|
+
import { internet } from "./fields/internet.js";
|
|
12
|
+
import { misc } from "./fields/misc.js";
|
|
13
|
+
const locales = {
|
|
14
|
+
EN, ES, PT, FR, DE, RU, JA, ZH, TR
|
|
15
|
+
};
|
|
16
|
+
function faker(initialLocale = "EN") {
|
|
17
|
+
let currentLocale = initialLocale;
|
|
18
|
+
const api = {
|
|
19
|
+
setLocale(locale) {
|
|
20
|
+
currentLocale = locale;
|
|
21
|
+
return api;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const withLocale = (fn) => (...args) => fn(locales[currentLocale], ...args);
|
|
25
|
+
return {
|
|
26
|
+
...api,
|
|
27
|
+
// PERSON
|
|
28
|
+
firstName: () => person.firstName(locales[currentLocale]),
|
|
29
|
+
lastName: () => person.lastName(locales[currentLocale]),
|
|
30
|
+
company: () => person.company(locales[currentLocale]),
|
|
31
|
+
jobTitle: () => person.jobTitle(),
|
|
32
|
+
// INTERNET
|
|
33
|
+
email: () => internet.email(locales[currentLocale]),
|
|
34
|
+
username: () => internet.username(),
|
|
35
|
+
password: () => internet.password(),
|
|
36
|
+
domain: () => internet.domain(locales[currentLocale]),
|
|
37
|
+
avatarUrl: () => internet.avatarUrl(),
|
|
38
|
+
url: () => internet.url(),
|
|
39
|
+
ip: () => internet.ip(),
|
|
40
|
+
mac: () => internet.mac(),
|
|
41
|
+
color: () => internet.color(),
|
|
42
|
+
// MISC
|
|
43
|
+
city: () => misc.city(locales[currentLocale]),
|
|
44
|
+
zipCode: () => misc.zipCode(),
|
|
45
|
+
phone: () => misc.phone(),
|
|
46
|
+
uuid: () => misc.uuid(),
|
|
47
|
+
boolean: () => misc.boolean(),
|
|
48
|
+
currency: () => misc.currency(),
|
|
49
|
+
numberBetween: misc.numberBetween,
|
|
50
|
+
lorem: () => misc.lorem()
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export { faker };
|
|
54
|
+
export default faker;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const DE = {
|
|
2
|
+
firstNames: ["Hans", "Anna", "Peter", "Laura", "Max"],
|
|
3
|
+
lastNames: ["Müller", "Schmidt", "Schneider", "Fischer"],
|
|
4
|
+
cities: ["Berlin", "Hamburg", "Munich", "Frankfurt"],
|
|
5
|
+
companies: ["Technik GmbH", "Software AG"],
|
|
6
|
+
domains: ["mail.de", "beispiel.de"]
|
|
7
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const EN = {
|
|
2
|
+
firstNames: ["John", "Jane", "Mike", "Anna", "Erick"],
|
|
3
|
+
lastNames: ["Smith", "Brown", "Taylor", "Doe"],
|
|
4
|
+
cities: ["New York", "Chicago", "Miami", "Texas"],
|
|
5
|
+
companies: ["Tech LLC", "Soft Inc", "TechLand Inc"],
|
|
6
|
+
domains: ["gmail.com", "example.com"]
|
|
7
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const ES = {
|
|
2
|
+
firstNames: ["Juan", "María", "Carlos", "Ana", "Luis", "Pablo", "Daniel"],
|
|
3
|
+
lastNames: ["Pérez", "Gómez", "López", "Rojas", "Rios"],
|
|
4
|
+
cities: ["La Paz", "Caracas", "Lima", "Buenos Aires", "Santiago", "Bogotá"],
|
|
5
|
+
companies: ["Tech SRL", "Soluciones SA", "Avantic", "Alteza"],
|
|
6
|
+
domains: ["correo.com", "mail.com"]
|
|
7
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const FR = {
|
|
2
|
+
firstNames: ["Jean", "Marie", "Pierre", "Anne", "Luc"],
|
|
3
|
+
lastNames: ["Martin", "Bernard", "Dubois", "Moreau"],
|
|
4
|
+
cities: ["Paris", "Lyon", "Marseille", "Nice"],
|
|
5
|
+
companies: ["Tech SARL", "Solutions SA"],
|
|
6
|
+
domains: ["email.fr", "exemple.fr"]
|
|
7
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const PT = {
|
|
2
|
+
firstNames: ["João", "Maria", "Carlos", "Ana", "Lucas"],
|
|
3
|
+
lastNames: ["Silva", "Santos", "Oliveira", "Pereira"],
|
|
4
|
+
cities: ["São Paulo", "Rio de Janeiro", "Belo Horizonte"],
|
|
5
|
+
companies: ["Tecnologia Ltda", "Soluções SA"],
|
|
6
|
+
domains: ["email.com", "exemplo.com"]
|
|
7
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const RU = {
|
|
2
|
+
firstNames: ["Ivan", "Olga", "Dmitry", "Anna", "Sergey"],
|
|
3
|
+
lastNames: ["Ivanov", "Smirnov", "Kuznetsov", "Popov"],
|
|
4
|
+
cities: ["Moscow", "Saint Petersburg", "Kazan"],
|
|
5
|
+
companies: ["Tech OOO", "Solutions LLC"],
|
|
6
|
+
domains: ["mail.ru", "example.ru"]
|
|
7
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const TR = {
|
|
2
|
+
firstNames: ["Ahmet", "Mehmet", "Ayşe", "Fatma", "Emre", "Elif", "Kemal", "Nihan"],
|
|
3
|
+
lastNames: ["Yılmaz", "Kaya", "Demir", "Şahin", "Çelik"],
|
|
4
|
+
cities: ["İstanbul", "Ankara", "İzmir", "Bursa", "Antalya"],
|
|
5
|
+
companies: ["Teknoloji AŞ", "Yazılım Ltd"],
|
|
6
|
+
domains: ["mail.com.tr", "ornek.com", "example.tr"]
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "faker-i18n",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Minimal fake data generator by field (ES, EN, PT, FR, DE, RU, JA, ZH, TR)",
|
|
5
|
+
"author": "mikefox10 <mikefoxtrotboa@gmail.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/**/*.js",
|
|
11
|
+
"dist/**/*.d.ts"
|
|
12
|
+
],
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "vitest",
|
|
22
|
+
"clean": "rm -rf dist",
|
|
23
|
+
"build": "npm run clean && tsc",
|
|
24
|
+
"prepare": "npm run build"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"faker",
|
|
28
|
+
"mock",
|
|
29
|
+
"fake-data",
|
|
30
|
+
"testing",
|
|
31
|
+
"typescript"
|
|
32
|
+
],
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"typescript": "^5.3.3",
|
|
35
|
+
"vitest": "^1.2.0",
|
|
36
|
+
"@types/node": "^20.11.0"
|
|
37
|
+
}
|
|
38
|
+
}
|