@storyteller-platform/transliteration 3.0.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/LICENSE.txt +20 -0
- package/README.md +309 -0
- package/dist/bin/slugify +25 -0
- package/dist/bin/transliterate +22 -0
- package/dist/browser/bundle.esm.min.js +2 -0
- package/dist/browser/bundle.esm.min.js.map +1 -0
- package/dist/browser/bundle.umd.min.js +6 -0
- package/dist/browser/bundle.umd.min.js.map +1 -0
- package/dist/browser/latin.esm.min.js +2 -0
- package/dist/browser/latin.esm.min.js.map +1 -0
- package/dist/browser/latin.umd.min.js +6 -0
- package/dist/browser/latin.umd.min.js.map +1 -0
- package/dist/chunk-X7MXKHQX.js +6 -0
- package/dist/chunk-X7MXKHQX.js.map +1 -0
- package/dist/index-BVy__XED.d.ts +136 -0
- package/dist/node/src/node/index.d.ts +6 -0
- package/dist/node/src/node/index.js +6 -0
- package/dist/node/src/node/index.js.map +1 -0
- package/dist/node/src/node/latin.d.ts +6 -0
- package/dist/node/src/node/latin.js +6 -0
- package/dist/node/src/node/latin.js.map +1 -0
- package/package.json +85 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
interface Charmap {
|
|
2
|
+
[key: string]: string;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
interface Mappable {
|
|
6
|
+
map: (pos: number, assoc?: number) => number;
|
|
7
|
+
mapResult: (pos: number, assoc?: number) => MapResult;
|
|
8
|
+
}
|
|
9
|
+
declare class MapResult {
|
|
10
|
+
readonly pos: number;
|
|
11
|
+
get deleted(): boolean;
|
|
12
|
+
get deletedBefore(): boolean;
|
|
13
|
+
get deletedAfter(): boolean;
|
|
14
|
+
get deletedAcross(): boolean;
|
|
15
|
+
}
|
|
16
|
+
declare class StepMap implements Mappable {
|
|
17
|
+
constructor(ranges: readonly number[], inverted?: boolean);
|
|
18
|
+
mapResult(pos: number, assoc?: number): MapResult;
|
|
19
|
+
map(pos: number, assoc?: number): number;
|
|
20
|
+
forEach(f: (oldStart: number, oldEnd: number, newStart: number, newEnd: number) => void): void;
|
|
21
|
+
invert(): StepMap;
|
|
22
|
+
static offset(n: number): StepMap;
|
|
23
|
+
static empty: StepMap;
|
|
24
|
+
}
|
|
25
|
+
declare class Mapping implements Mappable {
|
|
26
|
+
from: number;
|
|
27
|
+
to: number;
|
|
28
|
+
constructor(maps?: readonly StepMap[], mirror?: number[] | undefined, from?: number, to?: number);
|
|
29
|
+
get maps(): readonly StepMap[];
|
|
30
|
+
private _maps;
|
|
31
|
+
private ownData;
|
|
32
|
+
slice(from?: number, to?: number): Mapping;
|
|
33
|
+
appendMap(map: StepMap, mirrors?: number): void;
|
|
34
|
+
appendMapping(mapping: Mapping): void;
|
|
35
|
+
getMirror(n: number): number | undefined;
|
|
36
|
+
appendMappingInverted(mapping: Mapping): void;
|
|
37
|
+
invert(): Mapping;
|
|
38
|
+
map(pos: number, assoc?: number): number;
|
|
39
|
+
mapResult(pos: number, assoc?: number): MapResult;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type OptionReplaceArrayItem = [string | RegExp, string];
|
|
43
|
+
type OptionReplaceArray = OptionReplaceArrayItem[];
|
|
44
|
+
type OptionReplaceObject = {
|
|
45
|
+
[from: string]: string;
|
|
46
|
+
};
|
|
47
|
+
type OptionReplaceCombined = OptionReplaceArray | OptionReplaceObject;
|
|
48
|
+
type OptionsTransliterate = {
|
|
49
|
+
/**
|
|
50
|
+
* Ignore a list of strings untouched
|
|
51
|
+
* @example tr('你好,世界', { ignore: ['你'] }) // 你 Hao , Shi Jie
|
|
52
|
+
*/
|
|
53
|
+
ignore?: string[];
|
|
54
|
+
/**
|
|
55
|
+
* Replace a list of string / regex in the source string into the provided target string before transliteration
|
|
56
|
+
* The option can either be an array or an object
|
|
57
|
+
* @example tr('你好,世界', { replace: {你: 'You'} }) // You Hao , Shi Jie
|
|
58
|
+
* @example tr('你好,世界', { replace: [['你', 'You']] }) // You Hao , Shi Jie
|
|
59
|
+
* @example tr('你好,世界', { replace: [[/你/g, 'You']] }) // You Hao , Shi Jie
|
|
60
|
+
*/
|
|
61
|
+
replace?: OptionReplaceCombined;
|
|
62
|
+
/**
|
|
63
|
+
* Same as `replace` but after transliteration
|
|
64
|
+
*/
|
|
65
|
+
replaceAfter?: OptionReplaceCombined;
|
|
66
|
+
/**
|
|
67
|
+
* Decides whether or not to trim the result string after transliteration
|
|
68
|
+
* @default false
|
|
69
|
+
*/
|
|
70
|
+
trim?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Any characters not known by this library will be replaced by a specific string `unknown`
|
|
73
|
+
* @default ''
|
|
74
|
+
*/
|
|
75
|
+
unknown?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Fix Chinese spacing. For example, `你好` is transliterated to `Ni Hao` instead of `NiHao`. If you don't need to transliterate Chinese characters, set it to false to false to improve performance.
|
|
78
|
+
* @default true
|
|
79
|
+
*/
|
|
80
|
+
fixChineseSpacing?: boolean;
|
|
81
|
+
};
|
|
82
|
+
type OptionsSlugify = OptionsTransliterate & {
|
|
83
|
+
/**
|
|
84
|
+
* Whether the result need to be converted into lowercase
|
|
85
|
+
* @default true
|
|
86
|
+
*/
|
|
87
|
+
lowercase?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Whether the result need to be converted into uppercase
|
|
90
|
+
* @default false
|
|
91
|
+
*/
|
|
92
|
+
uppercase?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Custom separator string
|
|
95
|
+
* @default '-'
|
|
96
|
+
*/
|
|
97
|
+
separator?: string;
|
|
98
|
+
/**
|
|
99
|
+
* Allowed characters.
|
|
100
|
+
* When `allowedChars` is set to `'abc'`, then only characters match `/[abc]/g` will be preserved.
|
|
101
|
+
* Other characters will all be converted to `separator`
|
|
102
|
+
* @default 'a-zA-Z0-9-_.~''
|
|
103
|
+
*/
|
|
104
|
+
allowedChars?: string;
|
|
105
|
+
/**
|
|
106
|
+
* Fix Chinese spacing. For example, `你好` is transliterated to `Ni Hao` instead of `NiHao`. If you don't need to transliterate Chinese characters, set it to false to false to improve performance.
|
|
107
|
+
*/
|
|
108
|
+
fixChineseSpacing?: boolean;
|
|
109
|
+
};
|
|
110
|
+
type TransliterationFunction<T> = {
|
|
111
|
+
(source: string, options?: T): {
|
|
112
|
+
result: string;
|
|
113
|
+
mapping: Mapping;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Set default config
|
|
117
|
+
* @param options
|
|
118
|
+
* @param reset
|
|
119
|
+
*/
|
|
120
|
+
config: (options?: T, reset?: boolean) => T;
|
|
121
|
+
/**
|
|
122
|
+
* Set charmap data
|
|
123
|
+
* @param data
|
|
124
|
+
* @param reset
|
|
125
|
+
* @memberof Transliterate
|
|
126
|
+
*/
|
|
127
|
+
setData: (data?: Charmap, reset?: boolean) => Charmap;
|
|
128
|
+
/**
|
|
129
|
+
* Used by browser
|
|
130
|
+
*/
|
|
131
|
+
noConflict?: () => TransliterationFunction<T>;
|
|
132
|
+
};
|
|
133
|
+
type TransliterateFunction = TransliterationFunction<OptionsTransliterate>;
|
|
134
|
+
type SlugifyFunction = TransliterationFunction<OptionsSlugify>;
|
|
135
|
+
|
|
136
|
+
export type { SlugifyFunction as S, TransliterateFunction as T };
|