namefully 1.1.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/dist/lib/config.js +112 -0
- package/dist/lib/constants.js +30 -0
- package/dist/lib/error.js +92 -0
- package/dist/lib/full-name.js +115 -0
- package/dist/lib/index.js +27 -12
- package/dist/lib/name.js +230 -0
- package/dist/lib/namefully.js +368 -681
- package/dist/lib/parser.js +138 -0
- package/dist/lib/types.js +107 -0
- package/dist/lib/utils.js +92 -0
- package/dist/lib/validator.js +301 -0
- package/dist/types/config.d.ts +97 -0
- package/dist/types/constants.d.ts +4 -0
- package/dist/types/error.d.ts +158 -0
- package/dist/types/full-name.d.ts +54 -0
- package/dist/types/index.d.ts +21 -0
- package/dist/types/name.d.ts +126 -0
- package/dist/types/namefully.d.ts +313 -0
- package/dist/types/parser.d.ts +41 -0
- package/dist/types/types.d.ts +127 -0
- package/dist/types/utils.d.ts +53 -0
- package/dist/types/validator.d.ts +57 -0
- package/dist/umd/namefully.js +1503 -2900
- package/dist/umd/namefully.min.js +1 -3
- package/package.json +28 -38
- package/readme.md +138 -167
- package/changelog.md +0 -134
- package/dist/lib/core/constants.d.ts +0 -48
- package/dist/lib/core/constants.js +0 -101
- package/dist/lib/core/constants.js.map +0 -1
- package/dist/lib/core/core.d.ts +0 -17
- package/dist/lib/core/core.js +0 -24
- package/dist/lib/core/core.js.map +0 -1
- package/dist/lib/core/index.d.ts +0 -9
- package/dist/lib/core/index.js +0 -13
- package/dist/lib/core/index.js.map +0 -1
- package/dist/lib/core/parsers/array-name.parser.d.ts +0 -41
- package/dist/lib/core/parsers/array-name.parser.js +0 -86
- package/dist/lib/core/parsers/array-name.parser.js.map +0 -1
- package/dist/lib/core/parsers/array-string.parser.d.ts +0 -47
- package/dist/lib/core/parsers/array-string.parser.js +0 -95
- package/dist/lib/core/parsers/array-string.parser.js.map +0 -1
- package/dist/lib/core/parsers/index.d.ts +0 -11
- package/dist/lib/core/parsers/index.js +0 -11
- package/dist/lib/core/parsers/index.js.map +0 -1
- package/dist/lib/core/parsers/nama.parser.d.ts +0 -33
- package/dist/lib/core/parsers/nama.parser.js +0 -74
- package/dist/lib/core/parsers/nama.parser.js.map +0 -1
- package/dist/lib/core/parsers/parser.d.ts +0 -28
- package/dist/lib/core/parsers/parser.js +0 -3
- package/dist/lib/core/parsers/parser.js.map +0 -1
- package/dist/lib/core/parsers/string.parser.d.ts +0 -60
- package/dist/lib/core/parsers/string.parser.js +0 -62
- package/dist/lib/core/parsers/string.parser.js.map +0 -1
- package/dist/lib/core/utils.d.ts +0 -52
- package/dist/lib/core/utils.js +0 -178
- package/dist/lib/core/utils.js.map +0 -1
- package/dist/lib/index.d.ts +0 -10
- package/dist/lib/index.js.map +0 -1
- package/dist/lib/models/enums.d.ts +0 -106
- package/dist/lib/models/enums.js +0 -114
- package/dist/lib/models/enums.js.map +0 -1
- package/dist/lib/models/firstname.d.ts +0 -77
- package/dist/lib/models/firstname.js +0 -131
- package/dist/lib/models/firstname.js.map +0 -1
- package/dist/lib/models/fullname.d.ts +0 -73
- package/dist/lib/models/fullname.js +0 -99
- package/dist/lib/models/fullname.js.map +0 -1
- package/dist/lib/models/index.d.ts +0 -13
- package/dist/lib/models/index.js +0 -16
- package/dist/lib/models/index.js.map +0 -1
- package/dist/lib/models/lastname.d.ts +0 -80
- package/dist/lib/models/lastname.js +0 -157
- package/dist/lib/models/lastname.js.map +0 -1
- package/dist/lib/models/misc.d.ts +0 -108
- package/dist/lib/models/misc.js +0 -3
- package/dist/lib/models/misc.js.map +0 -1
- package/dist/lib/models/name.d.ts +0 -76
- package/dist/lib/models/name.js +0 -115
- package/dist/lib/models/name.js.map +0 -1
- package/dist/lib/models/summary.d.ts +0 -26
- package/dist/lib/models/summary.js +0 -61
- package/dist/lib/models/summary.js.map +0 -1
- package/dist/lib/namefully.d.ts +0 -302
- package/dist/lib/namefully.js.map +0 -1
- package/dist/lib/validators/array-name.validator.d.ts +0 -25
- package/dist/lib/validators/array-name.validator.js +0 -75
- package/dist/lib/validators/array-name.validator.js.map +0 -1
- package/dist/lib/validators/array-string.validator.d.ts +0 -43
- package/dist/lib/validators/array-string.validator.js +0 -76
- package/dist/lib/validators/array-string.validator.js.map +0 -1
- package/dist/lib/validators/common/validation-error.d.ts +0 -19
- package/dist/lib/validators/common/validation-error.js +0 -26
- package/dist/lib/validators/common/validation-error.js.map +0 -1
- package/dist/lib/validators/common/validation-rule.d.ts +0 -72
- package/dist/lib/validators/common/validation-rule.js +0 -76
- package/dist/lib/validators/common/validation-rule.js.map +0 -1
- package/dist/lib/validators/common/validation-type.d.ts +0 -24
- package/dist/lib/validators/common/validation-type.js +0 -28
- package/dist/lib/validators/common/validation-type.js.map +0 -1
- package/dist/lib/validators/firstname.validator.d.ts +0 -20
- package/dist/lib/validators/firstname.validator.js +0 -29
- package/dist/lib/validators/firstname.validator.js.map +0 -1
- package/dist/lib/validators/fullname.validator.d.ts +0 -21
- package/dist/lib/validators/fullname.validator.js +0 -38
- package/dist/lib/validators/fullname.validator.js.map +0 -1
- package/dist/lib/validators/index.d.ts +0 -21
- package/dist/lib/validators/index.js +0 -35
- package/dist/lib/validators/index.js.map +0 -1
- package/dist/lib/validators/lastname.validator.d.ts +0 -20
- package/dist/lib/validators/lastname.validator.js +0 -29
- package/dist/lib/validators/lastname.validator.js.map +0 -1
- package/dist/lib/validators/middlename.validator.d.ts +0 -20
- package/dist/lib/validators/middlename.validator.js +0 -38
- package/dist/lib/validators/middlename.validator.js.map +0 -1
- package/dist/lib/validators/nama.validator.d.ts +0 -21
- package/dist/lib/validators/nama.validator.js +0 -44
- package/dist/lib/validators/nama.validator.js.map +0 -1
- package/dist/lib/validators/namon.validator.d.ts +0 -20
- package/dist/lib/validators/namon.validator.js +0 -29
- package/dist/lib/validators/namon.validator.js.map +0 -1
- package/dist/lib/validators/prefix.validator.d.ts +0 -14
- package/dist/lib/validators/prefix.validator.js +0 -31
- package/dist/lib/validators/prefix.validator.js.map +0 -1
- package/dist/lib/validators/string-name.validator.d.ts +0 -20
- package/dist/lib/validators/string-name.validator.js +0 -29
- package/dist/lib/validators/string-name.validator.js.map +0 -1
- package/dist/lib/validators/suffix.validator.d.ts +0 -14
- package/dist/lib/validators/suffix.validator.js +0 -31
- package/dist/lib/validators/suffix.validator.js.map +0 -1
- package/dist/lib/validators/validator.d.ts +0 -13
- package/dist/lib/validators/validator.js +0 -9
- package/dist/lib/validators/validator.js.map +0 -1
- package/dist/umd/namefully.js.map +0 -1
- package/dist/umd/namefully.min.js.LICENSE.txt +0 -29
- package/dist/umd/namefully.min.js.map +0 -1
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { Config } from './config';
|
|
2
|
+
import { Name, JsonName } from './name';
|
|
3
|
+
import { Parser } from './parser';
|
|
4
|
+
import { Flat, NameOrder, NameType, Namon, Nullable, Surname } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* A helper for organizing person names in a particular order, way, or shape.
|
|
7
|
+
*
|
|
8
|
+
* Though `namefully` is easy to use, it does not magically guess which part of
|
|
9
|
+
* the name is what (prefix, suffix, first, last, or middle names). It relies
|
|
10
|
+
* actually on how the name parts are indicated (i.e., their roles) so that
|
|
11
|
+
* it can perform internally certain operations and saves us some extra
|
|
12
|
+
* calculations/processing. In addition, `Namefully` can be created using
|
|
13
|
+
* distinct raw data shapes. This is intended to give some flexibility to the
|
|
14
|
+
* developer so that he or she is not bound to a particular data format.
|
|
15
|
+
* By following closely the API reference to know how to harness its usability,
|
|
16
|
+
* this utility aims to save time in formatting names.
|
|
17
|
+
*
|
|
18
|
+
* `namefully` also works like a trapdoor. Once a raw data is provided and
|
|
19
|
+
* validated, a developer can only *access* in a vast amount of, yet effective
|
|
20
|
+
* ways the name info. *No editing* is possible. If the name is mistaken, a new
|
|
21
|
+
* instance of `Namefully` must be created. In other words, it's immutable.
|
|
22
|
+
* Remember, this utility's primary objective is to help manipulate a person name.
|
|
23
|
+
*
|
|
24
|
+
* Note that the name standards used for the current version of this library
|
|
25
|
+
* are as follows:
|
|
26
|
+
* `[prefix] firstName [middleName] lastName [suffix]`
|
|
27
|
+
* The opening `[` and closing `]` symbols mean that these parts are optional.
|
|
28
|
+
* In other words, the most basic and typical case is a name that looks like
|
|
29
|
+
* this: `John Smith`, where `John` is the first name piece and `Smith`, the last
|
|
30
|
+
* name piece.
|
|
31
|
+
*
|
|
32
|
+
* @see https://departments.weber.edu/qsupport&training/Data_Standards/Name.htm
|
|
33
|
+
* for more info on name standards.
|
|
34
|
+
*
|
|
35
|
+
* **IMPORTANT**: Keep in mind that the order of appearance (or name order) matters
|
|
36
|
+
* and may be altered through configured parameters, which will be seen later.
|
|
37
|
+
* By default, the order of appearance is as shown above and will be used as a
|
|
38
|
+
* basis for future examples and use cases.
|
|
39
|
+
*
|
|
40
|
+
* Once imported, all that is required to do is to create an instance of
|
|
41
|
+
* `Namefully` and the rest will follow.
|
|
42
|
+
*
|
|
43
|
+
* Some terminologies used across the library are:
|
|
44
|
+
* - namon: 1 piece of name (e.g., first name)
|
|
45
|
+
* - nama: 2+ pieces of name (e.g., first name + last name)
|
|
46
|
+
*
|
|
47
|
+
* Happy name handling 😊!
|
|
48
|
+
*/
|
|
49
|
+
export declare class Namefully {
|
|
50
|
+
#private;
|
|
51
|
+
/**
|
|
52
|
+
* Creates a name with distinguishable parts from a raw string content.
|
|
53
|
+
* @param names element to parse.
|
|
54
|
+
* @param options additional settings.
|
|
55
|
+
*
|
|
56
|
+
* An optional configuration may be provided with specifics on how to treat
|
|
57
|
+
* a full name during its course. By default, all name parts are validated
|
|
58
|
+
* against some basic validation rules to avoid common runtime exceptions.
|
|
59
|
+
*/
|
|
60
|
+
constructor(names: string | string[] | Name[] | JsonName | Parser, options?: Partial<Config>);
|
|
61
|
+
/**
|
|
62
|
+
* Constructs a `Namefully` instance from a text.
|
|
63
|
+
*
|
|
64
|
+
* It works like `parse` except that this function returns `null` where `parse`
|
|
65
|
+
* would throw a `NameError`.
|
|
66
|
+
*/
|
|
67
|
+
static tryParse(text: string): Namefully | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Constructs a `Namefully` instance from a text.
|
|
70
|
+
*
|
|
71
|
+
* It throws a `NameError` if the text cannot be parsed. Use `tryParse`
|
|
72
|
+
* instead if a `null` return is preferred over a throwable error.
|
|
73
|
+
*
|
|
74
|
+
* This operation is computed asynchronously, which gives more flexibility at
|
|
75
|
+
* the time of catching the error (and stack trace if any). The acceptable
|
|
76
|
+
* text format is a string composed of two or more name pieces. For instance,
|
|
77
|
+
* `John Lennon`, or `John Winston Ono Lennon` are parsable names and follow
|
|
78
|
+
* the basic name standard rules (i.e., first-middle-last).
|
|
79
|
+
*
|
|
80
|
+
* Keep in mind that prefix and suffix are not considered during the parsing
|
|
81
|
+
* process.
|
|
82
|
+
*/
|
|
83
|
+
static parse(text: string): Promise<Namefully>;
|
|
84
|
+
/** The current configuration. */
|
|
85
|
+
get config(): Config;
|
|
86
|
+
/** The number of characters of the `birthName`, including spaces. */
|
|
87
|
+
get length(): number;
|
|
88
|
+
/** The prefix part. */
|
|
89
|
+
get prefix(): Nullable<string>;
|
|
90
|
+
/** The firt name part. */
|
|
91
|
+
get first(): string;
|
|
92
|
+
/** The first middle name part if any. */
|
|
93
|
+
get middle(): Nullable<string>;
|
|
94
|
+
/** Returns true if any middle name has been set. */
|
|
95
|
+
get hasMiddle(): boolean;
|
|
96
|
+
/** The last name part. */
|
|
97
|
+
get last(): string;
|
|
98
|
+
/** The suffix part. */
|
|
99
|
+
get suffix(): Nullable<string>;
|
|
100
|
+
/** The birth name part. */
|
|
101
|
+
get birth(): string;
|
|
102
|
+
/** The shortest version of a person name. */
|
|
103
|
+
get short(): string;
|
|
104
|
+
/** The longest version of a person name. */
|
|
105
|
+
get long(): string;
|
|
106
|
+
/** The entire name set. */
|
|
107
|
+
get full(): string;
|
|
108
|
+
/** The first name combined with the last name's initial. */
|
|
109
|
+
get public(): string;
|
|
110
|
+
/** Returns the full name as set. */
|
|
111
|
+
toString(): string;
|
|
112
|
+
/** Fetches the raw form of a name piece. */
|
|
113
|
+
get(namon: Namon): Nullable<Name | Name[]>;
|
|
114
|
+
/** Whether this name is equal to another one from a raw-string perspective. */
|
|
115
|
+
equal(other: Namefully): boolean;
|
|
116
|
+
/** Gets a JSON representation of the full name. */
|
|
117
|
+
toJson(): JsonName;
|
|
118
|
+
/** Confirms that a name part has been set. */
|
|
119
|
+
has(namon: Namon): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Gets the full name ordered as configured.
|
|
122
|
+
*
|
|
123
|
+
* The name order `orderedBy` forces to order by first or last name by
|
|
124
|
+
* overriding the preset configuration.
|
|
125
|
+
*
|
|
126
|
+
* `Namefully.format` may also be used to alter manually the order of appearance
|
|
127
|
+
* of full name.
|
|
128
|
+
*
|
|
129
|
+
* For example:
|
|
130
|
+
* ```ts
|
|
131
|
+
* const name = new Namefully('Jon Stark Snow');
|
|
132
|
+
* console.log(name.fullName(NameOrder.LAST_NAME)); // "Snow Jon Stark"
|
|
133
|
+
* console.log(name.format('l f m')); // "Snow Jon Stark"
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
fullName(orderedBy?: NameOrder): string;
|
|
137
|
+
/**
|
|
138
|
+
* Gets the birth name ordered as configured, no `prefix` or `suffix`.
|
|
139
|
+
*
|
|
140
|
+
* @param orderedBy forces to order by first or last name by overriding the
|
|
141
|
+
* preset configuration.
|
|
142
|
+
*/
|
|
143
|
+
birthName(orderedBy?: NameOrder): string;
|
|
144
|
+
/**
|
|
145
|
+
* Gets the first name part of the `FullName`.
|
|
146
|
+
*
|
|
147
|
+
* @param withMore determines whether to include other pieces of the first
|
|
148
|
+
* name.
|
|
149
|
+
*/
|
|
150
|
+
firstName(withMore?: boolean): string;
|
|
151
|
+
/** Gets the middle name part of the `FullName`. */
|
|
152
|
+
middleName(): string[];
|
|
153
|
+
/**
|
|
154
|
+
* Gets the last name part of the `FullName`.
|
|
155
|
+
*
|
|
156
|
+
* @param format overrides the how-to formatting of a surname output,
|
|
157
|
+
* considering its sub-parts.
|
|
158
|
+
*/
|
|
159
|
+
lastName(format?: Surname): string;
|
|
160
|
+
/**
|
|
161
|
+
* Gets the initials of the `FullName`.
|
|
162
|
+
*
|
|
163
|
+
* @param {options.orderedBy} forces to order by first or last name by
|
|
164
|
+
* overriding the preset configuration.
|
|
165
|
+
* @param
|
|
166
|
+
*
|
|
167
|
+
* For example, given the names:
|
|
168
|
+
* - `John Smith` => `['J', 'S']`
|
|
169
|
+
* - `John Ben Smith` => `['J', 'B', 'S']`.
|
|
170
|
+
*/
|
|
171
|
+
initials(options?: {
|
|
172
|
+
orderedBy?: NameOrder;
|
|
173
|
+
only?: NameType;
|
|
174
|
+
}): string[];
|
|
175
|
+
/**
|
|
176
|
+
* Shortens a complex full name to a simple typical name, a combination of
|
|
177
|
+
* first and last name.
|
|
178
|
+
*
|
|
179
|
+
* @param orderedBy forces to order by first or last name by overriding the
|
|
180
|
+
* preset configuration.
|
|
181
|
+
*
|
|
182
|
+
* For a given name such as `Mr Keanu Charles Reeves`, shortening this name
|
|
183
|
+
* is equivalent to making it `Keanu Reeves`.
|
|
184
|
+
*
|
|
185
|
+
* As a shortened name, the namon of the first name is favored over the other
|
|
186
|
+
* names forming part of the entire first names, if any. Meanwhile, for
|
|
187
|
+
* the last name, the configured `surname` is prioritized.
|
|
188
|
+
*
|
|
189
|
+
* For a given `FirstName FatherName MotherName`, shortening this name when
|
|
190
|
+
* the surname is set as `mother` is equivalent to making it:
|
|
191
|
+
* `FirstName MotherName`.
|
|
192
|
+
*/
|
|
193
|
+
shorten(orderedBy?: NameOrder): string;
|
|
194
|
+
/**
|
|
195
|
+
* Flattens a long name using the name types as variants.
|
|
196
|
+
*
|
|
197
|
+
* While @param limit sets a threshold as a limited number of characters
|
|
198
|
+
* supported to flatten a `FullName`, @param by indicates which variant
|
|
199
|
+
* to use when doing so. By default, a full name gets flattened by
|
|
200
|
+
* `Flat.MIDDLE_NAME`.
|
|
201
|
+
*
|
|
202
|
+
* The flattening operation is only executed iff there is a valid entry and
|
|
203
|
+
* it surpasses the limit set. In the examples below, let us assume that the
|
|
204
|
+
* name goes beyond the limit value.
|
|
205
|
+
*
|
|
206
|
+
* Flattening a long name refers to reducing the name to the following forms.
|
|
207
|
+
* For example, `John Winston Ono Lennon` flattened by:
|
|
208
|
+
* * Flat.FIRST_NAME: => 'J. Winston Ono Lennon'
|
|
209
|
+
* * Flat.MIDDLE_NAME: => 'John W. O. Lennon'
|
|
210
|
+
* * Flat.LAST_NAME: => 'John Winston Ono L.'
|
|
211
|
+
* * Flat.FIRST_MID: => 'J. W. O. Lennon'
|
|
212
|
+
* * Flat.MID_LAST: => 'John W. O. L.'
|
|
213
|
+
* * Flat.ALL: => 'J. W. O. L.'
|
|
214
|
+
*
|
|
215
|
+
* With the help of the @param recursive flag, the above operation can happen
|
|
216
|
+
* recursively in the same order if the name is still too long. For example,
|
|
217
|
+
* flattening `John Winston Ono Lennon` using the following params:
|
|
218
|
+
* `flatten({ limit: 18, by: Flat.FIRST_NAME, recursive: true })`
|
|
219
|
+
* will result in `John W. O. Lennon` and not `J. Winston Ono Lennon`.
|
|
220
|
+
*
|
|
221
|
+
* A shorter version of this method is `zip()`.
|
|
222
|
+
*/
|
|
223
|
+
flatten(options: Partial<{
|
|
224
|
+
limit: number;
|
|
225
|
+
by: Flat;
|
|
226
|
+
withPeriod: boolean;
|
|
227
|
+
recursive: boolean;
|
|
228
|
+
withMore: boolean;
|
|
229
|
+
surname: Surname;
|
|
230
|
+
}>): string;
|
|
231
|
+
/**
|
|
232
|
+
* Zips or compacts a name using different forms of variants.
|
|
233
|
+
*
|
|
234
|
+
* @see `flatten()` for more details.
|
|
235
|
+
*/
|
|
236
|
+
zip(by?: Flat, withPeriod?: boolean): string;
|
|
237
|
+
/**
|
|
238
|
+
* Formats the full name as desired.
|
|
239
|
+
* @param pattern character used to format it.
|
|
240
|
+
*
|
|
241
|
+
* string format
|
|
242
|
+
* -------------
|
|
243
|
+
* - 'short': typical first + last name
|
|
244
|
+
* - 'long': birth name (without prefix and suffix)
|
|
245
|
+
* - 'public': first name combined with the last name's initial.
|
|
246
|
+
* - 'official': official document format
|
|
247
|
+
*
|
|
248
|
+
* char format
|
|
249
|
+
* -----------
|
|
250
|
+
* - 'b': birth name
|
|
251
|
+
* - 'B': capitalized birth name
|
|
252
|
+
* - 'f': first name
|
|
253
|
+
* - 'F': capitalized first name
|
|
254
|
+
* - 'l': last name
|
|
255
|
+
* - 'L': capitalized last name
|
|
256
|
+
* - 'm': middle names
|
|
257
|
+
* - 'M': capitalized middle names
|
|
258
|
+
* - 'o': official document format
|
|
259
|
+
* - 'O': official document format in capital letters
|
|
260
|
+
* - 'p': prefix
|
|
261
|
+
* - 'P': capitalized prefix
|
|
262
|
+
* - 's': suffix
|
|
263
|
+
* - 'S': capitalized suffix
|
|
264
|
+
*
|
|
265
|
+
* punctuations
|
|
266
|
+
* ------------
|
|
267
|
+
* - '.': period
|
|
268
|
+
* - ',': comma
|
|
269
|
+
* - ' ': space
|
|
270
|
+
* - '-': hyphen
|
|
271
|
+
* - '_': underscore
|
|
272
|
+
* - '$': an escape character to select only the initial of the next char.
|
|
273
|
+
*
|
|
274
|
+
* Given the name `Joe Jim Smith`, use `format` with the `pattern` string.
|
|
275
|
+
* - format('l f') => 'Smith Joe'
|
|
276
|
+
* - format('L, f') => 'SMITH, Joe'
|
|
277
|
+
* - format('short') => 'Joe Smith'
|
|
278
|
+
* - format() => 'SMITH, Joe Jim'
|
|
279
|
+
* - format(r'f $l.') => 'Joe S.'.
|
|
280
|
+
*
|
|
281
|
+
* Do note that the escape character is only valid for the birth name parts:
|
|
282
|
+
* first, middle, and last names.
|
|
283
|
+
*/
|
|
284
|
+
format(pattern: string): string;
|
|
285
|
+
/** Flips definitely the name order from the preset/current config. */
|
|
286
|
+
flip(): void;
|
|
287
|
+
/**
|
|
288
|
+
* Splits the name parts of a birth name.
|
|
289
|
+
* @param separator token for the split.
|
|
290
|
+
*/
|
|
291
|
+
split(separator?: string | RegExp): string[];
|
|
292
|
+
/**
|
|
293
|
+
* Joins the name parts of a birth name.
|
|
294
|
+
* @param separator token for the junction.
|
|
295
|
+
*/
|
|
296
|
+
join(separator?: string): string;
|
|
297
|
+
/** Transforms a birth name into UPPERCASE. */
|
|
298
|
+
toUpperCase(): string;
|
|
299
|
+
/** Transforms a birth name into lowercase. */
|
|
300
|
+
toLowerCase(): string;
|
|
301
|
+
/** Transforms a birth name into camelCase. */
|
|
302
|
+
toCamelCase(): string;
|
|
303
|
+
/** Transforms a birth name into PascalCase. */
|
|
304
|
+
toPascalCase(): string;
|
|
305
|
+
/** Transforms a birth name into snake_case. */
|
|
306
|
+
toSnakeCase(): string;
|
|
307
|
+
/** Transforms a birth name into hyphen-case. */
|
|
308
|
+
toHyphenCase(): string;
|
|
309
|
+
/** Transforms a birth name into dot.case. */
|
|
310
|
+
toDotCase(): string;
|
|
311
|
+
/** Transforms a birth name into ToGgLeCaSe. */
|
|
312
|
+
toToggleCase(): string;
|
|
313
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { FullName } from './full-name';
|
|
2
|
+
import { Config } from './config';
|
|
3
|
+
import { Name, JsonName } from './name';
|
|
4
|
+
/**
|
|
5
|
+
* A parser signature that helps to organize the names accordingly.
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class Parser<T = any> {
|
|
8
|
+
raw: T;
|
|
9
|
+
/**
|
|
10
|
+
* Constructs a custom parser accordingly.
|
|
11
|
+
* @param raw data to be parsed
|
|
12
|
+
*/
|
|
13
|
+
constructor(raw: T);
|
|
14
|
+
/**
|
|
15
|
+
* Builds a dynamic `Parser` on the fly and throws a `NameError` when unable
|
|
16
|
+
* to do so. The built parser only knows how to operate birth names.
|
|
17
|
+
*/
|
|
18
|
+
static build(text: string): Parser;
|
|
19
|
+
/**
|
|
20
|
+
* Builds asynchronously a dynamic `Parser`.
|
|
21
|
+
*/
|
|
22
|
+
static buildAsync(text: string): Promise<Parser>;
|
|
23
|
+
/**
|
|
24
|
+
* Parses the raw data into a `FullName` while considering some options.
|
|
25
|
+
* @param options additional configuration to apply.
|
|
26
|
+
*/
|
|
27
|
+
abstract parse(options?: Partial<Config>): FullName;
|
|
28
|
+
}
|
|
29
|
+
export declare class StringParser extends Parser<string> {
|
|
30
|
+
parse(options: Partial<Config>): FullName;
|
|
31
|
+
}
|
|
32
|
+
export declare class ArrayStringParser extends Parser<string[]> {
|
|
33
|
+
parse(options: Partial<Config>): FullName;
|
|
34
|
+
}
|
|
35
|
+
export declare class NamaParser extends Parser<JsonName> {
|
|
36
|
+
#private;
|
|
37
|
+
parse(options: Partial<Config>): FullName;
|
|
38
|
+
}
|
|
39
|
+
export declare class ArrayNameParser extends Parser<Name[]> {
|
|
40
|
+
parse(options: Partial<Config>): FullName;
|
|
41
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Make a type nullable.
|
|
3
|
+
*/
|
|
4
|
+
export type Nullable<T> = T | null | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* The abbreviation type to indicate whether or not to add period to a prefix
|
|
7
|
+
* using the American or British way.
|
|
8
|
+
*/
|
|
9
|
+
export declare enum Title {
|
|
10
|
+
US = "US",
|
|
11
|
+
UK = "UK"
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* An option indicating how to format a surname.
|
|
15
|
+
*
|
|
16
|
+
* This enum can be set via `Config` or when creating a `LastName`. As this can
|
|
17
|
+
* become ambiguous at the time of handling it, the value set in `Config` is
|
|
18
|
+
* prioritized and viewed as the source of truth for future considerations.
|
|
19
|
+
*/
|
|
20
|
+
export declare enum Surname {
|
|
21
|
+
FATHER = "father",
|
|
22
|
+
MOTHER = "mother",
|
|
23
|
+
HYPHENATED = "hyphenated",
|
|
24
|
+
ALL = "all"
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The order of appearance of a `FullName`.
|
|
28
|
+
*/
|
|
29
|
+
export declare enum NameOrder {
|
|
30
|
+
FIRST_NAME = "firstName",
|
|
31
|
+
LAST_NAME = "lastName"
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The types of name handled in this according the name standards.
|
|
35
|
+
*/
|
|
36
|
+
export declare enum NameType {
|
|
37
|
+
FIRST_NAME = "firstName",
|
|
38
|
+
MIDDLE_NAME = "middleName",
|
|
39
|
+
LAST_NAME = "lastName",
|
|
40
|
+
BIRTH_NAME = "birthName"
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The possible variants to indicate how to flatten a `FullName`.
|
|
44
|
+
*/
|
|
45
|
+
export declare enum Flat {
|
|
46
|
+
FIRST_NAME = "firstName",
|
|
47
|
+
MIDDLE_NAME = "middleName",
|
|
48
|
+
LAST_NAME = "lastName",
|
|
49
|
+
FIRST_MID = "firstMid",
|
|
50
|
+
MID_LAST = "midLast",
|
|
51
|
+
ALL = "all"
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The range to use when capitalizing a string content.
|
|
55
|
+
*/
|
|
56
|
+
export declare enum CapsRange {
|
|
57
|
+
NONE = 0,
|
|
58
|
+
INITIAL = 1,
|
|
59
|
+
ALL = 2
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The types of name handled in this utility according the name standards.
|
|
63
|
+
*/
|
|
64
|
+
export declare class Namon {
|
|
65
|
+
readonly index: number;
|
|
66
|
+
readonly key: string;
|
|
67
|
+
static readonly PREFIX: Namon;
|
|
68
|
+
static readonly FIRST_NAME: Namon;
|
|
69
|
+
static readonly MIDDLE_NAME: Namon;
|
|
70
|
+
static readonly LAST_NAME: Namon;
|
|
71
|
+
static readonly SUFFIX: Namon;
|
|
72
|
+
/**
|
|
73
|
+
* The list of supported name types.
|
|
74
|
+
*/
|
|
75
|
+
static readonly values: Namon[];
|
|
76
|
+
/**
|
|
77
|
+
* All the predefined name types.
|
|
78
|
+
*/
|
|
79
|
+
static readonly all: Map<string, Namon>;
|
|
80
|
+
private constructor();
|
|
81
|
+
/**
|
|
82
|
+
* Whether this string key is part of the predefined keys.
|
|
83
|
+
*/
|
|
84
|
+
static has(key: string): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Makes a string key a namon type.
|
|
87
|
+
*/
|
|
88
|
+
static cast(key: string): Nullable<Namon>;
|
|
89
|
+
/**
|
|
90
|
+
* String representation of this object.
|
|
91
|
+
*/
|
|
92
|
+
toString(): string;
|
|
93
|
+
/**
|
|
94
|
+
* Whether this and the other value are equal.
|
|
95
|
+
*/
|
|
96
|
+
equal(other: Namon | unknown): boolean;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The token used to indicate how to split string values.
|
|
100
|
+
*/
|
|
101
|
+
export declare class Separator {
|
|
102
|
+
readonly name: string;
|
|
103
|
+
readonly token: string;
|
|
104
|
+
static readonly COMMA: Separator;
|
|
105
|
+
static readonly COLON: Separator;
|
|
106
|
+
static readonly DOUBLE_QUOTE: Separator;
|
|
107
|
+
static readonly EMPTY: Separator;
|
|
108
|
+
static readonly HYPHEN: Separator;
|
|
109
|
+
static readonly PERIOD: Separator;
|
|
110
|
+
static readonly SEMI_COLON: Separator;
|
|
111
|
+
static readonly SINGLE_QUOTE: Separator;
|
|
112
|
+
static readonly SPACE: Separator;
|
|
113
|
+
static readonly UNDERSCORE: Separator;
|
|
114
|
+
/**
|
|
115
|
+
* All the available separators.
|
|
116
|
+
*/
|
|
117
|
+
static readonly all: Map<string, Separator>;
|
|
118
|
+
/**
|
|
119
|
+
* All the available tokens.
|
|
120
|
+
*/
|
|
121
|
+
static readonly tokens: string[];
|
|
122
|
+
private constructor();
|
|
123
|
+
/**
|
|
124
|
+
* String representation of this object.
|
|
125
|
+
*/
|
|
126
|
+
toString(): string;
|
|
127
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { NameOrder, CapsRange } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* A fixed set of values to handle specific positions for list of names.
|
|
4
|
+
*
|
|
5
|
+
* As for list of names, this helps to follow a specific order based on the
|
|
6
|
+
* count of elements. It is expected that the list has to be between two and
|
|
7
|
+
* five elements. Also, the order of appearance set in the configuration
|
|
8
|
+
* influences how the parsing is carried out.
|
|
9
|
+
*
|
|
10
|
+
* Ordered by first name, the parser works as follows:
|
|
11
|
+
* - 2 elements: firstName lastName
|
|
12
|
+
* - 3 elements: firstName middleName lastName
|
|
13
|
+
* - 4 elements: prefix firstName middleName lastName
|
|
14
|
+
* - 5 elements: prefix firstName middleName lastName suffix
|
|
15
|
+
*
|
|
16
|
+
* Ordered by last name, the parser works as follows:
|
|
17
|
+
* - 2 elements: lastName firstName
|
|
18
|
+
* - 3 elements: lastName firstName middleName
|
|
19
|
+
* - 4 elements: prefix lastName firstName middleName
|
|
20
|
+
* - 5 elements: prefix lastName firstName middleName suffix
|
|
21
|
+
*
|
|
22
|
+
* For example, `Jane Smith` (ordered by first name) is expected to be indexed:
|
|
23
|
+
* `['Jane', 'Smith']`.
|
|
24
|
+
*/
|
|
25
|
+
export declare class NameIndex {
|
|
26
|
+
readonly prefix: number;
|
|
27
|
+
readonly firstName: number;
|
|
28
|
+
readonly middleName: number;
|
|
29
|
+
readonly lastName: number;
|
|
30
|
+
readonly suffix: number;
|
|
31
|
+
/** The minimum number of parts in a list of names. */
|
|
32
|
+
static get min(): number;
|
|
33
|
+
/** The maximum number of parts in a list of names. */
|
|
34
|
+
static get max(): number;
|
|
35
|
+
private constructor();
|
|
36
|
+
/** The default or base indexing: firstName lastName. */
|
|
37
|
+
static base(): NameIndex;
|
|
38
|
+
/**
|
|
39
|
+
* Gets the name index for a list of names based on the `count` of elements
|
|
40
|
+
* and their `order` of appearance.
|
|
41
|
+
*/
|
|
42
|
+
static when(order: NameOrder, count?: number): NameIndex;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Capitalizes a string via a `CapsRange` option.
|
|
46
|
+
*/
|
|
47
|
+
export declare function capitalize(str: string, range?: CapsRange): string;
|
|
48
|
+
/** Decapitalizes a string via a `CapsRange` option. */
|
|
49
|
+
export declare function decapitalize(str: string, range?: CapsRange): string;
|
|
50
|
+
/** Toggles a string representation. */
|
|
51
|
+
export declare function toggleCase(str: string): string;
|
|
52
|
+
export declare function isStringArray(value?: unknown): boolean;
|
|
53
|
+
export declare function isNameArray(value?: unknown): boolean;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { FirstName, LastName, Name } from './name';
|
|
2
|
+
import { Namon } from './types';
|
|
3
|
+
import { NameIndex } from './utils';
|
|
4
|
+
export interface Validator<T> {
|
|
5
|
+
validate(value: T): void;
|
|
6
|
+
}
|
|
7
|
+
declare class ArrayValidator<T extends string | Name> implements Validator<T[]> {
|
|
8
|
+
validate(values: T[]): void;
|
|
9
|
+
}
|
|
10
|
+
declare class NamonValidator implements Validator<string | Name> {
|
|
11
|
+
#private;
|
|
12
|
+
static create(): NamonValidator;
|
|
13
|
+
validate(value: string | Name, type?: Namon): void;
|
|
14
|
+
}
|
|
15
|
+
declare class FirstNameValidator implements Validator<string | FirstName> {
|
|
16
|
+
#private;
|
|
17
|
+
static create(): FirstNameValidator;
|
|
18
|
+
validate(value: string | FirstName): void;
|
|
19
|
+
}
|
|
20
|
+
declare class MiddleNameValidator implements Validator<string | string[] | Name[]> {
|
|
21
|
+
#private;
|
|
22
|
+
static create(): MiddleNameValidator;
|
|
23
|
+
validate(value: string | string[] | Name[]): void;
|
|
24
|
+
}
|
|
25
|
+
declare class LastNameValidator implements Validator<string | LastName> {
|
|
26
|
+
#private;
|
|
27
|
+
static create(): LastNameValidator;
|
|
28
|
+
validate(value: string | LastName): void;
|
|
29
|
+
}
|
|
30
|
+
export declare class NamaValidator implements Validator<Map<Namon, string>> {
|
|
31
|
+
#private;
|
|
32
|
+
static create(): NamaValidator;
|
|
33
|
+
validate(value: Map<Namon, string>): void;
|
|
34
|
+
validateKeys(nama: Map<Namon, string>): void;
|
|
35
|
+
}
|
|
36
|
+
export declare class ArrayStringValidator extends ArrayValidator<string> {
|
|
37
|
+
readonly index: NameIndex;
|
|
38
|
+
constructor(index?: NameIndex);
|
|
39
|
+
validate(values: string[]): void;
|
|
40
|
+
validateIndex(values: string[]): void;
|
|
41
|
+
}
|
|
42
|
+
export declare class ArrayNameValidator implements Validator<Name[]> {
|
|
43
|
+
#private;
|
|
44
|
+
static create(): ArrayNameValidator;
|
|
45
|
+
validate(value: Name[]): void;
|
|
46
|
+
}
|
|
47
|
+
/** A list of validators for a specific namon. */
|
|
48
|
+
export declare abstract class Validators {
|
|
49
|
+
static namon: NamonValidator;
|
|
50
|
+
static nama: NamaValidator;
|
|
51
|
+
static prefix: NamonValidator;
|
|
52
|
+
static firstName: FirstNameValidator;
|
|
53
|
+
static middleName: MiddleNameValidator;
|
|
54
|
+
static lastName: LastNameValidator;
|
|
55
|
+
static suffix: NamonValidator;
|
|
56
|
+
}
|
|
57
|
+
export {};
|