namefully 1.2.0 → 1.3.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/dist/lib/builder.js +80 -0
- package/dist/lib/config.js +67 -144
- package/dist/lib/constants.js +2 -3
- package/dist/lib/error.js +3 -121
- package/dist/lib/full-name.js +46 -78
- package/dist/lib/index.js +12 -15
- package/dist/lib/name.js +57 -149
- package/dist/lib/namefully.js +132 -438
- package/dist/lib/parser.js +42 -71
- package/dist/lib/types.js +6 -80
- package/dist/lib/utils.js +26 -60
- package/dist/lib/validator.js +54 -101
- package/dist/types/builder.d.ts +73 -0
- package/dist/{lib/src → types}/config.d.ts +9 -33
- package/dist/{lib/src → types}/constants.d.ts +1 -1
- package/dist/{lib → types}/error.d.ts +8 -22
- package/dist/{lib → types}/full-name.d.ts +7 -24
- package/dist/{lib → types}/index.d.ts +6 -1
- package/dist/{lib/src → types}/name.d.ts +30 -81
- package/dist/{lib → types}/namefully.d.ts +45 -101
- package/dist/{lib → types}/parser.d.ts +5 -9
- package/dist/{lib/src → types}/types.d.ts +1 -1
- package/dist/{lib/src → types}/utils.d.ts +8 -16
- package/dist/{lib → types}/validator.d.ts +7 -16
- package/dist/umd/namefully.js +955 -1671
- package/dist/umd/namefully.min.js +1 -3
- package/package.json +46 -49
- package/readme.md +71 -42
- package/dist/example/index.js +0 -2734
- package/dist/lib/config.d.ts +0 -121
- package/dist/lib/config.js.map +0 -1
- package/dist/lib/constants.d.ts +0 -4
- package/dist/lib/constants.js.map +0 -1
- package/dist/lib/error.js.map +0 -1
- package/dist/lib/example/example.d.ts +0 -1
- package/dist/lib/full-name.js.map +0 -1
- package/dist/lib/index.js.map +0 -1
- package/dist/lib/name.d.ts +0 -177
- package/dist/lib/name.js.map +0 -1
- package/dist/lib/namefully.js.map +0 -1
- package/dist/lib/parser.js.map +0 -1
- package/dist/lib/src/error.d.ts +0 -172
- package/dist/lib/src/full-name.d.ts +0 -71
- package/dist/lib/src/index.d.ts +0 -20
- package/dist/lib/src/namefully.d.ts +0 -379
- package/dist/lib/src/parser.d.ts +0 -46
- package/dist/lib/src/validator.d.ts +0 -66
- package/dist/lib/types.d.ts +0 -127
- package/dist/lib/types.js.map +0 -1
- package/dist/lib/utils.d.ts +0 -63
- package/dist/lib/utils.js.map +0 -1
- package/dist/lib/validator.js.map +0 -1
- package/dist/umd/namefully.js.map +0 -1
- package/dist/umd/namefully.min.js.LICENSE.txt +0 -12
- package/dist/umd/namefully.min.js.map +0 -1
package/dist/umd/namefully.js
CHANGED
|
@@ -91,7 +91,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
91
91
|
/******/
|
|
92
92
|
/******/
|
|
93
93
|
/******/ // Load entry module and return exports
|
|
94
|
-
/******/ return __webpack_require__(__webpack_require__.s =
|
|
94
|
+
/******/ return __webpack_require__(__webpack_require__.s = 10);
|
|
95
95
|
/******/ })
|
|
96
96
|
/************************************************************************/
|
|
97
97
|
/******/ ([
|
|
@@ -102,114 +102,59 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
102
102
|
|
|
103
103
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
104
104
|
exports.Separator = exports.Namon = exports.CapsRange = exports.Flat = exports.NameType = exports.NameOrder = exports.Surname = exports.Title = void 0;
|
|
105
|
-
/**
|
|
106
|
-
* The abbreviation type to indicate whether or not to add period to a prefix
|
|
107
|
-
* using the American or British way.
|
|
108
|
-
*/
|
|
109
105
|
var Title;
|
|
110
106
|
(function (Title) {
|
|
111
|
-
// A period after the prefix.
|
|
112
107
|
Title["US"] = "US";
|
|
113
|
-
// No period after the prefix.
|
|
114
108
|
Title["UK"] = "UK";
|
|
115
|
-
})(Title
|
|
116
|
-
/**
|
|
117
|
-
* An option indicating how to format a surname.
|
|
118
|
-
*
|
|
119
|
-
* This enum can be set via `Config` or when creating a `LastName`. As this can
|
|
120
|
-
* become ambiguous at the time of handling it, the value set in `Config` is
|
|
121
|
-
* prioritized and viewed as the source of truth for future considerations.
|
|
122
|
-
*/
|
|
109
|
+
})(Title || (exports.Title = Title = {}));
|
|
123
110
|
var Surname;
|
|
124
111
|
(function (Surname) {
|
|
125
|
-
// The fatherly surname only.
|
|
126
112
|
Surname["FATHER"] = "father";
|
|
127
|
-
// The motherly surname only.
|
|
128
113
|
Surname["MOTHER"] = "mother";
|
|
129
|
-
// The junction of both the fatherly and motherly surnames with a hyphen.
|
|
130
114
|
Surname["HYPHENATED"] = "hyphenated";
|
|
131
|
-
// The junction of both the fatherly and motherly surnames with a space.
|
|
132
115
|
Surname["ALL"] = "all";
|
|
133
|
-
})(Surname
|
|
134
|
-
/**
|
|
135
|
-
* The order of appearance of a `FullName`.
|
|
136
|
-
*/
|
|
116
|
+
})(Surname || (exports.Surname = Surname = {}));
|
|
137
117
|
var NameOrder;
|
|
138
118
|
(function (NameOrder) {
|
|
139
|
-
// The first part of a full name, usually the first piece of a person name.
|
|
140
119
|
NameOrder["FIRST_NAME"] = "firstName";
|
|
141
|
-
// The last part of a full name, usually the last piece of a person name.
|
|
142
120
|
NameOrder["LAST_NAME"] = "lastName";
|
|
143
|
-
})(NameOrder
|
|
144
|
-
/**
|
|
145
|
-
* The types of name handled in this according the name standards.
|
|
146
|
-
*/
|
|
121
|
+
})(NameOrder || (exports.NameOrder = NameOrder = {}));
|
|
147
122
|
var NameType;
|
|
148
123
|
(function (NameType) {
|
|
149
124
|
NameType["FIRST_NAME"] = "firstName";
|
|
150
125
|
NameType["MIDDLE_NAME"] = "middleName";
|
|
151
126
|
NameType["LAST_NAME"] = "lastName";
|
|
152
127
|
NameType["BIRTH_NAME"] = "birthName";
|
|
153
|
-
})(NameType
|
|
154
|
-
/**
|
|
155
|
-
* The possible variants to indicate how to flatten a `FullName`.
|
|
156
|
-
*/
|
|
128
|
+
})(NameType || (exports.NameType = NameType = {}));
|
|
157
129
|
var Flat;
|
|
158
130
|
(function (Flat) {
|
|
159
|
-
// Use the first name's initial combined with the remaining parts.
|
|
160
131
|
Flat["FIRST_NAME"] = "firstName";
|
|
161
|
-
// Use the middle name's initial combined with the remaining parts.
|
|
162
132
|
Flat["MIDDLE_NAME"] = "middleName";
|
|
163
|
-
// Use the last name's initial combined with the remaining parts.
|
|
164
133
|
Flat["LAST_NAME"] = "lastName";
|
|
165
|
-
// Use both the first and middle names' initials combined with the remaining parts.
|
|
166
134
|
Flat["FIRST_MID"] = "firstMid";
|
|
167
|
-
// Use both the last and middle names' initials combined with the remaining parts.
|
|
168
135
|
Flat["MID_LAST"] = "midLast";
|
|
169
|
-
// Use the first, middle and last names' initials combined with the remaining parts.
|
|
170
136
|
Flat["ALL"] = "all";
|
|
171
|
-
})(Flat
|
|
172
|
-
/**
|
|
173
|
-
* The range to use when capitalizing a string content.
|
|
174
|
-
*/
|
|
137
|
+
})(Flat || (exports.Flat = Flat = {}));
|
|
175
138
|
var CapsRange;
|
|
176
139
|
(function (CapsRange) {
|
|
177
|
-
// No capitalization.
|
|
178
140
|
CapsRange[CapsRange["NONE"] = 0] = "NONE";
|
|
179
|
-
// Apply capitalization to the first letter.
|
|
180
141
|
CapsRange[CapsRange["INITIAL"] = 1] = "INITIAL";
|
|
181
|
-
// Apply capitalization to all the letters.
|
|
182
142
|
CapsRange[CapsRange["ALL"] = 2] = "ALL";
|
|
183
|
-
})(CapsRange
|
|
184
|
-
/**
|
|
185
|
-
* The types of name handled in this utility according the name standards.
|
|
186
|
-
*/
|
|
143
|
+
})(CapsRange || (exports.CapsRange = CapsRange = {}));
|
|
187
144
|
class Namon {
|
|
188
145
|
constructor(index, key) {
|
|
189
146
|
this.index = index;
|
|
190
147
|
this.key = key;
|
|
191
148
|
}
|
|
192
|
-
/**
|
|
193
|
-
* Whether this string key is part of the predefined keys.
|
|
194
|
-
*/
|
|
195
149
|
static has(key) {
|
|
196
150
|
return Namon.all.has(key);
|
|
197
151
|
}
|
|
198
|
-
/**
|
|
199
|
-
* Makes a string key a namon type.
|
|
200
|
-
*/
|
|
201
152
|
static cast(key) {
|
|
202
153
|
return Namon.has(key) ? Namon.all.get(key) : undefined;
|
|
203
154
|
}
|
|
204
|
-
/**
|
|
205
|
-
* String representation of this object.
|
|
206
|
-
*/
|
|
207
155
|
toString() {
|
|
208
156
|
return `Namon.${this.key}`;
|
|
209
157
|
}
|
|
210
|
-
/**
|
|
211
|
-
* Whether this and the other value are equal.
|
|
212
|
-
*/
|
|
213
158
|
equal(other) {
|
|
214
159
|
return other instanceof Namon && other.index === this.index && other.key === this.key;
|
|
215
160
|
}
|
|
@@ -220,13 +165,7 @@ Namon.FIRST_NAME = new Namon(1, 'firstName');
|
|
|
220
165
|
Namon.MIDDLE_NAME = new Namon(2, 'middleName');
|
|
221
166
|
Namon.LAST_NAME = new Namon(3, 'lastName');
|
|
222
167
|
Namon.SUFFIX = new Namon(4, 'suffix');
|
|
223
|
-
/**
|
|
224
|
-
* The list of supported name types.
|
|
225
|
-
*/
|
|
226
168
|
Namon.values = [Namon.PREFIX, Namon.FIRST_NAME, Namon.MIDDLE_NAME, Namon.LAST_NAME, Namon.SUFFIX];
|
|
227
|
-
/**
|
|
228
|
-
* All the predefined name types.
|
|
229
|
-
*/
|
|
230
169
|
Namon.all = new Map([
|
|
231
170
|
[Namon.PREFIX.key, Namon.PREFIX],
|
|
232
171
|
[Namon.FIRST_NAME.key, Namon.FIRST_NAME],
|
|
@@ -234,17 +173,11 @@ Namon.all = new Map([
|
|
|
234
173
|
[Namon.LAST_NAME.key, Namon.LAST_NAME],
|
|
235
174
|
[Namon.SUFFIX.key, Namon.SUFFIX],
|
|
236
175
|
]);
|
|
237
|
-
/**
|
|
238
|
-
* The token used to indicate how to split string values.
|
|
239
|
-
*/
|
|
240
176
|
class Separator {
|
|
241
177
|
constructor(name, token) {
|
|
242
178
|
this.name = name;
|
|
243
179
|
this.token = token;
|
|
244
180
|
}
|
|
245
|
-
/**
|
|
246
|
-
* String representation of this object.
|
|
247
|
-
*/
|
|
248
181
|
toString() {
|
|
249
182
|
return `Separator.${this.name}`;
|
|
250
183
|
}
|
|
@@ -260,9 +193,6 @@ Separator.SEMI_COLON = new Separator('semiColon', ';');
|
|
|
260
193
|
Separator.SINGLE_QUOTE = new Separator('singleQuote', `'`);
|
|
261
194
|
Separator.SPACE = new Separator('space', ' ');
|
|
262
195
|
Separator.UNDERSCORE = new Separator('underscore', '_');
|
|
263
|
-
/**
|
|
264
|
-
* All the available separators.
|
|
265
|
-
*/
|
|
266
196
|
Separator.all = new Map([
|
|
267
197
|
[Separator.COMMA.name, Separator.COMMA],
|
|
268
198
|
[Separator.COLON.name, Separator.COLON],
|
|
@@ -275,9 +205,6 @@ Separator.all = new Map([
|
|
|
275
205
|
[Separator.SPACE.name, Separator.SPACE],
|
|
276
206
|
[Separator.UNDERSCORE.name, Separator.UNDERSCORE],
|
|
277
207
|
]);
|
|
278
|
-
/**
|
|
279
|
-
* All the available tokens.
|
|
280
|
-
*/
|
|
281
208
|
Separator.tokens = [...Separator.all.values()].map((s) => s.token);
|
|
282
209
|
|
|
283
210
|
|
|
@@ -290,96 +217,35 @@ Separator.tokens = [...Separator.all.values()].map((s) => s.token);
|
|
|
290
217
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
291
218
|
exports.UnknownError = exports.NotAllowedError = exports.ValidationError = exports.InputError = exports.NameError = exports.NameErrorType = void 0;
|
|
292
219
|
const utils_1 = __webpack_require__(2);
|
|
293
|
-
/**
|
|
294
|
-
* The error types supported by `Namefully`.
|
|
295
|
-
*/
|
|
296
220
|
var NameErrorType;
|
|
297
221
|
(function (NameErrorType) {
|
|
298
|
-
/**
|
|
299
|
-
* Thrown when a name entry/argument is incorrect.
|
|
300
|
-
*
|
|
301
|
-
* For example, a name should have a minimum of 2 characters, so an empty
|
|
302
|
-
* string or a string of one character would cause this kind of error.
|
|
303
|
-
*/
|
|
304
222
|
NameErrorType[NameErrorType["INPUT"] = 0] = "INPUT";
|
|
305
|
-
/**
|
|
306
|
-
* Thrown when the name components do not match the validation rules if the
|
|
307
|
-
* `Config.bypass` is not flagged up. This bypass option skips the validation
|
|
308
|
-
* rules.
|
|
309
|
-
*
|
|
310
|
-
* See also: `ValidationError`
|
|
311
|
-
*/
|
|
312
223
|
NameErrorType[NameErrorType["VALIDATION"] = 1] = "VALIDATION";
|
|
313
|
-
/**
|
|
314
|
-
* Thrown by not allowed operations such as in NameBuilder or name formatting.
|
|
315
|
-
*
|
|
316
|
-
* See also: `NotAllowedError`, `Namefully.format`.
|
|
317
|
-
*/
|
|
318
224
|
NameErrorType[NameErrorType["NOT_ALLOWED"] = 2] = "NOT_ALLOWED";
|
|
319
|
-
/**
|
|
320
|
-
* Thrown by any other unknown sources or unexpected situation.
|
|
321
|
-
*/
|
|
322
225
|
NameErrorType[NameErrorType["UNKNOWN"] = 3] = "UNKNOWN";
|
|
323
|
-
})(NameErrorType
|
|
324
|
-
/**
|
|
325
|
-
* Base class for all name-related errors.
|
|
326
|
-
*
|
|
327
|
-
* A custom error is intended to convey information to the user about a failure,
|
|
328
|
-
* so that it can be addressed programmatically.
|
|
329
|
-
*
|
|
330
|
-
* A name handling failure is not considered a native error that should cause a
|
|
331
|
-
* program failure. Au contraire, it is expected that a programmer using this utility
|
|
332
|
-
* would consider validating a name using its own business rules. That is not
|
|
333
|
-
* this utility's job to guess those rules. So, the predefined `ValidationRules`
|
|
334
|
-
* obey some common validation techniques when it comes to sanitizing a person
|
|
335
|
-
* name. For this reason, the [Config.bypass] is set to `true` by default,
|
|
336
|
-
* indicating that those predefined rules should be skipped for the sake of the
|
|
337
|
-
* program.
|
|
338
|
-
*
|
|
339
|
-
* A programmer may leverage `Parser` to indicate business-tailored rules if he
|
|
340
|
-
* or she wants this utility to perform those safety checks behind the scenes.
|
|
341
|
-
*
|
|
342
|
-
* A name error intends to provide useful information about what causes the error
|
|
343
|
-
* and let the user take initiative on what happens next to the given name:
|
|
344
|
-
* reconstructing it or skipping it.
|
|
345
|
-
*/
|
|
226
|
+
})(NameErrorType || (exports.NameErrorType = NameErrorType = {}));
|
|
346
227
|
class NameError extends Error {
|
|
347
|
-
/**
|
|
348
|
-
* Creates an error with a message describing the issue for a name source.
|
|
349
|
-
* @param source name input that caused the error
|
|
350
|
-
* @param message a message describing the failure.
|
|
351
|
-
* @param type of `NameErrorType`
|
|
352
|
-
*/
|
|
353
228
|
constructor(source, message, type = NameErrorType.UNKNOWN) {
|
|
354
229
|
super(message);
|
|
355
230
|
this.source = source;
|
|
356
231
|
this.type = type;
|
|
357
232
|
this.name = 'NameError';
|
|
358
233
|
}
|
|
359
|
-
/**
|
|
360
|
-
* The actual source input which caused the error.
|
|
361
|
-
*/
|
|
362
234
|
get sourceAsString() {
|
|
363
235
|
let input = '';
|
|
364
236
|
if (!this.source)
|
|
365
237
|
input = '<undefined>';
|
|
366
238
|
if (typeof this.source === 'string')
|
|
367
239
|
input = this.source;
|
|
368
|
-
if (utils_1.isNameArray(this.source))
|
|
240
|
+
if ((0, utils_1.isNameArray)(this.source))
|
|
369
241
|
input = this.source.map((n) => n.toString()).join(' ');
|
|
370
|
-
if (utils_1.isStringArray(this.source))
|
|
242
|
+
if ((0, utils_1.isStringArray)(this.source))
|
|
371
243
|
input = this.source.join(' ');
|
|
372
244
|
return input;
|
|
373
245
|
}
|
|
374
|
-
/**
|
|
375
|
-
* Whether a message describing the failure exists.
|
|
376
|
-
*/
|
|
377
246
|
get hasMessage() {
|
|
378
247
|
return this.message && this.message.trim().length > 0;
|
|
379
248
|
}
|
|
380
|
-
/**
|
|
381
|
-
* Returns a string representation of the error.
|
|
382
|
-
*/
|
|
383
249
|
toString() {
|
|
384
250
|
let report = `${this.name} (${this.sourceAsString})`;
|
|
385
251
|
if (this.hasMessage)
|
|
@@ -388,42 +254,14 @@ class NameError extends Error {
|
|
|
388
254
|
}
|
|
389
255
|
}
|
|
390
256
|
exports.NameError = NameError;
|
|
391
|
-
/**
|
|
392
|
-
* An error thrown when a name source input is incorrect.
|
|
393
|
-
*
|
|
394
|
-
* A `Name` is a name for this utility under certain criteria (i.e., 2+ chars),
|
|
395
|
-
* hence, a wrong input will cause this kind of error. Another common reason
|
|
396
|
-
* may be a wrong key in a Json name parsing mechanism.
|
|
397
|
-
*
|
|
398
|
-
* Keep in mind that this error is different from a `ValidationError`.
|
|
399
|
-
*/
|
|
400
257
|
class InputError extends NameError {
|
|
401
|
-
/**
|
|
402
|
-
* Creates a new `InputError` with an optional error `message`.
|
|
403
|
-
*
|
|
404
|
-
* The name source is by nature a string content, maybe wrapped up in a different
|
|
405
|
-
* type. This string value may be extracted to form the following output:
|
|
406
|
-
* "InputError (stringName)",
|
|
407
|
-
* "InputError (stringName): message".
|
|
408
|
-
*/
|
|
409
258
|
constructor(error) {
|
|
410
259
|
super(error.source, error.message, NameErrorType.INPUT);
|
|
411
260
|
this.name = 'InputError';
|
|
412
261
|
}
|
|
413
262
|
}
|
|
414
263
|
exports.InputError = InputError;
|
|
415
|
-
/**
|
|
416
|
-
* An error thrown to indicate that a name fails the validation rules.
|
|
417
|
-
*/
|
|
418
264
|
class ValidationError extends NameError {
|
|
419
|
-
/**
|
|
420
|
-
* Creates error containing the invalid `nameType` and a `message` that
|
|
421
|
-
* briefly describes the problem if provided.
|
|
422
|
-
*
|
|
423
|
-
* For example, a validation error can be interpreted as:
|
|
424
|
-
* "ValidationError (nameType='stringName')",
|
|
425
|
-
* "ValidationError (nameType='stringName'): message"
|
|
426
|
-
*/
|
|
427
265
|
constructor(error) {
|
|
428
266
|
super(error.source, error.message, NameErrorType.VALIDATION);
|
|
429
267
|
this.nameType = error.nameType;
|
|
@@ -437,22 +275,7 @@ class ValidationError extends NameError {
|
|
|
437
275
|
}
|
|
438
276
|
}
|
|
439
277
|
exports.ValidationError = ValidationError;
|
|
440
|
-
/**
|
|
441
|
-
* Thrown by not allowed operations such as in name formatting.
|
|
442
|
-
*
|
|
443
|
-
* For example, this will occur when trying to format a name accordingly using
|
|
444
|
-
* a non-supported key.
|
|
445
|
-
*/
|
|
446
278
|
class NotAllowedError extends NameError {
|
|
447
|
-
/**
|
|
448
|
-
* Creates a new `NotAllowedError` with an optional error `message` and the
|
|
449
|
-
* `operation` name.
|
|
450
|
-
*
|
|
451
|
-
* For example, an error of this kind can be interpreted as:
|
|
452
|
-
* "NotAllowedError (stringName)",
|
|
453
|
-
* "NotAllowedError (stringName) - operationName",
|
|
454
|
-
* "NotAllowedError (stringName) - operationName: message"
|
|
455
|
-
*/
|
|
456
279
|
constructor(error) {
|
|
457
280
|
super(error.source, error.message, NameErrorType.NOT_ALLOWED);
|
|
458
281
|
this.operation = error.operation;
|
|
@@ -468,20 +291,7 @@ class NotAllowedError extends NameError {
|
|
|
468
291
|
}
|
|
469
292
|
}
|
|
470
293
|
exports.NotAllowedError = NotAllowedError;
|
|
471
|
-
/**
|
|
472
|
-
* A fallback error thrown by any unknown sources or unexpected failure that are
|
|
473
|
-
* not of `NameError`.
|
|
474
|
-
*
|
|
475
|
-
* In this particular case, an `origin` remains useful as it provides details
|
|
476
|
-
* on the sources and the true nature of the unexpected error.
|
|
477
|
-
* At this point, deciding whether to exit the program or not depends on the
|
|
478
|
-
* programmer.
|
|
479
|
-
*/
|
|
480
294
|
class UnknownError extends NameError {
|
|
481
|
-
/**
|
|
482
|
-
* Creates a new `UnknownError` with an optional error `message`.
|
|
483
|
-
* Optionally, the original error revealing the true nature of the failure.
|
|
484
|
-
*/
|
|
485
295
|
constructor(error) {
|
|
486
296
|
super(error.source, error.message, NameErrorType.UNKNOWN);
|
|
487
297
|
this.origin = error.error;
|
|
@@ -505,33 +315,16 @@ exports.UnknownError = UnknownError;
|
|
|
505
315
|
|
|
506
316
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
507
317
|
exports.isNameArray = exports.isStringArray = exports.toggleCase = exports.decapitalize = exports.capitalize = exports.NameIndex = void 0;
|
|
508
|
-
const constants_1 = __webpack_require__(
|
|
318
|
+
const constants_1 = __webpack_require__(4);
|
|
509
319
|
const name_1 = __webpack_require__(3);
|
|
510
320
|
const types_1 = __webpack_require__(0);
|
|
511
|
-
/**
|
|
512
|
-
* A fixed set of values to handle specific positions for list of names.
|
|
513
|
-
*
|
|
514
|
-
* As for list of names, this helps to follow a specific order based on the
|
|
515
|
-
* count of elements. It is expected that the list has to be between two and
|
|
516
|
-
* five elements. Also, the order of appearance set in the configuration
|
|
517
|
-
* influences how the parsing is carried out.
|
|
518
|
-
*
|
|
519
|
-
* Ordered by first name, the parser works as follows:
|
|
520
|
-
* - 2 elements: firstName lastName
|
|
521
|
-
* - 3 elements: firstName middleName lastName
|
|
522
|
-
* - 4 elements: prefix firstName middleName lastName
|
|
523
|
-
* - 5 elements: prefix firstName middleName lastName suffix
|
|
524
|
-
*
|
|
525
|
-
* Ordered by last name, the parser works as follows:
|
|
526
|
-
* - 2 elements: lastName firstName
|
|
527
|
-
* - 3 elements: lastName firstName middleName
|
|
528
|
-
* - 4 elements: prefix lastName firstName middleName
|
|
529
|
-
* - 5 elements: prefix lastName firstName middleName suffix
|
|
530
|
-
*
|
|
531
|
-
* For example, `Jane Smith` (ordered by first name) is expected to be indexed:
|
|
532
|
-
* `['Jane', 'Smith']`.
|
|
533
|
-
*/
|
|
534
321
|
class NameIndex {
|
|
322
|
+
static get min() {
|
|
323
|
+
return constants_1.MIN_NUMBER_OF_NAME_PARTS;
|
|
324
|
+
}
|
|
325
|
+
static get max() {
|
|
326
|
+
return constants_1.MAX_NUMBER_OF_NAME_PARTS;
|
|
327
|
+
}
|
|
535
328
|
constructor(prefix, firstName, middleName, lastName, suffix) {
|
|
536
329
|
this.prefix = prefix;
|
|
537
330
|
this.firstName = firstName;
|
|
@@ -539,38 +332,19 @@ class NameIndex {
|
|
|
539
332
|
this.lastName = lastName;
|
|
540
333
|
this.suffix = suffix;
|
|
541
334
|
}
|
|
542
|
-
/**
|
|
543
|
-
* The minimum number of parts in a list of names.
|
|
544
|
-
*/
|
|
545
|
-
static get min() {
|
|
546
|
-
return constants_1.MIN_NUMBER_OF_NAME_PARTS;
|
|
547
|
-
}
|
|
548
|
-
/**
|
|
549
|
-
* The maximum number of parts in a list of names.
|
|
550
|
-
*/
|
|
551
|
-
static get max() {
|
|
552
|
-
return constants_1.MAX_NUMBER_OF_NAME_PARTS;
|
|
553
|
-
}
|
|
554
|
-
/**
|
|
555
|
-
* The default or base indexing: firstName lastName.
|
|
556
|
-
*/
|
|
557
335
|
static base() {
|
|
558
336
|
return new this(-1, 0, -1, 1, -1);
|
|
559
337
|
}
|
|
560
|
-
/**
|
|
561
|
-
* Gets the name index for a list of names based on the `count` of elements
|
|
562
|
-
* and their `order` of appearance.
|
|
563
|
-
*/
|
|
564
338
|
static when(order, count = 2) {
|
|
565
339
|
if (order === types_1.NameOrder.FIRST_NAME) {
|
|
566
340
|
switch (count) {
|
|
567
|
-
case 2:
|
|
341
|
+
case 2:
|
|
568
342
|
return new this(-1, 0, -1, 1, -1);
|
|
569
|
-
case 3:
|
|
343
|
+
case 3:
|
|
570
344
|
return new this(-1, 0, 1, 2, -1);
|
|
571
|
-
case 4:
|
|
345
|
+
case 4:
|
|
572
346
|
return new this(0, 1, 2, 3, -1);
|
|
573
|
-
case 5:
|
|
347
|
+
case 5:
|
|
574
348
|
return new this(0, 1, 2, 3, 4);
|
|
575
349
|
default:
|
|
576
350
|
return NameIndex.base();
|
|
@@ -578,24 +352,33 @@ class NameIndex {
|
|
|
578
352
|
}
|
|
579
353
|
else {
|
|
580
354
|
switch (count) {
|
|
581
|
-
case 2:
|
|
355
|
+
case 2:
|
|
582
356
|
return new this(-1, 1, -1, 0, -1);
|
|
583
|
-
case 3:
|
|
357
|
+
case 3:
|
|
584
358
|
return new this(-1, 1, 2, 0, -1);
|
|
585
|
-
case 4:
|
|
359
|
+
case 4:
|
|
586
360
|
return new this(0, 2, 3, 1, -1);
|
|
587
|
-
case 5:
|
|
361
|
+
case 5:
|
|
588
362
|
return new this(0, 2, 3, 1, 4);
|
|
589
363
|
default:
|
|
590
364
|
return NameIndex.base();
|
|
591
365
|
}
|
|
592
366
|
}
|
|
593
367
|
}
|
|
368
|
+
static only({ prefix = -1, firstName, middleName = -1, lastName, suffix = -1 }) {
|
|
369
|
+
return new this(prefix, firstName, middleName, lastName, suffix);
|
|
370
|
+
}
|
|
371
|
+
toJson() {
|
|
372
|
+
return {
|
|
373
|
+
prefix: this.prefix,
|
|
374
|
+
firstName: this.firstName,
|
|
375
|
+
middleName: this.middleName,
|
|
376
|
+
lastName: this.lastName,
|
|
377
|
+
suffix: this.suffix,
|
|
378
|
+
};
|
|
379
|
+
}
|
|
594
380
|
}
|
|
595
381
|
exports.NameIndex = NameIndex;
|
|
596
|
-
/**
|
|
597
|
-
* Capitalizes a string via a `CapsRange` option.
|
|
598
|
-
*/
|
|
599
382
|
function capitalize(str, range = types_1.CapsRange.INITIAL) {
|
|
600
383
|
if (!str || range === types_1.CapsRange.NONE)
|
|
601
384
|
return str;
|
|
@@ -604,9 +387,6 @@ function capitalize(str, range = types_1.CapsRange.INITIAL) {
|
|
|
604
387
|
return range === types_1.CapsRange.INITIAL ? initial.concat(rest) : str.toUpperCase();
|
|
605
388
|
}
|
|
606
389
|
exports.capitalize = capitalize;
|
|
607
|
-
/**
|
|
608
|
-
* Decapitalizes a string via a `CapsRange` option.
|
|
609
|
-
*/
|
|
610
390
|
function decapitalize(str, range = types_1.CapsRange.INITIAL) {
|
|
611
391
|
if (!str || range === types_1.CapsRange.NONE)
|
|
612
392
|
return str;
|
|
@@ -615,9 +395,6 @@ function decapitalize(str, range = types_1.CapsRange.INITIAL) {
|
|
|
615
395
|
return range === types_1.CapsRange.INITIAL ? initial.concat(rest) : str.toLowerCase();
|
|
616
396
|
}
|
|
617
397
|
exports.decapitalize = decapitalize;
|
|
618
|
-
/**
|
|
619
|
-
* Toggles a string representation.
|
|
620
|
-
*/
|
|
621
398
|
function toggleCase(str) {
|
|
622
399
|
const chars = [];
|
|
623
400
|
for (const c of str) {
|
|
@@ -647,266 +424,177 @@ exports.isNameArray = isNameArray;
|
|
|
647
424
|
|
|
648
425
|
"use strict";
|
|
649
426
|
|
|
427
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
428
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
429
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
430
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
431
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
432
|
+
};
|
|
433
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
434
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
435
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
436
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
437
|
+
};
|
|
438
|
+
var _Name_namon, _FirstName_more, _LastName_mother;
|
|
650
439
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
651
440
|
exports.LastName = exports.FirstName = exports.Name = void 0;
|
|
652
441
|
const error_1 = __webpack_require__(1);
|
|
653
442
|
const types_1 = __webpack_require__(0);
|
|
654
443
|
const utils_1 = __webpack_require__(2);
|
|
655
|
-
/**
|
|
656
|
-
* Representation of a string type name with some extra capabilities.
|
|
657
|
-
*/
|
|
658
444
|
class Name {
|
|
659
|
-
/**
|
|
660
|
-
* Creates augmented names by adding extra functionality to a string name.
|
|
661
|
-
* @param type must be indicated to categorize the name so it can be
|
|
662
|
-
* treated accordingly.
|
|
663
|
-
* @param capsRange determines how the name should be capitalized initially.
|
|
664
|
-
*/
|
|
665
445
|
constructor(value, type, capsRange) {
|
|
666
446
|
this.type = type;
|
|
447
|
+
_Name_namon.set(this, void 0);
|
|
667
448
|
this.capsRange = capsRange !== null && capsRange !== void 0 ? capsRange : types_1.CapsRange.INITIAL;
|
|
668
449
|
this.value = value;
|
|
669
450
|
if (capsRange)
|
|
670
451
|
this.caps(capsRange);
|
|
671
452
|
}
|
|
672
453
|
set value(newValue) {
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
}
|
|
676
|
-
this.namon = newValue;
|
|
454
|
+
this.validate(newValue);
|
|
455
|
+
__classPrivateFieldSet(this, _Name_namon, newValue, "f");
|
|
677
456
|
this.initial = newValue[0];
|
|
678
457
|
}
|
|
679
|
-
/**
|
|
680
|
-
* The piece of string treated as a name.
|
|
681
|
-
*/
|
|
682
458
|
get value() {
|
|
683
|
-
return this
|
|
459
|
+
return __classPrivateFieldGet(this, _Name_namon, "f");
|
|
684
460
|
}
|
|
685
|
-
/**
|
|
686
|
-
* The length of the name.
|
|
687
|
-
*/
|
|
688
461
|
get length() {
|
|
689
|
-
return this.
|
|
462
|
+
return __classPrivateFieldGet(this, _Name_namon, "f").length;
|
|
690
463
|
}
|
|
691
|
-
/**
|
|
692
|
-
* Whether the name is a prefix.
|
|
693
|
-
*/
|
|
694
464
|
get isPrefix() {
|
|
695
465
|
return this.type === types_1.Namon.PREFIX;
|
|
696
466
|
}
|
|
697
|
-
/**
|
|
698
|
-
* Whether the name is a first name.
|
|
699
|
-
*/
|
|
700
467
|
get isFirstName() {
|
|
701
468
|
return this.type === types_1.Namon.FIRST_NAME;
|
|
702
469
|
}
|
|
703
|
-
/**
|
|
704
|
-
* Whether the name is a middle name.
|
|
705
|
-
*/
|
|
706
470
|
get isMiddleName() {
|
|
707
471
|
return this.type === types_1.Namon.MIDDLE_NAME;
|
|
708
472
|
}
|
|
709
|
-
/**
|
|
710
|
-
* Whether the name is a last name.
|
|
711
|
-
*/
|
|
712
473
|
get isLastName() {
|
|
713
474
|
return this.type === types_1.Namon.LAST_NAME;
|
|
714
475
|
}
|
|
715
|
-
/**
|
|
716
|
-
* Whether the name is a suffix.
|
|
717
|
-
*/
|
|
718
476
|
get isSuffix() {
|
|
719
477
|
return this.type === types_1.Namon.SUFFIX;
|
|
720
478
|
}
|
|
721
|
-
/**
|
|
722
|
-
* Creates a prefix.
|
|
723
|
-
*/
|
|
724
479
|
static prefix(value) {
|
|
725
480
|
return new this(value, types_1.Namon.PREFIX);
|
|
726
481
|
}
|
|
727
|
-
/**
|
|
728
|
-
* Creates a first name.
|
|
729
|
-
*/
|
|
730
482
|
static first(value) {
|
|
731
483
|
return new this(value, types_1.Namon.FIRST_NAME);
|
|
732
484
|
}
|
|
733
|
-
/**
|
|
734
|
-
* Creates a middle name.
|
|
735
|
-
*/
|
|
736
485
|
static middle(value) {
|
|
737
486
|
return new this(value, types_1.Namon.MIDDLE_NAME);
|
|
738
487
|
}
|
|
739
|
-
/**
|
|
740
|
-
* Creates a last name.
|
|
741
|
-
*/
|
|
742
488
|
static last(value) {
|
|
743
489
|
return new this(value, types_1.Namon.LAST_NAME);
|
|
744
490
|
}
|
|
745
|
-
/**
|
|
746
|
-
* Creates a suffix.
|
|
747
|
-
*/
|
|
748
491
|
static suffix(value) {
|
|
749
492
|
return new this(value, types_1.Namon.SUFFIX);
|
|
750
493
|
}
|
|
751
|
-
/**
|
|
752
|
-
* Gets the initials (first character) of this name.
|
|
753
|
-
*/
|
|
754
494
|
initials() {
|
|
755
495
|
return [this.initial];
|
|
756
496
|
}
|
|
757
|
-
/**
|
|
758
|
-
* String representation of this object.
|
|
759
|
-
*/
|
|
760
497
|
toString() {
|
|
761
|
-
return this
|
|
498
|
+
return __classPrivateFieldGet(this, _Name_namon, "f");
|
|
762
499
|
}
|
|
763
|
-
/**
|
|
764
|
-
* Returns true if the other is equal to this name.
|
|
765
|
-
*/
|
|
766
500
|
equal(other) {
|
|
767
501
|
return other instanceof Name && other.value === this.value && other.type === this.type;
|
|
768
502
|
}
|
|
769
|
-
/**
|
|
770
|
-
* Capitalizes the name.
|
|
771
|
-
*/
|
|
772
503
|
caps(range) {
|
|
773
|
-
this.value = utils_1.capitalize(this
|
|
504
|
+
this.value = (0, utils_1.capitalize)(__classPrivateFieldGet(this, _Name_namon, "f"), range !== null && range !== void 0 ? range : this.capsRange);
|
|
774
505
|
return this;
|
|
775
506
|
}
|
|
776
|
-
/**
|
|
777
|
-
* De-capitalizes the name.
|
|
778
|
-
*/
|
|
779
507
|
decaps(range) {
|
|
780
|
-
this.value = utils_1.decapitalize(this
|
|
508
|
+
this.value = (0, utils_1.decapitalize)(__classPrivateFieldGet(this, _Name_namon, "f"), range !== null && range !== void 0 ? range : this.capsRange);
|
|
781
509
|
return this;
|
|
782
510
|
}
|
|
511
|
+
validate(name) {
|
|
512
|
+
if ((name === null || name === void 0 ? void 0 : name.trim().length) < 2) {
|
|
513
|
+
throw new error_1.InputError({ source: name, message: 'must be 2+ characters' });
|
|
514
|
+
}
|
|
515
|
+
}
|
|
783
516
|
}
|
|
784
517
|
exports.Name = Name;
|
|
785
|
-
|
|
786
|
-
* Representation of a first name with some extra functionality.
|
|
787
|
-
*/
|
|
518
|
+
_Name_namon = new WeakMap();
|
|
788
519
|
class FirstName extends Name {
|
|
789
|
-
/**
|
|
790
|
-
* Creates an extended version of `Name` and flags it as a first name `type`.
|
|
791
|
-
*
|
|
792
|
-
* Some may consider `more` additional name parts of a given name as their
|
|
793
|
-
* first names, but not as their middle names. Though, it may mean the same,
|
|
794
|
-
* `more` provides the freedom to do it as it pleases.
|
|
795
|
-
*/
|
|
796
520
|
constructor(value, ...more) {
|
|
797
521
|
super(value, types_1.Namon.FIRST_NAME);
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
this._more = more;
|
|
522
|
+
_FirstName_more.set(this, void 0);
|
|
523
|
+
more.forEach((n) => this.validate(n));
|
|
524
|
+
__classPrivateFieldSet(this, _FirstName_more, more, "f");
|
|
804
525
|
}
|
|
805
|
-
/**
|
|
806
|
-
* Determines whether a first name has `more` name parts.
|
|
807
|
-
*/
|
|
808
526
|
get hasMore() {
|
|
809
|
-
return this.
|
|
527
|
+
return __classPrivateFieldGet(this, _FirstName_more, "f").length > 0;
|
|
810
528
|
}
|
|
811
529
|
get length() {
|
|
812
|
-
return super.length + (this.hasMore ? this.
|
|
530
|
+
return super.length + (this.hasMore ? __classPrivateFieldGet(this, _FirstName_more, "f").reduce((acc, n) => acc + n).length : 0);
|
|
813
531
|
}
|
|
814
|
-
/**
|
|
815
|
-
* Returns a combined version of the `value` and `more` if any.
|
|
816
|
-
*/
|
|
817
532
|
get asNames() {
|
|
818
533
|
const names = [Name.first(this.value)];
|
|
819
534
|
if (this.hasMore) {
|
|
820
|
-
names.push(...this.
|
|
535
|
+
names.push(...__classPrivateFieldGet(this, _FirstName_more, "f").map((n) => Name.first(n)));
|
|
821
536
|
}
|
|
822
537
|
return names;
|
|
823
538
|
}
|
|
824
|
-
/**
|
|
825
|
-
* The additional name parts of the first name.
|
|
826
|
-
*/
|
|
827
539
|
get more() {
|
|
828
|
-
return this
|
|
540
|
+
return __classPrivateFieldGet(this, _FirstName_more, "f");
|
|
829
541
|
}
|
|
830
542
|
toString(withMore = false) {
|
|
831
|
-
return withMore && this.hasMore ? `${this.value} ${this.
|
|
543
|
+
return withMore && this.hasMore ? `${this.value} ${__classPrivateFieldGet(this, _FirstName_more, "f").join(' ')}`.trim() : this.value;
|
|
832
544
|
}
|
|
833
545
|
initials(withMore = false) {
|
|
834
546
|
const inits = [this.initial];
|
|
835
547
|
if (withMore && this.hasMore) {
|
|
836
|
-
inits.push(...this.
|
|
548
|
+
inits.push(...__classPrivateFieldGet(this, _FirstName_more, "f").map((n) => n[0]));
|
|
837
549
|
}
|
|
838
550
|
return inits;
|
|
839
551
|
}
|
|
840
552
|
caps(range) {
|
|
841
553
|
range = range || this.capsRange;
|
|
842
|
-
this.value = utils_1.capitalize(this.value, range);
|
|
554
|
+
this.value = (0, utils_1.capitalize)(this.value, range);
|
|
843
555
|
if (this.hasMore)
|
|
844
|
-
this
|
|
556
|
+
__classPrivateFieldSet(this, _FirstName_more, __classPrivateFieldGet(this, _FirstName_more, "f").map((n) => (0, utils_1.capitalize)(n, range)), "f");
|
|
845
557
|
return this;
|
|
846
558
|
}
|
|
847
559
|
decaps(range) {
|
|
848
560
|
range = range || this.capsRange;
|
|
849
|
-
this.value = utils_1.decapitalize(this.value, range);
|
|
561
|
+
this.value = (0, utils_1.decapitalize)(this.value, range);
|
|
850
562
|
if (this.hasMore)
|
|
851
|
-
this
|
|
563
|
+
__classPrivateFieldSet(this, _FirstName_more, __classPrivateFieldGet(this, _FirstName_more, "f").map((n) => (0, utils_1.decapitalize)(n, range)), "f");
|
|
852
564
|
return this;
|
|
853
565
|
}
|
|
854
|
-
/**
|
|
855
|
-
* Makes a copy of the current name.
|
|
856
|
-
*/
|
|
857
566
|
copyWith(values) {
|
|
858
567
|
var _a, _b;
|
|
859
|
-
return new FirstName((_a = values.first) !== null && _a !== void 0 ? _a : this.value, ...((_b = values.more) !== null && _b !== void 0 ? _b : this
|
|
568
|
+
return new FirstName((_a = values.first) !== null && _a !== void 0 ? _a : this.value, ...((_b = values.more) !== null && _b !== void 0 ? _b : __classPrivateFieldGet(this, _FirstName_more, "f")));
|
|
860
569
|
}
|
|
861
570
|
}
|
|
862
571
|
exports.FirstName = FirstName;
|
|
863
|
-
|
|
864
|
-
* Representation of a last name with some extra functionality.
|
|
865
|
-
*/
|
|
572
|
+
_FirstName_more = new WeakMap();
|
|
866
573
|
class LastName extends Name {
|
|
867
|
-
/**
|
|
868
|
-
* Creates an extended version of `Name` and flags it as a last name `type`.
|
|
869
|
-
*
|
|
870
|
-
* Some people may keep their `mother`'s surname and want to keep a clear cut
|
|
871
|
-
* from their `father`'s surname. However, there are no clear rules about it.
|
|
872
|
-
*/
|
|
873
574
|
constructor(father, mother, format = types_1.Surname.FATHER) {
|
|
874
575
|
super(father, types_1.Namon.LAST_NAME);
|
|
875
576
|
this.format = format;
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
this._mother = mother;
|
|
577
|
+
_LastName_mother.set(this, void 0);
|
|
578
|
+
this.validate(mother);
|
|
579
|
+
__classPrivateFieldSet(this, _LastName_mother, mother, "f");
|
|
880
580
|
}
|
|
881
|
-
/**
|
|
882
|
-
* The surname inherited from a father side.
|
|
883
|
-
*/
|
|
884
581
|
get father() {
|
|
885
582
|
return this.value;
|
|
886
583
|
}
|
|
887
|
-
/**
|
|
888
|
-
* The surname inherited from a mother side.
|
|
889
|
-
*/
|
|
890
584
|
get mother() {
|
|
891
|
-
return this
|
|
585
|
+
return __classPrivateFieldGet(this, _LastName_mother, "f");
|
|
892
586
|
}
|
|
893
|
-
/**
|
|
894
|
-
* Returns `true` if the mother's surname is defined.
|
|
895
|
-
*/
|
|
896
587
|
get hasMother() {
|
|
897
|
-
return !!this
|
|
588
|
+
return !!__classPrivateFieldGet(this, _LastName_mother, "f");
|
|
898
589
|
}
|
|
899
590
|
get length() {
|
|
900
591
|
var _a, _b;
|
|
901
|
-
return super.length + ((_b = (_a = this
|
|
592
|
+
return super.length + ((_b = (_a = __classPrivateFieldGet(this, _LastName_mother, "f")) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0);
|
|
902
593
|
}
|
|
903
|
-
/**
|
|
904
|
-
* Returns a combined version of the `father` and `mother` if any.
|
|
905
|
-
*/
|
|
906
594
|
get asNames() {
|
|
907
595
|
const names = [Name.last(this.value)];
|
|
908
596
|
if (this.hasMother) {
|
|
909
|
-
names.push(Name.last(this
|
|
597
|
+
names.push(Name.last(__classPrivateFieldGet(this, _LastName_mother, "f")));
|
|
910
598
|
}
|
|
911
599
|
return names;
|
|
912
600
|
}
|
|
@@ -919,9 +607,9 @@ class LastName extends Name {
|
|
|
919
607
|
case types_1.Surname.MOTHER:
|
|
920
608
|
return (_a = this.mother) !== null && _a !== void 0 ? _a : '';
|
|
921
609
|
case types_1.Surname.HYPHENATED:
|
|
922
|
-
return this.hasMother ? `${this.value}-${this
|
|
610
|
+
return this.hasMother ? `${this.value}-${__classPrivateFieldGet(this, _LastName_mother, "f")}` : this.value;
|
|
923
611
|
case types_1.Surname.ALL:
|
|
924
|
-
return this.hasMother ? `${this.value} ${this
|
|
612
|
+
return this.hasMother ? `${this.value} ${__classPrivateFieldGet(this, _LastName_mother, "f")}` : this.value;
|
|
925
613
|
}
|
|
926
614
|
}
|
|
927
615
|
initials(format) {
|
|
@@ -930,13 +618,13 @@ class LastName extends Name {
|
|
|
930
618
|
switch (format) {
|
|
931
619
|
case types_1.Surname.MOTHER:
|
|
932
620
|
if (this.hasMother)
|
|
933
|
-
inits.push(this
|
|
621
|
+
inits.push(__classPrivateFieldGet(this, _LastName_mother, "f")[0]);
|
|
934
622
|
break;
|
|
935
623
|
case types_1.Surname.HYPHENATED:
|
|
936
624
|
case types_1.Surname.ALL:
|
|
937
625
|
inits.push(this.initial);
|
|
938
626
|
if (this.hasMother)
|
|
939
|
-
inits.push(this
|
|
627
|
+
inits.push(__classPrivateFieldGet(this, _LastName_mother, "f")[0]);
|
|
940
628
|
break;
|
|
941
629
|
case types_1.Surname.FATHER:
|
|
942
630
|
default:
|
|
@@ -946,27 +634,25 @@ class LastName extends Name {
|
|
|
946
634
|
}
|
|
947
635
|
caps(range) {
|
|
948
636
|
range = range || this.capsRange;
|
|
949
|
-
this.value = utils_1.capitalize(this.value, range);
|
|
637
|
+
this.value = (0, utils_1.capitalize)(this.value, range);
|
|
950
638
|
if (this.hasMother)
|
|
951
|
-
this
|
|
639
|
+
__classPrivateFieldSet(this, _LastName_mother, (0, utils_1.capitalize)(__classPrivateFieldGet(this, _LastName_mother, "f"), range), "f");
|
|
952
640
|
return this;
|
|
953
641
|
}
|
|
954
642
|
decaps(range) {
|
|
955
643
|
range = range || this.capsRange;
|
|
956
|
-
this.value = utils_1.decapitalize(this.value, range);
|
|
644
|
+
this.value = (0, utils_1.decapitalize)(this.value, range);
|
|
957
645
|
if (this.hasMother)
|
|
958
|
-
this
|
|
646
|
+
__classPrivateFieldSet(this, _LastName_mother, (0, utils_1.decapitalize)(__classPrivateFieldGet(this, _LastName_mother, "f"), range), "f");
|
|
959
647
|
return this;
|
|
960
648
|
}
|
|
961
|
-
/**
|
|
962
|
-
* Makes a copy of the current name.
|
|
963
|
-
*/
|
|
964
649
|
copyWith(values) {
|
|
965
650
|
var _a, _b, _c;
|
|
966
651
|
return new LastName((_a = values.father) !== null && _a !== void 0 ? _a : this.value, (_b = values.mother) !== null && _b !== void 0 ? _b : this.mother, (_c = values.format) !== null && _c !== void 0 ? _c : this.format);
|
|
967
652
|
}
|
|
968
653
|
}
|
|
969
654
|
exports.LastName = LastName;
|
|
655
|
+
_LastName_mother = new WeakMap();
|
|
970
656
|
|
|
971
657
|
|
|
972
658
|
/***/ }),
|
|
@@ -976,203 +662,8 @@ exports.LastName = LastName;
|
|
|
976
662
|
"use strict";
|
|
977
663
|
|
|
978
664
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
979
|
-
exports.
|
|
980
|
-
|
|
981
|
-
const defaultName = 'default';
|
|
982
|
-
const copyAlias = '_copy';
|
|
983
|
-
/**
|
|
984
|
-
* The Configuration to use across the other components.
|
|
985
|
-
*
|
|
986
|
-
* The multiton pattern is used to handle configurations across the `namefully`
|
|
987
|
-
* setup. This adds consistency when building other components such as `FirstName`,
|
|
988
|
-
* `LastName`, or `Name` of distinct types that may be of particular shapes.
|
|
989
|
-
*
|
|
990
|
-
* For example, a person's `FullName` may appear by:
|
|
991
|
-
* - NameOrder.FIRST_NAME: `Jon Snow` or
|
|
992
|
-
* - NameOrder.LAST_NAME: `Snow Jon`.
|
|
993
|
-
*
|
|
994
|
-
* `Config` makes it easy to set up a specific configuration for `Namefully`
|
|
995
|
-
* and reuse it through other instances or components along the way. If a new
|
|
996
|
-
* `Config` is needed, a named configuration may be created. It is actually
|
|
997
|
-
* advised to use named `Config.create(name)` instead as it may help mitigate issues
|
|
998
|
-
* and avoid confusion and ambiguity in the future. Plus, a named configuration
|
|
999
|
-
* explains its purpose.
|
|
1000
|
-
*
|
|
1001
|
-
* ```ts
|
|
1002
|
-
* const defaultConfig = Config.create();
|
|
1003
|
-
* const mergedConfig = Config.merge({ name: 'other', title: Title.US });
|
|
1004
|
-
* const copyConfig = mergedConfig.copyWith({ ending: true });
|
|
1005
|
-
* ```
|
|
1006
|
-
*
|
|
1007
|
-
* Additionally, a configuration may be merged with or copied from an existing
|
|
1008
|
-
* configuration, prioritizing the new one's values, as shown in the example
|
|
1009
|
-
* above.
|
|
1010
|
-
*/
|
|
1011
|
-
class Config {
|
|
1012
|
-
constructor(name, orderedBy = types_1.NameOrder.FIRST_NAME, separator = types_1.Separator.SPACE, title = types_1.Title.UK, ending = false, bypass = true, surname = types_1.Surname.FATHER) {
|
|
1013
|
-
this._name = name;
|
|
1014
|
-
this._orderedBy = orderedBy;
|
|
1015
|
-
this._separator = separator;
|
|
1016
|
-
this._title = title;
|
|
1017
|
-
this._ending = ending;
|
|
1018
|
-
this._bypass = bypass;
|
|
1019
|
-
this._surname = surname;
|
|
1020
|
-
}
|
|
1021
|
-
/**
|
|
1022
|
-
* The order of appearance of a full name.
|
|
1023
|
-
*/
|
|
1024
|
-
get orderedBy() {
|
|
1025
|
-
return this._orderedBy;
|
|
1026
|
-
}
|
|
1027
|
-
/**
|
|
1028
|
-
* The token used to indicate how to split string values.
|
|
1029
|
-
*/
|
|
1030
|
-
get separator() {
|
|
1031
|
-
return this._separator;
|
|
1032
|
-
}
|
|
1033
|
-
/**
|
|
1034
|
-
* The abbreviation type to indicate whether or not to add period to a prefix
|
|
1035
|
-
* using the American or British way.
|
|
1036
|
-
*/
|
|
1037
|
-
get title() {
|
|
1038
|
-
return this._title;
|
|
1039
|
-
}
|
|
1040
|
-
/**
|
|
1041
|
-
* The option indicating if an ending suffix is used in a formal way.
|
|
1042
|
-
*/
|
|
1043
|
-
get ending() {
|
|
1044
|
-
return this._ending;
|
|
1045
|
-
}
|
|
1046
|
-
/**
|
|
1047
|
-
* A bypass of the validation rules with this option. This option is ideal
|
|
1048
|
-
* to avoid checking their validity.
|
|
1049
|
-
*/
|
|
1050
|
-
get bypass() {
|
|
1051
|
-
return this._bypass;
|
|
1052
|
-
}
|
|
1053
|
-
/**
|
|
1054
|
-
* An option indicating how to format a surname.
|
|
1055
|
-
*
|
|
1056
|
-
* The supported formats are:
|
|
1057
|
-
* - `FATHER` name only
|
|
1058
|
-
* - `MOTHER` name only
|
|
1059
|
-
* - `HYPHENATED`, joining both father and mother names with a hyphen
|
|
1060
|
-
* - `ALL`, joining both father and mother names with a space.
|
|
1061
|
-
*
|
|
1062
|
-
* Note that this option can be set when creating a `LastName`. As this can
|
|
1063
|
-
* become ambiguous at the time of handling it, the value set in this is
|
|
1064
|
-
* prioritized and viewed as the source of truth for future considerations.
|
|
1065
|
-
*/
|
|
1066
|
-
get surname() {
|
|
1067
|
-
return this._surname;
|
|
1068
|
-
}
|
|
1069
|
-
/**
|
|
1070
|
-
* The name of the cached configuration.
|
|
1071
|
-
*/
|
|
1072
|
-
get name() {
|
|
1073
|
-
return this._name;
|
|
1074
|
-
}
|
|
1075
|
-
/**
|
|
1076
|
-
* Returns a named configuration with default values.
|
|
1077
|
-
* @param name describing its purpose.
|
|
1078
|
-
*/
|
|
1079
|
-
static create(name = defaultName) {
|
|
1080
|
-
if (!Config.cache.has(name)) {
|
|
1081
|
-
Config.cache.set(name, new this(name));
|
|
1082
|
-
}
|
|
1083
|
-
return Config.cache.get(name);
|
|
1084
|
-
}
|
|
1085
|
-
/**
|
|
1086
|
-
* Returns a combined version of the existing values of the default configuration
|
|
1087
|
-
* and the provided optional values of another configuration.
|
|
1088
|
-
* @param other partial config to be combined with.
|
|
1089
|
-
*/
|
|
1090
|
-
static merge(other) {
|
|
1091
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1092
|
-
if (!other) {
|
|
1093
|
-
return Config.create();
|
|
1094
|
-
}
|
|
1095
|
-
else {
|
|
1096
|
-
const config = Config.create(other.name);
|
|
1097
|
-
config._orderedBy = (_a = other.orderedBy) !== null && _a !== void 0 ? _a : config.orderedBy;
|
|
1098
|
-
config._separator = (_b = other.separator) !== null && _b !== void 0 ? _b : config.separator;
|
|
1099
|
-
config._title = (_c = other.title) !== null && _c !== void 0 ? _c : config.title;
|
|
1100
|
-
config._ending = (_d = other.ending) !== null && _d !== void 0 ? _d : config.ending;
|
|
1101
|
-
config._bypass = (_e = other.bypass) !== null && _e !== void 0 ? _e : config.bypass;
|
|
1102
|
-
config._surname = (_f = other.surname) !== null && _f !== void 0 ? _f : config.surname;
|
|
1103
|
-
return config;
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
/**
|
|
1107
|
-
* Returns a copy of this configuration merged with the provided values.
|
|
1108
|
-
*
|
|
1109
|
-
* The word `_copy` is added to the existing config's name to create the new
|
|
1110
|
-
* config's name if the name already exists for previous configurations. This
|
|
1111
|
-
* is useful to maintain the uniqueness of each configuration. For example,
|
|
1112
|
-
* if the new copy is made from the default configuration, this new copy will
|
|
1113
|
-
* be named `default_copy`.
|
|
1114
|
-
*/
|
|
1115
|
-
copyWith(options = {}) {
|
|
1116
|
-
const { name, orderedBy, separator, title, ending, bypass, surname } = options;
|
|
1117
|
-
const config = Config.create(this.genNewName(name !== null && name !== void 0 ? name : this.name + copyAlias));
|
|
1118
|
-
config._orderedBy = orderedBy !== null && orderedBy !== void 0 ? orderedBy : this.orderedBy;
|
|
1119
|
-
config._separator = separator !== null && separator !== void 0 ? separator : this.separator;
|
|
1120
|
-
config._title = title !== null && title !== void 0 ? title : this.title;
|
|
1121
|
-
config._ending = ending !== null && ending !== void 0 ? ending : this.ending;
|
|
1122
|
-
config._bypass = bypass !== null && bypass !== void 0 ? bypass : this.bypass;
|
|
1123
|
-
config._surname = surname !== null && surname !== void 0 ? surname : this.surname;
|
|
1124
|
-
return config;
|
|
1125
|
-
}
|
|
1126
|
-
/**
|
|
1127
|
-
* Makes an exact copy of the current configuration.
|
|
1128
|
-
*/
|
|
1129
|
-
clone() {
|
|
1130
|
-
return this.copyWith();
|
|
1131
|
-
}
|
|
1132
|
-
/**
|
|
1133
|
-
* Resets the configuration by setting it back to its default values.
|
|
1134
|
-
*/
|
|
1135
|
-
reset() {
|
|
1136
|
-
this._orderedBy = types_1.NameOrder.FIRST_NAME;
|
|
1137
|
-
this._separator = types_1.Separator.SPACE;
|
|
1138
|
-
this._title = types_1.Title.UK;
|
|
1139
|
-
this._ending = false;
|
|
1140
|
-
this._bypass = true;
|
|
1141
|
-
this._surname = types_1.Surname.FATHER;
|
|
1142
|
-
Config.cache.set(this.name, this);
|
|
1143
|
-
}
|
|
1144
|
-
/**
|
|
1145
|
-
* Alters the name order between the first and last name, and rearrange the
|
|
1146
|
-
* order of appearance of a name set.
|
|
1147
|
-
*/
|
|
1148
|
-
updateOrder(order) {
|
|
1149
|
-
if (order && order !== this._orderedBy) {
|
|
1150
|
-
Config.cache.get(this.name)._orderedBy = order;
|
|
1151
|
-
}
|
|
1152
|
-
}
|
|
1153
|
-
/**
|
|
1154
|
-
* Generates a unique new name.
|
|
1155
|
-
*/
|
|
1156
|
-
genNewName(name) {
|
|
1157
|
-
return name === this.name || Config.cache.has(name) ? this.genNewName(name + copyAlias) : name;
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
exports.Config = Config;
|
|
1161
|
-
/**
|
|
1162
|
-
* Cache for multiple instances.
|
|
1163
|
-
*/
|
|
1164
|
-
Config.cache = new Map();
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
/***/ }),
|
|
1168
|
-
/* 5 */
|
|
1169
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
1170
|
-
|
|
1171
|
-
"use strict";
|
|
1172
|
-
|
|
1173
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1174
|
-
exports.ALLOWED_TOKENS = exports.MAX_NUMBER_OF_NAME_PARTS = exports.MIN_NUMBER_OF_NAME_PARTS = exports.version = void 0;
|
|
1175
|
-
exports.version = '1.2.0';
|
|
665
|
+
exports.ALLOWED_TOKENS = exports.MAX_NUMBER_OF_NAME_PARTS = exports.MIN_NUMBER_OF_NAME_PARTS = exports.VERSION = void 0;
|
|
666
|
+
exports.VERSION = '1.3.0';
|
|
1176
667
|
exports.MIN_NUMBER_OF_NAME_PARTS = 2;
|
|
1177
668
|
exports.MAX_NUMBER_OF_NAME_PARTS = 5;
|
|
1178
669
|
exports.ALLOWED_TOKENS = [
|
|
@@ -1202,266 +693,620 @@ exports.ALLOWED_TOKENS = [
|
|
|
1202
693
|
|
|
1203
694
|
|
|
1204
695
|
/***/ }),
|
|
1205
|
-
/*
|
|
696
|
+
/* 5 */
|
|
1206
697
|
/***/ (function(module, exports, __webpack_require__) {
|
|
1207
698
|
|
|
1208
699
|
"use strict";
|
|
1209
700
|
|
|
701
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
702
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
703
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
704
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
705
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
706
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
707
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
708
|
+
});
|
|
709
|
+
};
|
|
710
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
711
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
712
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
713
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
714
|
+
};
|
|
715
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
716
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
717
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
718
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
719
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
720
|
+
};
|
|
721
|
+
var _Namefully_instances, _Namefully_fullName, _Namefully_toParser, _Namefully_map;
|
|
1210
722
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1211
|
-
exports.
|
|
1212
|
-
const
|
|
723
|
+
exports.Namefully = void 0;
|
|
724
|
+
const constants_1 = __webpack_require__(4);
|
|
1213
725
|
const error_1 = __webpack_require__(1);
|
|
1214
|
-
const
|
|
726
|
+
const parser_1 = __webpack_require__(8);
|
|
1215
727
|
const types_1 = __webpack_require__(0);
|
|
1216
|
-
const
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
* Creates a full name as it goes
|
|
1236
|
-
* @param options optional configuration for additional features.
|
|
1237
|
-
*/
|
|
1238
|
-
constructor(options) {
|
|
1239
|
-
this._middleName = [];
|
|
1240
|
-
this._config = config_1.Config.merge(options);
|
|
728
|
+
const utils_1 = __webpack_require__(2);
|
|
729
|
+
class Namefully {
|
|
730
|
+
constructor(names, options) {
|
|
731
|
+
_Namefully_instances.add(this);
|
|
732
|
+
_Namefully_fullName.set(this, void 0);
|
|
733
|
+
__classPrivateFieldSet(this, _Namefully_fullName, __classPrivateFieldGet(this, _Namefully_instances, "m", _Namefully_toParser).call(this, names).parse(options), "f");
|
|
734
|
+
}
|
|
735
|
+
static tryParse(text, index) {
|
|
736
|
+
try {
|
|
737
|
+
return new Namefully(parser_1.Parser.build(text, index));
|
|
738
|
+
}
|
|
739
|
+
catch (_a) {
|
|
740
|
+
return undefined;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
static parse(text, index) {
|
|
744
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
745
|
+
return parser_1.Parser.buildAsync(text, index).then((parser) => new Namefully(parser));
|
|
746
|
+
});
|
|
1241
747
|
}
|
|
1242
|
-
/**
|
|
1243
|
-
* A snapshot of the configuration used to set up this full name.
|
|
1244
|
-
*/
|
|
1245
748
|
get config() {
|
|
1246
|
-
return this.
|
|
749
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").config;
|
|
750
|
+
}
|
|
751
|
+
get length() {
|
|
752
|
+
return this.birth.length;
|
|
1247
753
|
}
|
|
1248
|
-
/**
|
|
1249
|
-
* The prefix part of the full name.
|
|
1250
|
-
*/
|
|
1251
754
|
get prefix() {
|
|
1252
|
-
|
|
755
|
+
var _a;
|
|
756
|
+
return (_a = __classPrivateFieldGet(this, _Namefully_fullName, "f").prefix) === null || _a === void 0 ? void 0 : _a.toString();
|
|
1253
757
|
}
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
*/
|
|
1257
|
-
get firstName() {
|
|
1258
|
-
return this._firstName;
|
|
758
|
+
get first() {
|
|
759
|
+
return this.firstName();
|
|
1259
760
|
}
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
*/
|
|
1263
|
-
get lastName() {
|
|
1264
|
-
return this._lastName;
|
|
761
|
+
get middle() {
|
|
762
|
+
return this.hasMiddle ? this.middleName()[0] : undefined;
|
|
1265
763
|
}
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
get
|
|
1270
|
-
return this.
|
|
764
|
+
get hasMiddle() {
|
|
765
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").has(types_1.Namon.MIDDLE_NAME);
|
|
766
|
+
}
|
|
767
|
+
get last() {
|
|
768
|
+
return this.lastName();
|
|
1271
769
|
}
|
|
1272
|
-
/**
|
|
1273
|
-
* The suffix part of the full name.
|
|
1274
|
-
*/
|
|
1275
770
|
get suffix() {
|
|
1276
|
-
|
|
771
|
+
var _a;
|
|
772
|
+
return (_a = __classPrivateFieldGet(this, _Namefully_fullName, "f").suffix) === null || _a === void 0 ? void 0 : _a.toString();
|
|
1277
773
|
}
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
* @param json parsable name element
|
|
1281
|
-
* @param config optional configuration for additional features.
|
|
1282
|
-
*/
|
|
1283
|
-
static parse(json, config) {
|
|
1284
|
-
try {
|
|
1285
|
-
const fullName = new FullName(config);
|
|
1286
|
-
fullName.setPrefix(json.prefix);
|
|
1287
|
-
fullName.setFirstName(json.firstName);
|
|
1288
|
-
fullName.setMiddleName(json.middleName);
|
|
1289
|
-
fullName.setLastName(json.lastName);
|
|
1290
|
-
fullName.setSuffix(json.suffix);
|
|
1291
|
-
return fullName;
|
|
1292
|
-
}
|
|
1293
|
-
catch (error) {
|
|
1294
|
-
if (error instanceof error_1.NameError) {
|
|
1295
|
-
throw error;
|
|
1296
|
-
}
|
|
1297
|
-
else {
|
|
1298
|
-
throw new error_1.UnknownError({
|
|
1299
|
-
source: Object.values(json).join(' '),
|
|
1300
|
-
message: 'could not parse JSON content',
|
|
1301
|
-
error,
|
|
1302
|
-
});
|
|
1303
|
-
}
|
|
1304
|
-
}
|
|
774
|
+
get birth() {
|
|
775
|
+
return this.birthName();
|
|
1305
776
|
}
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
return this;
|
|
1309
|
-
if (!this._config.bypass)
|
|
1310
|
-
validator_1.Validators.prefix.validate(name);
|
|
1311
|
-
const prefix = name instanceof name_1.Name ? name.value : name;
|
|
1312
|
-
this._prefix = name_1.Name.prefix(this._config.title === types_1.Title.US ? `${prefix}.` : prefix);
|
|
1313
|
-
return this;
|
|
777
|
+
get short() {
|
|
778
|
+
return this.shorten();
|
|
1314
779
|
}
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
validator_1.Validators.firstName.validate(name);
|
|
1318
|
-
this._firstName = name instanceof name_1.FirstName ? name : new name_1.FirstName(name);
|
|
1319
|
-
return this;
|
|
780
|
+
get long() {
|
|
781
|
+
return this.birth;
|
|
1320
782
|
}
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
validator_1.Validators.lastName.validate(name);
|
|
1324
|
-
this._lastName = name instanceof name_1.LastName ? name : new name_1.LastName(name);
|
|
1325
|
-
return this;
|
|
783
|
+
get full() {
|
|
784
|
+
return this.fullName();
|
|
1326
785
|
}
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
return;
|
|
1330
|
-
if (!this._config.bypass)
|
|
1331
|
-
validator_1.Validators.middleName.validate(names);
|
|
1332
|
-
this._middleName = names.map((name) => name instanceof name_1.Name ? name : name_1.Name.middle(name));
|
|
1333
|
-
return this;
|
|
786
|
+
get public() {
|
|
787
|
+
return this.format('f $l');
|
|
1334
788
|
}
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
return this;
|
|
1338
|
-
if (!this._config.bypass)
|
|
1339
|
-
validator_1.Validators.suffix.validate(name);
|
|
1340
|
-
this._suffix = name_1.Name.suffix(name instanceof name_1.Name ? name.value : name);
|
|
1341
|
-
return this;
|
|
789
|
+
get salutation() {
|
|
790
|
+
return this.format('p l');
|
|
1342
791
|
}
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
792
|
+
toString() {
|
|
793
|
+
return this.full;
|
|
794
|
+
}
|
|
795
|
+
get(namon) {
|
|
1347
796
|
if (namon.equal(types_1.Namon.PREFIX))
|
|
1348
|
-
return
|
|
797
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").prefix;
|
|
798
|
+
if (namon.equal(types_1.Namon.FIRST_NAME))
|
|
799
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName;
|
|
800
|
+
if (namon.equal(types_1.Namon.MIDDLE_NAME))
|
|
801
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").middleName;
|
|
802
|
+
if (namon.equal(types_1.Namon.LAST_NAME))
|
|
803
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName;
|
|
1349
804
|
if (namon.equal(types_1.Namon.SUFFIX))
|
|
1350
|
-
return
|
|
1351
|
-
return
|
|
805
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").suffix;
|
|
806
|
+
return undefined;
|
|
1352
807
|
}
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
/***/ }),
|
|
1358
|
-
/* 7 */
|
|
1359
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
1360
|
-
|
|
1361
|
-
"use strict";
|
|
1362
|
-
|
|
1363
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1364
|
-
exports.Validators = exports.ArrayNameValidator = exports.ArrayStringValidator = exports.NamaValidator = void 0;
|
|
1365
|
-
const constants_1 = __webpack_require__(5);
|
|
1366
|
-
const error_1 = __webpack_require__(1);
|
|
1367
|
-
const name_1 = __webpack_require__(3);
|
|
1368
|
-
const types_1 = __webpack_require__(0);
|
|
1369
|
-
const utils_1 = __webpack_require__(2);
|
|
1370
|
-
/**
|
|
1371
|
-
* Represents a set of validation rules (regex)
|
|
1372
|
-
*
|
|
1373
|
-
* This regex is intented to match specific alphabets only as a person name does
|
|
1374
|
-
* not contain special characters. `\w` does not cover non-Latin characters. So,
|
|
1375
|
-
* it is extended using unicode chars to cover more cases (e.g., Icelandic).
|
|
1376
|
-
* It matches as follows:
|
|
1377
|
-
* [a-z]: Latin alphabet from a (index 97) to z (index 122)
|
|
1378
|
-
* [A-Z]: Latin alphabet from A (index 65) to Z (index 90)
|
|
1379
|
-
* [\u00C0-\u00D6]: Latin/German chars from À (index 192) to Ö (index 214)
|
|
1380
|
-
* [\u00D8-\u00f6]: German/Icelandic chars from Ø (index 216) to ö (index 246)
|
|
1381
|
-
* [\u00f8-\u00ff]: German/Icelandic chars from ø (index 248) to ÿ (index 255)
|
|
1382
|
-
* [\u0400-\u04FF]: Cyrillic alphabet from Ѐ (index 1024) to ӿ (index 1279)
|
|
1383
|
-
* [Ά-ωΑ-ώ]: Greek alphabet from Ά (index 902) to ω (index 969)
|
|
1384
|
-
*/
|
|
1385
|
-
class ValidationRule {
|
|
1386
|
-
}
|
|
1387
|
-
ValidationRule.base = /[a-zA-Z\u00C0-\u00D6\u00D8-\u00f6\u00f8-\u00ff\u0400-\u04FFΆ-ωΑ-ώ]/;
|
|
1388
|
-
/**
|
|
1389
|
-
* Matches one name part (namon) that is of nature:
|
|
1390
|
-
* - Latin (English, Spanish, French, etc.)
|
|
1391
|
-
* - European (Greek, Cyrillic, Icelandic, German)
|
|
1392
|
-
* - hyphenated
|
|
1393
|
-
* - with apostrophe
|
|
1394
|
-
* - with space
|
|
1395
|
-
*/
|
|
1396
|
-
ValidationRule.namon = new RegExp(`^${ValidationRule.base.source}+(([' -]${ValidationRule.base.source})?${ValidationRule.base.source}*)*$`);
|
|
1397
|
-
/**
|
|
1398
|
-
* Matches one name part (namon) that is of nature:
|
|
1399
|
-
* - Latin (English, Spanish, French, etc.)
|
|
1400
|
-
* - European (Greek, Cyrillic, Icelandic, German)
|
|
1401
|
-
* - hyphenated
|
|
1402
|
-
* - with apostrophe
|
|
1403
|
-
*/
|
|
1404
|
-
ValidationRule.firstName = ValidationRule.namon;
|
|
1405
|
-
/**
|
|
1406
|
-
* Matches 1+ names part (namon) that are of nature:
|
|
1407
|
-
* - Latin (English, Spanish, French, etc.)
|
|
1408
|
-
* - European (Greek, Cyrillic, Icelandic, German)
|
|
1409
|
-
* - hyphenated
|
|
1410
|
-
* - with apostrophe
|
|
1411
|
-
* - with space
|
|
1412
|
-
*/
|
|
1413
|
-
ValidationRule.middleName = new RegExp(`^${ValidationRule.base.source}+(([' -]${ValidationRule.base.source})?${ValidationRule.base.source}*)*$`);
|
|
1414
|
-
/**
|
|
1415
|
-
* Matches one name part (namon) that is of nature:
|
|
1416
|
-
* - Latin (English, Spanish, French, etc.)
|
|
1417
|
-
* - European (Greek, Cyrillic, Icelandic, German)
|
|
1418
|
-
* - hyphenated
|
|
1419
|
-
* - with apostrophe
|
|
1420
|
-
* - with space
|
|
1421
|
-
*/
|
|
1422
|
-
ValidationRule.lastName = ValidationRule.namon;
|
|
1423
|
-
class ArrayValidator {
|
|
1424
|
-
validate(values) {
|
|
1425
|
-
if (values.length === 0 ||
|
|
1426
|
-
values.length < constants_1.MIN_NUMBER_OF_NAME_PARTS ||
|
|
1427
|
-
values.length > constants_1.MAX_NUMBER_OF_NAME_PARTS) {
|
|
1428
|
-
throw new error_1.InputError({
|
|
1429
|
-
source: values.map((n) => n.toString()),
|
|
1430
|
-
message: `expecting a list of ${constants_1.MIN_NUMBER_OF_NAME_PARTS}-${constants_1.MIN_NUMBER_OF_NAME_PARTS} elements`,
|
|
1431
|
-
});
|
|
1432
|
-
}
|
|
808
|
+
equal(other) {
|
|
809
|
+
return this.toString() === other.toString();
|
|
1433
810
|
}
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
811
|
+
toJson() {
|
|
812
|
+
return {
|
|
813
|
+
prefix: this.prefix,
|
|
814
|
+
firstName: this.first,
|
|
815
|
+
middleName: this.middleName(),
|
|
816
|
+
lastName: this.last,
|
|
817
|
+
suffix: this.suffix,
|
|
818
|
+
};
|
|
1439
819
|
}
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
}
|
|
820
|
+
has(namon) {
|
|
821
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").has(namon);
|
|
822
|
+
}
|
|
823
|
+
fullName(orderedBy) {
|
|
824
|
+
const sep = this.config.ending ? ',' : '';
|
|
825
|
+
const names = [];
|
|
826
|
+
orderedBy = orderedBy || this.config.orderedBy;
|
|
827
|
+
if (this.prefix)
|
|
828
|
+
names.push(this.prefix);
|
|
829
|
+
if (orderedBy === types_1.NameOrder.FIRST_NAME) {
|
|
830
|
+
names.push(this.first, ...this.middleName(), this.last + sep);
|
|
1452
831
|
}
|
|
1453
832
|
else {
|
|
1454
|
-
|
|
1455
|
-
source: typeof value,
|
|
1456
|
-
message: 'expecting types of string | Name',
|
|
1457
|
-
});
|
|
833
|
+
names.push(this.last, this.first, this.middleName().join(' ') + sep);
|
|
1458
834
|
}
|
|
835
|
+
if (this.suffix)
|
|
836
|
+
names.push(this.suffix);
|
|
837
|
+
return names.join(' ').trim();
|
|
1459
838
|
}
|
|
1460
|
-
|
|
839
|
+
birthName(orderedBy) {
|
|
840
|
+
orderedBy = orderedBy || this.config.orderedBy;
|
|
841
|
+
return orderedBy === types_1.NameOrder.FIRST_NAME
|
|
842
|
+
? [this.first, ...this.middleName(), this.last].join(' ')
|
|
843
|
+
: [this.last, this.first, ...this.middleName()].join(' ');
|
|
844
|
+
}
|
|
845
|
+
firstName(withMore = true) {
|
|
846
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.toString(withMore);
|
|
847
|
+
}
|
|
848
|
+
middleName() {
|
|
849
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").middleName.map((n) => n.value);
|
|
850
|
+
}
|
|
851
|
+
lastName(format) {
|
|
852
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.toString(format);
|
|
853
|
+
}
|
|
854
|
+
initials(options) {
|
|
855
|
+
const firstInits = __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.initials();
|
|
856
|
+
const midInits = __classPrivateFieldGet(this, _Namefully_fullName, "f").middleName.map((n) => n.initials()[0]);
|
|
857
|
+
const lastInits = __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.initials();
|
|
858
|
+
if (options === null || options === void 0 ? void 0 : options.asJson)
|
|
859
|
+
return { firstName: firstInits, middleName: midInits, lastName: lastInits };
|
|
860
|
+
const initials = [];
|
|
861
|
+
const { orderedBy = this.config.orderedBy, only = types_1.NameType.BIRTH_NAME } = options !== null && options !== void 0 ? options : {};
|
|
862
|
+
if (only !== types_1.NameType.BIRTH_NAME) {
|
|
863
|
+
if (only === types_1.NameType.FIRST_NAME) {
|
|
864
|
+
initials.push(...firstInits);
|
|
865
|
+
}
|
|
866
|
+
else if (only === types_1.NameType.MIDDLE_NAME) {
|
|
867
|
+
initials.push(...midInits);
|
|
868
|
+
}
|
|
869
|
+
else {
|
|
870
|
+
initials.push(...lastInits);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
else if (orderedBy === types_1.NameOrder.FIRST_NAME) {
|
|
874
|
+
initials.push(...firstInits, ...midInits, ...lastInits);
|
|
875
|
+
}
|
|
876
|
+
else {
|
|
877
|
+
initials.push(...lastInits, ...firstInits, ...midInits);
|
|
878
|
+
}
|
|
879
|
+
return initials;
|
|
880
|
+
}
|
|
881
|
+
shorten(orderedBy) {
|
|
882
|
+
orderedBy = orderedBy || this.config.orderedBy;
|
|
883
|
+
return orderedBy === types_1.NameOrder.FIRST_NAME
|
|
884
|
+
? [__classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.value, __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.toString()].join(' ')
|
|
885
|
+
: [__classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.toString(), __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.value].join(' ');
|
|
886
|
+
}
|
|
887
|
+
flatten(options) {
|
|
888
|
+
if (this.length <= options.limit)
|
|
889
|
+
return this.full;
|
|
890
|
+
const { by = types_1.Flat.MIDDLE_NAME, limit = 20, recursive = false, withMore = false, withPeriod = true, surname, } = options;
|
|
891
|
+
const sep = withPeriod ? '.' : '';
|
|
892
|
+
const fn = __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.toString();
|
|
893
|
+
const mn = this.middleName().join(' ');
|
|
894
|
+
const ln = __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.toString();
|
|
895
|
+
const hasMid = this.hasMiddle;
|
|
896
|
+
const f = __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.initials(withMore).join(sep + ' ') + sep;
|
|
897
|
+
const l = __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.initials(surname).join(sep + ' ') + sep;
|
|
898
|
+
const m = hasMid ? __classPrivateFieldGet(this, _Namefully_fullName, "f").middleName.map((n) => n.initials()[0]).join(sep + ' ') + sep : '';
|
|
899
|
+
let name = [];
|
|
900
|
+
if (this.config.orderedBy === types_1.NameOrder.FIRST_NAME) {
|
|
901
|
+
switch (by) {
|
|
902
|
+
case types_1.Flat.FIRST_NAME:
|
|
903
|
+
name = hasMid ? [f, mn, ln] : [f, ln];
|
|
904
|
+
break;
|
|
905
|
+
case types_1.Flat.LAST_NAME:
|
|
906
|
+
name = hasMid ? [fn, mn, l] : [fn, l];
|
|
907
|
+
break;
|
|
908
|
+
case types_1.Flat.MIDDLE_NAME:
|
|
909
|
+
name = hasMid ? [fn, m, ln] : [fn, ln];
|
|
910
|
+
break;
|
|
911
|
+
case types_1.Flat.FIRST_MID:
|
|
912
|
+
name = hasMid ? [f, m, ln] : [f, ln];
|
|
913
|
+
break;
|
|
914
|
+
case types_1.Flat.MID_LAST:
|
|
915
|
+
name = hasMid ? [fn, m, l] : [fn, l];
|
|
916
|
+
break;
|
|
917
|
+
case types_1.Flat.ALL:
|
|
918
|
+
name = hasMid ? [f, m, l] : [f, l];
|
|
919
|
+
break;
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
else {
|
|
923
|
+
switch (by) {
|
|
924
|
+
case types_1.Flat.FIRST_NAME:
|
|
925
|
+
name = hasMid ? [ln, f, mn] : [ln, f];
|
|
926
|
+
break;
|
|
927
|
+
case types_1.Flat.LAST_NAME:
|
|
928
|
+
name = hasMid ? [l, fn, mn] : [l, fn];
|
|
929
|
+
break;
|
|
930
|
+
case types_1.Flat.MIDDLE_NAME:
|
|
931
|
+
name = hasMid ? [ln, fn, m] : [ln, fn];
|
|
932
|
+
break;
|
|
933
|
+
case types_1.Flat.FIRST_MID:
|
|
934
|
+
name = hasMid ? [ln, f, m] : [ln, f];
|
|
935
|
+
break;
|
|
936
|
+
case types_1.Flat.MID_LAST:
|
|
937
|
+
name = hasMid ? [l, fn, m] : [l, fn];
|
|
938
|
+
break;
|
|
939
|
+
case types_1.Flat.ALL:
|
|
940
|
+
name = hasMid ? [l, f, m] : [l, f];
|
|
941
|
+
break;
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
const flat = name.join(' ');
|
|
945
|
+
if (recursive && flat.length > limit) {
|
|
946
|
+
const next = by === types_1.Flat.FIRST_NAME
|
|
947
|
+
? types_1.Flat.MIDDLE_NAME
|
|
948
|
+
: by === types_1.Flat.MIDDLE_NAME
|
|
949
|
+
? types_1.Flat.LAST_NAME
|
|
950
|
+
: by === types_1.Flat.LAST_NAME
|
|
951
|
+
? types_1.Flat.FIRST_MID
|
|
952
|
+
: by === types_1.Flat.FIRST_MID
|
|
953
|
+
? types_1.Flat.MID_LAST
|
|
954
|
+
: by === types_1.Flat.MID_LAST
|
|
955
|
+
? types_1.Flat.ALL
|
|
956
|
+
: by === types_1.Flat.ALL
|
|
957
|
+
? types_1.Flat.ALL
|
|
958
|
+
: by;
|
|
959
|
+
if (next === by)
|
|
960
|
+
return flat;
|
|
961
|
+
return this.flatten(Object.assign(Object.assign({}, options), { by: next }));
|
|
962
|
+
}
|
|
963
|
+
return flat;
|
|
964
|
+
}
|
|
965
|
+
zip(by = types_1.Flat.MID_LAST, withPeriod = true) {
|
|
966
|
+
return this.flatten({ limit: 0, by, withPeriod });
|
|
967
|
+
}
|
|
968
|
+
format(pattern) {
|
|
969
|
+
var _a;
|
|
970
|
+
if (pattern === 'short')
|
|
971
|
+
return this.short;
|
|
972
|
+
if (pattern === 'long')
|
|
973
|
+
return this.long;
|
|
974
|
+
if (pattern === 'public')
|
|
975
|
+
return this.public;
|
|
976
|
+
if (pattern === 'official')
|
|
977
|
+
pattern = 'o';
|
|
978
|
+
let group = '';
|
|
979
|
+
const formatted = [];
|
|
980
|
+
for (const char of pattern.split('')) {
|
|
981
|
+
if (constants_1.ALLOWED_TOKENS.indexOf(char) === -1) {
|
|
982
|
+
throw new error_1.NotAllowedError({
|
|
983
|
+
source: this.full,
|
|
984
|
+
operation: 'format',
|
|
985
|
+
message: `unsupported character <${char}> from ${pattern}.`,
|
|
986
|
+
});
|
|
987
|
+
}
|
|
988
|
+
group += char;
|
|
989
|
+
if (char === '$')
|
|
990
|
+
continue;
|
|
991
|
+
formatted.push((_a = __classPrivateFieldGet(this, _Namefully_instances, "m", _Namefully_map).call(this, group)) !== null && _a !== void 0 ? _a : '');
|
|
992
|
+
group = '';
|
|
993
|
+
}
|
|
994
|
+
return formatted.join('').trim();
|
|
995
|
+
}
|
|
996
|
+
flip() {
|
|
997
|
+
this.config.updateOrder(this.config.orderedBy === types_1.NameOrder.FIRST_NAME ? types_1.NameOrder.LAST_NAME : types_1.NameOrder.FIRST_NAME);
|
|
998
|
+
}
|
|
999
|
+
split(separator = /[' -]/g) {
|
|
1000
|
+
return this.birth.replace(separator, ' ').split(' ');
|
|
1001
|
+
}
|
|
1002
|
+
join(separator = '') {
|
|
1003
|
+
return this.split().join(separator);
|
|
1004
|
+
}
|
|
1005
|
+
toUpperCase() {
|
|
1006
|
+
return this.birth.toUpperCase();
|
|
1007
|
+
}
|
|
1008
|
+
toLowerCase() {
|
|
1009
|
+
return this.birth.toLowerCase();
|
|
1010
|
+
}
|
|
1011
|
+
toCamelCase() {
|
|
1012
|
+
return (0, utils_1.decapitalize)(this.toPascalCase());
|
|
1013
|
+
}
|
|
1014
|
+
toPascalCase() {
|
|
1015
|
+
return this.split()
|
|
1016
|
+
.map((n) => (0, utils_1.capitalize)(n))
|
|
1017
|
+
.join('');
|
|
1018
|
+
}
|
|
1019
|
+
toSnakeCase() {
|
|
1020
|
+
return this.split()
|
|
1021
|
+
.map((n) => n.toLowerCase())
|
|
1022
|
+
.join('_');
|
|
1023
|
+
}
|
|
1024
|
+
toHyphenCase() {
|
|
1025
|
+
return this.split()
|
|
1026
|
+
.map((n) => n.toLowerCase())
|
|
1027
|
+
.join('-');
|
|
1028
|
+
}
|
|
1029
|
+
toDotCase() {
|
|
1030
|
+
return this.split()
|
|
1031
|
+
.map((n) => n.toLowerCase())
|
|
1032
|
+
.join('.');
|
|
1033
|
+
}
|
|
1034
|
+
toToggleCase() {
|
|
1035
|
+
return (0, utils_1.toggleCase)(this.birth);
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
exports.Namefully = Namefully;
|
|
1039
|
+
_Namefully_fullName = new WeakMap(), _Namefully_instances = new WeakSet(), _Namefully_toParser = function _Namefully_toParser(raw) {
|
|
1040
|
+
if (raw instanceof parser_1.Parser)
|
|
1041
|
+
return raw;
|
|
1042
|
+
if (typeof raw === 'string')
|
|
1043
|
+
return new parser_1.StringParser(raw);
|
|
1044
|
+
if ((0, utils_1.isStringArray)(raw))
|
|
1045
|
+
return new parser_1.ArrayStringParser(raw);
|
|
1046
|
+
if ((0, utils_1.isNameArray)(raw))
|
|
1047
|
+
return new parser_1.ArrayNameParser(raw);
|
|
1048
|
+
if (typeof raw === 'object')
|
|
1049
|
+
return new parser_1.NamaParser(raw);
|
|
1050
|
+
throw new error_1.InputError({ source: raw, message: 'Cannot parse raw data. Review expected data types.' });
|
|
1051
|
+
}, _Namefully_map = function _Namefully_map(char) {
|
|
1052
|
+
var _a, _b;
|
|
1053
|
+
switch (char) {
|
|
1054
|
+
case '.':
|
|
1055
|
+
case ',':
|
|
1056
|
+
case ' ':
|
|
1057
|
+
case '-':
|
|
1058
|
+
case '_':
|
|
1059
|
+
return char;
|
|
1060
|
+
case 'b':
|
|
1061
|
+
return this.birth;
|
|
1062
|
+
case 'B':
|
|
1063
|
+
return this.birth.toUpperCase();
|
|
1064
|
+
case 'f':
|
|
1065
|
+
return this.first;
|
|
1066
|
+
case 'F':
|
|
1067
|
+
return this.first.toUpperCase();
|
|
1068
|
+
case 'l':
|
|
1069
|
+
return this.last;
|
|
1070
|
+
case 'L':
|
|
1071
|
+
return this.last.toUpperCase();
|
|
1072
|
+
case 'm':
|
|
1073
|
+
case 'M':
|
|
1074
|
+
return char === 'm' ? this.middleName().join(' ') : this.middleName().join(' ').toUpperCase();
|
|
1075
|
+
case 'o':
|
|
1076
|
+
case 'O':
|
|
1077
|
+
return ((character) => {
|
|
1078
|
+
const sep = this.config.ending ? ',' : '', names = [];
|
|
1079
|
+
if (this.prefix)
|
|
1080
|
+
names.push(this.prefix);
|
|
1081
|
+
names.push(`${this.last},`.toUpperCase());
|
|
1082
|
+
if (this.hasMiddle) {
|
|
1083
|
+
names.push(this.first, this.middleName().join(' ') + sep);
|
|
1084
|
+
}
|
|
1085
|
+
else {
|
|
1086
|
+
names.push(this.first + sep);
|
|
1087
|
+
}
|
|
1088
|
+
if (this.suffix)
|
|
1089
|
+
names.push(this.suffix);
|
|
1090
|
+
const nama = names.join(' ').trim();
|
|
1091
|
+
return character === 'o' ? nama : nama.toUpperCase();
|
|
1092
|
+
})(char);
|
|
1093
|
+
case 'p':
|
|
1094
|
+
return this.prefix;
|
|
1095
|
+
case 'P':
|
|
1096
|
+
return (_a = this.prefix) === null || _a === void 0 ? void 0 : _a.toUpperCase();
|
|
1097
|
+
case 's':
|
|
1098
|
+
return this.suffix;
|
|
1099
|
+
case 'S':
|
|
1100
|
+
return (_b = this.suffix) === null || _b === void 0 ? void 0 : _b.toUpperCase();
|
|
1101
|
+
case '$f':
|
|
1102
|
+
case '$F':
|
|
1103
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.initials()[0];
|
|
1104
|
+
case '$l':
|
|
1105
|
+
case '$L':
|
|
1106
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.initials()[0];
|
|
1107
|
+
case '$m':
|
|
1108
|
+
case '$M':
|
|
1109
|
+
return this.hasMiddle ? this.middle[0] : undefined;
|
|
1110
|
+
default:
|
|
1111
|
+
return undefined;
|
|
1112
|
+
}
|
|
1113
|
+
};
|
|
1114
|
+
exports.default = (names, options) => {
|
|
1115
|
+
return new Namefully(names, options);
|
|
1116
|
+
};
|
|
1117
|
+
|
|
1118
|
+
|
|
1119
|
+
/***/ }),
|
|
1120
|
+
/* 6 */
|
|
1121
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
1122
|
+
|
|
1123
|
+
"use strict";
|
|
1124
|
+
|
|
1125
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
1126
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
1127
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
1128
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
1129
|
+
};
|
|
1130
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
1131
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
1132
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
1133
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
1134
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
1135
|
+
};
|
|
1136
|
+
var _Config_instances, _a, _Config_name, _Config_orderedBy, _Config_separator, _Config_title, _Config_ending, _Config_bypass, _Config_surname, _Config_genNewName;
|
|
1137
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1138
|
+
exports.Config = void 0;
|
|
1139
|
+
const types_1 = __webpack_require__(0);
|
|
1140
|
+
const defaultName = 'default';
|
|
1141
|
+
const copyAlias = '_copy';
|
|
1142
|
+
class Config {
|
|
1143
|
+
get orderedBy() {
|
|
1144
|
+
return __classPrivateFieldGet(this, _Config_orderedBy, "f");
|
|
1145
|
+
}
|
|
1146
|
+
get separator() {
|
|
1147
|
+
return __classPrivateFieldGet(this, _Config_separator, "f");
|
|
1148
|
+
}
|
|
1149
|
+
get title() {
|
|
1150
|
+
return __classPrivateFieldGet(this, _Config_title, "f");
|
|
1151
|
+
}
|
|
1152
|
+
get ending() {
|
|
1153
|
+
return __classPrivateFieldGet(this, _Config_ending, "f");
|
|
1154
|
+
}
|
|
1155
|
+
get bypass() {
|
|
1156
|
+
return __classPrivateFieldGet(this, _Config_bypass, "f");
|
|
1157
|
+
}
|
|
1158
|
+
get surname() {
|
|
1159
|
+
return __classPrivateFieldGet(this, _Config_surname, "f");
|
|
1160
|
+
}
|
|
1161
|
+
get name() {
|
|
1162
|
+
return __classPrivateFieldGet(this, _Config_name, "f");
|
|
1163
|
+
}
|
|
1164
|
+
constructor(name, orderedBy = types_1.NameOrder.FIRST_NAME, separator = types_1.Separator.SPACE, title = types_1.Title.UK, ending = false, bypass = true, surname = types_1.Surname.FATHER) {
|
|
1165
|
+
_Config_instances.add(this);
|
|
1166
|
+
_Config_name.set(this, void 0);
|
|
1167
|
+
_Config_orderedBy.set(this, void 0);
|
|
1168
|
+
_Config_separator.set(this, void 0);
|
|
1169
|
+
_Config_title.set(this, void 0);
|
|
1170
|
+
_Config_ending.set(this, void 0);
|
|
1171
|
+
_Config_bypass.set(this, void 0);
|
|
1172
|
+
_Config_surname.set(this, void 0);
|
|
1173
|
+
__classPrivateFieldSet(this, _Config_name, name, "f");
|
|
1174
|
+
__classPrivateFieldSet(this, _Config_orderedBy, orderedBy, "f");
|
|
1175
|
+
__classPrivateFieldSet(this, _Config_separator, separator, "f");
|
|
1176
|
+
__classPrivateFieldSet(this, _Config_title, title, "f");
|
|
1177
|
+
__classPrivateFieldSet(this, _Config_ending, ending, "f");
|
|
1178
|
+
__classPrivateFieldSet(this, _Config_bypass, bypass, "f");
|
|
1179
|
+
__classPrivateFieldSet(this, _Config_surname, surname, "f");
|
|
1180
|
+
}
|
|
1181
|
+
static create(name = defaultName) {
|
|
1182
|
+
if (!_a.cache.has(name))
|
|
1183
|
+
_a.cache.set(name, new this(name));
|
|
1184
|
+
return _a.cache.get(name);
|
|
1185
|
+
}
|
|
1186
|
+
static merge(other) {
|
|
1187
|
+
var _b, _c, _d, _e, _f, _g;
|
|
1188
|
+
if (!other) {
|
|
1189
|
+
return _a.create();
|
|
1190
|
+
}
|
|
1191
|
+
else {
|
|
1192
|
+
const config = _a.create(other.name);
|
|
1193
|
+
__classPrivateFieldSet(config, _Config_orderedBy, (_b = other.orderedBy) !== null && _b !== void 0 ? _b : config.orderedBy, "f");
|
|
1194
|
+
__classPrivateFieldSet(config, _Config_separator, (_c = other.separator) !== null && _c !== void 0 ? _c : config.separator, "f");
|
|
1195
|
+
__classPrivateFieldSet(config, _Config_title, (_d = other.title) !== null && _d !== void 0 ? _d : config.title, "f");
|
|
1196
|
+
__classPrivateFieldSet(config, _Config_ending, (_e = other.ending) !== null && _e !== void 0 ? _e : config.ending, "f");
|
|
1197
|
+
__classPrivateFieldSet(config, _Config_bypass, (_f = other.bypass) !== null && _f !== void 0 ? _f : config.bypass, "f");
|
|
1198
|
+
__classPrivateFieldSet(config, _Config_surname, (_g = other.surname) !== null && _g !== void 0 ? _g : config.surname, "f");
|
|
1199
|
+
return config;
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
copyWith(options = {}) {
|
|
1203
|
+
const { name, orderedBy, separator, title, ending, bypass, surname } = options;
|
|
1204
|
+
const config = _a.create(__classPrivateFieldGet(this, _Config_instances, "m", _Config_genNewName).call(this, name !== null && name !== void 0 ? name : this.name + copyAlias));
|
|
1205
|
+
__classPrivateFieldSet(config, _Config_orderedBy, orderedBy !== null && orderedBy !== void 0 ? orderedBy : this.orderedBy, "f");
|
|
1206
|
+
__classPrivateFieldSet(config, _Config_separator, separator !== null && separator !== void 0 ? separator : this.separator, "f");
|
|
1207
|
+
__classPrivateFieldSet(config, _Config_title, title !== null && title !== void 0 ? title : this.title, "f");
|
|
1208
|
+
__classPrivateFieldSet(config, _Config_ending, ending !== null && ending !== void 0 ? ending : this.ending, "f");
|
|
1209
|
+
__classPrivateFieldSet(config, _Config_bypass, bypass !== null && bypass !== void 0 ? bypass : this.bypass, "f");
|
|
1210
|
+
__classPrivateFieldSet(config, _Config_surname, surname !== null && surname !== void 0 ? surname : this.surname, "f");
|
|
1211
|
+
return config;
|
|
1212
|
+
}
|
|
1213
|
+
clone() {
|
|
1214
|
+
return this.copyWith();
|
|
1215
|
+
}
|
|
1216
|
+
reset() {
|
|
1217
|
+
__classPrivateFieldSet(this, _Config_orderedBy, types_1.NameOrder.FIRST_NAME, "f");
|
|
1218
|
+
__classPrivateFieldSet(this, _Config_separator, types_1.Separator.SPACE, "f");
|
|
1219
|
+
__classPrivateFieldSet(this, _Config_title, types_1.Title.UK, "f");
|
|
1220
|
+
__classPrivateFieldSet(this, _Config_ending, false, "f");
|
|
1221
|
+
__classPrivateFieldSet(this, _Config_bypass, true, "f");
|
|
1222
|
+
__classPrivateFieldSet(this, _Config_surname, types_1.Surname.FATHER, "f");
|
|
1223
|
+
_a.cache.set(this.name, this);
|
|
1224
|
+
}
|
|
1225
|
+
updateOrder(order) {
|
|
1226
|
+
if (order && order !== __classPrivateFieldGet(this, _Config_orderedBy, "f")) {
|
|
1227
|
+
__classPrivateFieldSet(_a.cache.get(this.name), _Config_orderedBy, order, "f");
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
exports.Config = Config;
|
|
1232
|
+
_a = Config, _Config_name = new WeakMap(), _Config_orderedBy = new WeakMap(), _Config_separator = new WeakMap(), _Config_title = new WeakMap(), _Config_ending = new WeakMap(), _Config_bypass = new WeakMap(), _Config_surname = new WeakMap(), _Config_instances = new WeakSet(), _Config_genNewName = function _Config_genNewName(name) {
|
|
1233
|
+
return name === this.name || _a.cache.has(name) ? __classPrivateFieldGet(this, _Config_instances, "m", _Config_genNewName).call(this, name + copyAlias) : name;
|
|
1234
|
+
};
|
|
1235
|
+
Config.cache = new Map();
|
|
1236
|
+
|
|
1237
|
+
|
|
1238
|
+
/***/ }),
|
|
1239
|
+
/* 7 */
|
|
1240
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
1241
|
+
|
|
1242
|
+
"use strict";
|
|
1243
|
+
|
|
1244
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
1245
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
1246
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
1247
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
1248
|
+
};
|
|
1249
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
1250
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
1251
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
1252
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
1253
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
1254
|
+
};
|
|
1255
|
+
var _a, _NamonValidator_validator, _b, _FirstNameValidator_validator, _c, _MiddleNameValidator_validator, _d, _LastNameValidator_validator, _e, _NameValidator_validator, _f, _NamaValidator_validator, _ArrayNameValidator_instances, _g, _ArrayNameValidator_validator, _ArrayNameValidator_hasBasicNames;
|
|
1256
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1257
|
+
exports.Validators = exports.ArrayNameValidator = exports.ArrayStringValidator = exports.NamaValidator = void 0;
|
|
1258
|
+
const constants_1 = __webpack_require__(4);
|
|
1259
|
+
const error_1 = __webpack_require__(1);
|
|
1260
|
+
const name_1 = __webpack_require__(3);
|
|
1261
|
+
const types_1 = __webpack_require__(0);
|
|
1262
|
+
const utils_1 = __webpack_require__(2);
|
|
1263
|
+
class ValidationRule {
|
|
1264
|
+
}
|
|
1265
|
+
ValidationRule.base = /[a-zA-Z\u00C0-\u00D6\u00D8-\u00f6\u00f8-\u00ff\u0400-\u04FFΆ-ωΑ-ώ]/;
|
|
1266
|
+
ValidationRule.namon = new RegExp(`^${ValidationRule.base.source}+(([' -]${ValidationRule.base.source})?${ValidationRule.base.source}*)*$`);
|
|
1267
|
+
ValidationRule.firstName = ValidationRule.namon;
|
|
1268
|
+
ValidationRule.middleName = new RegExp(`^${ValidationRule.base.source}+(([' -]${ValidationRule.base.source})?${ValidationRule.base.source}*)*$`);
|
|
1269
|
+
ValidationRule.lastName = ValidationRule.namon;
|
|
1270
|
+
class ArrayValidator {
|
|
1271
|
+
validate(values) {
|
|
1272
|
+
if (values.length === 0 || values.length < constants_1.MIN_NUMBER_OF_NAME_PARTS || values.length > constants_1.MAX_NUMBER_OF_NAME_PARTS) {
|
|
1273
|
+
throw new error_1.InputError({
|
|
1274
|
+
source: values.map((n) => n.toString()),
|
|
1275
|
+
message: `expecting a list of ${constants_1.MIN_NUMBER_OF_NAME_PARTS}-${constants_1.MIN_NUMBER_OF_NAME_PARTS} elements`,
|
|
1276
|
+
});
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
class NamonValidator {
|
|
1281
|
+
static create() {
|
|
1282
|
+
return __classPrivateFieldGet(this, _a, "f", _NamonValidator_validator) || (__classPrivateFieldSet(this, _a, new this(), "f", _NamonValidator_validator));
|
|
1283
|
+
}
|
|
1284
|
+
validate(value, type) {
|
|
1285
|
+
if (value instanceof name_1.Name) {
|
|
1286
|
+
NameValidator.create().validate(value, type);
|
|
1287
|
+
}
|
|
1288
|
+
else if (typeof value === 'string') {
|
|
1289
|
+
if (!ValidationRule.namon.test(value)) {
|
|
1290
|
+
throw new error_1.ValidationError({
|
|
1291
|
+
source: value,
|
|
1292
|
+
nameType: 'namon',
|
|
1293
|
+
message: 'invalid content',
|
|
1294
|
+
});
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
else {
|
|
1298
|
+
throw new error_1.InputError({
|
|
1299
|
+
source: typeof value,
|
|
1300
|
+
message: 'expecting types of string | Name',
|
|
1301
|
+
});
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
_a = NamonValidator;
|
|
1306
|
+
_NamonValidator_validator = { value: void 0 };
|
|
1461
1307
|
class FirstNameValidator {
|
|
1462
|
-
constructor() { }
|
|
1463
1308
|
static create() {
|
|
1464
|
-
return this
|
|
1309
|
+
return __classPrivateFieldGet(this, _b, "f", _FirstNameValidator_validator) || (__classPrivateFieldSet(this, _b, new this(), "f", _FirstNameValidator_validator));
|
|
1465
1310
|
}
|
|
1466
1311
|
validate(value) {
|
|
1467
1312
|
if (value instanceof name_1.FirstName) {
|
|
@@ -1484,10 +1329,11 @@ class FirstNameValidator {
|
|
|
1484
1329
|
}
|
|
1485
1330
|
}
|
|
1486
1331
|
}
|
|
1332
|
+
_b = FirstNameValidator;
|
|
1333
|
+
_FirstNameValidator_validator = { value: void 0 };
|
|
1487
1334
|
class MiddleNameValidator {
|
|
1488
|
-
constructor() { }
|
|
1489
1335
|
static create() {
|
|
1490
|
-
return this
|
|
1336
|
+
return __classPrivateFieldGet(this, _c, "f", _MiddleNameValidator_validator) || (__classPrivateFieldSet(this, _c, new this(), "f", _MiddleNameValidator_validator));
|
|
1491
1337
|
}
|
|
1492
1338
|
validate(value) {
|
|
1493
1339
|
if (typeof value === 'string') {
|
|
@@ -1521,10 +1367,11 @@ class MiddleNameValidator {
|
|
|
1521
1367
|
}
|
|
1522
1368
|
}
|
|
1523
1369
|
}
|
|
1370
|
+
_c = MiddleNameValidator;
|
|
1371
|
+
_MiddleNameValidator_validator = { value: void 0 };
|
|
1524
1372
|
class LastNameValidator {
|
|
1525
|
-
constructor() { }
|
|
1526
1373
|
static create() {
|
|
1527
|
-
return this
|
|
1374
|
+
return __classPrivateFieldGet(this, _d, "f", _LastNameValidator_validator) || (__classPrivateFieldSet(this, _d, new this(), "f", _LastNameValidator_validator));
|
|
1528
1375
|
}
|
|
1529
1376
|
validate(value) {
|
|
1530
1377
|
if (value instanceof name_1.LastName) {
|
|
@@ -1547,10 +1394,11 @@ class LastNameValidator {
|
|
|
1547
1394
|
}
|
|
1548
1395
|
}
|
|
1549
1396
|
}
|
|
1397
|
+
_d = LastNameValidator;
|
|
1398
|
+
_LastNameValidator_validator = { value: void 0 };
|
|
1550
1399
|
class NameValidator {
|
|
1551
|
-
constructor() { }
|
|
1552
1400
|
static create() {
|
|
1553
|
-
return this
|
|
1401
|
+
return __classPrivateFieldGet(this, _e, "f", _NameValidator_validator) || (__classPrivateFieldSet(this, _e, new this(), "f", _NameValidator_validator));
|
|
1554
1402
|
}
|
|
1555
1403
|
validate(name, type) {
|
|
1556
1404
|
if (type && name.type !== type) {
|
|
@@ -1569,10 +1417,11 @@ class NameValidator {
|
|
|
1569
1417
|
}
|
|
1570
1418
|
}
|
|
1571
1419
|
}
|
|
1420
|
+
_e = NameValidator;
|
|
1421
|
+
_NameValidator_validator = { value: void 0 };
|
|
1572
1422
|
class NamaValidator {
|
|
1573
|
-
constructor() { }
|
|
1574
1423
|
static create() {
|
|
1575
|
-
return this
|
|
1424
|
+
return __classPrivateFieldGet(this, _f, "f", _NamaValidator_validator) || (__classPrivateFieldSet(this, _f, new this(), "f", _NamaValidator_validator));
|
|
1576
1425
|
}
|
|
1577
1426
|
validate(value) {
|
|
1578
1427
|
this.validateKeys(value);
|
|
@@ -1610,6 +1459,8 @@ class NamaValidator {
|
|
|
1610
1459
|
}
|
|
1611
1460
|
}
|
|
1612
1461
|
exports.NamaValidator = NamaValidator;
|
|
1462
|
+
_f = NamaValidator;
|
|
1463
|
+
_NamaValidator_validator = { value: void 0 };
|
|
1613
1464
|
class ArrayStringValidator extends ArrayValidator {
|
|
1614
1465
|
constructor(index = utils_1.NameIndex.base()) {
|
|
1615
1466
|
super();
|
|
@@ -1617,30 +1468,14 @@ class ArrayStringValidator extends ArrayValidator {
|
|
|
1617
1468
|
}
|
|
1618
1469
|
validate(values) {
|
|
1619
1470
|
this.validateIndex(values);
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
Validators.lastName.validate(values[this.index.lastName]);
|
|
1629
|
-
break;
|
|
1630
|
-
case 4:
|
|
1631
|
-
Validators.namon.validate(values[this.index.prefix]);
|
|
1632
|
-
Validators.firstName.validate(values[this.index.firstName]);
|
|
1633
|
-
Validators.middleName.validate(values[this.index.middleName]);
|
|
1634
|
-
Validators.lastName.validate(values[this.index.lastName]);
|
|
1635
|
-
break;
|
|
1636
|
-
case 5:
|
|
1637
|
-
Validators.namon.validate(values[this.index.prefix]);
|
|
1638
|
-
Validators.firstName.validate(values[this.index.firstName]);
|
|
1639
|
-
Validators.middleName.validate(values[this.index.middleName]);
|
|
1640
|
-
Validators.lastName.validate(values[this.index.lastName]);
|
|
1641
|
-
Validators.namon.validate(values[this.index.suffix]);
|
|
1642
|
-
break;
|
|
1643
|
-
}
|
|
1471
|
+
Validators.firstName.validate(values[this.index.firstName]);
|
|
1472
|
+
Validators.lastName.validate(values[this.index.lastName]);
|
|
1473
|
+
if (values.length >= 3)
|
|
1474
|
+
Validators.middleName.validate(values[this.index.middleName]);
|
|
1475
|
+
if (values.length >= 4)
|
|
1476
|
+
Validators.namon.validate(values[this.index.prefix]);
|
|
1477
|
+
if (values.length === 5)
|
|
1478
|
+
Validators.namon.validate(values[this.index.suffix]);
|
|
1644
1479
|
}
|
|
1645
1480
|
validateIndex(values) {
|
|
1646
1481
|
super.validate(values);
|
|
@@ -1648,9 +1483,11 @@ class ArrayStringValidator extends ArrayValidator {
|
|
|
1648
1483
|
}
|
|
1649
1484
|
exports.ArrayStringValidator = ArrayStringValidator;
|
|
1650
1485
|
class ArrayNameValidator {
|
|
1651
|
-
constructor() {
|
|
1486
|
+
constructor() {
|
|
1487
|
+
_ArrayNameValidator_instances.add(this);
|
|
1488
|
+
}
|
|
1652
1489
|
static create() {
|
|
1653
|
-
return this
|
|
1490
|
+
return __classPrivateFieldGet(this, _g, "f", _ArrayNameValidator_validator) || (__classPrivateFieldSet(this, _g, new this(), "f", _ArrayNameValidator_validator));
|
|
1654
1491
|
}
|
|
1655
1492
|
validate(value) {
|
|
1656
1493
|
if (value.length < constants_1.MIN_NUMBER_OF_NAME_PARTS) {
|
|
@@ -1659,27 +1496,25 @@ class ArrayNameValidator {
|
|
|
1659
1496
|
message: `expecting at least ${constants_1.MIN_NUMBER_OF_NAME_PARTS} elements`,
|
|
1660
1497
|
});
|
|
1661
1498
|
}
|
|
1662
|
-
if (!this.
|
|
1499
|
+
if (!__classPrivateFieldGet(this, _ArrayNameValidator_instances, "m", _ArrayNameValidator_hasBasicNames).call(this, value)) {
|
|
1663
1500
|
throw new error_1.InputError({
|
|
1664
1501
|
source: value,
|
|
1665
1502
|
message: 'both first and last names are required',
|
|
1666
1503
|
});
|
|
1667
1504
|
}
|
|
1668
1505
|
}
|
|
1669
|
-
hasBasicNames(names) {
|
|
1670
|
-
const accumulator = {};
|
|
1671
|
-
for (const name of names) {
|
|
1672
|
-
if (name.isFirstName || name.isLastName) {
|
|
1673
|
-
accumulator[name.type.key] = name.toString();
|
|
1674
|
-
}
|
|
1675
|
-
}
|
|
1676
|
-
return Object.keys(accumulator).length === constants_1.MIN_NUMBER_OF_NAME_PARTS;
|
|
1677
|
-
}
|
|
1678
1506
|
}
|
|
1679
1507
|
exports.ArrayNameValidator = ArrayNameValidator;
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1508
|
+
_g = ArrayNameValidator, _ArrayNameValidator_instances = new WeakSet(), _ArrayNameValidator_hasBasicNames = function _ArrayNameValidator_hasBasicNames(names) {
|
|
1509
|
+
const accumulator = {};
|
|
1510
|
+
for (const name of names) {
|
|
1511
|
+
if (name.isFirstName || name.isLastName) {
|
|
1512
|
+
accumulator[name.type.key] = name.toString();
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
return Object.keys(accumulator).length === constants_1.MIN_NUMBER_OF_NAME_PARTS;
|
|
1516
|
+
};
|
|
1517
|
+
_ArrayNameValidator_validator = { value: void 0 };
|
|
1683
1518
|
class Validators {
|
|
1684
1519
|
}
|
|
1685
1520
|
exports.Validators = Validators;
|
|
@@ -1698,34 +1533,35 @@ Validators.suffix = NamonValidator.create();
|
|
|
1698
1533
|
|
|
1699
1534
|
"use strict";
|
|
1700
1535
|
|
|
1536
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
1537
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
1538
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
1539
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
1540
|
+
};
|
|
1541
|
+
var _NamaParser_instances, _NamaParser_asNama;
|
|
1701
1542
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1702
1543
|
exports.ArrayNameParser = exports.NamaParser = exports.ArrayStringParser = exports.StringParser = exports.Parser = void 0;
|
|
1703
|
-
const full_name_1 = __webpack_require__(
|
|
1704
|
-
const config_1 = __webpack_require__(
|
|
1544
|
+
const full_name_1 = __webpack_require__(9);
|
|
1545
|
+
const config_1 = __webpack_require__(6);
|
|
1705
1546
|
const utils_1 = __webpack_require__(2);
|
|
1706
1547
|
const validator_1 = __webpack_require__(7);
|
|
1707
1548
|
const name_1 = __webpack_require__(3);
|
|
1708
1549
|
const types_1 = __webpack_require__(0);
|
|
1709
1550
|
const error_1 = __webpack_require__(1);
|
|
1710
|
-
/**
|
|
1711
|
-
* A parser signature that helps to organize the names accordingly.
|
|
1712
|
-
*/
|
|
1713
1551
|
class Parser {
|
|
1714
|
-
/**
|
|
1715
|
-
* Constructs a custom parser accordingly.
|
|
1716
|
-
* @param raw data to be parsed
|
|
1717
|
-
*/
|
|
1718
1552
|
constructor(raw) {
|
|
1719
1553
|
this.raw = raw;
|
|
1720
1554
|
}
|
|
1721
|
-
|
|
1722
|
-
* Builds a dynamic `Parser` on the fly and throws a `NameError` when unable
|
|
1723
|
-
* to do so. The built parser only knows how to operate birth names.
|
|
1724
|
-
*/
|
|
1725
|
-
static build(text) {
|
|
1555
|
+
static build(text, index) {
|
|
1726
1556
|
const parts = text.trim().split(types_1.Separator.SPACE.token);
|
|
1727
1557
|
const length = parts.length;
|
|
1728
|
-
if (
|
|
1558
|
+
if (index instanceof utils_1.NameIndex) {
|
|
1559
|
+
const names = Object.entries(index.toJson())
|
|
1560
|
+
.filter(([, position]) => position > -1 && position < length)
|
|
1561
|
+
.map(([key, position]) => new name_1.Name(parts[position], types_1.Namon.all.get(key)));
|
|
1562
|
+
return new ArrayNameParser(names);
|
|
1563
|
+
}
|
|
1564
|
+
if (length < 2) {
|
|
1729
1565
|
throw new error_1.InputError({
|
|
1730
1566
|
source: text,
|
|
1731
1567
|
message: 'cannot build from invalid input',
|
|
@@ -1740,12 +1576,9 @@ class Parser {
|
|
|
1740
1576
|
return new ArrayStringParser([first, middles.join(' '), last]);
|
|
1741
1577
|
}
|
|
1742
1578
|
}
|
|
1743
|
-
|
|
1744
|
-
* Builds asynchronously a dynamic `Parser`.
|
|
1745
|
-
*/
|
|
1746
|
-
static buildAsync(text) {
|
|
1579
|
+
static buildAsync(text, index) {
|
|
1747
1580
|
try {
|
|
1748
|
-
return Promise.resolve(Parser.build(text));
|
|
1581
|
+
return Promise.resolve(Parser.build(text, index));
|
|
1749
1582
|
}
|
|
1750
1583
|
catch (error) {
|
|
1751
1584
|
return Promise.reject(error);
|
|
@@ -1754,9 +1587,6 @@ class Parser {
|
|
|
1754
1587
|
}
|
|
1755
1588
|
exports.Parser = Parser;
|
|
1756
1589
|
class StringParser extends Parser {
|
|
1757
|
-
constructor(raw) {
|
|
1758
|
-
super(raw);
|
|
1759
|
-
}
|
|
1760
1590
|
parse(options) {
|
|
1761
1591
|
const config = config_1.Config.merge(options);
|
|
1762
1592
|
const names = this.raw.split(config.separator.token);
|
|
@@ -1765,9 +1595,6 @@ class StringParser extends Parser {
|
|
|
1765
1595
|
}
|
|
1766
1596
|
exports.StringParser = StringParser;
|
|
1767
1597
|
class ArrayStringParser extends Parser {
|
|
1768
|
-
constructor(raw) {
|
|
1769
|
-
super(raw);
|
|
1770
|
-
}
|
|
1771
1598
|
parse(options) {
|
|
1772
1599
|
const config = config_1.Config.merge(options);
|
|
1773
1600
|
const fullName = new full_name_1.FullName(config);
|
|
@@ -1780,69 +1607,49 @@ class ArrayStringParser extends Parser {
|
|
|
1780
1607
|
else {
|
|
1781
1608
|
validator.validate(raw);
|
|
1782
1609
|
}
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
break;
|
|
1793
|
-
case 4:
|
|
1794
|
-
fullName.setPrefix(name_1.Name.prefix(raw[index.prefix]));
|
|
1795
|
-
fullName.setFirstName(new name_1.FirstName(raw[index.firstName]));
|
|
1796
|
-
fullName.setMiddleName(this.split(raw[index.middleName], config));
|
|
1797
|
-
fullName.setLastName(new name_1.LastName(raw[index.lastName]));
|
|
1798
|
-
break;
|
|
1799
|
-
case 5:
|
|
1800
|
-
fullName.setPrefix(name_1.Name.prefix(raw[index.prefix]));
|
|
1801
|
-
fullName.setFirstName(new name_1.FirstName(raw[index.firstName]));
|
|
1802
|
-
fullName.setMiddleName(this.split(raw[index.middleName], config));
|
|
1803
|
-
fullName.setLastName(new name_1.LastName(raw[index.lastName]));
|
|
1804
|
-
fullName.setSuffix(name_1.Name.suffix(raw[index.suffix]));
|
|
1805
|
-
break;
|
|
1806
|
-
}
|
|
1610
|
+
const { firstName, lastName, middleName, prefix, suffix } = index;
|
|
1611
|
+
fullName.setFirstName(new name_1.FirstName(raw[firstName]));
|
|
1612
|
+
fullName.setLastName(new name_1.LastName(raw[lastName]));
|
|
1613
|
+
if (raw.length >= 3)
|
|
1614
|
+
fullName.setMiddleName(raw[middleName].split(config.separator.token));
|
|
1615
|
+
if (raw.length >= 4)
|
|
1616
|
+
fullName.setPrefix(name_1.Name.prefix(raw[prefix]));
|
|
1617
|
+
if (raw.length === 5)
|
|
1618
|
+
fullName.setSuffix(name_1.Name.suffix(raw[suffix]));
|
|
1807
1619
|
return fullName;
|
|
1808
1620
|
}
|
|
1809
|
-
split(raw, config) {
|
|
1810
|
-
return raw.split(config.separator.token).map((name) => name_1.Name.middle(name));
|
|
1811
|
-
}
|
|
1812
1621
|
}
|
|
1813
1622
|
exports.ArrayStringParser = ArrayStringParser;
|
|
1814
1623
|
class NamaParser extends Parser {
|
|
1815
|
-
constructor(
|
|
1816
|
-
super(
|
|
1624
|
+
constructor() {
|
|
1625
|
+
super(...arguments);
|
|
1626
|
+
_NamaParser_instances.add(this);
|
|
1817
1627
|
}
|
|
1818
1628
|
parse(options) {
|
|
1819
1629
|
const config = config_1.Config.merge(options);
|
|
1820
1630
|
if (config.bypass) {
|
|
1821
|
-
validator_1.NamaValidator.create().validateKeys(this.
|
|
1631
|
+
validator_1.NamaValidator.create().validateKeys(__classPrivateFieldGet(this, _NamaParser_instances, "m", _NamaParser_asNama).call(this));
|
|
1822
1632
|
}
|
|
1823
1633
|
else {
|
|
1824
|
-
validator_1.NamaValidator.create().validate(this.
|
|
1634
|
+
validator_1.NamaValidator.create().validate(__classPrivateFieldGet(this, _NamaParser_instances, "m", _NamaParser_asNama).call(this));
|
|
1825
1635
|
}
|
|
1826
1636
|
return full_name_1.FullName.parse(this.raw, config);
|
|
1827
1637
|
}
|
|
1828
|
-
asNama() {
|
|
1829
|
-
return new Map(Object.entries(this.raw).map(([key, value]) => {
|
|
1830
|
-
const namon = types_1.Namon.cast(key);
|
|
1831
|
-
if (!namon) {
|
|
1832
|
-
throw new error_1.InputError({
|
|
1833
|
-
source: Object.values(this.raw).join(' '),
|
|
1834
|
-
message: `unsupported key "${key}"`,
|
|
1835
|
-
});
|
|
1836
|
-
}
|
|
1837
|
-
return [namon, value];
|
|
1838
|
-
}));
|
|
1839
|
-
}
|
|
1840
1638
|
}
|
|
1841
1639
|
exports.NamaParser = NamaParser;
|
|
1640
|
+
_NamaParser_instances = new WeakSet(), _NamaParser_asNama = function _NamaParser_asNama() {
|
|
1641
|
+
return new Map(Object.entries(this.raw).map(([key, value]) => {
|
|
1642
|
+
const namon = types_1.Namon.cast(key);
|
|
1643
|
+
if (!namon) {
|
|
1644
|
+
throw new error_1.InputError({
|
|
1645
|
+
source: Object.values(this.raw).join(' '),
|
|
1646
|
+
message: `unsupported key "${key}"`,
|
|
1647
|
+
});
|
|
1648
|
+
}
|
|
1649
|
+
return [namon, value];
|
|
1650
|
+
}));
|
|
1651
|
+
};
|
|
1842
1652
|
class ArrayNameParser extends Parser {
|
|
1843
|
-
constructor(raw) {
|
|
1844
|
-
super(raw);
|
|
1845
|
-
}
|
|
1846
1653
|
parse(options) {
|
|
1847
1654
|
const config = config_1.Config.merge(options);
|
|
1848
1655
|
const fullName = new full_name_1.FullName(config);
|
|
@@ -1877,771 +1684,248 @@ exports.ArrayNameParser = ArrayNameParser;
|
|
|
1877
1684
|
|
|
1878
1685
|
"use strict";
|
|
1879
1686
|
|
|
1880
|
-
var
|
|
1881
|
-
if (
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
o[k2] = m[k];
|
|
1886
|
-
}));
|
|
1887
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
1888
|
-
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
|
|
1687
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
1688
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
1689
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
1690
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
1691
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
1889
1692
|
};
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
* `namefully` is a JavaScript utility for handing person names.
|
|
1895
|
-
*
|
|
1896
|
-
* Sources
|
|
1897
|
-
* - repo: https://github.com/ralflorent/namefully
|
|
1898
|
-
* - docs: https://namefully.netlify.app
|
|
1899
|
-
* - npm: https://npmjs.com/package/namefully
|
|
1900
|
-
*
|
|
1901
|
-
* @license MIT
|
|
1902
|
-
*/
|
|
1903
|
-
__exportStar(__webpack_require__(4), exports);
|
|
1904
|
-
__exportStar(__webpack_require__(1), exports);
|
|
1905
|
-
__exportStar(__webpack_require__(6), exports);
|
|
1906
|
-
__exportStar(__webpack_require__(3), exports);
|
|
1907
|
-
__exportStar(__webpack_require__(10), exports);
|
|
1908
|
-
var parser_1 = __webpack_require__(8);
|
|
1909
|
-
Object.defineProperty(exports, "Parser", { enumerable: true, get: function () { return parser_1.Parser; } });
|
|
1910
|
-
__exportStar(__webpack_require__(0), exports);
|
|
1911
|
-
var utils_1 = __webpack_require__(2);
|
|
1912
|
-
Object.defineProperty(exports, "NameIndex", { enumerable: true, get: function () { return utils_1.NameIndex; } });
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
/***/ }),
|
|
1916
|
-
/* 10 */
|
|
1917
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
1918
|
-
|
|
1919
|
-
"use strict";
|
|
1920
|
-
|
|
1921
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1922
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1923
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1924
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
1925
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
1926
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1927
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1928
|
-
});
|
|
1693
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
1694
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
1695
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
1696
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
1929
1697
|
};
|
|
1698
|
+
var _FullName_prefix, _FullName_firstName, _FullName_middleName, _FullName_lastName, _FullName_suffix, _FullName_config;
|
|
1930
1699
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1931
|
-
exports.
|
|
1932
|
-
const config_1 = __webpack_require__(
|
|
1933
|
-
const constants_1 = __webpack_require__(5);
|
|
1700
|
+
exports.FullName = void 0;
|
|
1701
|
+
const config_1 = __webpack_require__(6);
|
|
1934
1702
|
const error_1 = __webpack_require__(1);
|
|
1935
|
-
const
|
|
1703
|
+
const name_1 = __webpack_require__(3);
|
|
1936
1704
|
const types_1 = __webpack_require__(0);
|
|
1937
|
-
const
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
* developer so that he or she is not bound to a particular data format.
|
|
1948
|
-
* By following closely the API reference to know how to harness its usability,
|
|
1949
|
-
* this utility aims to save time in formatting names.
|
|
1950
|
-
*
|
|
1951
|
-
* `namefully` also works like a trapdoor. Once a raw data is provided and
|
|
1952
|
-
* validated, a developer can only *access* in a vast amount of, yet effective
|
|
1953
|
-
* ways the name info. *No editing* is possible. If the name is mistaken, a new
|
|
1954
|
-
* instance of `Namefully` must be created. In other words, it's immutable.
|
|
1955
|
-
* Remember, this utility's primary objective is to help manipulate a person name.
|
|
1956
|
-
*
|
|
1957
|
-
* Note that the name standards used for the current version of this library
|
|
1958
|
-
* are as follows:
|
|
1959
|
-
* `[prefix] firstName [middleName] lastName [suffix]`
|
|
1960
|
-
* The opening `[` and closing `]` symbols mean that these parts are optional.
|
|
1961
|
-
* In other words, the most basic and typical case is a name that looks like
|
|
1962
|
-
* this: `John Smith`, where `John` is the first name piece and `Smith`, the last
|
|
1963
|
-
* name piece.
|
|
1964
|
-
*
|
|
1965
|
-
* @see https://departments.weber.edu/qsupport&training/Data_Standards/Name.htm
|
|
1966
|
-
* for more info on name standards.
|
|
1967
|
-
*
|
|
1968
|
-
* **IMPORTANT**: Keep in mind that the order of appearance (or name order) matters
|
|
1969
|
-
* and may be altered through configured parameters, which will be seen later.
|
|
1970
|
-
* By default, the order of appearance is as shown above and will be used as a
|
|
1971
|
-
* basis for future examples and use cases.
|
|
1972
|
-
*
|
|
1973
|
-
* Once imported, all that is required to do is to create an instance of
|
|
1974
|
-
* `Namefully` and the rest will follow.
|
|
1975
|
-
*
|
|
1976
|
-
* Some terminologies used across the library are:
|
|
1977
|
-
* - namon: 1 piece of name (e.g., first name)
|
|
1978
|
-
* - nama: 2+ pieces of name (e.g., first name + last name)
|
|
1979
|
-
*
|
|
1980
|
-
* Happy name handling 😊!
|
|
1981
|
-
*/
|
|
1982
|
-
class Namefully {
|
|
1983
|
-
/**
|
|
1984
|
-
* Creates a name with distinguishable parts from a raw string content.
|
|
1985
|
-
* @param names element to parse.
|
|
1986
|
-
* @param options additional settings.
|
|
1987
|
-
*
|
|
1988
|
-
* An optional configuration may be provided with specifics on how to treat
|
|
1989
|
-
* a full name during its course. By default, all name parts are validated
|
|
1990
|
-
* against some basic validation rules to avoid common runtime exceptions.
|
|
1991
|
-
*/
|
|
1992
|
-
constructor(names, options) {
|
|
1993
|
-
this.build(this.toParser(names), options);
|
|
1994
|
-
}
|
|
1995
|
-
/**
|
|
1996
|
-
* Constructs a `Namefully` instance from a text.
|
|
1997
|
-
*
|
|
1998
|
-
* It works like `parse` except that this function returns `null` where `parse`
|
|
1999
|
-
* would throw a `NameError`.
|
|
2000
|
-
*/
|
|
2001
|
-
static tryParse(text) {
|
|
2002
|
-
try {
|
|
2003
|
-
return new this(parser_1.Parser.build(text));
|
|
2004
|
-
}
|
|
2005
|
-
catch (error) {
|
|
2006
|
-
return undefined;
|
|
2007
|
-
}
|
|
2008
|
-
}
|
|
2009
|
-
/**
|
|
2010
|
-
* Constructs a `Namefully` instance from a text.
|
|
2011
|
-
*
|
|
2012
|
-
* It throws a `NameError` if the text cannot be parsed. Use `tryParse`
|
|
2013
|
-
* instead if a `null` return is preferred over a throwable error.
|
|
2014
|
-
*
|
|
2015
|
-
* This operation is computed asynchronously, which gives more flexibility at
|
|
2016
|
-
* the time of catching the error (and stack trace if any). The acceptable
|
|
2017
|
-
* text format is a string composed of two or more name pieces. For instance,
|
|
2018
|
-
* `John Lennon`, or `John Winston Ono Lennon` are parsable names and follow
|
|
2019
|
-
* the basic name standard rules (i.e., first-middle-last).
|
|
2020
|
-
*
|
|
2021
|
-
* Keep in mind that prefix and suffix are not considered during the parsing
|
|
2022
|
-
* process.
|
|
2023
|
-
*/
|
|
2024
|
-
static parse(text) {
|
|
2025
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2026
|
-
return parser_1.Parser.buildAsync(text).then((parser) => new Namefully(parser));
|
|
2027
|
-
});
|
|
1705
|
+
const validator_1 = __webpack_require__(7);
|
|
1706
|
+
class FullName {
|
|
1707
|
+
constructor(options) {
|
|
1708
|
+
_FullName_prefix.set(this, void 0);
|
|
1709
|
+
_FullName_firstName.set(this, void 0);
|
|
1710
|
+
_FullName_middleName.set(this, []);
|
|
1711
|
+
_FullName_lastName.set(this, void 0);
|
|
1712
|
+
_FullName_suffix.set(this, void 0);
|
|
1713
|
+
_FullName_config.set(this, void 0);
|
|
1714
|
+
__classPrivateFieldSet(this, _FullName_config, config_1.Config.merge(options), "f");
|
|
2028
1715
|
}
|
|
2029
|
-
/**
|
|
2030
|
-
* The current configuration.
|
|
2031
|
-
*/
|
|
2032
1716
|
get config() {
|
|
2033
|
-
return this
|
|
1717
|
+
return __classPrivateFieldGet(this, _FullName_config, "f");
|
|
2034
1718
|
}
|
|
2035
|
-
/**
|
|
2036
|
-
* The number of characters of the `birthName`, including spaces.
|
|
2037
|
-
*/
|
|
2038
|
-
get length() {
|
|
2039
|
-
return this.birth.length;
|
|
2040
|
-
}
|
|
2041
|
-
/**
|
|
2042
|
-
* The prefix part.
|
|
2043
|
-
*/
|
|
2044
1719
|
get prefix() {
|
|
2045
|
-
|
|
2046
|
-
return (_a = this._fullName.prefix) === null || _a === void 0 ? void 0 : _a.toString();
|
|
2047
|
-
}
|
|
2048
|
-
/**
|
|
2049
|
-
* The firt name.
|
|
2050
|
-
*/
|
|
2051
|
-
get first() {
|
|
2052
|
-
return this.firstName();
|
|
1720
|
+
return __classPrivateFieldGet(this, _FullName_prefix, "f");
|
|
2053
1721
|
}
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
*/
|
|
2057
|
-
get middle() {
|
|
2058
|
-
return this.hasMiddle ? this.middleName()[0] : undefined;
|
|
1722
|
+
get firstName() {
|
|
1723
|
+
return __classPrivateFieldGet(this, _FullName_firstName, "f");
|
|
2059
1724
|
}
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
*/
|
|
2063
|
-
get hasMiddle() {
|
|
2064
|
-
return this._fullName.has(types_1.Namon.MIDDLE_NAME);
|
|
1725
|
+
get lastName() {
|
|
1726
|
+
return __classPrivateFieldGet(this, _FullName_lastName, "f");
|
|
2065
1727
|
}
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
*/
|
|
2069
|
-
get last() {
|
|
2070
|
-
return this.lastName();
|
|
1728
|
+
get middleName() {
|
|
1729
|
+
return __classPrivateFieldGet(this, _FullName_middleName, "f");
|
|
2071
1730
|
}
|
|
2072
|
-
/**
|
|
2073
|
-
* The suffix part.
|
|
2074
|
-
*/
|
|
2075
1731
|
get suffix() {
|
|
2076
|
-
|
|
2077
|
-
return (_a = this._fullName.suffix) === null || _a === void 0 ? void 0 : _a.toString();
|
|
2078
|
-
}
|
|
2079
|
-
/**
|
|
2080
|
-
* The birth name.
|
|
2081
|
-
*/
|
|
2082
|
-
get birth() {
|
|
2083
|
-
return this.birthName();
|
|
1732
|
+
return __classPrivateFieldGet(this, _FullName_suffix, "f");
|
|
2084
1733
|
}
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
1734
|
+
static parse(json, config) {
|
|
1735
|
+
try {
|
|
1736
|
+
const fullName = new FullName(config);
|
|
1737
|
+
fullName.setPrefix(json.prefix);
|
|
1738
|
+
fullName.setFirstName(json.firstName);
|
|
1739
|
+
fullName.setMiddleName(json.middleName);
|
|
1740
|
+
fullName.setLastName(json.lastName);
|
|
1741
|
+
fullName.setSuffix(json.suffix);
|
|
1742
|
+
return fullName;
|
|
1743
|
+
}
|
|
1744
|
+
catch (error) {
|
|
1745
|
+
if (error instanceof error_1.NameError)
|
|
1746
|
+
throw error;
|
|
1747
|
+
throw new error_1.UnknownError({
|
|
1748
|
+
source: Object.values(json).join(' '),
|
|
1749
|
+
message: 'could not parse JSON content',
|
|
1750
|
+
error,
|
|
1751
|
+
});
|
|
1752
|
+
}
|
|
2090
1753
|
}
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
1754
|
+
setPrefix(name) {
|
|
1755
|
+
if (!name)
|
|
1756
|
+
return this;
|
|
1757
|
+
if (!__classPrivateFieldGet(this, _FullName_config, "f").bypass)
|
|
1758
|
+
validator_1.Validators.prefix.validate(name);
|
|
1759
|
+
const prefix = name instanceof name_1.Name ? name.value : name;
|
|
1760
|
+
__classPrivateFieldSet(this, _FullName_prefix, name_1.Name.prefix(__classPrivateFieldGet(this, _FullName_config, "f").title === types_1.Title.US ? `${prefix}.` : prefix), "f");
|
|
1761
|
+
return this;
|
|
2096
1762
|
}
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
return this
|
|
1763
|
+
setFirstName(name) {
|
|
1764
|
+
if (!__classPrivateFieldGet(this, _FullName_config, "f").bypass)
|
|
1765
|
+
validator_1.Validators.firstName.validate(name);
|
|
1766
|
+
__classPrivateFieldSet(this, _FullName_firstName, name instanceof name_1.FirstName ? name : new name_1.FirstName(name), "f");
|
|
1767
|
+
return this;
|
|
2102
1768
|
}
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
return this
|
|
1769
|
+
setLastName(name) {
|
|
1770
|
+
if (!__classPrivateFieldGet(this, _FullName_config, "f").bypass)
|
|
1771
|
+
validator_1.Validators.lastName.validate(name);
|
|
1772
|
+
__classPrivateFieldSet(this, _FullName_lastName, name instanceof name_1.LastName ? name : new name_1.LastName(name), "f");
|
|
1773
|
+
return this;
|
|
2108
1774
|
}
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
1775
|
+
setMiddleName(names) {
|
|
1776
|
+
if (!Array.isArray(names))
|
|
1777
|
+
return this;
|
|
1778
|
+
if (!__classPrivateFieldGet(this, _FullName_config, "f").bypass)
|
|
1779
|
+
validator_1.Validators.middleName.validate(names);
|
|
1780
|
+
__classPrivateFieldSet(this, _FullName_middleName, names.map((name) => (name instanceof name_1.Name ? name : name_1.Name.middle(name))), "f");
|
|
1781
|
+
return this;
|
|
2114
1782
|
}
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
1783
|
+
setSuffix(name) {
|
|
1784
|
+
if (!name)
|
|
1785
|
+
return this;
|
|
1786
|
+
if (!__classPrivateFieldGet(this, _FullName_config, "f").bypass)
|
|
1787
|
+
validator_1.Validators.suffix.validate(name);
|
|
1788
|
+
__classPrivateFieldSet(this, _FullName_suffix, name_1.Name.suffix(name instanceof name_1.Name ? name.value : name), "f");
|
|
1789
|
+
return this;
|
|
1790
|
+
}
|
|
1791
|
+
has(namon) {
|
|
2119
1792
|
if (namon.equal(types_1.Namon.PREFIX))
|
|
2120
|
-
return this
|
|
2121
|
-
if (namon.equal(types_1.Namon.FIRST_NAME))
|
|
2122
|
-
return this._fullName.firstName;
|
|
2123
|
-
if (namon.equal(types_1.Namon.MIDDLE_NAME))
|
|
2124
|
-
return this._fullName.middleName;
|
|
2125
|
-
if (namon.equal(types_1.Namon.LAST_NAME))
|
|
2126
|
-
return this._fullName.lastName;
|
|
1793
|
+
return !!__classPrivateFieldGet(this, _FullName_prefix, "f");
|
|
2127
1794
|
if (namon.equal(types_1.Namon.SUFFIX))
|
|
2128
|
-
return this
|
|
2129
|
-
return
|
|
2130
|
-
}
|
|
2131
|
-
/**
|
|
2132
|
-
* Whether this name is equal to another one from a raw-string perspective.
|
|
2133
|
-
*/
|
|
2134
|
-
equal(other) {
|
|
2135
|
-
return this.toString() === other.toString();
|
|
1795
|
+
return !!__classPrivateFieldGet(this, _FullName_suffix, "f");
|
|
1796
|
+
return namon.equal(types_1.Namon.MIDDLE_NAME) ? __classPrivateFieldGet(this, _FullName_middleName, "f").length > 0 : true;
|
|
2136
1797
|
}
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
1798
|
+
}
|
|
1799
|
+
exports.FullName = FullName;
|
|
1800
|
+
_FullName_prefix = new WeakMap(), _FullName_firstName = new WeakMap(), _FullName_middleName = new WeakMap(), _FullName_lastName = new WeakMap(), _FullName_suffix = new WeakMap(), _FullName_config = new WeakMap();
|
|
1801
|
+
|
|
1802
|
+
|
|
1803
|
+
/***/ }),
|
|
1804
|
+
/* 10 */
|
|
1805
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
1806
|
+
|
|
1807
|
+
"use strict";
|
|
1808
|
+
|
|
1809
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
1810
|
+
if (k2 === undefined) k2 = k;
|
|
1811
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1812
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1813
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
2148
1814
|
}
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
1815
|
+
Object.defineProperty(o, k2, desc);
|
|
1816
|
+
}) : (function(o, m, k, k2) {
|
|
1817
|
+
if (k2 === undefined) k2 = k;
|
|
1818
|
+
o[k2] = m[k];
|
|
1819
|
+
}));
|
|
1820
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
1821
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
1822
|
+
};
|
|
1823
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1824
|
+
exports.NameIndex = exports.Parser = exports.version = void 0;
|
|
1825
|
+
const namefully_1 = __webpack_require__(5);
|
|
1826
|
+
__exportStar(__webpack_require__(11), exports);
|
|
1827
|
+
__exportStar(__webpack_require__(6), exports);
|
|
1828
|
+
var constants_1 = __webpack_require__(4);
|
|
1829
|
+
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return constants_1.VERSION; } });
|
|
1830
|
+
__exportStar(__webpack_require__(1), exports);
|
|
1831
|
+
__exportStar(__webpack_require__(9), exports);
|
|
1832
|
+
__exportStar(__webpack_require__(3), exports);
|
|
1833
|
+
__exportStar(__webpack_require__(5), exports);
|
|
1834
|
+
var parser_1 = __webpack_require__(8);
|
|
1835
|
+
Object.defineProperty(exports, "Parser", { enumerable: true, get: function () { return parser_1.Parser; } });
|
|
1836
|
+
__exportStar(__webpack_require__(0), exports);
|
|
1837
|
+
var utils_1 = __webpack_require__(2);
|
|
1838
|
+
Object.defineProperty(exports, "NameIndex", { enumerable: true, get: function () { return utils_1.NameIndex; } });
|
|
1839
|
+
exports.default = namefully_1.default;
|
|
1840
|
+
|
|
1841
|
+
|
|
1842
|
+
/***/ }),
|
|
1843
|
+
/* 11 */
|
|
1844
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
1845
|
+
|
|
1846
|
+
"use strict";
|
|
1847
|
+
|
|
1848
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1849
|
+
exports.NameBuilder = void 0;
|
|
1850
|
+
const namefully_1 = __webpack_require__(5);
|
|
1851
|
+
const validator_1 = __webpack_require__(7);
|
|
1852
|
+
class Builder {
|
|
1853
|
+
constructor(prebuild, postbuild, preclear, postclear) {
|
|
1854
|
+
this.prebuild = prebuild;
|
|
1855
|
+
this.postbuild = postbuild;
|
|
1856
|
+
this.preclear = preclear;
|
|
1857
|
+
this.postclear = postclear;
|
|
1858
|
+
this.queue = [];
|
|
1859
|
+
this.instance = null;
|
|
2186
1860
|
}
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
*
|
|
2190
|
-
* @param orderedBy forces to order by first or last name by overriding the
|
|
2191
|
-
* preset configuration.
|
|
2192
|
-
*/
|
|
2193
|
-
birthName(orderedBy) {
|
|
2194
|
-
orderedBy = orderedBy || this._config.orderedBy;
|
|
2195
|
-
return orderedBy === types_1.NameOrder.FIRST_NAME
|
|
2196
|
-
? [this.first, ...this.middleName(), this.last].join(' ')
|
|
2197
|
-
: [this.last, this.first, ...this.middleName()].join(' ');
|
|
1861
|
+
get size() {
|
|
1862
|
+
return this.queue.length;
|
|
2198
1863
|
}
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
*
|
|
2202
|
-
* @param withMore determines whether to include other pieces of the first
|
|
2203
|
-
* name.
|
|
2204
|
-
*/
|
|
2205
|
-
firstName(withMore = true) {
|
|
2206
|
-
return this._fullName.firstName.toString(withMore);
|
|
1864
|
+
removeFirst() {
|
|
1865
|
+
return this.queue.length > 0 ? this.queue.shift() : undefined;
|
|
2207
1866
|
}
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
*/
|
|
2211
|
-
middleName() {
|
|
2212
|
-
return this._fullName.middleName.map((n) => n.value);
|
|
2213
|
-
}
|
|
2214
|
-
/**
|
|
2215
|
-
* Gets the last name part of the `FullName`.
|
|
2216
|
-
*
|
|
2217
|
-
* @param format overrides the how-to formatting of a surname output,
|
|
2218
|
-
* considering its sub-parts.
|
|
2219
|
-
*/
|
|
2220
|
-
lastName(format) {
|
|
2221
|
-
return this._fullName.lastName.toString(format);
|
|
2222
|
-
}
|
|
2223
|
-
/**
|
|
2224
|
-
* Gets the initials of the `FullName`.
|
|
2225
|
-
*
|
|
2226
|
-
* @param {options.orderedBy} forces to order by first or last name by
|
|
2227
|
-
* overriding the preset configuration.
|
|
2228
|
-
* @param
|
|
2229
|
-
*
|
|
2230
|
-
* For example, given the names:
|
|
2231
|
-
* - `John Smith` => `['J', 'S']`
|
|
2232
|
-
* - `John Ben Smith` => `['J', 'B', 'S']`.
|
|
2233
|
-
*/
|
|
2234
|
-
initials(options) {
|
|
2235
|
-
const initials = [];
|
|
2236
|
-
const firstInits = this._fullName.firstName.initials();
|
|
2237
|
-
const midInits = this._fullName.middleName.map((n) => n.initials()[0]);
|
|
2238
|
-
const lastInits = this._fullName.lastName.initials();
|
|
2239
|
-
const mergedOptions = Object.assign({ orderedBy: this._config.orderedBy, only: types_1.NameType.BIRTH_NAME }, options);
|
|
2240
|
-
const { orderedBy, only } = mergedOptions;
|
|
2241
|
-
if (only !== types_1.NameType.BIRTH_NAME) {
|
|
2242
|
-
if (only === types_1.NameType.FIRST_NAME) {
|
|
2243
|
-
initials.push(...firstInits);
|
|
2244
|
-
}
|
|
2245
|
-
else if (only === types_1.NameType.MIDDLE_NAME) {
|
|
2246
|
-
initials.push(...midInits);
|
|
2247
|
-
}
|
|
2248
|
-
else {
|
|
2249
|
-
initials.push(...lastInits);
|
|
2250
|
-
}
|
|
2251
|
-
}
|
|
2252
|
-
else if (orderedBy === types_1.NameOrder.FIRST_NAME) {
|
|
2253
|
-
initials.push(...firstInits, ...midInits, ...lastInits);
|
|
2254
|
-
}
|
|
2255
|
-
else {
|
|
2256
|
-
initials.push(...lastInits, ...firstInits, ...midInits);
|
|
2257
|
-
}
|
|
2258
|
-
return initials;
|
|
1867
|
+
removeLast() {
|
|
1868
|
+
return this.queue.length > 0 ? this.queue.pop() : undefined;
|
|
2259
1869
|
}
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
* first and last name.
|
|
2263
|
-
*
|
|
2264
|
-
* @param orderedBy forces to order by first or last name by overriding the
|
|
2265
|
-
* preset configuration.
|
|
2266
|
-
*
|
|
2267
|
-
* For a given name such as `Mr Keanu Charles Reeves`, shortening this name
|
|
2268
|
-
* is equivalent to making it `Keanu Reeves`.
|
|
2269
|
-
*
|
|
2270
|
-
* As a shortened name, the namon of the first name is favored over the other
|
|
2271
|
-
* names forming part of the entire first names, if any. Meanwhile, for
|
|
2272
|
-
* the last name, the configured `surname` is prioritized.
|
|
2273
|
-
*
|
|
2274
|
-
* For a given `FirstName FatherName MotherName`, shortening this name when
|
|
2275
|
-
* the surname is set as `mother` is equivalent to making it:
|
|
2276
|
-
* `FirstName MotherName`.
|
|
2277
|
-
*/
|
|
2278
|
-
shorten(orderedBy) {
|
|
2279
|
-
orderedBy = orderedBy || this._config.orderedBy;
|
|
2280
|
-
return orderedBy === types_1.NameOrder.FIRST_NAME
|
|
2281
|
-
? [this._fullName.firstName.value, this._fullName.lastName.toString()].join(' ')
|
|
2282
|
-
: [this._fullName.lastName.toString(), this._fullName.firstName.value].join(' ');
|
|
2283
|
-
}
|
|
2284
|
-
/**
|
|
2285
|
-
* Flattens a long name using the name types as variants.
|
|
2286
|
-
*
|
|
2287
|
-
* While @param limit sets a threshold as a limited number of characters
|
|
2288
|
-
* supported to flatten a `FullName`, @param by indicates which variant
|
|
2289
|
-
* to use when doing so. By default, a full name gets flattened by
|
|
2290
|
-
* `Flat.MIDDLE_NAME`.
|
|
2291
|
-
*
|
|
2292
|
-
* The flattening operation is only executed iff there is a valid entry and
|
|
2293
|
-
* it surpasses the limit set. In the examples below, let us assume that the
|
|
2294
|
-
* name goes beyond the limit value.
|
|
2295
|
-
*
|
|
2296
|
-
* Flattening a long name refers to reducing the name to the following forms.
|
|
2297
|
-
* For example, `John Winston Ono Lennon` flattened by:
|
|
2298
|
-
* * Flat.FIRST_NAME: => 'J. Winston Ono Lennon'
|
|
2299
|
-
* * Flat.MIDDLE_NAME: => 'John W. O. Lennon'
|
|
2300
|
-
* * Flat.LAST_NAME: => 'John Winston Ono L.'
|
|
2301
|
-
* * Flat.FIRST_MID: => 'J. W. O. Lennon'
|
|
2302
|
-
* * Flat.MID_LAST: => 'John W. O. L.'
|
|
2303
|
-
* * Flat.ALL: => 'J. W. O. L.'
|
|
2304
|
-
*
|
|
2305
|
-
* With the help of the @param recursive flag, the above operation can happen
|
|
2306
|
-
* recursively in the same order if the name is still too long. For example,
|
|
2307
|
-
* flattening `John Winston Ono Lennon` using the following params:
|
|
2308
|
-
* `flatten({ limit: 18, by: Flat.FIRST_NAME, recursive: true })`
|
|
2309
|
-
* will result in `John W. O. Lennon` and not `J. Winston Ono Lennon`.
|
|
2310
|
-
*
|
|
2311
|
-
* A shorter version of this method is `zip()`.
|
|
2312
|
-
*/
|
|
2313
|
-
flatten(options) {
|
|
2314
|
-
if (this.length <= options.limit)
|
|
2315
|
-
return this.full;
|
|
2316
|
-
const mergedOptions = Object.assign({ limit: 20, by: types_1.Flat.MIDDLE_NAME, withPeriod: true, recursive: false, withMore: false }, options);
|
|
2317
|
-
const { by, limit, recursive, withMore, withPeriod, surname } = mergedOptions;
|
|
2318
|
-
const sep = withPeriod ? '.' : '';
|
|
2319
|
-
const fn = this._fullName.firstName.toString();
|
|
2320
|
-
const mn = this.middleName().join(' ');
|
|
2321
|
-
const ln = this._fullName.lastName.toString();
|
|
2322
|
-
const hasMid = this.hasMiddle;
|
|
2323
|
-
const f = this._fullName.firstName.initials(withMore).join(sep + ' ') + sep;
|
|
2324
|
-
const l = this._fullName.lastName.initials(surname).join(sep + ' ') + sep;
|
|
2325
|
-
const m = hasMid ? this._fullName.middleName.map((n) => n.initials()[0]).join(sep + ' ') + sep : '';
|
|
2326
|
-
let name = [];
|
|
2327
|
-
if (this._config.orderedBy === types_1.NameOrder.FIRST_NAME) {
|
|
2328
|
-
switch (by) {
|
|
2329
|
-
case types_1.Flat.FIRST_NAME:
|
|
2330
|
-
name = hasMid ? [f, mn, ln] : [f, ln];
|
|
2331
|
-
break;
|
|
2332
|
-
case types_1.Flat.LAST_NAME:
|
|
2333
|
-
name = hasMid ? [fn, mn, l] : [fn, l];
|
|
2334
|
-
break;
|
|
2335
|
-
case types_1.Flat.MIDDLE_NAME:
|
|
2336
|
-
name = hasMid ? [fn, m, ln] : [fn, ln];
|
|
2337
|
-
break;
|
|
2338
|
-
case types_1.Flat.FIRST_MID:
|
|
2339
|
-
name = hasMid ? [f, m, ln] : [f, ln];
|
|
2340
|
-
break;
|
|
2341
|
-
case types_1.Flat.MID_LAST:
|
|
2342
|
-
name = hasMid ? [fn, m, l] : [fn, l];
|
|
2343
|
-
break;
|
|
2344
|
-
case types_1.Flat.ALL:
|
|
2345
|
-
name = hasMid ? [f, m, l] : [f, l];
|
|
2346
|
-
break;
|
|
2347
|
-
}
|
|
2348
|
-
}
|
|
2349
|
-
else {
|
|
2350
|
-
switch (by) {
|
|
2351
|
-
case types_1.Flat.FIRST_NAME:
|
|
2352
|
-
name = hasMid ? [ln, f, mn] : [ln, f];
|
|
2353
|
-
break;
|
|
2354
|
-
case types_1.Flat.LAST_NAME:
|
|
2355
|
-
name = hasMid ? [l, fn, mn] : [l, fn];
|
|
2356
|
-
break;
|
|
2357
|
-
case types_1.Flat.MIDDLE_NAME:
|
|
2358
|
-
name = hasMid ? [ln, fn, m] : [ln, fn];
|
|
2359
|
-
break;
|
|
2360
|
-
case types_1.Flat.FIRST_MID:
|
|
2361
|
-
name = hasMid ? [ln, f, m] : [ln, f];
|
|
2362
|
-
break;
|
|
2363
|
-
case types_1.Flat.MID_LAST:
|
|
2364
|
-
name = hasMid ? [l, fn, m] : [l, fn];
|
|
2365
|
-
break;
|
|
2366
|
-
case types_1.Flat.ALL:
|
|
2367
|
-
name = hasMid ? [l, f, m] : [l, f];
|
|
2368
|
-
break;
|
|
2369
|
-
}
|
|
2370
|
-
}
|
|
2371
|
-
const flat = name.join(' ');
|
|
2372
|
-
if (recursive && flat.length > limit) {
|
|
2373
|
-
const next = by === types_1.Flat.FIRST_NAME
|
|
2374
|
-
? types_1.Flat.MIDDLE_NAME
|
|
2375
|
-
: by === types_1.Flat.MIDDLE_NAME
|
|
2376
|
-
? types_1.Flat.LAST_NAME
|
|
2377
|
-
: by === types_1.Flat.LAST_NAME
|
|
2378
|
-
? types_1.Flat.FIRST_MID
|
|
2379
|
-
: by === types_1.Flat.FIRST_MID
|
|
2380
|
-
? types_1.Flat.MID_LAST
|
|
2381
|
-
: by === types_1.Flat.MID_LAST
|
|
2382
|
-
? types_1.Flat.ALL
|
|
2383
|
-
: by === types_1.Flat.ALL
|
|
2384
|
-
? types_1.Flat.ALL
|
|
2385
|
-
: by;
|
|
2386
|
-
if (next === by)
|
|
2387
|
-
return flat;
|
|
2388
|
-
return this.flatten(Object.assign(Object.assign({}, options), { by: next }));
|
|
2389
|
-
}
|
|
2390
|
-
return flat;
|
|
1870
|
+
addFirst(value) {
|
|
1871
|
+
this.queue.unshift(value);
|
|
2391
1872
|
}
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
*
|
|
2395
|
-
* @see `flatten()` for more details.
|
|
2396
|
-
*/
|
|
2397
|
-
zip(by = types_1.Flat.MID_LAST, withPeriod = true) {
|
|
2398
|
-
return this.flatten({ limit: 0, by, withPeriod });
|
|
1873
|
+
addLast(value) {
|
|
1874
|
+
this.queue.push(value);
|
|
2399
1875
|
}
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
* @param pattern character used to format it.
|
|
2403
|
-
*
|
|
2404
|
-
* string format
|
|
2405
|
-
* -------------
|
|
2406
|
-
* - 'short': typical first + last name
|
|
2407
|
-
* - 'long': birth name (without prefix and suffix)
|
|
2408
|
-
* - 'public': first name combined with the last name's initial.
|
|
2409
|
-
* - 'official': official document format
|
|
2410
|
-
*
|
|
2411
|
-
* char format
|
|
2412
|
-
* -----------
|
|
2413
|
-
* - 'b': birth name
|
|
2414
|
-
* - 'B': capitalized birth name
|
|
2415
|
-
* - 'f': first name
|
|
2416
|
-
* - 'F': capitalized first name
|
|
2417
|
-
* - 'l': last name
|
|
2418
|
-
* - 'L': capitalized last name
|
|
2419
|
-
* - 'm': middle names
|
|
2420
|
-
* - 'M': capitalized middle names
|
|
2421
|
-
* - 'o': official document format
|
|
2422
|
-
* - 'O': official document format in capital letters
|
|
2423
|
-
* - 'p': prefix
|
|
2424
|
-
* - 'P': capitalized prefix
|
|
2425
|
-
* - 's': suffix
|
|
2426
|
-
* - 'S': capitalized suffix
|
|
2427
|
-
*
|
|
2428
|
-
* punctuations
|
|
2429
|
-
* ------------
|
|
2430
|
-
* - '.': period
|
|
2431
|
-
* - ',': comma
|
|
2432
|
-
* - ' ': space
|
|
2433
|
-
* - '-': hyphen
|
|
2434
|
-
* - '_': underscore
|
|
2435
|
-
* - '$': an escape character to select only the initial of the next char.
|
|
2436
|
-
*
|
|
2437
|
-
* Given the name `Joe Jim Smith`, use `format` with the `pattern` string.
|
|
2438
|
-
* - format('l f') => 'Smith Joe'
|
|
2439
|
-
* - format('L, f') => 'SMITH, Joe'
|
|
2440
|
-
* - format('short') => 'Joe Smith'
|
|
2441
|
-
* - format() => 'SMITH, Joe Jim'
|
|
2442
|
-
* - format(r'f $l.') => 'Joe S.'.
|
|
2443
|
-
*
|
|
2444
|
-
* Do note that the escape character is only valid for the birth name parts:
|
|
2445
|
-
* first, middle, and last names.
|
|
2446
|
-
*/
|
|
2447
|
-
format(pattern) {
|
|
2448
|
-
var _a;
|
|
2449
|
-
if (pattern === 'short')
|
|
2450
|
-
return this.short;
|
|
2451
|
-
if (pattern === 'long')
|
|
2452
|
-
return this.long;
|
|
2453
|
-
if (pattern === 'public')
|
|
2454
|
-
return this.public;
|
|
2455
|
-
if (pattern === 'official')
|
|
2456
|
-
pattern = 'o';
|
|
2457
|
-
let group = '';
|
|
2458
|
-
const formatted = [];
|
|
2459
|
-
for (const char of pattern.split('')) {
|
|
2460
|
-
if (constants_1.ALLOWED_TOKENS.indexOf(char) === -1) {
|
|
2461
|
-
throw new error_1.NotAllowedError({
|
|
2462
|
-
source: this.full,
|
|
2463
|
-
operation: 'format',
|
|
2464
|
-
message: `unsupported character <${char}> from ${pattern}.`,
|
|
2465
|
-
});
|
|
2466
|
-
}
|
|
2467
|
-
group += char;
|
|
2468
|
-
if (char === '$')
|
|
2469
|
-
continue;
|
|
2470
|
-
formatted.push((_a = this.map(group)) !== null && _a !== void 0 ? _a : '');
|
|
2471
|
-
group = '';
|
|
2472
|
-
}
|
|
2473
|
-
return formatted.join('').trim();
|
|
1876
|
+
add(...values) {
|
|
1877
|
+
this.queue.push(...values);
|
|
2474
1878
|
}
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
this._config.updateOrder(types_1.NameOrder.LAST_NAME);
|
|
2481
|
-
console.log(`The name order is now changed to: ${types_1.NameOrder.LAST_NAME}`);
|
|
1879
|
+
remove(value) {
|
|
1880
|
+
const index = this.queue.indexOf(value);
|
|
1881
|
+
if (index !== -1) {
|
|
1882
|
+
this.queue.splice(index, 1);
|
|
1883
|
+
return true;
|
|
2482
1884
|
}
|
|
2483
|
-
|
|
2484
|
-
this._config.updateOrder(types_1.NameOrder.FIRST_NAME);
|
|
2485
|
-
console.log(`The name order is now changed to: ${types_1.NameOrder.FIRST_NAME}`);
|
|
2486
|
-
}
|
|
2487
|
-
}
|
|
2488
|
-
/**
|
|
2489
|
-
* Splits the name parts of a birth name.
|
|
2490
|
-
* @param separator token for the split.
|
|
2491
|
-
*/
|
|
2492
|
-
split(separator = /[' -]/g) {
|
|
2493
|
-
return this.birth.replace(separator, ' ').split(' ');
|
|
2494
|
-
}
|
|
2495
|
-
/**
|
|
2496
|
-
* Joins the name parts of a birth name.
|
|
2497
|
-
* @param separator token for the junction.
|
|
2498
|
-
*/
|
|
2499
|
-
join(separator = '') {
|
|
2500
|
-
return this.split().join(separator);
|
|
1885
|
+
return false;
|
|
2501
1886
|
}
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
*/
|
|
2505
|
-
toUpperCase() {
|
|
2506
|
-
return this.birth.toUpperCase();
|
|
2507
|
-
}
|
|
2508
|
-
/**
|
|
2509
|
-
* Transforms a birth name into lowercase
|
|
2510
|
-
*/
|
|
2511
|
-
toLowerCase() {
|
|
2512
|
-
return this.birth.toLowerCase();
|
|
1887
|
+
removeWhere(callback) {
|
|
1888
|
+
this.queue = this.queue.filter((item) => !callback(item));
|
|
2513
1889
|
}
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
*/
|
|
2517
|
-
toCamelCase() {
|
|
2518
|
-
return utils_1.decapitalize(this.toPascalCase());
|
|
1890
|
+
retainWhere(callback) {
|
|
1891
|
+
this.queue = this.queue.filter(callback);
|
|
2519
1892
|
}
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
1893
|
+
clear() {
|
|
1894
|
+
var _a, _b;
|
|
1895
|
+
if (this.instance !== null)
|
|
1896
|
+
(_a = this.preclear) === null || _a === void 0 ? void 0 : _a.call(this, this.instance);
|
|
1897
|
+
this.queue = [];
|
|
1898
|
+
(_b = this.postclear) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
1899
|
+
this.instance = null;
|
|
2527
1900
|
}
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
.map((n) => n.toLowerCase())
|
|
2534
|
-
.join('_');
|
|
1901
|
+
}
|
|
1902
|
+
class NameBuilder extends Builder {
|
|
1903
|
+
constructor(names, prebuild, postbuild, preclear, postclear) {
|
|
1904
|
+
super(prebuild, postbuild, preclear, postclear);
|
|
1905
|
+
this.add(...names);
|
|
2535
1906
|
}
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
*/
|
|
2539
|
-
toHyphenCase() {
|
|
2540
|
-
return this.split()
|
|
2541
|
-
.map((n) => n.toLowerCase())
|
|
2542
|
-
.join('-');
|
|
1907
|
+
static create(name) {
|
|
1908
|
+
return new NameBuilder(name ? [name] : []);
|
|
2543
1909
|
}
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
*/
|
|
2547
|
-
toDotCase() {
|
|
2548
|
-
return this.split()
|
|
2549
|
-
.map((n) => n.toLowerCase())
|
|
2550
|
-
.join('.');
|
|
1910
|
+
static of(...initialNames) {
|
|
1911
|
+
return new NameBuilder(initialNames);
|
|
2551
1912
|
}
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
*/
|
|
2555
|
-
toToggleCase() {
|
|
2556
|
-
return utils_1.toggleCase(this.birth);
|
|
2557
|
-
}
|
|
2558
|
-
build(parser, options) {
|
|
2559
|
-
this._config = config_1.Config.merge(options);
|
|
2560
|
-
this._fullName = parser.parse(this._config);
|
|
2561
|
-
}
|
|
2562
|
-
toParser(raw) {
|
|
2563
|
-
if (raw instanceof parser_1.Parser)
|
|
2564
|
-
return raw;
|
|
2565
|
-
if (typeof raw === 'string')
|
|
2566
|
-
return new parser_1.StringParser(raw);
|
|
2567
|
-
if (utils_1.isStringArray(raw))
|
|
2568
|
-
return new parser_1.ArrayStringParser(raw);
|
|
2569
|
-
if (utils_1.isNameArray(raw))
|
|
2570
|
-
return new parser_1.ArrayNameParser(raw);
|
|
2571
|
-
if (typeof raw === 'object')
|
|
2572
|
-
return new parser_1.NamaParser(raw);
|
|
2573
|
-
throw new error_1.InputError({
|
|
2574
|
-
source: raw,
|
|
2575
|
-
message: 'Cannot parse raw data. Review expected data types.',
|
|
2576
|
-
});
|
|
1913
|
+
static use({ names, prebuild, postbuild, preclear, postclear, }) {
|
|
1914
|
+
return new NameBuilder(names !== null && names !== void 0 ? names : [], prebuild, postbuild, preclear, postclear);
|
|
2577
1915
|
}
|
|
2578
|
-
|
|
1916
|
+
build(config) {
|
|
2579
1917
|
var _a, _b;
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
return char;
|
|
2587
|
-
case 'b':
|
|
2588
|
-
return this.birth;
|
|
2589
|
-
case 'B':
|
|
2590
|
-
return this.birth.toUpperCase();
|
|
2591
|
-
case 'f':
|
|
2592
|
-
return this.first;
|
|
2593
|
-
case 'F':
|
|
2594
|
-
return this.first.toUpperCase();
|
|
2595
|
-
case 'l':
|
|
2596
|
-
return this.last;
|
|
2597
|
-
case 'L':
|
|
2598
|
-
return this.last.toUpperCase();
|
|
2599
|
-
case 'm':
|
|
2600
|
-
case 'M':
|
|
2601
|
-
return char === 'm' ? this.middleName().join(' ') : this.middleName().join(' ').toUpperCase();
|
|
2602
|
-
case 'o':
|
|
2603
|
-
case 'O':
|
|
2604
|
-
const sep = this._config.ending ? ',' : '';
|
|
2605
|
-
const names = [];
|
|
2606
|
-
if (this.prefix)
|
|
2607
|
-
names.push(this.prefix);
|
|
2608
|
-
names.push(`${this.last},`.toUpperCase());
|
|
2609
|
-
if (this.hasMiddle) {
|
|
2610
|
-
names.push(this.first, this.middleName().join(' ') + sep);
|
|
2611
|
-
}
|
|
2612
|
-
else {
|
|
2613
|
-
names.push(this.first + sep);
|
|
2614
|
-
}
|
|
2615
|
-
if (this.suffix)
|
|
2616
|
-
names.push(this.suffix);
|
|
2617
|
-
const nama = names.join(' ').trim();
|
|
2618
|
-
return char === 'o' ? nama : nama.toUpperCase();
|
|
2619
|
-
case 'p':
|
|
2620
|
-
return this.prefix;
|
|
2621
|
-
case 'P':
|
|
2622
|
-
return (_a = this.prefix) === null || _a === void 0 ? void 0 : _a.toUpperCase();
|
|
2623
|
-
case 's':
|
|
2624
|
-
return this.suffix;
|
|
2625
|
-
case 'S':
|
|
2626
|
-
return (_b = this.suffix) === null || _b === void 0 ? void 0 : _b.toUpperCase();
|
|
2627
|
-
case '$f':
|
|
2628
|
-
case '$F':
|
|
2629
|
-
return this._fullName.firstName.initials()[0];
|
|
2630
|
-
case '$l':
|
|
2631
|
-
case '$L':
|
|
2632
|
-
return this._fullName.lastName.initials()[0];
|
|
2633
|
-
case '$m':
|
|
2634
|
-
case '$M':
|
|
2635
|
-
return this.hasMiddle ? this.middle[0] : undefined;
|
|
2636
|
-
default:
|
|
2637
|
-
return undefined;
|
|
2638
|
-
}
|
|
1918
|
+
(_a = this.prebuild) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
1919
|
+
const names = [...this.queue];
|
|
1920
|
+
validator_1.ArrayNameValidator.create().validate(names);
|
|
1921
|
+
this.instance = new namefully_1.Namefully(names, config);
|
|
1922
|
+
(_b = this.postbuild) === null || _b === void 0 ? void 0 : _b.call(this, this.instance);
|
|
1923
|
+
return this.instance;
|
|
2639
1924
|
}
|
|
2640
1925
|
}
|
|
2641
|
-
exports.
|
|
1926
|
+
exports.NameBuilder = NameBuilder;
|
|
2642
1927
|
|
|
2643
1928
|
|
|
2644
1929
|
/***/ })
|
|
2645
1930
|
/******/ ]);
|
|
2646
|
-
});
|
|
2647
|
-
//# sourceMappingURL=namefully.js.map
|
|
1931
|
+
});
|