volleyballsimtypes 0.0.374 → 0.0.375
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.
|
@@ -17,6 +17,14 @@ interface FakerLike {
|
|
|
17
17
|
boolean: () => boolean;
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Romanize a name to the Latin alphabet so it is readable regardless of the source script.
|
|
22
|
+
* Already-Latin names (including accented ones like "José" or "Müller") are returned unchanged;
|
|
23
|
+
* non-Latin scripts (Japanese, Arabic, Cyrillic, Greek, Thai, Korean, ...) are transliterated and
|
|
24
|
+
* re-cased word-by-word. Note: CJK kanji transliterate to Chinese-style readings (readable but not
|
|
25
|
+
* the exact native reading).
|
|
26
|
+
*/
|
|
27
|
+
export declare function romanize(s: string): string;
|
|
20
28
|
export declare function generateGenericTeamNames(locales: string[], amount: number): string[];
|
|
21
29
|
export declare function generatePlayerName(locales: string[], amount: number): Array<{
|
|
22
30
|
first: string;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getFakerInstance = getFakerInstance;
|
|
4
|
+
exports.romanize = romanize;
|
|
4
5
|
exports.generateGenericTeamNames = generateGenericTeamNames;
|
|
5
6
|
exports.generatePlayerName = generatePlayerName;
|
|
6
7
|
const faker_1 = require("@faker-js/faker");
|
|
8
|
+
const transliteration_1 = require("transliteration");
|
|
7
9
|
function isFakerKey(k) {
|
|
8
10
|
return k in faker_1.allFakers;
|
|
9
11
|
}
|
|
@@ -27,6 +29,24 @@ function clean(s) {
|
|
|
27
29
|
function capitalize(s) {
|
|
28
30
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
29
31
|
}
|
|
32
|
+
// Latin letters (incl. accents), digits, spaces, and common name punctuation.
|
|
33
|
+
const LATIN_NAME = /^[\p{Script=Latin}0-9\s'.-]+$/u;
|
|
34
|
+
/**
|
|
35
|
+
* Romanize a name to the Latin alphabet so it is readable regardless of the source script.
|
|
36
|
+
* Already-Latin names (including accented ones like "José" or "Müller") are returned unchanged;
|
|
37
|
+
* non-Latin scripts (Japanese, Arabic, Cyrillic, Greek, Thai, Korean, ...) are transliterated and
|
|
38
|
+
* re-cased word-by-word. Note: CJK kanji transliterate to Chinese-style readings (readable but not
|
|
39
|
+
* the exact native reading).
|
|
40
|
+
*/
|
|
41
|
+
function romanize(s) {
|
|
42
|
+
if (s.length === 0 || LATIN_NAME.test(s))
|
|
43
|
+
return s;
|
|
44
|
+
return (0, transliteration_1.transliterate)(s)
|
|
45
|
+
.split(/\s+/)
|
|
46
|
+
.filter(part => part.length > 0)
|
|
47
|
+
.map(part => capitalize(part.toLowerCase()))
|
|
48
|
+
.join(' ');
|
|
49
|
+
}
|
|
30
50
|
function nonEmpty(s) {
|
|
31
51
|
return s != null && s.length > 0 ? s : undefined;
|
|
32
52
|
}
|
|
@@ -37,12 +57,12 @@ function generateTeamName(faker) {
|
|
|
37
57
|
nonEmpty(faker.location.county?.()) ??
|
|
38
58
|
faker.word.noun();
|
|
39
59
|
const mascot = capitalize(faker.word.noun());
|
|
40
|
-
return clean(`${city} ${mascot}`);
|
|
60
|
+
return clean(romanize(`${city} ${mascot}`));
|
|
41
61
|
}
|
|
42
62
|
else {
|
|
43
63
|
const adjective = capitalize(faker.word.adjective());
|
|
44
64
|
const noun = capitalize(faker.word.noun());
|
|
45
|
-
return clean(`${adjective} ${noun}`);
|
|
65
|
+
return clean(romanize(`${adjective} ${noun}`));
|
|
46
66
|
}
|
|
47
67
|
}
|
|
48
68
|
const MAX_LAST_NAME_LENGTH = 16;
|
|
@@ -72,10 +92,10 @@ function generatePlayerName(locales, amount) {
|
|
|
72
92
|
return [];
|
|
73
93
|
const faker = getFakerInstance(locales);
|
|
74
94
|
return Array.from({ length: amount }, () => {
|
|
75
|
-
const first = clean(faker.person.firstName());
|
|
76
|
-
let last = clean(faker.person.lastName());
|
|
95
|
+
const first = clean(romanize(faker.person.firstName()));
|
|
96
|
+
let last = clean(romanize(faker.person.lastName()));
|
|
77
97
|
while (last.length > MAX_LAST_NAME_LENGTH) {
|
|
78
|
-
last = clean(faker.person.lastName());
|
|
98
|
+
last = clean(romanize(faker.person.lastName()));
|
|
79
99
|
}
|
|
80
100
|
return { first, last };
|
|
81
101
|
});
|
|
@@ -17,6 +17,14 @@ interface FakerLike {
|
|
|
17
17
|
boolean: () => boolean;
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Romanize a name to the Latin alphabet so it is readable regardless of the source script.
|
|
22
|
+
* Already-Latin names (including accented ones like "José" or "Müller") are returned unchanged;
|
|
23
|
+
* non-Latin scripts (Japanese, Arabic, Cyrillic, Greek, Thai, Korean, ...) are transliterated and
|
|
24
|
+
* re-cased word-by-word. Note: CJK kanji transliterate to Chinese-style readings (readable but not
|
|
25
|
+
* the exact native reading).
|
|
26
|
+
*/
|
|
27
|
+
export declare function romanize(s: string): string;
|
|
20
28
|
export declare function generateGenericTeamNames(locales: string[], amount: number): string[];
|
|
21
29
|
export declare function generatePlayerName(locales: string[], amount: number): Array<{
|
|
22
30
|
first: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { allFakers, faker as FakerModule } from '@faker-js/faker';
|
|
2
|
+
import { transliterate } from 'transliteration';
|
|
2
3
|
function isFakerKey(k) {
|
|
3
4
|
return k in allFakers;
|
|
4
5
|
}
|
|
@@ -22,6 +23,24 @@ function clean(s) {
|
|
|
22
23
|
function capitalize(s) {
|
|
23
24
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
24
25
|
}
|
|
26
|
+
// Latin letters (incl. accents), digits, spaces, and common name punctuation.
|
|
27
|
+
const LATIN_NAME = /^[\p{Script=Latin}0-9\s'.-]+$/u;
|
|
28
|
+
/**
|
|
29
|
+
* Romanize a name to the Latin alphabet so it is readable regardless of the source script.
|
|
30
|
+
* Already-Latin names (including accented ones like "José" or "Müller") are returned unchanged;
|
|
31
|
+
* non-Latin scripts (Japanese, Arabic, Cyrillic, Greek, Thai, Korean, ...) are transliterated and
|
|
32
|
+
* re-cased word-by-word. Note: CJK kanji transliterate to Chinese-style readings (readable but not
|
|
33
|
+
* the exact native reading).
|
|
34
|
+
*/
|
|
35
|
+
export function romanize(s) {
|
|
36
|
+
if (s.length === 0 || LATIN_NAME.test(s))
|
|
37
|
+
return s;
|
|
38
|
+
return transliterate(s)
|
|
39
|
+
.split(/\s+/)
|
|
40
|
+
.filter(part => part.length > 0)
|
|
41
|
+
.map(part => capitalize(part.toLowerCase()))
|
|
42
|
+
.join(' ');
|
|
43
|
+
}
|
|
25
44
|
function nonEmpty(s) {
|
|
26
45
|
return s != null && s.length > 0 ? s : undefined;
|
|
27
46
|
}
|
|
@@ -32,12 +51,12 @@ function generateTeamName(faker) {
|
|
|
32
51
|
nonEmpty(faker.location.county?.()) ??
|
|
33
52
|
faker.word.noun();
|
|
34
53
|
const mascot = capitalize(faker.word.noun());
|
|
35
|
-
return clean(`${city} ${mascot}`);
|
|
54
|
+
return clean(romanize(`${city} ${mascot}`));
|
|
36
55
|
}
|
|
37
56
|
else {
|
|
38
57
|
const adjective = capitalize(faker.word.adjective());
|
|
39
58
|
const noun = capitalize(faker.word.noun());
|
|
40
|
-
return clean(`${adjective} ${noun}`);
|
|
59
|
+
return clean(romanize(`${adjective} ${noun}`));
|
|
41
60
|
}
|
|
42
61
|
}
|
|
43
62
|
const MAX_LAST_NAME_LENGTH = 16;
|
|
@@ -67,10 +86,10 @@ export function generatePlayerName(locales, amount) {
|
|
|
67
86
|
return [];
|
|
68
87
|
const faker = getFakerInstance(locales);
|
|
69
88
|
return Array.from({ length: amount }, () => {
|
|
70
|
-
const first = clean(faker.person.firstName());
|
|
71
|
-
let last = clean(faker.person.lastName());
|
|
89
|
+
const first = clean(romanize(faker.person.firstName()));
|
|
90
|
+
let last = clean(romanize(faker.person.lastName()));
|
|
72
91
|
while (last.length > MAX_LAST_NAME_LENGTH) {
|
|
73
|
-
last = clean(faker.person.lastName());
|
|
92
|
+
last = clean(romanize(faker.person.lastName()));
|
|
74
93
|
}
|
|
75
94
|
return { first, last };
|
|
76
95
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "volleyballsimtypes",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.375",
|
|
4
4
|
"description": "vbsim types",
|
|
5
5
|
"main": "./dist/cjs/src/index.js",
|
|
6
6
|
"module": "./dist/esm/src/index.js",
|
|
@@ -94,6 +94,7 @@
|
|
|
94
94
|
"lz-string": "^1.5.0",
|
|
95
95
|
"msgpackr": "^1.11.9",
|
|
96
96
|
"pino": "^9.9.0",
|
|
97
|
+
"transliteration": "^2.3.5",
|
|
97
98
|
"uuid": "^9.0.0",
|
|
98
99
|
"zod": "^4.3.6"
|
|
99
100
|
},
|