namefully 1.2.1 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/builder.js +80 -0
- package/dist/lib/config.js +10 -4
- package/dist/lib/constants.js +3 -26
- package/dist/lib/error.js +5 -10
- package/dist/lib/full-name.js +39 -14
- package/dist/lib/index.js +3 -0
- package/dist/lib/name.js +28 -29
- package/dist/lib/namefully.js +99 -78
- package/dist/lib/parser.js +33 -43
- package/dist/lib/types.js +19 -1
- package/dist/lib/utils.js +30 -30
- package/dist/lib/validator.js +42 -72
- package/dist/types/builder.d.ts +75 -0
- package/dist/types/config.d.ts +2 -5
- package/dist/types/constants.d.ts +2 -2
- package/dist/types/error.d.ts +11 -16
- package/dist/types/full-name.d.ts +16 -13
- package/dist/types/index.d.ts +5 -1
- package/dist/types/name.d.ts +25 -26
- package/dist/types/namefully.d.ts +126 -92
- package/dist/types/parser.d.ts +11 -13
- package/dist/types/types.d.ts +19 -48
- package/dist/types/utils.d.ts +7 -7
- package/dist/types/validator.d.ts +1 -1
- package/dist/umd/namefully.js +1149 -1058
- package/dist/umd/namefully.min.js +1 -1
- package/package.json +20 -17
- package/readme.md +63 -35
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
|
/******/ ([
|
|
@@ -150,7 +150,10 @@ class Namon {
|
|
|
150
150
|
return Namon.all.has(key);
|
|
151
151
|
}
|
|
152
152
|
static cast(key) {
|
|
153
|
-
|
|
153
|
+
var _a;
|
|
154
|
+
const searchValue = String(key).toLowerCase();
|
|
155
|
+
const namon = (_a = Object.entries(Namon.aliases).find(([, list]) => list.includes(searchValue))) === null || _a === void 0 ? void 0 : _a[0];
|
|
156
|
+
return Namon.has(namon !== null && namon !== void 0 ? namon : '') ? Namon.all.get(key) : undefined;
|
|
154
157
|
}
|
|
155
158
|
toString() {
|
|
156
159
|
return `Namon.${this.key}`;
|
|
@@ -173,11 +176,26 @@ Namon.all = new Map([
|
|
|
173
176
|
[Namon.LAST_NAME.key, Namon.LAST_NAME],
|
|
174
177
|
[Namon.SUFFIX.key, Namon.SUFFIX],
|
|
175
178
|
]);
|
|
179
|
+
Namon.aliases = {
|
|
180
|
+
[Namon.PREFIX.key]: ['prefix', 'px', 'p'],
|
|
181
|
+
[Namon.FIRST_NAME.key]: ['firstname', 'first', 'fn', 'f'],
|
|
182
|
+
[Namon.MIDDLE_NAME.key]: ['middlename', 'middle', 'mid', 'mn', 'm'],
|
|
183
|
+
[Namon.LAST_NAME.key]: ['lastname', 'last', 'ln', 'l'],
|
|
184
|
+
[Namon.SUFFIX.key]: ['suffix', 'sx', 's'],
|
|
185
|
+
};
|
|
176
186
|
class Separator {
|
|
177
187
|
constructor(name, token) {
|
|
178
188
|
this.name = name;
|
|
179
189
|
this.token = token;
|
|
180
190
|
}
|
|
191
|
+
static cast(key) {
|
|
192
|
+
for (const [name, separator] of Separator.all) {
|
|
193
|
+
if (separator.token === key || name.toLowerCase() === key.toLowerCase()) {
|
|
194
|
+
return separator;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
181
199
|
toString() {
|
|
182
200
|
return `Separator.${this.name}`;
|
|
183
201
|
}
|
|
@@ -232,19 +250,14 @@ class NameError extends Error {
|
|
|
232
250
|
this.name = 'NameError';
|
|
233
251
|
}
|
|
234
252
|
get sourceAsString() {
|
|
235
|
-
let input = '';
|
|
236
|
-
if (!this.source)
|
|
237
|
-
input = '<undefined>';
|
|
238
253
|
if (typeof this.source === 'string')
|
|
239
|
-
|
|
240
|
-
if ((0, utils_1.isNameArray)(this.source))
|
|
241
|
-
input = this.source.map((n) => n.toString()).join(' ');
|
|
254
|
+
return this.source;
|
|
242
255
|
if ((0, utils_1.isStringArray)(this.source))
|
|
243
|
-
|
|
244
|
-
return
|
|
256
|
+
return this.source.join(' ');
|
|
257
|
+
return '<undefined>';
|
|
245
258
|
}
|
|
246
259
|
get hasMessage() {
|
|
247
|
-
return this.message
|
|
260
|
+
return this.message.trim().length > 0;
|
|
248
261
|
}
|
|
249
262
|
toString() {
|
|
250
263
|
let report = `${this.name} (${this.sourceAsString})`;
|
|
@@ -294,7 +307,7 @@ exports.NotAllowedError = NotAllowedError;
|
|
|
294
307
|
class UnknownError extends NameError {
|
|
295
308
|
constructor(error) {
|
|
296
309
|
super(error.source, error.message, NameErrorType.UNKNOWN);
|
|
297
|
-
this.origin = error.
|
|
310
|
+
this.origin = error.origin;
|
|
298
311
|
this.name = 'UnknownError';
|
|
299
312
|
}
|
|
300
313
|
toString() {
|
|
@@ -314,10 +327,9 @@ exports.UnknownError = UnknownError;
|
|
|
314
327
|
"use strict";
|
|
315
328
|
|
|
316
329
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
317
|
-
exports.
|
|
318
|
-
const constants_1 = __webpack_require__(4);
|
|
319
|
-
const name_1 = __webpack_require__(3);
|
|
330
|
+
exports.isStringArray = exports.toggleCase = exports.decapitalize = exports.capitalize = exports.NameIndex = void 0;
|
|
320
331
|
const types_1 = __webpack_require__(0);
|
|
332
|
+
const constants_1 = __webpack_require__(4);
|
|
321
333
|
class NameIndex {
|
|
322
334
|
static get min() {
|
|
323
335
|
return constants_1.MIN_NUMBER_OF_NAME_PARTS;
|
|
@@ -331,21 +343,22 @@ class NameIndex {
|
|
|
331
343
|
this.middleName = middleName;
|
|
332
344
|
this.lastName = lastName;
|
|
333
345
|
this.suffix = suffix;
|
|
346
|
+
this.json = this.toJson;
|
|
334
347
|
}
|
|
335
348
|
static base() {
|
|
336
|
-
return new
|
|
349
|
+
return new NameIndex(-1, 0, -1, 1, -1);
|
|
337
350
|
}
|
|
338
351
|
static when(order, count = 2) {
|
|
339
352
|
if (order === types_1.NameOrder.FIRST_NAME) {
|
|
340
353
|
switch (count) {
|
|
341
354
|
case 2:
|
|
342
|
-
return new
|
|
355
|
+
return new NameIndex(-1, 0, -1, 1, -1);
|
|
343
356
|
case 3:
|
|
344
|
-
return new
|
|
357
|
+
return new NameIndex(-1, 0, 1, 2, -1);
|
|
345
358
|
case 4:
|
|
346
|
-
return new
|
|
359
|
+
return new NameIndex(0, 1, 2, 3, -1);
|
|
347
360
|
case 5:
|
|
348
|
-
return new
|
|
361
|
+
return new NameIndex(0, 1, 2, 3, 4);
|
|
349
362
|
default:
|
|
350
363
|
return NameIndex.base();
|
|
351
364
|
}
|
|
@@ -353,57 +366,57 @@ class NameIndex {
|
|
|
353
366
|
else {
|
|
354
367
|
switch (count) {
|
|
355
368
|
case 2:
|
|
356
|
-
return new
|
|
369
|
+
return new NameIndex(-1, 1, -1, 0, -1);
|
|
357
370
|
case 3:
|
|
358
|
-
return new
|
|
371
|
+
return new NameIndex(-1, 1, 2, 0, -1);
|
|
359
372
|
case 4:
|
|
360
|
-
return new
|
|
373
|
+
return new NameIndex(0, 2, 3, 1, -1);
|
|
361
374
|
case 5:
|
|
362
|
-
return new
|
|
375
|
+
return new NameIndex(0, 2, 3, 1, 4);
|
|
363
376
|
default:
|
|
364
377
|
return NameIndex.base();
|
|
365
378
|
}
|
|
366
379
|
}
|
|
367
380
|
}
|
|
381
|
+
static only({ prefix = -1, firstName, middleName = -1, lastName, suffix = -1 }) {
|
|
382
|
+
return new NameIndex(prefix, firstName, middleName, lastName, suffix);
|
|
383
|
+
}
|
|
384
|
+
toJson() {
|
|
385
|
+
return {
|
|
386
|
+
prefix: this.prefix,
|
|
387
|
+
firstName: this.firstName,
|
|
388
|
+
middleName: this.middleName,
|
|
389
|
+
lastName: this.lastName,
|
|
390
|
+
suffix: this.suffix,
|
|
391
|
+
};
|
|
392
|
+
}
|
|
368
393
|
}
|
|
369
394
|
exports.NameIndex = NameIndex;
|
|
370
395
|
function capitalize(str, range = types_1.CapsRange.INITIAL) {
|
|
371
396
|
if (!str || range === types_1.CapsRange.NONE)
|
|
372
397
|
return str;
|
|
373
|
-
const initial = str[0].toUpperCase();
|
|
374
|
-
const rest = str.slice(1).toLowerCase();
|
|
398
|
+
const [initial, rest] = [str[0].toUpperCase(), str.slice(1).toLowerCase()];
|
|
375
399
|
return range === types_1.CapsRange.INITIAL ? initial.concat(rest) : str.toUpperCase();
|
|
376
400
|
}
|
|
377
401
|
exports.capitalize = capitalize;
|
|
378
402
|
function decapitalize(str, range = types_1.CapsRange.INITIAL) {
|
|
379
403
|
if (!str || range === types_1.CapsRange.NONE)
|
|
380
404
|
return str;
|
|
381
|
-
const initial = str[0].toLowerCase();
|
|
382
|
-
const rest = str.slice(1);
|
|
405
|
+
const [initial, rest] = [str[0].toLowerCase(), str.slice(1)];
|
|
383
406
|
return range === types_1.CapsRange.INITIAL ? initial.concat(rest) : str.toLowerCase();
|
|
384
407
|
}
|
|
385
408
|
exports.decapitalize = decapitalize;
|
|
386
409
|
function toggleCase(str) {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}
|
|
392
|
-
else {
|
|
393
|
-
chars.push(c.toUpperCase());
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
return chars.join('');
|
|
410
|
+
return str
|
|
411
|
+
.split('')
|
|
412
|
+
.map((c) => (c === c.toUpperCase() ? c.toLowerCase() : c.toUpperCase()))
|
|
413
|
+
.join('');
|
|
397
414
|
}
|
|
398
415
|
exports.toggleCase = toggleCase;
|
|
399
416
|
function isStringArray(value) {
|
|
400
417
|
return Array.isArray(value) && value.length > 0 && value.every((e) => typeof e === 'string');
|
|
401
418
|
}
|
|
402
419
|
exports.isStringArray = isStringArray;
|
|
403
|
-
function isNameArray(value) {
|
|
404
|
-
return Array.isArray(value) && value.length > 0 && value.every((e) => e instanceof name_1.Name);
|
|
405
|
-
}
|
|
406
|
-
exports.isNameArray = isNameArray;
|
|
407
420
|
|
|
408
421
|
|
|
409
422
|
/***/ }),
|
|
@@ -425,7 +438,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
425
438
|
};
|
|
426
439
|
var _Name_namon, _FirstName_more, _LastName_mother;
|
|
427
440
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
428
|
-
exports.LastName = exports.FirstName = exports.Name = void 0;
|
|
441
|
+
exports.isNameArray = exports.LastName = exports.FirstName = exports.Name = void 0;
|
|
429
442
|
const error_1 = __webpack_require__(1);
|
|
430
443
|
const types_1 = __webpack_require__(0);
|
|
431
444
|
const utils_1 = __webpack_require__(2);
|
|
@@ -465,19 +478,19 @@ class Name {
|
|
|
465
478
|
return this.type === types_1.Namon.SUFFIX;
|
|
466
479
|
}
|
|
467
480
|
static prefix(value) {
|
|
468
|
-
return new
|
|
481
|
+
return new Name(value, types_1.Namon.PREFIX);
|
|
469
482
|
}
|
|
470
483
|
static first(value) {
|
|
471
|
-
return new
|
|
484
|
+
return new Name(value, types_1.Namon.FIRST_NAME);
|
|
472
485
|
}
|
|
473
486
|
static middle(value) {
|
|
474
|
-
return new
|
|
487
|
+
return new Name(value, types_1.Namon.MIDDLE_NAME);
|
|
475
488
|
}
|
|
476
489
|
static last(value) {
|
|
477
|
-
return new
|
|
490
|
+
return new Name(value, types_1.Namon.LAST_NAME);
|
|
478
491
|
}
|
|
479
492
|
static suffix(value) {
|
|
480
|
-
return new
|
|
493
|
+
return new Name(value, types_1.Namon.SUFFIX);
|
|
481
494
|
}
|
|
482
495
|
initials() {
|
|
483
496
|
return [this.initial];
|
|
@@ -497,8 +510,8 @@ class Name {
|
|
|
497
510
|
return this;
|
|
498
511
|
}
|
|
499
512
|
validate(name) {
|
|
500
|
-
if (
|
|
501
|
-
throw new error_1.InputError({ source: name, message: 'must be
|
|
513
|
+
if (typeof name === 'string' && name.trim().length < 1) {
|
|
514
|
+
throw new error_1.InputError({ source: name, message: 'must be 1+ characters' });
|
|
502
515
|
}
|
|
503
516
|
}
|
|
504
517
|
}
|
|
@@ -508,7 +521,7 @@ class FirstName extends Name {
|
|
|
508
521
|
constructor(value, ...more) {
|
|
509
522
|
super(value, types_1.Namon.FIRST_NAME);
|
|
510
523
|
_FirstName_more.set(this, void 0);
|
|
511
|
-
more.forEach(
|
|
524
|
+
more.forEach(this.validate);
|
|
512
525
|
__classPrivateFieldSet(this, _FirstName_more, more, "f");
|
|
513
526
|
}
|
|
514
527
|
get hasMore() {
|
|
@@ -519,9 +532,8 @@ class FirstName extends Name {
|
|
|
519
532
|
}
|
|
520
533
|
get asNames() {
|
|
521
534
|
const names = [Name.first(this.value)];
|
|
522
|
-
if (this.hasMore)
|
|
523
|
-
names.push(...__classPrivateFieldGet(this, _FirstName_more, "f").map(
|
|
524
|
-
}
|
|
535
|
+
if (this.hasMore)
|
|
536
|
+
names.push(...__classPrivateFieldGet(this, _FirstName_more, "f").map(Name.first));
|
|
525
537
|
return names;
|
|
526
538
|
}
|
|
527
539
|
get more() {
|
|
@@ -532,9 +544,8 @@ class FirstName extends Name {
|
|
|
532
544
|
}
|
|
533
545
|
initials(withMore = false) {
|
|
534
546
|
const inits = [this.initial];
|
|
535
|
-
if (withMore && this.hasMore)
|
|
547
|
+
if (withMore && this.hasMore)
|
|
536
548
|
inits.push(...__classPrivateFieldGet(this, _FirstName_more, "f").map((n) => n[0]));
|
|
537
|
-
}
|
|
538
549
|
return inits;
|
|
539
550
|
}
|
|
540
551
|
caps(range) {
|
|
@@ -553,7 +564,7 @@ class FirstName extends Name {
|
|
|
553
564
|
}
|
|
554
565
|
copyWith(values) {
|
|
555
566
|
var _a, _b;
|
|
556
|
-
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")));
|
|
567
|
+
return new FirstName((_a = values === null || values === void 0 ? void 0 : values.first) !== null && _a !== void 0 ? _a : this.value, ...((_b = values === null || values === void 0 ? void 0 : values.more) !== null && _b !== void 0 ? _b : __classPrivateFieldGet(this, _FirstName_more, "f")));
|
|
557
568
|
}
|
|
558
569
|
}
|
|
559
570
|
exports.FirstName = FirstName;
|
|
@@ -581,9 +592,8 @@ class LastName extends Name {
|
|
|
581
592
|
}
|
|
582
593
|
get asNames() {
|
|
583
594
|
const names = [Name.last(this.value)];
|
|
584
|
-
if (this
|
|
595
|
+
if (__classPrivateFieldGet(this, _LastName_mother, "f"))
|
|
585
596
|
names.push(Name.last(__classPrivateFieldGet(this, _LastName_mother, "f")));
|
|
586
|
-
}
|
|
587
597
|
return names;
|
|
588
598
|
}
|
|
589
599
|
toString(format) {
|
|
@@ -596,39 +606,37 @@ class LastName extends Name {
|
|
|
596
606
|
return (_a = this.mother) !== null && _a !== void 0 ? _a : '';
|
|
597
607
|
case types_1.Surname.HYPHENATED:
|
|
598
608
|
return this.hasMother ? `${this.value}-${__classPrivateFieldGet(this, _LastName_mother, "f")}` : this.value;
|
|
599
|
-
|
|
609
|
+
default:
|
|
600
610
|
return this.hasMother ? `${this.value} ${__classPrivateFieldGet(this, _LastName_mother, "f")}` : this.value;
|
|
601
611
|
}
|
|
602
612
|
}
|
|
603
613
|
initials(format) {
|
|
604
|
-
format = format || this.format;
|
|
605
614
|
const inits = [];
|
|
606
|
-
switch (format) {
|
|
607
|
-
case types_1.Surname.MOTHER:
|
|
608
|
-
if (this.hasMother)
|
|
609
|
-
inits.push(__classPrivateFieldGet(this, _LastName_mother, "f")[0]);
|
|
610
|
-
break;
|
|
615
|
+
switch (format !== null && format !== void 0 ? format : this.format) {
|
|
611
616
|
case types_1.Surname.HYPHENATED:
|
|
612
617
|
case types_1.Surname.ALL:
|
|
613
618
|
inits.push(this.initial);
|
|
614
|
-
if (this
|
|
619
|
+
if (__classPrivateFieldGet(this, _LastName_mother, "f"))
|
|
620
|
+
inits.push(__classPrivateFieldGet(this, _LastName_mother, "f")[0]);
|
|
621
|
+
break;
|
|
622
|
+
case types_1.Surname.MOTHER:
|
|
623
|
+
if (__classPrivateFieldGet(this, _LastName_mother, "f"))
|
|
615
624
|
inits.push(__classPrivateFieldGet(this, _LastName_mother, "f")[0]);
|
|
616
625
|
break;
|
|
617
|
-
case types_1.Surname.FATHER:
|
|
618
626
|
default:
|
|
619
627
|
inits.push(this.initial);
|
|
620
628
|
}
|
|
621
629
|
return inits;
|
|
622
630
|
}
|
|
623
631
|
caps(range) {
|
|
624
|
-
range
|
|
632
|
+
range !== null && range !== void 0 ? range : (range = this.capsRange);
|
|
625
633
|
this.value = (0, utils_1.capitalize)(this.value, range);
|
|
626
634
|
if (this.hasMother)
|
|
627
635
|
__classPrivateFieldSet(this, _LastName_mother, (0, utils_1.capitalize)(__classPrivateFieldGet(this, _LastName_mother, "f"), range), "f");
|
|
628
636
|
return this;
|
|
629
637
|
}
|
|
630
638
|
decaps(range) {
|
|
631
|
-
range
|
|
639
|
+
range !== null && range !== void 0 ? range : (range = this.capsRange);
|
|
632
640
|
this.value = (0, utils_1.decapitalize)(this.value, range);
|
|
633
641
|
if (this.hasMother)
|
|
634
642
|
__classPrivateFieldSet(this, _LastName_mother, (0, utils_1.decapitalize)(__classPrivateFieldGet(this, _LastName_mother, "f"), range), "f");
|
|
@@ -636,11 +644,15 @@ class LastName extends Name {
|
|
|
636
644
|
}
|
|
637
645
|
copyWith(values) {
|
|
638
646
|
var _a, _b, _c;
|
|
639
|
-
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);
|
|
647
|
+
return new LastName((_a = values === null || values === void 0 ? void 0 : values.father) !== null && _a !== void 0 ? _a : this.value, (_b = values === null || values === void 0 ? void 0 : values.mother) !== null && _b !== void 0 ? _b : this.mother, (_c = values === null || values === void 0 ? void 0 : values.format) !== null && _c !== void 0 ? _c : this.format);
|
|
640
648
|
}
|
|
641
649
|
}
|
|
642
650
|
exports.LastName = LastName;
|
|
643
651
|
_LastName_mother = new WeakMap();
|
|
652
|
+
function isNameArray(value) {
|
|
653
|
+
return Array.isArray(value) && value.length > 0 && value.every((e) => e instanceof Name);
|
|
654
|
+
}
|
|
655
|
+
exports.isNameArray = isNameArray;
|
|
644
656
|
|
|
645
657
|
|
|
646
658
|
/***/ }),
|
|
@@ -650,34 +662,11 @@ _LastName_mother = new WeakMap();
|
|
|
650
662
|
"use strict";
|
|
651
663
|
|
|
652
664
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
653
|
-
exports.
|
|
654
|
-
exports.VERSION = '1.
|
|
665
|
+
exports.ALLOWED_FORMAT_TOKENS = exports.MAX_NUMBER_OF_NAME_PARTS = exports.MIN_NUMBER_OF_NAME_PARTS = exports.VERSION = void 0;
|
|
666
|
+
exports.VERSION = '1.3.1';
|
|
655
667
|
exports.MIN_NUMBER_OF_NAME_PARTS = 2;
|
|
656
668
|
exports.MAX_NUMBER_OF_NAME_PARTS = 5;
|
|
657
|
-
exports.
|
|
658
|
-
'.',
|
|
659
|
-
',',
|
|
660
|
-
' ',
|
|
661
|
-
'-',
|
|
662
|
-
'_',
|
|
663
|
-
'b',
|
|
664
|
-
'B',
|
|
665
|
-
'f',
|
|
666
|
-
'F',
|
|
667
|
-
'l',
|
|
668
|
-
'L',
|
|
669
|
-
'm',
|
|
670
|
-
'M',
|
|
671
|
-
'n',
|
|
672
|
-
'N',
|
|
673
|
-
'o',
|
|
674
|
-
'O',
|
|
675
|
-
'p',
|
|
676
|
-
'P',
|
|
677
|
-
's',
|
|
678
|
-
'S',
|
|
679
|
-
'$',
|
|
680
|
-
];
|
|
669
|
+
exports.ALLOWED_FORMAT_TOKENS = ` .,_-()[]<>'"bBfFlLmMnNoOpPsS$`;
|
|
681
670
|
|
|
682
671
|
|
|
683
672
|
/***/ }),
|
|
@@ -686,6 +675,15 @@ exports.ALLOWED_TOKENS = [
|
|
|
686
675
|
|
|
687
676
|
"use strict";
|
|
688
677
|
|
|
678
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
679
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
680
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
681
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
682
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
683
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
684
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
685
|
+
});
|
|
686
|
+
};
|
|
689
687
|
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
690
688
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
691
689
|
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");
|
|
@@ -697,540 +695,420 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
697
695
|
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");
|
|
698
696
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
699
697
|
};
|
|
700
|
-
var
|
|
698
|
+
var _Namefully_instances, _Namefully_fullName, _Namefully_toParser, _Namefully_map;
|
|
701
699
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
702
|
-
exports.
|
|
700
|
+
exports.Namefully = void 0;
|
|
701
|
+
const constants_1 = __webpack_require__(4);
|
|
702
|
+
const name_1 = __webpack_require__(3);
|
|
703
|
+
const error_1 = __webpack_require__(1);
|
|
704
|
+
const utils_1 = __webpack_require__(2);
|
|
703
705
|
const types_1 = __webpack_require__(0);
|
|
704
|
-
const
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
706
|
+
const parser_1 = __webpack_require__(8);
|
|
707
|
+
class Namefully {
|
|
708
|
+
constructor(names, options) {
|
|
709
|
+
_Namefully_instances.add(this);
|
|
710
|
+
_Namefully_fullName.set(this, void 0);
|
|
711
|
+
this.json = this.toJson;
|
|
712
|
+
__classPrivateFieldSet(this, _Namefully_fullName, __classPrivateFieldGet(this, _Namefully_instances, "m", _Namefully_toParser).call(this, names).parse(options), "f");
|
|
709
713
|
}
|
|
710
|
-
|
|
711
|
-
|
|
714
|
+
static tryParse(text, index) {
|
|
715
|
+
try {
|
|
716
|
+
return new Namefully(parser_1.Parser.build(text, index));
|
|
717
|
+
}
|
|
718
|
+
catch (_a) {
|
|
719
|
+
return undefined;
|
|
720
|
+
}
|
|
712
721
|
}
|
|
713
|
-
|
|
714
|
-
return
|
|
722
|
+
static parse(text, index) {
|
|
723
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
724
|
+
return parser_1.Parser.buildAsync(text, index).then((parser) => new Namefully(parser));
|
|
725
|
+
});
|
|
715
726
|
}
|
|
716
|
-
get
|
|
717
|
-
return __classPrivateFieldGet(this,
|
|
727
|
+
get config() {
|
|
728
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").config;
|
|
718
729
|
}
|
|
719
|
-
get
|
|
720
|
-
return
|
|
730
|
+
get length() {
|
|
731
|
+
return this.birth.length;
|
|
721
732
|
}
|
|
722
|
-
get
|
|
723
|
-
|
|
733
|
+
get prefix() {
|
|
734
|
+
var _a;
|
|
735
|
+
return (_a = __classPrivateFieldGet(this, _Namefully_fullName, "f").prefix) === null || _a === void 0 ? void 0 : _a.toString();
|
|
724
736
|
}
|
|
725
|
-
get
|
|
726
|
-
return
|
|
737
|
+
get first() {
|
|
738
|
+
return this.firstName();
|
|
727
739
|
}
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
_Config_name.set(this, void 0);
|
|
731
|
-
_Config_orderedBy.set(this, void 0);
|
|
732
|
-
_Config_separator.set(this, void 0);
|
|
733
|
-
_Config_title.set(this, void 0);
|
|
734
|
-
_Config_ending.set(this, void 0);
|
|
735
|
-
_Config_bypass.set(this, void 0);
|
|
736
|
-
_Config_surname.set(this, void 0);
|
|
737
|
-
__classPrivateFieldSet(this, _Config_name, name, "f");
|
|
738
|
-
__classPrivateFieldSet(this, _Config_orderedBy, orderedBy, "f");
|
|
739
|
-
__classPrivateFieldSet(this, _Config_separator, separator, "f");
|
|
740
|
-
__classPrivateFieldSet(this, _Config_title, title, "f");
|
|
741
|
-
__classPrivateFieldSet(this, _Config_ending, ending, "f");
|
|
742
|
-
__classPrivateFieldSet(this, _Config_bypass, bypass, "f");
|
|
743
|
-
__classPrivateFieldSet(this, _Config_surname, surname, "f");
|
|
740
|
+
get middle() {
|
|
741
|
+
return this.hasMiddle ? this.middleName()[0] : undefined;
|
|
744
742
|
}
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
_a.cache.set(name, new this(name));
|
|
748
|
-
return _a.cache.get(name);
|
|
743
|
+
get hasMiddle() {
|
|
744
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").has(types_1.Namon.MIDDLE_NAME);
|
|
749
745
|
}
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
if (!other) {
|
|
753
|
-
return _a.create();
|
|
754
|
-
}
|
|
755
|
-
else {
|
|
756
|
-
const config = _a.create(other.name);
|
|
757
|
-
__classPrivateFieldSet(config, _Config_orderedBy, (_b = other.orderedBy) !== null && _b !== void 0 ? _b : config.orderedBy, "f");
|
|
758
|
-
__classPrivateFieldSet(config, _Config_separator, (_c = other.separator) !== null && _c !== void 0 ? _c : config.separator, "f");
|
|
759
|
-
__classPrivateFieldSet(config, _Config_title, (_d = other.title) !== null && _d !== void 0 ? _d : config.title, "f");
|
|
760
|
-
__classPrivateFieldSet(config, _Config_ending, (_e = other.ending) !== null && _e !== void 0 ? _e : config.ending, "f");
|
|
761
|
-
__classPrivateFieldSet(config, _Config_bypass, (_f = other.bypass) !== null && _f !== void 0 ? _f : config.bypass, "f");
|
|
762
|
-
__classPrivateFieldSet(config, _Config_surname, (_g = other.surname) !== null && _g !== void 0 ? _g : config.surname, "f");
|
|
763
|
-
return config;
|
|
764
|
-
}
|
|
746
|
+
get last() {
|
|
747
|
+
return this.lastName();
|
|
765
748
|
}
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
__classPrivateFieldSet(config, _Config_orderedBy, orderedBy !== null && orderedBy !== void 0 ? orderedBy : this.orderedBy, "f");
|
|
770
|
-
__classPrivateFieldSet(config, _Config_separator, separator !== null && separator !== void 0 ? separator : this.separator, "f");
|
|
771
|
-
__classPrivateFieldSet(config, _Config_title, title !== null && title !== void 0 ? title : this.title, "f");
|
|
772
|
-
__classPrivateFieldSet(config, _Config_ending, ending !== null && ending !== void 0 ? ending : this.ending, "f");
|
|
773
|
-
__classPrivateFieldSet(config, _Config_bypass, bypass !== null && bypass !== void 0 ? bypass : this.bypass, "f");
|
|
774
|
-
__classPrivateFieldSet(config, _Config_surname, surname !== null && surname !== void 0 ? surname : this.surname, "f");
|
|
775
|
-
return config;
|
|
749
|
+
get suffix() {
|
|
750
|
+
var _a;
|
|
751
|
+
return (_a = __classPrivateFieldGet(this, _Namefully_fullName, "f").suffix) === null || _a === void 0 ? void 0 : _a.toString();
|
|
776
752
|
}
|
|
777
|
-
|
|
778
|
-
return this.
|
|
753
|
+
get birth() {
|
|
754
|
+
return this.birthName();
|
|
779
755
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
__classPrivateFieldSet(this, _Config_separator, types_1.Separator.SPACE, "f");
|
|
783
|
-
__classPrivateFieldSet(this, _Config_title, types_1.Title.UK, "f");
|
|
784
|
-
__classPrivateFieldSet(this, _Config_ending, false, "f");
|
|
785
|
-
__classPrivateFieldSet(this, _Config_bypass, true, "f");
|
|
786
|
-
__classPrivateFieldSet(this, _Config_surname, types_1.Surname.FATHER, "f");
|
|
787
|
-
_a.cache.set(this.name, this);
|
|
756
|
+
get short() {
|
|
757
|
+
return this.shorten();
|
|
788
758
|
}
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
__classPrivateFieldSet(_a.cache.get(this.name), _Config_orderedBy, order, "f");
|
|
792
|
-
}
|
|
759
|
+
get long() {
|
|
760
|
+
return this.birth;
|
|
793
761
|
}
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
_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) {
|
|
797
|
-
return name === this.name || _a.cache.has(name) ? __classPrivateFieldGet(this, _Config_instances, "m", _Config_genNewName).call(this, name + copyAlias) : name;
|
|
798
|
-
};
|
|
799
|
-
Config.cache = new Map();
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
/***/ }),
|
|
803
|
-
/* 6 */
|
|
804
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
805
|
-
|
|
806
|
-
"use strict";
|
|
807
|
-
|
|
808
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
809
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
810
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
811
|
-
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");
|
|
812
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
813
|
-
};
|
|
814
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
815
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
816
|
-
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");
|
|
817
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
818
|
-
};
|
|
819
|
-
var _FullName_prefix, _FullName_firstName, _FullName_middleName, _FullName_lastName, _FullName_suffix, _FullName_config;
|
|
820
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
821
|
-
exports.FullName = void 0;
|
|
822
|
-
const config_1 = __webpack_require__(5);
|
|
823
|
-
const error_1 = __webpack_require__(1);
|
|
824
|
-
const name_1 = __webpack_require__(3);
|
|
825
|
-
const types_1 = __webpack_require__(0);
|
|
826
|
-
const validator_1 = __webpack_require__(7);
|
|
827
|
-
class FullName {
|
|
828
|
-
constructor(options) {
|
|
829
|
-
_FullName_prefix.set(this, void 0);
|
|
830
|
-
_FullName_firstName.set(this, void 0);
|
|
831
|
-
_FullName_middleName.set(this, []);
|
|
832
|
-
_FullName_lastName.set(this, void 0);
|
|
833
|
-
_FullName_suffix.set(this, void 0);
|
|
834
|
-
_FullName_config.set(this, void 0);
|
|
835
|
-
__classPrivateFieldSet(this, _FullName_config, config_1.Config.merge(options), "f");
|
|
762
|
+
get full() {
|
|
763
|
+
return this.fullName();
|
|
836
764
|
}
|
|
837
|
-
get
|
|
838
|
-
return
|
|
765
|
+
get public() {
|
|
766
|
+
return this.format('f $l');
|
|
839
767
|
}
|
|
840
|
-
get
|
|
841
|
-
return
|
|
768
|
+
get salutation() {
|
|
769
|
+
return this.format('p l');
|
|
842
770
|
}
|
|
843
|
-
get
|
|
844
|
-
return __classPrivateFieldGet(this,
|
|
771
|
+
get parts() {
|
|
772
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").toIterable();
|
|
845
773
|
}
|
|
846
|
-
get
|
|
847
|
-
return
|
|
774
|
+
get size() {
|
|
775
|
+
return Array.from(this.parts).length;
|
|
848
776
|
}
|
|
849
|
-
|
|
850
|
-
|
|
777
|
+
*[(_Namefully_fullName = new WeakMap(), _Namefully_instances = new WeakSet(), Symbol.iterator)]() {
|
|
778
|
+
yield* __classPrivateFieldGet(this, _Namefully_fullName, "f").toIterable(true);
|
|
851
779
|
}
|
|
852
|
-
|
|
853
|
-
return
|
|
780
|
+
toString() {
|
|
781
|
+
return this.full;
|
|
854
782
|
}
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
throw new error_1.UnknownError({
|
|
869
|
-
source: Object.values(json).join(' '),
|
|
870
|
-
message: 'could not parse JSON content',
|
|
871
|
-
error,
|
|
872
|
-
});
|
|
873
|
-
}
|
|
783
|
+
get(key) {
|
|
784
|
+
const namon = typeof key === 'string' ? types_1.Namon.cast(key) : key;
|
|
785
|
+
if (namon === null || namon === void 0 ? void 0 : namon.equal(types_1.Namon.PREFIX))
|
|
786
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").prefix;
|
|
787
|
+
if (namon === null || namon === void 0 ? void 0 : namon.equal(types_1.Namon.FIRST_NAME))
|
|
788
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName;
|
|
789
|
+
if (namon === null || namon === void 0 ? void 0 : namon.equal(types_1.Namon.MIDDLE_NAME))
|
|
790
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").middleName;
|
|
791
|
+
if (namon === null || namon === void 0 ? void 0 : namon.equal(types_1.Namon.LAST_NAME))
|
|
792
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName;
|
|
793
|
+
if (namon === null || namon === void 0 ? void 0 : namon.equal(types_1.Namon.SUFFIX))
|
|
794
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").suffix;
|
|
795
|
+
return undefined;
|
|
874
796
|
}
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
return this;
|
|
878
|
-
if (!__classPrivateFieldGet(this, _FullName_config, "f").bypass)
|
|
879
|
-
validator_1.Validators.prefix.validate(name);
|
|
880
|
-
const prefix = name instanceof name_1.Name ? name.value : name;
|
|
881
|
-
__classPrivateFieldSet(this, _FullName_prefix, name_1.Name.prefix(__classPrivateFieldGet(this, _FullName_config, "f").title === types_1.Title.US ? `${prefix}.` : prefix), "f");
|
|
882
|
-
return this;
|
|
797
|
+
equal(other) {
|
|
798
|
+
return this.toString() === other.toString();
|
|
883
799
|
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
if (!__classPrivateFieldGet(this, _FullName_config, "f").bypass)
|
|
892
|
-
validator_1.Validators.lastName.validate(name);
|
|
893
|
-
__classPrivateFieldSet(this, _FullName_lastName, name instanceof name_1.LastName ? name : new name_1.LastName(name), "f");
|
|
894
|
-
return this;
|
|
895
|
-
}
|
|
896
|
-
setMiddleName(names) {
|
|
897
|
-
if (!Array.isArray(names))
|
|
898
|
-
return this;
|
|
899
|
-
if (!__classPrivateFieldGet(this, _FullName_config, "f").bypass)
|
|
900
|
-
validator_1.Validators.middleName.validate(names);
|
|
901
|
-
__classPrivateFieldSet(this, _FullName_middleName, names.map((name) => (name instanceof name_1.Name ? name : name_1.Name.middle(name))), "f");
|
|
902
|
-
return this;
|
|
800
|
+
deepEqual(other) {
|
|
801
|
+
const others = Array.from(other.parts);
|
|
802
|
+
for (const part of this.parts) {
|
|
803
|
+
if (!others.some((name) => name.equal(part)))
|
|
804
|
+
return false;
|
|
805
|
+
}
|
|
806
|
+
return true;
|
|
903
807
|
}
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
808
|
+
toJson() {
|
|
809
|
+
return {
|
|
810
|
+
prefix: this.prefix,
|
|
811
|
+
firstName: this.first,
|
|
812
|
+
middleName: this.middleName(),
|
|
813
|
+
lastName: this.last,
|
|
814
|
+
suffix: this.suffix,
|
|
815
|
+
};
|
|
911
816
|
}
|
|
912
817
|
has(namon) {
|
|
913
|
-
|
|
914
|
-
return !!__classPrivateFieldGet(this, _FullName_prefix, "f");
|
|
915
|
-
if (namon.equal(types_1.Namon.SUFFIX))
|
|
916
|
-
return !!__classPrivateFieldGet(this, _FullName_suffix, "f");
|
|
917
|
-
return namon.equal(types_1.Namon.MIDDLE_NAME) ? __classPrivateFieldGet(this, _FullName_middleName, "f").length > 0 : true;
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
exports.FullName = FullName;
|
|
921
|
-
_FullName_prefix = new WeakMap(), _FullName_firstName = new WeakMap(), _FullName_middleName = new WeakMap(), _FullName_lastName = new WeakMap(), _FullName_suffix = new WeakMap(), _FullName_config = new WeakMap();
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
/***/ }),
|
|
925
|
-
/* 7 */
|
|
926
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
927
|
-
|
|
928
|
-
"use strict";
|
|
929
|
-
|
|
930
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
931
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
932
|
-
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");
|
|
933
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
934
|
-
};
|
|
935
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
936
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
937
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
938
|
-
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");
|
|
939
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
940
|
-
};
|
|
941
|
-
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;
|
|
942
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
943
|
-
exports.Validators = exports.ArrayNameValidator = exports.ArrayStringValidator = exports.NamaValidator = void 0;
|
|
944
|
-
const constants_1 = __webpack_require__(4);
|
|
945
|
-
const error_1 = __webpack_require__(1);
|
|
946
|
-
const name_1 = __webpack_require__(3);
|
|
947
|
-
const types_1 = __webpack_require__(0);
|
|
948
|
-
const utils_1 = __webpack_require__(2);
|
|
949
|
-
class ValidationRule {
|
|
950
|
-
}
|
|
951
|
-
ValidationRule.base = /[a-zA-Z\u00C0-\u00D6\u00D8-\u00f6\u00f8-\u00ff\u0400-\u04FFΆ-ωΑ-ώ]/;
|
|
952
|
-
ValidationRule.namon = new RegExp(`^${ValidationRule.base.source}+(([' -]${ValidationRule.base.source})?${ValidationRule.base.source}*)*$`);
|
|
953
|
-
ValidationRule.firstName = ValidationRule.namon;
|
|
954
|
-
ValidationRule.middleName = new RegExp(`^${ValidationRule.base.source}+(([' -]${ValidationRule.base.source})?${ValidationRule.base.source}*)*$`);
|
|
955
|
-
ValidationRule.lastName = ValidationRule.namon;
|
|
956
|
-
class ArrayValidator {
|
|
957
|
-
validate(values) {
|
|
958
|
-
if (values.length === 0 || values.length < constants_1.MIN_NUMBER_OF_NAME_PARTS || values.length > constants_1.MAX_NUMBER_OF_NAME_PARTS) {
|
|
959
|
-
throw new error_1.InputError({
|
|
960
|
-
source: values.map((n) => n.toString()),
|
|
961
|
-
message: `expecting a list of ${constants_1.MIN_NUMBER_OF_NAME_PARTS}-${constants_1.MIN_NUMBER_OF_NAME_PARTS} elements`,
|
|
962
|
-
});
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
class NamonValidator {
|
|
967
|
-
static create() {
|
|
968
|
-
return __classPrivateFieldGet(this, _a, "f", _NamonValidator_validator) || (__classPrivateFieldSet(this, _a, new this(), "f", _NamonValidator_validator));
|
|
818
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").has(namon);
|
|
969
819
|
}
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
source: value,
|
|
978
|
-
nameType: 'namon',
|
|
979
|
-
message: 'invalid content',
|
|
980
|
-
});
|
|
981
|
-
}
|
|
820
|
+
fullName(orderedBy) {
|
|
821
|
+
const sep = this.config.ending ? ',' : '';
|
|
822
|
+
const names = [];
|
|
823
|
+
if (this.prefix)
|
|
824
|
+
names.push(this.prefix);
|
|
825
|
+
if ((orderedBy !== null && orderedBy !== void 0 ? orderedBy : this.config.orderedBy) === types_1.NameOrder.FIRST_NAME) {
|
|
826
|
+
names.push(this.first, ...this.middleName(), this.last + sep);
|
|
982
827
|
}
|
|
983
828
|
else {
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
}
|
|
829
|
+
names.push(this.last);
|
|
830
|
+
if (this.hasMiddle) {
|
|
831
|
+
names.push(this.first, this.middleName().join(' ') + sep);
|
|
832
|
+
}
|
|
833
|
+
else {
|
|
834
|
+
names.push(this.first + sep);
|
|
835
|
+
}
|
|
988
836
|
}
|
|
837
|
+
if (this.suffix)
|
|
838
|
+
names.push(this.suffix);
|
|
839
|
+
return names.join(' ').trim();
|
|
989
840
|
}
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
return __classPrivateFieldGet(this, _b, "f", _FirstNameValidator_validator) || (__classPrivateFieldSet(this, _b, new this(), "f", _FirstNameValidator_validator));
|
|
841
|
+
birthName(orderedBy) {
|
|
842
|
+
orderedBy !== null && orderedBy !== void 0 ? orderedBy : (orderedBy = this.config.orderedBy);
|
|
843
|
+
return orderedBy === types_1.NameOrder.FIRST_NAME
|
|
844
|
+
? [this.first, ...this.middleName(), this.last].join(' ')
|
|
845
|
+
: [this.last, this.first, ...this.middleName()].join(' ');
|
|
996
846
|
}
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
847
|
+
firstName(withMore = true) {
|
|
848
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.toString(withMore);
|
|
849
|
+
}
|
|
850
|
+
middleName() {
|
|
851
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").middleName.map((n) => n.value);
|
|
852
|
+
}
|
|
853
|
+
lastName(format) {
|
|
854
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.toString(format);
|
|
855
|
+
}
|
|
856
|
+
initials(options) {
|
|
857
|
+
const { orderedBy = this.config.orderedBy, only = types_1.NameType.BIRTH_NAME, asJson } = options !== null && options !== void 0 ? options : {};
|
|
858
|
+
const firstInits = __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.initials();
|
|
859
|
+
const midInits = __classPrivateFieldGet(this, _Namefully_fullName, "f").middleName.map((n) => n.value[0]);
|
|
860
|
+
const lastInits = __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.initials();
|
|
861
|
+
if (asJson)
|
|
862
|
+
return { firstName: firstInits, middleName: midInits, lastName: lastInits };
|
|
863
|
+
if (only !== types_1.NameType.BIRTH_NAME) {
|
|
864
|
+
return only === types_1.NameType.FIRST_NAME ? firstInits : only === types_1.NameType.MIDDLE_NAME ? midInits : lastInits;
|
|
1000
865
|
}
|
|
1001
|
-
else if (
|
|
1002
|
-
|
|
1003
|
-
throw new error_1.ValidationError({
|
|
1004
|
-
source: value,
|
|
1005
|
-
nameType: 'firstName',
|
|
1006
|
-
message: 'invalid content',
|
|
1007
|
-
});
|
|
1008
|
-
}
|
|
866
|
+
else if (orderedBy === types_1.NameOrder.FIRST_NAME) {
|
|
867
|
+
return [...firstInits, ...midInits, ...lastInits];
|
|
1009
868
|
}
|
|
1010
869
|
else {
|
|
1011
|
-
|
|
1012
|
-
source: typeof value,
|
|
1013
|
-
message: 'expecting types string | FirstName',
|
|
1014
|
-
});
|
|
870
|
+
return [...lastInits, ...firstInits, ...midInits];
|
|
1015
871
|
}
|
|
1016
872
|
}
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
873
|
+
shorten(orderedBy) {
|
|
874
|
+
orderedBy !== null && orderedBy !== void 0 ? orderedBy : (orderedBy = this.config.orderedBy);
|
|
875
|
+
const { firstName, lastName } = __classPrivateFieldGet(this, _Namefully_fullName, "f");
|
|
876
|
+
return orderedBy === types_1.NameOrder.FIRST_NAME
|
|
877
|
+
? [firstName.value, lastName.toString()].join(' ')
|
|
878
|
+
: [lastName.toString(), firstName.value].join(' ');
|
|
1023
879
|
}
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
880
|
+
flatten(options) {
|
|
881
|
+
const { by = types_1.Flat.MIDDLE_NAME, limit = 20, recursive = false, withMore = false, withPeriod = true, surname, } = options;
|
|
882
|
+
if (this.length <= limit)
|
|
883
|
+
return this.full;
|
|
884
|
+
const { firstName, lastName, middleName } = __classPrivateFieldGet(this, _Namefully_fullName, "f");
|
|
885
|
+
const sep = withPeriod ? '.' : '';
|
|
886
|
+
const hasMid = this.hasMiddle;
|
|
887
|
+
const fn = firstName.toString();
|
|
888
|
+
const mn = this.middleName().join(' ');
|
|
889
|
+
const ln = lastName.toString();
|
|
890
|
+
const f = firstName.initials(withMore).join(sep + ' ') + sep;
|
|
891
|
+
const l = lastName.initials(surname).join(sep + ' ') + sep;
|
|
892
|
+
const m = hasMid ? middleName.map((n) => n.value[0]).join(sep + ' ') + sep : '';
|
|
893
|
+
let name = [];
|
|
894
|
+
if (this.config.orderedBy === types_1.NameOrder.FIRST_NAME) {
|
|
895
|
+
switch (by) {
|
|
896
|
+
case types_1.Flat.FIRST_NAME:
|
|
897
|
+
name = hasMid ? [f, mn, ln] : [f, ln];
|
|
898
|
+
break;
|
|
899
|
+
case types_1.Flat.LAST_NAME:
|
|
900
|
+
name = hasMid ? [fn, mn, l] : [fn, l];
|
|
901
|
+
break;
|
|
902
|
+
case types_1.Flat.MIDDLE_NAME:
|
|
903
|
+
name = hasMid ? [fn, m, ln] : [fn, ln];
|
|
904
|
+
break;
|
|
905
|
+
case types_1.Flat.FIRST_MID:
|
|
906
|
+
name = hasMid ? [f, m, ln] : [f, ln];
|
|
907
|
+
break;
|
|
908
|
+
case types_1.Flat.MID_LAST:
|
|
909
|
+
name = hasMid ? [fn, m, l] : [fn, l];
|
|
910
|
+
break;
|
|
911
|
+
default:
|
|
912
|
+
name = hasMid ? [f, m, l] : [f, l];
|
|
913
|
+
break;
|
|
1032
914
|
}
|
|
1033
915
|
}
|
|
1034
|
-
else
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
916
|
+
else {
|
|
917
|
+
switch (by) {
|
|
918
|
+
case types_1.Flat.FIRST_NAME:
|
|
919
|
+
name = hasMid ? [ln, f, mn] : [ln, f];
|
|
920
|
+
break;
|
|
921
|
+
case types_1.Flat.LAST_NAME:
|
|
922
|
+
name = hasMid ? [l, fn, mn] : [l, fn];
|
|
923
|
+
break;
|
|
924
|
+
case types_1.Flat.MIDDLE_NAME:
|
|
925
|
+
name = hasMid ? [ln, fn, m] : [ln, fn];
|
|
926
|
+
break;
|
|
927
|
+
case types_1.Flat.FIRST_MID:
|
|
928
|
+
name = hasMid ? [ln, f, m] : [ln, f];
|
|
929
|
+
break;
|
|
930
|
+
case types_1.Flat.MID_LAST:
|
|
931
|
+
name = hasMid ? [l, fn, m] : [l, fn];
|
|
932
|
+
break;
|
|
933
|
+
default:
|
|
934
|
+
name = hasMid ? [l, f, m] : [l, f];
|
|
935
|
+
break;
|
|
1046
936
|
}
|
|
1047
937
|
}
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
938
|
+
const flat = name.join(' ');
|
|
939
|
+
if (recursive && flat.length > limit) {
|
|
940
|
+
const next = by === types_1.Flat.FIRST_NAME
|
|
941
|
+
? types_1.Flat.MIDDLE_NAME
|
|
942
|
+
: by === types_1.Flat.MIDDLE_NAME
|
|
943
|
+
? types_1.Flat.LAST_NAME
|
|
944
|
+
: by === types_1.Flat.LAST_NAME
|
|
945
|
+
? types_1.Flat.FIRST_MID
|
|
946
|
+
: by === types_1.Flat.FIRST_MID
|
|
947
|
+
? types_1.Flat.MID_LAST
|
|
948
|
+
: by === types_1.Flat.MID_LAST
|
|
949
|
+
? types_1.Flat.ALL
|
|
950
|
+
: by === types_1.Flat.ALL
|
|
951
|
+
? types_1.Flat.ALL
|
|
952
|
+
: by;
|
|
953
|
+
if (next === by)
|
|
954
|
+
return flat;
|
|
955
|
+
return this.flatten(Object.assign(Object.assign({}, options), { by: next }));
|
|
1053
956
|
}
|
|
957
|
+
return flat;
|
|
1054
958
|
}
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
_MiddleNameValidator_validator = { value: void 0 };
|
|
1058
|
-
class LastNameValidator {
|
|
1059
|
-
static create() {
|
|
1060
|
-
return __classPrivateFieldGet(this, _d, "f", _LastNameValidator_validator) || (__classPrivateFieldSet(this, _d, new this(), "f", _LastNameValidator_validator));
|
|
959
|
+
zip(by = types_1.Flat.MID_LAST, withPeriod = true) {
|
|
960
|
+
return this.flatten({ limit: 0, by, withPeriod });
|
|
1061
961
|
}
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
962
|
+
format(pattern) {
|
|
963
|
+
var _a;
|
|
964
|
+
if (pattern === 'short')
|
|
965
|
+
return this.short;
|
|
966
|
+
if (pattern === 'long')
|
|
967
|
+
return this.long;
|
|
968
|
+
if (pattern === 'public')
|
|
969
|
+
return this.public;
|
|
970
|
+
if (pattern === 'official')
|
|
971
|
+
pattern = 'o';
|
|
972
|
+
let group = '';
|
|
973
|
+
const formatted = [];
|
|
974
|
+
for (const char of pattern) {
|
|
975
|
+
if (!constants_1.ALLOWED_FORMAT_TOKENS.includes(char)) {
|
|
976
|
+
throw new error_1.NotAllowedError({
|
|
977
|
+
source: this.full,
|
|
978
|
+
operation: 'format',
|
|
979
|
+
message: `unsupported character <${char}> from ${pattern}.`,
|
|
1072
980
|
});
|
|
1073
981
|
}
|
|
982
|
+
group += char;
|
|
983
|
+
if (char === '$')
|
|
984
|
+
continue;
|
|
985
|
+
formatted.push((_a = __classPrivateFieldGet(this, _Namefully_instances, "m", _Namefully_map).call(this, group)) !== null && _a !== void 0 ? _a : '');
|
|
986
|
+
group = '';
|
|
1074
987
|
}
|
|
1075
|
-
|
|
1076
|
-
throw new error_1.InputError({
|
|
1077
|
-
source: typeof value,
|
|
1078
|
-
message: 'expecting types string | LastName',
|
|
1079
|
-
});
|
|
1080
|
-
}
|
|
988
|
+
return formatted.join('').trim();
|
|
1081
989
|
}
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
class NameValidator {
|
|
1086
|
-
static create() {
|
|
1087
|
-
return __classPrivateFieldGet(this, _e, "f", _NameValidator_validator) || (__classPrivateFieldSet(this, _e, new this(), "f", _NameValidator_validator));
|
|
990
|
+
flip() {
|
|
991
|
+
const order = this.config.orderedBy === types_1.NameOrder.FIRST_NAME ? types_1.NameOrder.LAST_NAME : types_1.NameOrder.FIRST_NAME;
|
|
992
|
+
this.config.update({ orderedBy: order });
|
|
1088
993
|
}
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
throw new error_1.ValidationError({
|
|
1092
|
-
source: [name],
|
|
1093
|
-
nameType: name.type.toString(),
|
|
1094
|
-
message: 'wrong type',
|
|
1095
|
-
});
|
|
1096
|
-
}
|
|
1097
|
-
if (!ValidationRule.namon.test(name.value)) {
|
|
1098
|
-
throw new error_1.ValidationError({
|
|
1099
|
-
source: [name],
|
|
1100
|
-
nameType: name.type.toString(),
|
|
1101
|
-
message: 'invalid content',
|
|
1102
|
-
});
|
|
1103
|
-
}
|
|
994
|
+
split(separator = /[' -]/g) {
|
|
995
|
+
return this.birth.replace(separator, ' ').split(' ');
|
|
1104
996
|
}
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
_NameValidator_validator = { value: void 0 };
|
|
1108
|
-
class NamaValidator {
|
|
1109
|
-
static create() {
|
|
1110
|
-
return __classPrivateFieldGet(this, _f, "f", _NamaValidator_validator) || (__classPrivateFieldSet(this, _f, new this(), "f", _NamaValidator_validator));
|
|
997
|
+
join(separator = '') {
|
|
998
|
+
return this.split().join(separator);
|
|
1111
999
|
}
|
|
1112
|
-
|
|
1113
|
-
this.
|
|
1114
|
-
Validators.firstName.validate(value.get(types_1.Namon.FIRST_NAME));
|
|
1115
|
-
Validators.lastName.validate(value.get(types_1.Namon.LAST_NAME));
|
|
1116
|
-
if (value.has(types_1.Namon.PREFIX)) {
|
|
1117
|
-
Validators.namon.validate(value.get(types_1.Namon.PREFIX));
|
|
1118
|
-
}
|
|
1119
|
-
if (value.has(types_1.Namon.SUFFIX)) {
|
|
1120
|
-
Validators.namon.validate(value.get(types_1.Namon.SUFFIX));
|
|
1121
|
-
}
|
|
1000
|
+
toUpperCase() {
|
|
1001
|
+
return this.birth.toUpperCase();
|
|
1122
1002
|
}
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
throw new error_1.InputError({ source: undefined, message: 'Map<k,v> must not be empty' });
|
|
1126
|
-
}
|
|
1127
|
-
else if (nama.size < constants_1.MIN_NUMBER_OF_NAME_PARTS || nama.size > constants_1.MAX_NUMBER_OF_NAME_PARTS) {
|
|
1128
|
-
throw new error_1.InputError({
|
|
1129
|
-
source: [...nama.values()],
|
|
1130
|
-
message: `expecting ${constants_1.MIN_NUMBER_OF_NAME_PARTS}-${constants_1.MIN_NUMBER_OF_NAME_PARTS} fields`,
|
|
1131
|
-
});
|
|
1132
|
-
}
|
|
1133
|
-
if (!nama.has(types_1.Namon.FIRST_NAME)) {
|
|
1134
|
-
throw new error_1.InputError({
|
|
1135
|
-
source: [...nama.values()],
|
|
1136
|
-
message: '"firstName" is a required key',
|
|
1137
|
-
});
|
|
1138
|
-
}
|
|
1139
|
-
if (!nama.has(types_1.Namon.LAST_NAME)) {
|
|
1140
|
-
throw new error_1.InputError({
|
|
1141
|
-
source: [...nama.values()],
|
|
1142
|
-
message: '"lastName" is a required key',
|
|
1143
|
-
});
|
|
1144
|
-
}
|
|
1003
|
+
toLowerCase() {
|
|
1004
|
+
return this.birth.toLowerCase();
|
|
1145
1005
|
}
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
_f = NamaValidator;
|
|
1149
|
-
_NamaValidator_validator = { value: void 0 };
|
|
1150
|
-
class ArrayStringValidator extends ArrayValidator {
|
|
1151
|
-
constructor(index = utils_1.NameIndex.base()) {
|
|
1152
|
-
super();
|
|
1153
|
-
this.index = index;
|
|
1006
|
+
toCamelCase() {
|
|
1007
|
+
return (0, utils_1.decapitalize)(this.toPascalCase());
|
|
1154
1008
|
}
|
|
1155
|
-
|
|
1156
|
-
this.
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
Validators.firstName.validate(values[this.index.firstName]);
|
|
1160
|
-
Validators.lastName.validate(values[this.index.lastName]);
|
|
1161
|
-
break;
|
|
1162
|
-
case 3:
|
|
1163
|
-
Validators.firstName.validate(values[this.index.firstName]);
|
|
1164
|
-
Validators.middleName.validate(values[this.index.middleName]);
|
|
1165
|
-
Validators.lastName.validate(values[this.index.lastName]);
|
|
1166
|
-
break;
|
|
1167
|
-
case 4:
|
|
1168
|
-
Validators.namon.validate(values[this.index.prefix]);
|
|
1169
|
-
Validators.firstName.validate(values[this.index.firstName]);
|
|
1170
|
-
Validators.middleName.validate(values[this.index.middleName]);
|
|
1171
|
-
Validators.lastName.validate(values[this.index.lastName]);
|
|
1172
|
-
break;
|
|
1173
|
-
case 5:
|
|
1174
|
-
Validators.namon.validate(values[this.index.prefix]);
|
|
1175
|
-
Validators.firstName.validate(values[this.index.firstName]);
|
|
1176
|
-
Validators.middleName.validate(values[this.index.middleName]);
|
|
1177
|
-
Validators.lastName.validate(values[this.index.lastName]);
|
|
1178
|
-
Validators.namon.validate(values[this.index.suffix]);
|
|
1179
|
-
break;
|
|
1180
|
-
}
|
|
1009
|
+
toPascalCase() {
|
|
1010
|
+
return this.split()
|
|
1011
|
+
.map((n) => (0, utils_1.capitalize)(n))
|
|
1012
|
+
.join('');
|
|
1181
1013
|
}
|
|
1182
|
-
|
|
1183
|
-
|
|
1014
|
+
toSnakeCase() {
|
|
1015
|
+
return this.split()
|
|
1016
|
+
.map((n) => n.toLowerCase())
|
|
1017
|
+
.join('_');
|
|
1184
1018
|
}
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
_ArrayNameValidator_instances.add(this);
|
|
1019
|
+
toHyphenCase() {
|
|
1020
|
+
return this.split()
|
|
1021
|
+
.map((n) => n.toLowerCase())
|
|
1022
|
+
.join('-');
|
|
1190
1023
|
}
|
|
1191
|
-
|
|
1192
|
-
return
|
|
1024
|
+
toDotCase() {
|
|
1025
|
+
return this.split()
|
|
1026
|
+
.map((n) => n.toLowerCase())
|
|
1027
|
+
.join('.');
|
|
1193
1028
|
}
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
throw new error_1.InputError({
|
|
1197
|
-
source: value,
|
|
1198
|
-
message: `expecting at least ${constants_1.MIN_NUMBER_OF_NAME_PARTS} elements`,
|
|
1199
|
-
});
|
|
1200
|
-
}
|
|
1201
|
-
if (!__classPrivateFieldGet(this, _ArrayNameValidator_instances, "m", _ArrayNameValidator_hasBasicNames).call(this, value)) {
|
|
1202
|
-
throw new error_1.InputError({
|
|
1203
|
-
source: value,
|
|
1204
|
-
message: 'both first and last names are required',
|
|
1205
|
-
});
|
|
1206
|
-
}
|
|
1029
|
+
toToggleCase() {
|
|
1030
|
+
return (0, utils_1.toggleCase)(this.birth);
|
|
1207
1031
|
}
|
|
1208
1032
|
}
|
|
1209
|
-
exports.
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1033
|
+
exports.Namefully = Namefully;
|
|
1034
|
+
_Namefully_toParser = function _Namefully_toParser(raw) {
|
|
1035
|
+
if (raw instanceof parser_1.Parser)
|
|
1036
|
+
return raw;
|
|
1037
|
+
if (typeof raw === 'string')
|
|
1038
|
+
return new parser_1.StringParser(raw);
|
|
1039
|
+
if ((0, utils_1.isStringArray)(raw))
|
|
1040
|
+
return new parser_1.ArrayStringParser(raw);
|
|
1041
|
+
if ((0, name_1.isNameArray)(raw))
|
|
1042
|
+
return new parser_1.ArrayNameParser(raw);
|
|
1043
|
+
if (typeof raw === 'object')
|
|
1044
|
+
return new parser_1.NamaParser(raw);
|
|
1045
|
+
throw new error_1.InputError({ source: raw, message: 'Cannot parse raw data; review expected data types.' });
|
|
1046
|
+
}, _Namefully_map = function _Namefully_map(char) {
|
|
1047
|
+
var _a, _b;
|
|
1048
|
+
switch (char) {
|
|
1049
|
+
case 'b':
|
|
1050
|
+
return this.birth;
|
|
1051
|
+
case 'B':
|
|
1052
|
+
return this.birth.toUpperCase();
|
|
1053
|
+
case 'f':
|
|
1054
|
+
return this.first;
|
|
1055
|
+
case 'F':
|
|
1056
|
+
return this.first.toUpperCase();
|
|
1057
|
+
case 'l':
|
|
1058
|
+
return this.last;
|
|
1059
|
+
case 'L':
|
|
1060
|
+
return this.last.toUpperCase();
|
|
1061
|
+
case 'm':
|
|
1062
|
+
case 'M':
|
|
1063
|
+
return char === 'm' ? this.middleName().join(' ') : this.middleName().join(' ').toUpperCase();
|
|
1064
|
+
case 'o':
|
|
1065
|
+
case 'O':
|
|
1066
|
+
return ((character) => {
|
|
1067
|
+
const sep = this.config.ending ? ',' : '';
|
|
1068
|
+
const names = [];
|
|
1069
|
+
if (this.prefix)
|
|
1070
|
+
names.push(this.prefix);
|
|
1071
|
+
names.push(`${this.last},`.toUpperCase());
|
|
1072
|
+
if (this.hasMiddle)
|
|
1073
|
+
names.push(this.first, this.middleName().join(' ') + sep);
|
|
1074
|
+
else
|
|
1075
|
+
names.push(this.first + sep);
|
|
1076
|
+
if (this.suffix)
|
|
1077
|
+
names.push(this.suffix);
|
|
1078
|
+
const nama = names.join(' ').trim();
|
|
1079
|
+
return character === 'o' ? nama : nama.toUpperCase();
|
|
1080
|
+
})(char);
|
|
1081
|
+
case 'p':
|
|
1082
|
+
return this.prefix;
|
|
1083
|
+
case 'P':
|
|
1084
|
+
return (_a = this.prefix) === null || _a === void 0 ? void 0 : _a.toUpperCase();
|
|
1085
|
+
case 's':
|
|
1086
|
+
return this.suffix;
|
|
1087
|
+
case 'S':
|
|
1088
|
+
return (_b = this.suffix) === null || _b === void 0 ? void 0 : _b.toUpperCase();
|
|
1089
|
+
case '$f':
|
|
1090
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.value[0];
|
|
1091
|
+
case '$F':
|
|
1092
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.initials(true).join('');
|
|
1093
|
+
case '$l':
|
|
1094
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.value[0];
|
|
1095
|
+
case '$L':
|
|
1096
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.initials().join('');
|
|
1097
|
+
case '$m':
|
|
1098
|
+
return this.hasMiddle ? this.middle[0] : undefined;
|
|
1099
|
+
case '$M':
|
|
1100
|
+
return this.hasMiddle ? __classPrivateFieldGet(this, _Namefully_fullName, "f").middleName.map((n) => n.value[0]).join('') : undefined;
|
|
1101
|
+
default:
|
|
1102
|
+
return constants_1.ALLOWED_FORMAT_TOKENS.includes(char) ? char : undefined;
|
|
1216
1103
|
}
|
|
1217
|
-
return Object.keys(accumulator).length === constants_1.MIN_NUMBER_OF_NAME_PARTS;
|
|
1218
1104
|
};
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
}
|
|
1222
|
-
exports.Validators = Validators;
|
|
1223
|
-
Validators.namon = NamonValidator.create();
|
|
1224
|
-
Validators.nama = NamaValidator.create();
|
|
1225
|
-
Validators.prefix = NamonValidator.create();
|
|
1226
|
-
Validators.firstName = FirstNameValidator.create();
|
|
1227
|
-
Validators.middleName = MiddleNameValidator.create();
|
|
1228
|
-
Validators.lastName = LastNameValidator.create();
|
|
1229
|
-
Validators.suffix = NamonValidator.create();
|
|
1105
|
+
exports.default = (names, options) => {
|
|
1106
|
+
return new Namefully(names, options);
|
|
1107
|
+
};
|
|
1230
1108
|
|
|
1231
1109
|
|
|
1232
1110
|
/***/ }),
|
|
1233
|
-
/*
|
|
1111
|
+
/* 6 */
|
|
1234
1112
|
/***/ (function(module, exports, __webpack_require__) {
|
|
1235
1113
|
|
|
1236
1114
|
"use strict";
|
|
@@ -1240,191 +1118,126 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
1240
1118
|
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");
|
|
1241
1119
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
1242
1120
|
};
|
|
1243
|
-
var
|
|
1121
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
1122
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
1123
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
1124
|
+
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");
|
|
1125
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
1126
|
+
};
|
|
1127
|
+
var _Config_instances, _a, _Config_name, _Config_orderedBy, _Config_separator, _Config_title, _Config_ending, _Config_bypass, _Config_surname, _Config_genNewName;
|
|
1244
1128
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1245
|
-
exports.
|
|
1246
|
-
const full_name_1 = __webpack_require__(6);
|
|
1247
|
-
const config_1 = __webpack_require__(5);
|
|
1248
|
-
const utils_1 = __webpack_require__(2);
|
|
1249
|
-
const validator_1 = __webpack_require__(7);
|
|
1250
|
-
const name_1 = __webpack_require__(3);
|
|
1129
|
+
exports.Config = void 0;
|
|
1251
1130
|
const types_1 = __webpack_require__(0);
|
|
1252
|
-
const
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1131
|
+
const defaultName = 'default';
|
|
1132
|
+
const copyAlias = '_copy';
|
|
1133
|
+
class Config {
|
|
1134
|
+
get orderedBy() {
|
|
1135
|
+
return __classPrivateFieldGet(this, _Config_orderedBy, "f");
|
|
1256
1136
|
}
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
const length = parts.length;
|
|
1260
|
-
if (length < 2) {
|
|
1261
|
-
throw new error_1.InputError({
|
|
1262
|
-
source: text,
|
|
1263
|
-
message: 'cannot build from invalid input',
|
|
1264
|
-
});
|
|
1265
|
-
}
|
|
1266
|
-
else if (length === 2 || length === 3) {
|
|
1267
|
-
return new StringParser(text);
|
|
1268
|
-
}
|
|
1269
|
-
else {
|
|
1270
|
-
const last = parts.pop();
|
|
1271
|
-
const [first, ...middles] = parts;
|
|
1272
|
-
return new ArrayStringParser([first, middles.join(' '), last]);
|
|
1273
|
-
}
|
|
1137
|
+
get separator() {
|
|
1138
|
+
return __classPrivateFieldGet(this, _Config_separator, "f");
|
|
1274
1139
|
}
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
return Promise.resolve(Parser.build(text));
|
|
1278
|
-
}
|
|
1279
|
-
catch (error) {
|
|
1280
|
-
return Promise.reject(error);
|
|
1281
|
-
}
|
|
1140
|
+
get title() {
|
|
1141
|
+
return __classPrivateFieldGet(this, _Config_title, "f");
|
|
1282
1142
|
}
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
class StringParser extends Parser {
|
|
1286
|
-
parse(options) {
|
|
1287
|
-
const config = config_1.Config.merge(options);
|
|
1288
|
-
const names = this.raw.split(config.separator.token);
|
|
1289
|
-
return new ArrayStringParser(names).parse(options);
|
|
1143
|
+
get ending() {
|
|
1144
|
+
return __classPrivateFieldGet(this, _Config_ending, "f");
|
|
1290
1145
|
}
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
class ArrayStringParser extends Parser {
|
|
1294
|
-
parse(options) {
|
|
1295
|
-
const config = config_1.Config.merge(options);
|
|
1296
|
-
const fullName = new full_name_1.FullName(config);
|
|
1297
|
-
const raw = this.raw.map((n) => n.trim());
|
|
1298
|
-
const index = utils_1.NameIndex.when(config.orderedBy, raw.length);
|
|
1299
|
-
const validator = new validator_1.ArrayStringValidator(index);
|
|
1300
|
-
if (config.bypass) {
|
|
1301
|
-
validator.validateIndex(raw);
|
|
1302
|
-
}
|
|
1303
|
-
else {
|
|
1304
|
-
validator.validate(raw);
|
|
1305
|
-
}
|
|
1306
|
-
const { firstName, lastName, middleName, prefix, suffix } = index;
|
|
1307
|
-
fullName.setFirstName(new name_1.FirstName(raw[firstName]));
|
|
1308
|
-
fullName.setLastName(new name_1.LastName(raw[lastName]));
|
|
1309
|
-
if (raw.length >= 3)
|
|
1310
|
-
fullName.setMiddleName(raw[middleName].split(config.separator.token));
|
|
1311
|
-
if (raw.length >= 4)
|
|
1312
|
-
fullName.setPrefix(name_1.Name.prefix(raw[prefix]));
|
|
1313
|
-
if (raw.length === 5)
|
|
1314
|
-
fullName.setSuffix(name_1.Name.suffix(raw[suffix]));
|
|
1315
|
-
return fullName;
|
|
1146
|
+
get bypass() {
|
|
1147
|
+
return __classPrivateFieldGet(this, _Config_bypass, "f");
|
|
1316
1148
|
}
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
class NamaParser extends Parser {
|
|
1320
|
-
constructor() {
|
|
1321
|
-
super(...arguments);
|
|
1322
|
-
_NamaParser_instances.add(this);
|
|
1149
|
+
get surname() {
|
|
1150
|
+
return __classPrivateFieldGet(this, _Config_surname, "f");
|
|
1323
1151
|
}
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1152
|
+
get name() {
|
|
1153
|
+
return __classPrivateFieldGet(this, _Config_name, "f");
|
|
1154
|
+
}
|
|
1155
|
+
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) {
|
|
1156
|
+
_Config_instances.add(this);
|
|
1157
|
+
_Config_name.set(this, void 0);
|
|
1158
|
+
_Config_orderedBy.set(this, void 0);
|
|
1159
|
+
_Config_separator.set(this, void 0);
|
|
1160
|
+
_Config_title.set(this, void 0);
|
|
1161
|
+
_Config_ending.set(this, void 0);
|
|
1162
|
+
_Config_bypass.set(this, void 0);
|
|
1163
|
+
_Config_surname.set(this, void 0);
|
|
1164
|
+
__classPrivateFieldSet(this, _Config_name, name, "f");
|
|
1165
|
+
__classPrivateFieldSet(this, _Config_orderedBy, orderedBy, "f");
|
|
1166
|
+
__classPrivateFieldSet(this, _Config_separator, separator, "f");
|
|
1167
|
+
__classPrivateFieldSet(this, _Config_title, title, "f");
|
|
1168
|
+
__classPrivateFieldSet(this, _Config_ending, ending, "f");
|
|
1169
|
+
__classPrivateFieldSet(this, _Config_bypass, bypass, "f");
|
|
1170
|
+
__classPrivateFieldSet(this, _Config_surname, surname, "f");
|
|
1171
|
+
}
|
|
1172
|
+
static create(name = defaultName) {
|
|
1173
|
+
if (!_a.cache.has(name))
|
|
1174
|
+
_a.cache.set(name, new this(name));
|
|
1175
|
+
return _a.cache.get(name);
|
|
1176
|
+
}
|
|
1177
|
+
static merge(other) {
|
|
1178
|
+
var _b, _c, _d, _e, _f, _g;
|
|
1179
|
+
if (!other) {
|
|
1180
|
+
return _a.create();
|
|
1328
1181
|
}
|
|
1329
1182
|
else {
|
|
1330
|
-
|
|
1183
|
+
const config = _a.create(other.name);
|
|
1184
|
+
__classPrivateFieldSet(config, _Config_orderedBy, (_b = other.orderedBy) !== null && _b !== void 0 ? _b : config.orderedBy, "f");
|
|
1185
|
+
__classPrivateFieldSet(config, _Config_separator, (_c = other.separator) !== null && _c !== void 0 ? _c : config.separator, "f");
|
|
1186
|
+
__classPrivateFieldSet(config, _Config_title, (_d = other.title) !== null && _d !== void 0 ? _d : config.title, "f");
|
|
1187
|
+
__classPrivateFieldSet(config, _Config_ending, (_e = other.ending) !== null && _e !== void 0 ? _e : config.ending, "f");
|
|
1188
|
+
__classPrivateFieldSet(config, _Config_bypass, (_f = other.bypass) !== null && _f !== void 0 ? _f : config.bypass, "f");
|
|
1189
|
+
__classPrivateFieldSet(config, _Config_surname, (_g = other.surname) !== null && _g !== void 0 ? _g : config.surname, "f");
|
|
1190
|
+
return config;
|
|
1331
1191
|
}
|
|
1332
|
-
return full_name_1.FullName.parse(this.raw, config);
|
|
1333
1192
|
}
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
}
|
|
1345
|
-
return [namon, value];
|
|
1346
|
-
}));
|
|
1347
|
-
};
|
|
1348
|
-
class ArrayNameParser extends Parser {
|
|
1349
|
-
parse(options) {
|
|
1350
|
-
const config = config_1.Config.merge(options);
|
|
1351
|
-
const fullName = new full_name_1.FullName(config);
|
|
1352
|
-
validator_1.ArrayNameValidator.create().validate(this.raw);
|
|
1353
|
-
for (const name of this.raw) {
|
|
1354
|
-
if (name.isPrefix) {
|
|
1355
|
-
fullName.setPrefix(name);
|
|
1356
|
-
}
|
|
1357
|
-
else if (name.isSuffix) {
|
|
1358
|
-
fullName.setSuffix(name);
|
|
1359
|
-
}
|
|
1360
|
-
else if (name.isFirstName) {
|
|
1361
|
-
fullName.setFirstName(name instanceof name_1.FirstName ? name : new name_1.FirstName(name.value));
|
|
1362
|
-
}
|
|
1363
|
-
else if (name.isMiddleName) {
|
|
1364
|
-
fullName.middleName.push(name);
|
|
1365
|
-
}
|
|
1366
|
-
else if (name.isLastName) {
|
|
1367
|
-
const lastName = new name_1.LastName(name.value, name instanceof name_1.LastName ? name.mother : undefined, config.surname);
|
|
1368
|
-
fullName.setLastName(lastName);
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
return fullName;
|
|
1193
|
+
copyWith(options = {}) {
|
|
1194
|
+
const { name, orderedBy, separator, title, ending, bypass, surname } = options;
|
|
1195
|
+
const config = _a.create(__classPrivateFieldGet(this, _Config_instances, "m", _Config_genNewName).call(this, name !== null && name !== void 0 ? name : this.name + copyAlias));
|
|
1196
|
+
__classPrivateFieldSet(config, _Config_orderedBy, orderedBy !== null && orderedBy !== void 0 ? orderedBy : this.orderedBy, "f");
|
|
1197
|
+
__classPrivateFieldSet(config, _Config_separator, separator !== null && separator !== void 0 ? separator : this.separator, "f");
|
|
1198
|
+
__classPrivateFieldSet(config, _Config_title, title !== null && title !== void 0 ? title : this.title, "f");
|
|
1199
|
+
__classPrivateFieldSet(config, _Config_ending, ending !== null && ending !== void 0 ? ending : this.ending, "f");
|
|
1200
|
+
__classPrivateFieldSet(config, _Config_bypass, bypass !== null && bypass !== void 0 ? bypass : this.bypass, "f");
|
|
1201
|
+
__classPrivateFieldSet(config, _Config_surname, surname !== null && surname !== void 0 ? surname : this.surname, "f");
|
|
1202
|
+
return config;
|
|
1372
1203
|
}
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
/***/ }),
|
|
1378
|
-
/* 9 */
|
|
1379
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
1380
|
-
|
|
1381
|
-
"use strict";
|
|
1382
|
-
|
|
1383
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
1384
|
-
if (k2 === undefined) k2 = k;
|
|
1385
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1386
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1387
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
1204
|
+
clone() {
|
|
1205
|
+
return this.copyWith();
|
|
1388
1206
|
}
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1207
|
+
reset() {
|
|
1208
|
+
__classPrivateFieldSet(this, _Config_orderedBy, types_1.NameOrder.FIRST_NAME, "f");
|
|
1209
|
+
__classPrivateFieldSet(this, _Config_separator, types_1.Separator.SPACE, "f");
|
|
1210
|
+
__classPrivateFieldSet(this, _Config_title, types_1.Title.UK, "f");
|
|
1211
|
+
__classPrivateFieldSet(this, _Config_ending, false, "f");
|
|
1212
|
+
__classPrivateFieldSet(this, _Config_bypass, true, "f");
|
|
1213
|
+
__classPrivateFieldSet(this, _Config_surname, types_1.Surname.FATHER, "f");
|
|
1214
|
+
_a.cache.set(this.name, this);
|
|
1215
|
+
}
|
|
1216
|
+
update({ orderedBy, title, ending }) {
|
|
1217
|
+
const config = _a.cache.get(this.name);
|
|
1218
|
+
if (!config)
|
|
1219
|
+
return;
|
|
1220
|
+
if (orderedBy !== __classPrivateFieldGet(this, _Config_orderedBy, "f"))
|
|
1221
|
+
__classPrivateFieldSet(config, _Config_orderedBy, orderedBy, "f");
|
|
1222
|
+
if (title !== __classPrivateFieldGet(this, _Config_title, "f"))
|
|
1223
|
+
__classPrivateFieldSet(config, _Config_title, title, "f");
|
|
1224
|
+
if (ending !== __classPrivateFieldGet(this, _Config_ending, "f"))
|
|
1225
|
+
__classPrivateFieldSet(config, _Config_ending, ending, "f");
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
exports.Config = Config;
|
|
1229
|
+
_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) {
|
|
1230
|
+
return name === this.name || _a.cache.has(name) ? __classPrivateFieldGet(this, _Config_instances, "m", _Config_genNewName).call(this, name + copyAlias) : name;
|
|
1396
1231
|
};
|
|
1397
|
-
|
|
1398
|
-
exports.NameIndex = exports.Parser = exports.version = void 0;
|
|
1399
|
-
__exportStar(__webpack_require__(5), exports);
|
|
1400
|
-
var constants_1 = __webpack_require__(4);
|
|
1401
|
-
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return constants_1.VERSION; } });
|
|
1402
|
-
__exportStar(__webpack_require__(1), exports);
|
|
1403
|
-
__exportStar(__webpack_require__(6), exports);
|
|
1404
|
-
__exportStar(__webpack_require__(3), exports);
|
|
1405
|
-
__exportStar(__webpack_require__(10), exports);
|
|
1406
|
-
var parser_1 = __webpack_require__(8);
|
|
1407
|
-
Object.defineProperty(exports, "Parser", { enumerable: true, get: function () { return parser_1.Parser; } });
|
|
1408
|
-
__exportStar(__webpack_require__(0), exports);
|
|
1409
|
-
var utils_1 = __webpack_require__(2);
|
|
1410
|
-
Object.defineProperty(exports, "NameIndex", { enumerable: true, get: function () { return utils_1.NameIndex; } });
|
|
1232
|
+
Config.cache = new Map();
|
|
1411
1233
|
|
|
1412
1234
|
|
|
1413
1235
|
/***/ }),
|
|
1414
|
-
/*
|
|
1236
|
+
/* 7 */
|
|
1415
1237
|
/***/ (function(module, exports, __webpack_require__) {
|
|
1416
1238
|
|
|
1417
1239
|
"use strict";
|
|
1418
1240
|
|
|
1419
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1420
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1421
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1422
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
1423
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
1424
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1425
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1426
|
-
});
|
|
1427
|
-
};
|
|
1428
1241
|
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
1429
1242
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
1430
1243
|
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");
|
|
@@ -1436,395 +1249,673 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
1436
1249
|
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");
|
|
1437
1250
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
1438
1251
|
};
|
|
1439
|
-
var
|
|
1252
|
+
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;
|
|
1440
1253
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1441
|
-
exports.
|
|
1442
|
-
const constants_1 = __webpack_require__(4);
|
|
1443
|
-
const error_1 = __webpack_require__(1);
|
|
1444
|
-
const parser_1 = __webpack_require__(8);
|
|
1254
|
+
exports.Validators = exports.ArrayNameValidator = exports.ArrayStringValidator = exports.NamaValidator = void 0;
|
|
1445
1255
|
const types_1 = __webpack_require__(0);
|
|
1446
1256
|
const utils_1 = __webpack_require__(2);
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1257
|
+
const name_1 = __webpack_require__(3);
|
|
1258
|
+
const error_1 = __webpack_require__(1);
|
|
1259
|
+
const constants_1 = __webpack_require__(4);
|
|
1260
|
+
class ValidationRule {
|
|
1261
|
+
}
|
|
1262
|
+
ValidationRule.base = /[a-zA-Z\u00C0-\u00D6\u00D8-\u00f6\u00f8-\u00ff\u0400-\u04FFΆ-ωΑ-ώ]/;
|
|
1263
|
+
ValidationRule.namon = new RegExp(`^${ValidationRule.base.source}+(([' -]${ValidationRule.base.source})?${ValidationRule.base.source}*)*$`);
|
|
1264
|
+
ValidationRule.firstName = ValidationRule.namon;
|
|
1265
|
+
ValidationRule.middleName = new RegExp(`^${ValidationRule.base.source}+(([' -]${ValidationRule.base.source})?${ValidationRule.base.source}*)*$`);
|
|
1266
|
+
ValidationRule.lastName = ValidationRule.namon;
|
|
1267
|
+
const toNameSource = (values) => {
|
|
1268
|
+
return (0, name_1.isNameArray)(values) ? values.map((n) => n.toString()).join(' ') : '';
|
|
1269
|
+
};
|
|
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.MAX_NUMBER_OF_NAME_PARTS} elements`,
|
|
1276
|
+
});
|
|
1277
|
+
}
|
|
1452
1278
|
}
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1279
|
+
}
|
|
1280
|
+
class NamonValidator {
|
|
1281
|
+
static create() {
|
|
1282
|
+
return __classPrivateFieldGet(this, _a, "f", _NamonValidator_validator) || (__classPrivateFieldSet(this, _a, new _a(), "f", _NamonValidator_validator));
|
|
1283
|
+
}
|
|
1284
|
+
validate(value, type) {
|
|
1285
|
+
if (value instanceof name_1.Name) {
|
|
1286
|
+
NameValidator.create().validate(value, type);
|
|
1456
1287
|
}
|
|
1457
|
-
|
|
1458
|
-
|
|
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 name content failing namon regex',
|
|
1294
|
+
});
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
else {
|
|
1298
|
+
throw new error_1.InputError({ source: typeof value, message: 'expecting types of string or Name' });
|
|
1459
1299
|
}
|
|
1460
1300
|
}
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
return __classPrivateFieldGet(this, _Namefully_fullName, "f").config;
|
|
1301
|
+
}
|
|
1302
|
+
_a = NamonValidator;
|
|
1303
|
+
_NamonValidator_validator = { value: void 0 };
|
|
1304
|
+
class FirstNameValidator {
|
|
1305
|
+
static create() {
|
|
1306
|
+
return __classPrivateFieldGet(this, _b, "f", _FirstNameValidator_validator) || (__classPrivateFieldSet(this, _b, new _b(), "f", _FirstNameValidator_validator));
|
|
1468
1307
|
}
|
|
1469
|
-
|
|
1470
|
-
|
|
1308
|
+
validate(value) {
|
|
1309
|
+
if (value instanceof name_1.FirstName) {
|
|
1310
|
+
value.asNames.forEach((name) => this.validate(name.value));
|
|
1311
|
+
}
|
|
1312
|
+
else if (typeof value === 'string') {
|
|
1313
|
+
if (!ValidationRule.firstName.test(value)) {
|
|
1314
|
+
throw new error_1.ValidationError({
|
|
1315
|
+
source: value,
|
|
1316
|
+
nameType: 'firstName',
|
|
1317
|
+
message: 'invalid name content failing firstName regex',
|
|
1318
|
+
});
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
else {
|
|
1322
|
+
throw new error_1.InputError({ source: typeof value, message: 'expecting types string or FirstName' });
|
|
1323
|
+
}
|
|
1471
1324
|
}
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
return this
|
|
1478
|
-
}
|
|
1479
|
-
get middle() {
|
|
1480
|
-
return this.hasMiddle ? this.middleName()[0] : undefined;
|
|
1325
|
+
}
|
|
1326
|
+
_b = FirstNameValidator;
|
|
1327
|
+
_FirstNameValidator_validator = { value: void 0 };
|
|
1328
|
+
class MiddleNameValidator {
|
|
1329
|
+
static create() {
|
|
1330
|
+
return __classPrivateFieldGet(this, _c, "f", _MiddleNameValidator_validator) || (__classPrivateFieldSet(this, _c, new _c(), "f", _MiddleNameValidator_validator));
|
|
1481
1331
|
}
|
|
1482
|
-
|
|
1483
|
-
|
|
1332
|
+
validate(value) {
|
|
1333
|
+
if (typeof value === 'string') {
|
|
1334
|
+
if (!ValidationRule.middleName.test(value)) {
|
|
1335
|
+
throw new error_1.ValidationError({
|
|
1336
|
+
source: value,
|
|
1337
|
+
nameType: 'middleName',
|
|
1338
|
+
message: 'invalid name content failing middleName regex',
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
else if (Array.isArray(value)) {
|
|
1343
|
+
try {
|
|
1344
|
+
const validator = NamonValidator.create();
|
|
1345
|
+
for (const name of value)
|
|
1346
|
+
validator.validate(name, types_1.Namon.MIDDLE_NAME);
|
|
1347
|
+
}
|
|
1348
|
+
catch (error) {
|
|
1349
|
+
throw new error_1.ValidationError({
|
|
1350
|
+
source: toNameSource(value),
|
|
1351
|
+
nameType: 'middleName',
|
|
1352
|
+
message: error === null || error === void 0 ? void 0 : error.message,
|
|
1353
|
+
});
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
else {
|
|
1357
|
+
throw new error_1.InputError({
|
|
1358
|
+
source: typeof value,
|
|
1359
|
+
message: 'expecting types of string, string[] or Name[]',
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1484
1362
|
}
|
|
1485
|
-
|
|
1486
|
-
|
|
1363
|
+
}
|
|
1364
|
+
_c = MiddleNameValidator;
|
|
1365
|
+
_MiddleNameValidator_validator = { value: void 0 };
|
|
1366
|
+
class LastNameValidator {
|
|
1367
|
+
static create() {
|
|
1368
|
+
return __classPrivateFieldGet(this, _d, "f", _LastNameValidator_validator) || (__classPrivateFieldSet(this, _d, new _d(), "f", _LastNameValidator_validator));
|
|
1487
1369
|
}
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1370
|
+
validate(value) {
|
|
1371
|
+
if (value instanceof name_1.LastName) {
|
|
1372
|
+
value.asNames.forEach((name) => this.validate(name.value));
|
|
1373
|
+
}
|
|
1374
|
+
else if (typeof value === 'string') {
|
|
1375
|
+
if (!ValidationRule.lastName.test(value)) {
|
|
1376
|
+
throw new error_1.ValidationError({
|
|
1377
|
+
source: value,
|
|
1378
|
+
nameType: 'lastName',
|
|
1379
|
+
message: 'invalid name content failing lastName regex',
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
else {
|
|
1384
|
+
throw new error_1.InputError({ source: typeof value, message: 'expecting types string or LastName' });
|
|
1385
|
+
}
|
|
1491
1386
|
}
|
|
1492
|
-
|
|
1493
|
-
|
|
1387
|
+
}
|
|
1388
|
+
_d = LastNameValidator;
|
|
1389
|
+
_LastNameValidator_validator = { value: void 0 };
|
|
1390
|
+
class NameValidator {
|
|
1391
|
+
static create() {
|
|
1392
|
+
return __classPrivateFieldGet(this, _e, "f", _NameValidator_validator) || (__classPrivateFieldSet(this, _e, new _e(), "f", _NameValidator_validator));
|
|
1494
1393
|
}
|
|
1495
|
-
|
|
1496
|
-
|
|
1394
|
+
validate(name, type) {
|
|
1395
|
+
if (type && name.type !== type) {
|
|
1396
|
+
throw new error_1.ValidationError({
|
|
1397
|
+
source: name.toString(),
|
|
1398
|
+
nameType: name.type.toString(),
|
|
1399
|
+
message: 'wrong name type; only Namon types are supported',
|
|
1400
|
+
});
|
|
1401
|
+
}
|
|
1402
|
+
if (!ValidationRule.namon.test(name.value)) {
|
|
1403
|
+
throw new error_1.ValidationError({
|
|
1404
|
+
source: name.toString(),
|
|
1405
|
+
nameType: name.type.toString(),
|
|
1406
|
+
message: 'invalid name content failing namon regex',
|
|
1407
|
+
});
|
|
1408
|
+
}
|
|
1497
1409
|
}
|
|
1498
|
-
|
|
1499
|
-
|
|
1410
|
+
}
|
|
1411
|
+
_e = NameValidator;
|
|
1412
|
+
_NameValidator_validator = { value: void 0 };
|
|
1413
|
+
class NamaValidator {
|
|
1414
|
+
static create() {
|
|
1415
|
+
return __classPrivateFieldGet(this, _f, "f", _NamaValidator_validator) || (__classPrivateFieldSet(this, _f, new _f(), "f", _NamaValidator_validator));
|
|
1500
1416
|
}
|
|
1501
|
-
|
|
1502
|
-
|
|
1417
|
+
validate(value) {
|
|
1418
|
+
this.validateKeys(value);
|
|
1419
|
+
Validators.firstName.validate(value.get(types_1.Namon.FIRST_NAME));
|
|
1420
|
+
Validators.lastName.validate(value.get(types_1.Namon.LAST_NAME));
|
|
1421
|
+
if (value.has(types_1.Namon.PREFIX))
|
|
1422
|
+
Validators.namon.validate(value.get(types_1.Namon.PREFIX));
|
|
1423
|
+
if (value.has(types_1.Namon.SUFFIX))
|
|
1424
|
+
Validators.namon.validate(value.get(types_1.Namon.SUFFIX));
|
|
1503
1425
|
}
|
|
1504
|
-
|
|
1505
|
-
|
|
1426
|
+
validateKeys(nama) {
|
|
1427
|
+
if (!nama.size) {
|
|
1428
|
+
throw new error_1.InputError({ source: undefined, message: 'Map<k,v> must not be empty' });
|
|
1429
|
+
}
|
|
1430
|
+
else if (nama.size < constants_1.MIN_NUMBER_OF_NAME_PARTS || nama.size > constants_1.MAX_NUMBER_OF_NAME_PARTS) {
|
|
1431
|
+
throw new error_1.InputError({
|
|
1432
|
+
source: [...nama.values()],
|
|
1433
|
+
message: `expecting ${constants_1.MIN_NUMBER_OF_NAME_PARTS}-${constants_1.MAX_NUMBER_OF_NAME_PARTS} fields`,
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
if (!nama.has(types_1.Namon.FIRST_NAME)) {
|
|
1437
|
+
throw new error_1.InputError({ source: [...nama.values()], message: '"firstName" is a required key' });
|
|
1438
|
+
}
|
|
1439
|
+
if (!nama.has(types_1.Namon.LAST_NAME)) {
|
|
1440
|
+
throw new error_1.InputError({ source: [...nama.values()], message: '"lastName" is a required key' });
|
|
1441
|
+
}
|
|
1506
1442
|
}
|
|
1507
|
-
|
|
1508
|
-
|
|
1443
|
+
}
|
|
1444
|
+
exports.NamaValidator = NamaValidator;
|
|
1445
|
+
_f = NamaValidator;
|
|
1446
|
+
_NamaValidator_validator = { value: void 0 };
|
|
1447
|
+
class ArrayStringValidator extends ArrayValidator {
|
|
1448
|
+
constructor(index = utils_1.NameIndex.base()) {
|
|
1449
|
+
super();
|
|
1450
|
+
this.index = index;
|
|
1509
1451
|
}
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
return __classPrivateFieldGet(this, _Namefully_fullName, "f").suffix;
|
|
1521
|
-
return undefined;
|
|
1452
|
+
validate(values) {
|
|
1453
|
+
this.validateIndex(values);
|
|
1454
|
+
Validators.firstName.validate(values[this.index.firstName]);
|
|
1455
|
+
Validators.lastName.validate(values[this.index.lastName]);
|
|
1456
|
+
if (values.length >= 3)
|
|
1457
|
+
Validators.middleName.validate(values[this.index.middleName]);
|
|
1458
|
+
if (values.length >= 4)
|
|
1459
|
+
Validators.namon.validate(values[this.index.prefix]);
|
|
1460
|
+
if (values.length === 5)
|
|
1461
|
+
Validators.namon.validate(values[this.index.suffix]);
|
|
1522
1462
|
}
|
|
1523
|
-
|
|
1524
|
-
|
|
1463
|
+
validateIndex(values) {
|
|
1464
|
+
super.validate(values);
|
|
1525
1465
|
}
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
lastName: this.last,
|
|
1532
|
-
suffix: this.suffix,
|
|
1533
|
-
};
|
|
1466
|
+
}
|
|
1467
|
+
exports.ArrayStringValidator = ArrayStringValidator;
|
|
1468
|
+
class ArrayNameValidator {
|
|
1469
|
+
constructor() {
|
|
1470
|
+
_ArrayNameValidator_instances.add(this);
|
|
1534
1471
|
}
|
|
1535
|
-
|
|
1536
|
-
return __classPrivateFieldGet(this,
|
|
1472
|
+
static create() {
|
|
1473
|
+
return __classPrivateFieldGet(this, _g, "f", _ArrayNameValidator_validator) || (__classPrivateFieldSet(this, _g, new _g(), "f", _ArrayNameValidator_validator));
|
|
1537
1474
|
}
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
if (orderedBy === types_1.NameOrder.FIRST_NAME) {
|
|
1545
|
-
names.push(this.first, ...this.middleName(), this.last + sep);
|
|
1475
|
+
validate(value) {
|
|
1476
|
+
if (value.length < constants_1.MIN_NUMBER_OF_NAME_PARTS) {
|
|
1477
|
+
throw new error_1.InputError({
|
|
1478
|
+
source: toNameSource(value),
|
|
1479
|
+
message: `expecting at least ${constants_1.MIN_NUMBER_OF_NAME_PARTS} elements`,
|
|
1480
|
+
});
|
|
1546
1481
|
}
|
|
1547
|
-
|
|
1548
|
-
|
|
1482
|
+
if (!__classPrivateFieldGet(this, _ArrayNameValidator_instances, "m", _ArrayNameValidator_hasBasicNames).call(this, value)) {
|
|
1483
|
+
throw new error_1.InputError({
|
|
1484
|
+
source: toNameSource(value),
|
|
1485
|
+
message: 'both first and last names are required',
|
|
1486
|
+
});
|
|
1549
1487
|
}
|
|
1550
|
-
if (this.suffix)
|
|
1551
|
-
names.push(this.suffix);
|
|
1552
|
-
return names.join(' ').trim();
|
|
1553
|
-
}
|
|
1554
|
-
birthName(orderedBy) {
|
|
1555
|
-
orderedBy = orderedBy || this.config.orderedBy;
|
|
1556
|
-
return orderedBy === types_1.NameOrder.FIRST_NAME
|
|
1557
|
-
? [this.first, ...this.middleName(), this.last].join(' ')
|
|
1558
|
-
: [this.last, this.first, ...this.middleName()].join(' ');
|
|
1559
|
-
}
|
|
1560
|
-
firstName(withMore = true) {
|
|
1561
|
-
return __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.toString(withMore);
|
|
1562
1488
|
}
|
|
1563
|
-
|
|
1564
|
-
|
|
1489
|
+
}
|
|
1490
|
+
exports.ArrayNameValidator = ArrayNameValidator;
|
|
1491
|
+
_g = ArrayNameValidator, _ArrayNameValidator_instances = new WeakSet(), _ArrayNameValidator_hasBasicNames = function _ArrayNameValidator_hasBasicNames(names) {
|
|
1492
|
+
const accumulator = {};
|
|
1493
|
+
for (const name of names) {
|
|
1494
|
+
if (name.isFirstName || name.isLastName) {
|
|
1495
|
+
accumulator[name.type.key] = name.toString();
|
|
1496
|
+
}
|
|
1565
1497
|
}
|
|
1566
|
-
|
|
1567
|
-
|
|
1498
|
+
return Object.keys(accumulator).length === constants_1.MIN_NUMBER_OF_NAME_PARTS;
|
|
1499
|
+
};
|
|
1500
|
+
_ArrayNameValidator_validator = { value: void 0 };
|
|
1501
|
+
class Validators {
|
|
1502
|
+
}
|
|
1503
|
+
exports.Validators = Validators;
|
|
1504
|
+
Validators.namon = NamonValidator.create();
|
|
1505
|
+
Validators.nama = NamaValidator.create();
|
|
1506
|
+
Validators.prefix = NamonValidator.create();
|
|
1507
|
+
Validators.firstName = FirstNameValidator.create();
|
|
1508
|
+
Validators.middleName = MiddleNameValidator.create();
|
|
1509
|
+
Validators.lastName = LastNameValidator.create();
|
|
1510
|
+
Validators.suffix = NamonValidator.create();
|
|
1511
|
+
|
|
1512
|
+
|
|
1513
|
+
/***/ }),
|
|
1514
|
+
/* 8 */
|
|
1515
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
1516
|
+
|
|
1517
|
+
"use strict";
|
|
1518
|
+
|
|
1519
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1520
|
+
exports.ArrayNameParser = exports.NamaParser = exports.ArrayStringParser = exports.StringParser = exports.Parser = void 0;
|
|
1521
|
+
const config_1 = __webpack_require__(6);
|
|
1522
|
+
const utils_1 = __webpack_require__(2);
|
|
1523
|
+
const error_1 = __webpack_require__(1);
|
|
1524
|
+
const full_name_1 = __webpack_require__(9);
|
|
1525
|
+
const types_1 = __webpack_require__(0);
|
|
1526
|
+
const name_1 = __webpack_require__(3);
|
|
1527
|
+
const validator_1 = __webpack_require__(7);
|
|
1528
|
+
class Parser {
|
|
1529
|
+
constructor(raw) {
|
|
1530
|
+
this.raw = raw;
|
|
1568
1531
|
}
|
|
1569
|
-
|
|
1570
|
-
const
|
|
1571
|
-
const
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
if (only === types_1.NameType.FIRST_NAME) {
|
|
1578
|
-
initials.push(...firstInits);
|
|
1579
|
-
}
|
|
1580
|
-
else if (only === types_1.NameType.MIDDLE_NAME) {
|
|
1581
|
-
initials.push(...midInits);
|
|
1582
|
-
}
|
|
1583
|
-
else {
|
|
1584
|
-
initials.push(...lastInits);
|
|
1585
|
-
}
|
|
1532
|
+
static build(text, index) {
|
|
1533
|
+
const parts = text.trim().split(types_1.Separator.SPACE.token);
|
|
1534
|
+
const length = parts.length;
|
|
1535
|
+
if (index instanceof utils_1.NameIndex) {
|
|
1536
|
+
const names = Object.entries(index.json())
|
|
1537
|
+
.filter(([, position]) => position > -1 && position < length)
|
|
1538
|
+
.map(([key, position]) => new name_1.Name(parts[position], types_1.Namon.all.get(key)));
|
|
1539
|
+
return new ArrayNameParser(names);
|
|
1586
1540
|
}
|
|
1587
|
-
|
|
1588
|
-
|
|
1541
|
+
if (length < 2) {
|
|
1542
|
+
throw new error_1.InputError({ source: text, message: 'expecting at least 2 name parts' });
|
|
1543
|
+
}
|
|
1544
|
+
else if (length === 2 || length === 3) {
|
|
1545
|
+
return new StringParser(text);
|
|
1589
1546
|
}
|
|
1590
1547
|
else {
|
|
1591
|
-
|
|
1548
|
+
const last = parts.pop();
|
|
1549
|
+
const [first, ...middles] = parts;
|
|
1550
|
+
return new ArrayStringParser([first, middles.join(' '), last]);
|
|
1592
1551
|
}
|
|
1593
|
-
return initials;
|
|
1594
1552
|
}
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1553
|
+
static buildAsync(text, index) {
|
|
1554
|
+
try {
|
|
1555
|
+
return Promise.resolve(Parser.build(text, index));
|
|
1556
|
+
}
|
|
1557
|
+
catch (error) {
|
|
1558
|
+
return Promise.reject(error);
|
|
1559
|
+
}
|
|
1600
1560
|
}
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
const
|
|
1606
|
-
const
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
const
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
break;
|
|
1620
|
-
case types_1.Flat.LAST_NAME:
|
|
1621
|
-
name = hasMid ? [fn, mn, l] : [fn, l];
|
|
1622
|
-
break;
|
|
1623
|
-
case types_1.Flat.MIDDLE_NAME:
|
|
1624
|
-
name = hasMid ? [fn, m, ln] : [fn, ln];
|
|
1625
|
-
break;
|
|
1626
|
-
case types_1.Flat.FIRST_MID:
|
|
1627
|
-
name = hasMid ? [f, m, ln] : [f, ln];
|
|
1628
|
-
break;
|
|
1629
|
-
case types_1.Flat.MID_LAST:
|
|
1630
|
-
name = hasMid ? [fn, m, l] : [fn, l];
|
|
1631
|
-
break;
|
|
1632
|
-
case types_1.Flat.ALL:
|
|
1633
|
-
name = hasMid ? [f, m, l] : [f, l];
|
|
1634
|
-
break;
|
|
1635
|
-
}
|
|
1561
|
+
}
|
|
1562
|
+
exports.Parser = Parser;
|
|
1563
|
+
class StringParser extends Parser {
|
|
1564
|
+
parse(options) {
|
|
1565
|
+
const config = config_1.Config.merge(options);
|
|
1566
|
+
const names = this.raw.split(config.separator.token);
|
|
1567
|
+
return new ArrayStringParser(names).parse(config);
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
exports.StringParser = StringParser;
|
|
1571
|
+
class ArrayStringParser extends Parser {
|
|
1572
|
+
parse(options) {
|
|
1573
|
+
const config = config_1.Config.merge(options);
|
|
1574
|
+
const raw = this.raw.map((n) => n.trim());
|
|
1575
|
+
const index = utils_1.NameIndex.when(config.orderedBy, raw.length);
|
|
1576
|
+
const validator = new validator_1.ArrayStringValidator(index);
|
|
1577
|
+
if (config.bypass) {
|
|
1578
|
+
validator.validateIndex(raw);
|
|
1636
1579
|
}
|
|
1637
1580
|
else {
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1581
|
+
validator.validate(raw);
|
|
1582
|
+
}
|
|
1583
|
+
const { firstName, lastName, middleName, prefix, suffix } = index;
|
|
1584
|
+
const fullName = new full_name_1.FullName(config)
|
|
1585
|
+
.setFirstName(new name_1.FirstName(raw[firstName]))
|
|
1586
|
+
.setLastName(new name_1.LastName(raw[lastName]));
|
|
1587
|
+
if (raw.length >= 3)
|
|
1588
|
+
fullName.setMiddleName(raw[middleName].split(config.separator.token));
|
|
1589
|
+
if (raw.length >= 4)
|
|
1590
|
+
fullName.setPrefix(name_1.Name.prefix(raw[prefix]));
|
|
1591
|
+
if (raw.length === 5)
|
|
1592
|
+
fullName.setSuffix(name_1.Name.suffix(raw[suffix]));
|
|
1593
|
+
return fullName;
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
exports.ArrayStringParser = ArrayStringParser;
|
|
1597
|
+
class NamaParser extends Parser {
|
|
1598
|
+
parse(options) {
|
|
1599
|
+
const config = config_1.Config.merge(options);
|
|
1600
|
+
const names = new Map(Object.entries(this.raw).map(([key, value]) => {
|
|
1601
|
+
const namon = types_1.Namon.cast(key);
|
|
1602
|
+
if (!namon) {
|
|
1603
|
+
throw new error_1.InputError({
|
|
1604
|
+
source: Object.values(this.raw).join(' '),
|
|
1605
|
+
message: `unsupported key "${key}"`,
|
|
1606
|
+
});
|
|
1657
1607
|
}
|
|
1608
|
+
return [namon, value];
|
|
1609
|
+
}));
|
|
1610
|
+
if (config.bypass) {
|
|
1611
|
+
validator_1.Validators.nama.validateKeys(names);
|
|
1658
1612
|
}
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
const next = by === types_1.Flat.FIRST_NAME
|
|
1662
|
-
? types_1.Flat.MIDDLE_NAME
|
|
1663
|
-
: by === types_1.Flat.MIDDLE_NAME
|
|
1664
|
-
? types_1.Flat.LAST_NAME
|
|
1665
|
-
: by === types_1.Flat.LAST_NAME
|
|
1666
|
-
? types_1.Flat.FIRST_MID
|
|
1667
|
-
: by === types_1.Flat.FIRST_MID
|
|
1668
|
-
? types_1.Flat.MID_LAST
|
|
1669
|
-
: by === types_1.Flat.MID_LAST
|
|
1670
|
-
? types_1.Flat.ALL
|
|
1671
|
-
: by === types_1.Flat.ALL
|
|
1672
|
-
? types_1.Flat.ALL
|
|
1673
|
-
: by;
|
|
1674
|
-
if (next === by)
|
|
1675
|
-
return flat;
|
|
1676
|
-
return this.flatten(Object.assign(Object.assign({}, options), { by: next }));
|
|
1613
|
+
else {
|
|
1614
|
+
validator_1.Validators.nama.validate(names);
|
|
1677
1615
|
}
|
|
1678
|
-
return
|
|
1679
|
-
}
|
|
1680
|
-
zip(by = types_1.Flat.MID_LAST, withPeriod = true) {
|
|
1681
|
-
return this.flatten({ limit: 0, by, withPeriod });
|
|
1616
|
+
return full_name_1.FullName.parse(this.raw, config);
|
|
1682
1617
|
}
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
if (
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1618
|
+
}
|
|
1619
|
+
exports.NamaParser = NamaParser;
|
|
1620
|
+
class ArrayNameParser extends Parser {
|
|
1621
|
+
parse(options) {
|
|
1622
|
+
validator_1.ArrayNameValidator.create().validate(this.raw);
|
|
1623
|
+
const fullName = new full_name_1.FullName(options);
|
|
1624
|
+
for (const name of this.raw) {
|
|
1625
|
+
if (name.isPrefix) {
|
|
1626
|
+
fullName.setPrefix(name);
|
|
1627
|
+
}
|
|
1628
|
+
else if (name.isSuffix) {
|
|
1629
|
+
fullName.setSuffix(name);
|
|
1630
|
+
}
|
|
1631
|
+
else if (name.isFirstName) {
|
|
1632
|
+
fullName.setFirstName(name instanceof name_1.FirstName ? name : new name_1.FirstName(name.value));
|
|
1633
|
+
}
|
|
1634
|
+
else if (name.isMiddleName) {
|
|
1635
|
+
fullName.middleName.push(name);
|
|
1636
|
+
}
|
|
1637
|
+
else if (name.isLastName) {
|
|
1638
|
+
const mother = name instanceof name_1.LastName ? name.mother : undefined;
|
|
1639
|
+
fullName.setLastName(new name_1.LastName(name.value, mother, fullName.config.surname));
|
|
1702
1640
|
}
|
|
1703
|
-
group += char;
|
|
1704
|
-
if (char === '$')
|
|
1705
|
-
continue;
|
|
1706
|
-
formatted.push((_a = __classPrivateFieldGet(this, _Namefully_instances, "m", _Namefully_map).call(this, group)) !== null && _a !== void 0 ? _a : '');
|
|
1707
|
-
group = '';
|
|
1708
1641
|
}
|
|
1709
|
-
return
|
|
1642
|
+
return fullName;
|
|
1710
1643
|
}
|
|
1711
|
-
|
|
1712
|
-
|
|
1644
|
+
}
|
|
1645
|
+
exports.ArrayNameParser = ArrayNameParser;
|
|
1646
|
+
|
|
1647
|
+
|
|
1648
|
+
/***/ }),
|
|
1649
|
+
/* 9 */
|
|
1650
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
1651
|
+
|
|
1652
|
+
"use strict";
|
|
1653
|
+
|
|
1654
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
1655
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
1656
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
1657
|
+
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");
|
|
1658
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
1659
|
+
};
|
|
1660
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
1661
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
1662
|
+
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");
|
|
1663
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
1664
|
+
};
|
|
1665
|
+
var _FullName_prefix, _FullName_firstName, _FullName_middleName, _FullName_lastName, _FullName_suffix, _FullName_config;
|
|
1666
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1667
|
+
exports.FullName = void 0;
|
|
1668
|
+
const config_1 = __webpack_require__(6);
|
|
1669
|
+
const validator_1 = __webpack_require__(7);
|
|
1670
|
+
const types_1 = __webpack_require__(0);
|
|
1671
|
+
const error_1 = __webpack_require__(1);
|
|
1672
|
+
const name_1 = __webpack_require__(3);
|
|
1673
|
+
class FullName {
|
|
1674
|
+
constructor(options) {
|
|
1675
|
+
_FullName_prefix.set(this, void 0);
|
|
1676
|
+
_FullName_firstName.set(this, void 0);
|
|
1677
|
+
_FullName_middleName.set(this, []);
|
|
1678
|
+
_FullName_lastName.set(this, void 0);
|
|
1679
|
+
_FullName_suffix.set(this, void 0);
|
|
1680
|
+
_FullName_config.set(this, void 0);
|
|
1681
|
+
__classPrivateFieldSet(this, _FullName_config, config_1.Config.merge(options), "f");
|
|
1713
1682
|
}
|
|
1714
|
-
|
|
1715
|
-
return this
|
|
1683
|
+
get config() {
|
|
1684
|
+
return __classPrivateFieldGet(this, _FullName_config, "f");
|
|
1716
1685
|
}
|
|
1717
|
-
|
|
1718
|
-
return this
|
|
1686
|
+
get prefix() {
|
|
1687
|
+
return __classPrivateFieldGet(this, _FullName_prefix, "f");
|
|
1719
1688
|
}
|
|
1720
|
-
|
|
1721
|
-
return this
|
|
1689
|
+
get firstName() {
|
|
1690
|
+
return __classPrivateFieldGet(this, _FullName_firstName, "f");
|
|
1722
1691
|
}
|
|
1723
|
-
|
|
1724
|
-
return this
|
|
1692
|
+
get lastName() {
|
|
1693
|
+
return __classPrivateFieldGet(this, _FullName_lastName, "f");
|
|
1725
1694
|
}
|
|
1726
|
-
|
|
1727
|
-
return (
|
|
1695
|
+
get middleName() {
|
|
1696
|
+
return __classPrivateFieldGet(this, _FullName_middleName, "f");
|
|
1728
1697
|
}
|
|
1729
|
-
|
|
1730
|
-
return this
|
|
1731
|
-
.map((n) => (0, utils_1.capitalize)(n))
|
|
1732
|
-
.join('');
|
|
1698
|
+
get suffix() {
|
|
1699
|
+
return __classPrivateFieldGet(this, _FullName_suffix, "f");
|
|
1733
1700
|
}
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1701
|
+
static parse(json, config) {
|
|
1702
|
+
var _a;
|
|
1703
|
+
try {
|
|
1704
|
+
const { prefix, firstName: fn, middleName: mn, lastName: ln, suffix } = json;
|
|
1705
|
+
return new FullName(config)
|
|
1706
|
+
.setPrefix(prefix)
|
|
1707
|
+
.setFirstName(typeof fn === 'string' ? fn : new name_1.FirstName(fn.value, ...((_a = fn.more) !== null && _a !== void 0 ? _a : [])))
|
|
1708
|
+
.setMiddleName(typeof mn === 'string' ? [mn] : (mn !== null && mn !== void 0 ? mn : []))
|
|
1709
|
+
.setLastName(typeof ln === 'string' ? ln : new name_1.LastName(ln.father, ln.mother))
|
|
1710
|
+
.setSuffix(suffix);
|
|
1711
|
+
}
|
|
1712
|
+
catch (error) {
|
|
1713
|
+
if (error instanceof error_1.NameError)
|
|
1714
|
+
throw error;
|
|
1715
|
+
throw new error_1.UnknownError({
|
|
1716
|
+
source: Object.values(json).join(' '),
|
|
1717
|
+
message: 'could not parse JSON content',
|
|
1718
|
+
origin: error instanceof Error ? error : new Error(String(error)),
|
|
1719
|
+
});
|
|
1720
|
+
}
|
|
1738
1721
|
}
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1722
|
+
setPrefix(name) {
|
|
1723
|
+
if (!name)
|
|
1724
|
+
return this;
|
|
1725
|
+
if (!__classPrivateFieldGet(this, _FullName_config, "f").bypass)
|
|
1726
|
+
validator_1.Validators.prefix.validate(name);
|
|
1727
|
+
const prefix = name instanceof name_1.Name ? name.value : name;
|
|
1728
|
+
__classPrivateFieldSet(this, _FullName_prefix, name_1.Name.prefix(__classPrivateFieldGet(this, _FullName_config, "f").title === types_1.Title.US && !prefix.endsWith('.') ? `${prefix}.` : prefix), "f");
|
|
1729
|
+
return this;
|
|
1743
1730
|
}
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
.
|
|
1747
|
-
|
|
1731
|
+
setFirstName(name) {
|
|
1732
|
+
if (!__classPrivateFieldGet(this, _FullName_config, "f").bypass)
|
|
1733
|
+
validator_1.Validators.firstName.validate(name);
|
|
1734
|
+
__classPrivateFieldSet(this, _FullName_firstName, name instanceof name_1.FirstName ? name : new name_1.FirstName(name), "f");
|
|
1735
|
+
return this;
|
|
1748
1736
|
}
|
|
1749
|
-
|
|
1750
|
-
|
|
1737
|
+
setLastName(name) {
|
|
1738
|
+
if (!__classPrivateFieldGet(this, _FullName_config, "f").bypass)
|
|
1739
|
+
validator_1.Validators.lastName.validate(name);
|
|
1740
|
+
__classPrivateFieldSet(this, _FullName_lastName, name instanceof name_1.LastName ? name : new name_1.LastName(name), "f");
|
|
1741
|
+
return this;
|
|
1742
|
+
}
|
|
1743
|
+
setMiddleName(names) {
|
|
1744
|
+
if (!Array.isArray(names))
|
|
1745
|
+
return this;
|
|
1746
|
+
if (!__classPrivateFieldGet(this, _FullName_config, "f").bypass)
|
|
1747
|
+
validator_1.Validators.middleName.validate(names);
|
|
1748
|
+
__classPrivateFieldSet(this, _FullName_middleName, names.map((n) => (n instanceof name_1.Name ? n : name_1.Name.middle(n))), "f");
|
|
1749
|
+
return this;
|
|
1750
|
+
}
|
|
1751
|
+
setSuffix(name) {
|
|
1752
|
+
if (!name)
|
|
1753
|
+
return this;
|
|
1754
|
+
if (!__classPrivateFieldGet(this, _FullName_config, "f").bypass)
|
|
1755
|
+
validator_1.Validators.suffix.validate(name);
|
|
1756
|
+
__classPrivateFieldSet(this, _FullName_suffix, name_1.Name.suffix(name instanceof name_1.Name ? name.value : name), "f");
|
|
1757
|
+
return this;
|
|
1758
|
+
}
|
|
1759
|
+
has(key) {
|
|
1760
|
+
const namon = typeof key === 'string' ? types_1.Namon.cast(key) : key;
|
|
1761
|
+
if (!namon)
|
|
1762
|
+
return false;
|
|
1763
|
+
if (namon.equal(types_1.Namon.PREFIX))
|
|
1764
|
+
return !!__classPrivateFieldGet(this, _FullName_prefix, "f");
|
|
1765
|
+
if (namon.equal(types_1.Namon.SUFFIX))
|
|
1766
|
+
return !!__classPrivateFieldGet(this, _FullName_suffix, "f");
|
|
1767
|
+
return namon.equal(types_1.Namon.MIDDLE_NAME) ? __classPrivateFieldGet(this, _FullName_middleName, "f").length > 0 : true;
|
|
1768
|
+
}
|
|
1769
|
+
toString() {
|
|
1770
|
+
return Array.from(this.toIterable(true)).join(' ');
|
|
1771
|
+
}
|
|
1772
|
+
*toIterable(flat = false) {
|
|
1773
|
+
if (__classPrivateFieldGet(this, _FullName_prefix, "f"))
|
|
1774
|
+
yield __classPrivateFieldGet(this, _FullName_prefix, "f");
|
|
1775
|
+
if (flat) {
|
|
1776
|
+
yield* __classPrivateFieldGet(this, _FullName_firstName, "f").asNames;
|
|
1777
|
+
yield* __classPrivateFieldGet(this, _FullName_middleName, "f");
|
|
1778
|
+
yield* __classPrivateFieldGet(this, _FullName_lastName, "f").asNames;
|
|
1779
|
+
}
|
|
1780
|
+
else {
|
|
1781
|
+
yield __classPrivateFieldGet(this, _FullName_firstName, "f");
|
|
1782
|
+
yield* __classPrivateFieldGet(this, _FullName_middleName, "f");
|
|
1783
|
+
yield __classPrivateFieldGet(this, _FullName_lastName, "f");
|
|
1784
|
+
}
|
|
1785
|
+
if (__classPrivateFieldGet(this, _FullName_suffix, "f"))
|
|
1786
|
+
yield __classPrivateFieldGet(this, _FullName_suffix, "f");
|
|
1787
|
+
}
|
|
1788
|
+
*[(_FullName_prefix = new WeakMap(), _FullName_firstName = new WeakMap(), _FullName_middleName = new WeakMap(), _FullName_lastName = new WeakMap(), _FullName_suffix = new WeakMap(), _FullName_config = new WeakMap(), Symbol.iterator)]() {
|
|
1789
|
+
yield* this.toIterable(true);
|
|
1751
1790
|
}
|
|
1752
1791
|
}
|
|
1753
|
-
exports.
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
if (
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
var _a, _b;
|
|
1768
|
-
switch (char) {
|
|
1769
|
-
case '.':
|
|
1770
|
-
case ',':
|
|
1771
|
-
case ' ':
|
|
1772
|
-
case '-':
|
|
1773
|
-
case '_':
|
|
1774
|
-
return char;
|
|
1775
|
-
case 'b':
|
|
1776
|
-
return this.birth;
|
|
1777
|
-
case 'B':
|
|
1778
|
-
return this.birth.toUpperCase();
|
|
1779
|
-
case 'f':
|
|
1780
|
-
return this.first;
|
|
1781
|
-
case 'F':
|
|
1782
|
-
return this.first.toUpperCase();
|
|
1783
|
-
case 'l':
|
|
1784
|
-
return this.last;
|
|
1785
|
-
case 'L':
|
|
1786
|
-
return this.last.toUpperCase();
|
|
1787
|
-
case 'm':
|
|
1788
|
-
case 'M':
|
|
1789
|
-
return char === 'm' ? this.middleName().join(' ') : this.middleName().join(' ').toUpperCase();
|
|
1790
|
-
case 'o':
|
|
1791
|
-
case 'O':
|
|
1792
|
-
const sep = this.config.ending ? ',' : '';
|
|
1793
|
-
const names = [];
|
|
1794
|
-
if (this.prefix)
|
|
1795
|
-
names.push(this.prefix);
|
|
1796
|
-
names.push(`${this.last},`.toUpperCase());
|
|
1797
|
-
if (this.hasMiddle) {
|
|
1798
|
-
names.push(this.first, this.middleName().join(' ') + sep);
|
|
1799
|
-
}
|
|
1800
|
-
else {
|
|
1801
|
-
names.push(this.first + sep);
|
|
1802
|
-
}
|
|
1803
|
-
if (this.suffix)
|
|
1804
|
-
names.push(this.suffix);
|
|
1805
|
-
const nama = names.join(' ').trim();
|
|
1806
|
-
return char === 'o' ? nama : nama.toUpperCase();
|
|
1807
|
-
case 'p':
|
|
1808
|
-
return this.prefix;
|
|
1809
|
-
case 'P':
|
|
1810
|
-
return (_a = this.prefix) === null || _a === void 0 ? void 0 : _a.toUpperCase();
|
|
1811
|
-
case 's':
|
|
1812
|
-
return this.suffix;
|
|
1813
|
-
case 'S':
|
|
1814
|
-
return (_b = this.suffix) === null || _b === void 0 ? void 0 : _b.toUpperCase();
|
|
1815
|
-
case '$f':
|
|
1816
|
-
case '$F':
|
|
1817
|
-
return __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.initials()[0];
|
|
1818
|
-
case '$l':
|
|
1819
|
-
case '$L':
|
|
1820
|
-
return __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.initials()[0];
|
|
1821
|
-
case '$m':
|
|
1822
|
-
case '$M':
|
|
1823
|
-
return this.hasMiddle ? this.middle[0] : undefined;
|
|
1824
|
-
default:
|
|
1825
|
-
return undefined;
|
|
1792
|
+
exports.FullName = FullName;
|
|
1793
|
+
|
|
1794
|
+
|
|
1795
|
+
/***/ }),
|
|
1796
|
+
/* 10 */
|
|
1797
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
1798
|
+
|
|
1799
|
+
"use strict";
|
|
1800
|
+
|
|
1801
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
1802
|
+
if (k2 === undefined) k2 = k;
|
|
1803
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1804
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1805
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
1826
1806
|
}
|
|
1807
|
+
Object.defineProperty(o, k2, desc);
|
|
1808
|
+
}) : (function(o, m, k, k2) {
|
|
1809
|
+
if (k2 === undefined) k2 = k;
|
|
1810
|
+
o[k2] = m[k];
|
|
1811
|
+
}));
|
|
1812
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
1813
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
1827
1814
|
};
|
|
1815
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1816
|
+
exports.NameIndex = exports.Parser = exports.version = void 0;
|
|
1817
|
+
const namefully_1 = __webpack_require__(5);
|
|
1818
|
+
__exportStar(__webpack_require__(11), exports);
|
|
1819
|
+
__exportStar(__webpack_require__(6), exports);
|
|
1820
|
+
var constants_1 = __webpack_require__(4);
|
|
1821
|
+
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return constants_1.VERSION; } });
|
|
1822
|
+
__exportStar(__webpack_require__(1), exports);
|
|
1823
|
+
__exportStar(__webpack_require__(9), exports);
|
|
1824
|
+
__exportStar(__webpack_require__(3), exports);
|
|
1825
|
+
__exportStar(__webpack_require__(5), exports);
|
|
1826
|
+
var parser_1 = __webpack_require__(8);
|
|
1827
|
+
Object.defineProperty(exports, "Parser", { enumerable: true, get: function () { return parser_1.Parser; } });
|
|
1828
|
+
__exportStar(__webpack_require__(0), exports);
|
|
1829
|
+
var utils_1 = __webpack_require__(2);
|
|
1830
|
+
Object.defineProperty(exports, "NameIndex", { enumerable: true, get: function () { return utils_1.NameIndex; } });
|
|
1831
|
+
exports.default = namefully_1.default;
|
|
1832
|
+
|
|
1833
|
+
|
|
1834
|
+
/***/ }),
|
|
1835
|
+
/* 11 */
|
|
1836
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
1837
|
+
|
|
1838
|
+
"use strict";
|
|
1839
|
+
|
|
1840
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1841
|
+
exports.NameBuilder = void 0;
|
|
1842
|
+
const namefully_1 = __webpack_require__(5);
|
|
1843
|
+
const validator_1 = __webpack_require__(7);
|
|
1844
|
+
class Builder {
|
|
1845
|
+
constructor(prebuild, postbuild, preclear, postclear) {
|
|
1846
|
+
this.prebuild = prebuild;
|
|
1847
|
+
this.postbuild = postbuild;
|
|
1848
|
+
this.preclear = preclear;
|
|
1849
|
+
this.postclear = postclear;
|
|
1850
|
+
this.queue = [];
|
|
1851
|
+
this.instance = null;
|
|
1852
|
+
}
|
|
1853
|
+
get size() {
|
|
1854
|
+
return this.queue.length;
|
|
1855
|
+
}
|
|
1856
|
+
removeFirst() {
|
|
1857
|
+
return this.queue.length > 0 ? this.queue.shift() : undefined;
|
|
1858
|
+
}
|
|
1859
|
+
removeLast() {
|
|
1860
|
+
return this.queue.length > 0 ? this.queue.pop() : undefined;
|
|
1861
|
+
}
|
|
1862
|
+
addFirst(value) {
|
|
1863
|
+
this.queue.unshift(value);
|
|
1864
|
+
}
|
|
1865
|
+
addLast(value) {
|
|
1866
|
+
this.queue.push(value);
|
|
1867
|
+
}
|
|
1868
|
+
add(...values) {
|
|
1869
|
+
this.queue.push(...values);
|
|
1870
|
+
}
|
|
1871
|
+
remove(value) {
|
|
1872
|
+
const index = this.queue.indexOf(value);
|
|
1873
|
+
if (index !== -1) {
|
|
1874
|
+
this.queue.splice(index, 1);
|
|
1875
|
+
return true;
|
|
1876
|
+
}
|
|
1877
|
+
return false;
|
|
1878
|
+
}
|
|
1879
|
+
removeWhere(callback) {
|
|
1880
|
+
this.queue = this.queue.filter((item) => !callback(item));
|
|
1881
|
+
}
|
|
1882
|
+
retainWhere(callback) {
|
|
1883
|
+
this.queue = this.queue.filter(callback);
|
|
1884
|
+
}
|
|
1885
|
+
clear() {
|
|
1886
|
+
var _a, _b;
|
|
1887
|
+
if (this.instance !== null)
|
|
1888
|
+
(_a = this.preclear) === null || _a === void 0 ? void 0 : _a.call(this, this.instance);
|
|
1889
|
+
this.queue = [];
|
|
1890
|
+
(_b = this.postclear) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
1891
|
+
this.instance = null;
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
class NameBuilder extends Builder {
|
|
1895
|
+
constructor(names, prebuild, postbuild, preclear, postclear) {
|
|
1896
|
+
super(prebuild, postbuild, preclear, postclear);
|
|
1897
|
+
this.add(...names);
|
|
1898
|
+
}
|
|
1899
|
+
static create(name) {
|
|
1900
|
+
return new NameBuilder(name ? [name] : []);
|
|
1901
|
+
}
|
|
1902
|
+
static of(...initialNames) {
|
|
1903
|
+
return new NameBuilder(initialNames);
|
|
1904
|
+
}
|
|
1905
|
+
static use({ names, prebuild, postbuild, preclear, postclear, }) {
|
|
1906
|
+
return new NameBuilder(names !== null && names !== void 0 ? names : [], prebuild, postbuild, preclear, postclear);
|
|
1907
|
+
}
|
|
1908
|
+
build(config) {
|
|
1909
|
+
var _a, _b;
|
|
1910
|
+
(_a = this.prebuild) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
1911
|
+
const names = [...this.queue];
|
|
1912
|
+
validator_1.ArrayNameValidator.create().validate(names);
|
|
1913
|
+
this.instance = new namefully_1.Namefully(names, config);
|
|
1914
|
+
(_b = this.postbuild) === null || _b === void 0 ? void 0 : _b.call(this, this.instance);
|
|
1915
|
+
return this.instance;
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
exports.NameBuilder = NameBuilder;
|
|
1828
1919
|
|
|
1829
1920
|
|
|
1830
1921
|
/***/ })
|