namefully 1.3.0 → 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.
@@ -150,7 +150,10 @@ class Namon {
150
150
  return Namon.all.has(key);
151
151
  }
152
152
  static cast(key) {
153
- return Namon.has(key) ? Namon.all.get(key) : undefined;
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
- input = this.source;
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
- input = this.source.join(' ');
244
- return input;
256
+ return this.source.join(' ');
257
+ return '<undefined>';
245
258
  }
246
259
  get hasMessage() {
247
- return this.message && this.message.trim().length > 0;
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.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.isNameArray = exports.isStringArray = exports.toggleCase = exports.decapitalize = exports.capitalize = exports.NameIndex = void 0;
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 this(-1, 0, -1, 1, -1);
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 this(-1, 0, -1, 1, -1);
355
+ return new NameIndex(-1, 0, -1, 1, -1);
343
356
  case 3:
344
- return new this(-1, 0, 1, 2, -1);
357
+ return new NameIndex(-1, 0, 1, 2, -1);
345
358
  case 4:
346
- return new this(0, 1, 2, 3, -1);
359
+ return new NameIndex(0, 1, 2, 3, -1);
347
360
  case 5:
348
- return new this(0, 1, 2, 3, 4);
361
+ return new NameIndex(0, 1, 2, 3, 4);
349
362
  default:
350
363
  return NameIndex.base();
351
364
  }
@@ -353,20 +366,20 @@ class NameIndex {
353
366
  else {
354
367
  switch (count) {
355
368
  case 2:
356
- return new this(-1, 1, -1, 0, -1);
369
+ return new NameIndex(-1, 1, -1, 0, -1);
357
370
  case 3:
358
- return new this(-1, 1, 2, 0, -1);
371
+ return new NameIndex(-1, 1, 2, 0, -1);
359
372
  case 4:
360
- return new this(0, 2, 3, 1, -1);
373
+ return new NameIndex(0, 2, 3, 1, -1);
361
374
  case 5:
362
- return new this(0, 2, 3, 1, 4);
375
+ return new NameIndex(0, 2, 3, 1, 4);
363
376
  default:
364
377
  return NameIndex.base();
365
378
  }
366
379
  }
367
380
  }
368
381
  static only({ prefix = -1, firstName, middleName = -1, lastName, suffix = -1 }) {
369
- return new this(prefix, firstName, middleName, lastName, suffix);
382
+ return new NameIndex(prefix, firstName, middleName, lastName, suffix);
370
383
  }
371
384
  toJson() {
372
385
  return {
@@ -382,40 +395,28 @@ exports.NameIndex = NameIndex;
382
395
  function capitalize(str, range = types_1.CapsRange.INITIAL) {
383
396
  if (!str || range === types_1.CapsRange.NONE)
384
397
  return str;
385
- const initial = str[0].toUpperCase();
386
- const rest = str.slice(1).toLowerCase();
398
+ const [initial, rest] = [str[0].toUpperCase(), str.slice(1).toLowerCase()];
387
399
  return range === types_1.CapsRange.INITIAL ? initial.concat(rest) : str.toUpperCase();
388
400
  }
389
401
  exports.capitalize = capitalize;
390
402
  function decapitalize(str, range = types_1.CapsRange.INITIAL) {
391
403
  if (!str || range === types_1.CapsRange.NONE)
392
404
  return str;
393
- const initial = str[0].toLowerCase();
394
- const rest = str.slice(1);
405
+ const [initial, rest] = [str[0].toLowerCase(), str.slice(1)];
395
406
  return range === types_1.CapsRange.INITIAL ? initial.concat(rest) : str.toLowerCase();
396
407
  }
397
408
  exports.decapitalize = decapitalize;
398
409
  function toggleCase(str) {
399
- const chars = [];
400
- for (const c of str) {
401
- if (c === c.toUpperCase()) {
402
- chars.push(c.toLowerCase());
403
- }
404
- else {
405
- chars.push(c.toUpperCase());
406
- }
407
- }
408
- return chars.join('');
410
+ return str
411
+ .split('')
412
+ .map((c) => (c === c.toUpperCase() ? c.toLowerCase() : c.toUpperCase()))
413
+ .join('');
409
414
  }
410
415
  exports.toggleCase = toggleCase;
411
416
  function isStringArray(value) {
412
417
  return Array.isArray(value) && value.length > 0 && value.every((e) => typeof e === 'string');
413
418
  }
414
419
  exports.isStringArray = isStringArray;
415
- function isNameArray(value) {
416
- return Array.isArray(value) && value.length > 0 && value.every((e) => e instanceof name_1.Name);
417
- }
418
- exports.isNameArray = isNameArray;
419
420
 
420
421
 
421
422
  /***/ }),
@@ -437,7 +438,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
437
438
  };
438
439
  var _Name_namon, _FirstName_more, _LastName_mother;
439
440
  Object.defineProperty(exports, "__esModule", { value: true });
440
- exports.LastName = exports.FirstName = exports.Name = void 0;
441
+ exports.isNameArray = exports.LastName = exports.FirstName = exports.Name = void 0;
441
442
  const error_1 = __webpack_require__(1);
442
443
  const types_1 = __webpack_require__(0);
443
444
  const utils_1 = __webpack_require__(2);
@@ -477,19 +478,19 @@ class Name {
477
478
  return this.type === types_1.Namon.SUFFIX;
478
479
  }
479
480
  static prefix(value) {
480
- return new this(value, types_1.Namon.PREFIX);
481
+ return new Name(value, types_1.Namon.PREFIX);
481
482
  }
482
483
  static first(value) {
483
- return new this(value, types_1.Namon.FIRST_NAME);
484
+ return new Name(value, types_1.Namon.FIRST_NAME);
484
485
  }
485
486
  static middle(value) {
486
- return new this(value, types_1.Namon.MIDDLE_NAME);
487
+ return new Name(value, types_1.Namon.MIDDLE_NAME);
487
488
  }
488
489
  static last(value) {
489
- return new this(value, types_1.Namon.LAST_NAME);
490
+ return new Name(value, types_1.Namon.LAST_NAME);
490
491
  }
491
492
  static suffix(value) {
492
- return new this(value, types_1.Namon.SUFFIX);
493
+ return new Name(value, types_1.Namon.SUFFIX);
493
494
  }
494
495
  initials() {
495
496
  return [this.initial];
@@ -509,8 +510,8 @@ class Name {
509
510
  return this;
510
511
  }
511
512
  validate(name) {
512
- if ((name === null || name === void 0 ? void 0 : name.trim().length) < 2) {
513
- throw new error_1.InputError({ source: name, message: 'must be 2+ characters' });
513
+ if (typeof name === 'string' && name.trim().length < 1) {
514
+ throw new error_1.InputError({ source: name, message: 'must be 1+ characters' });
514
515
  }
515
516
  }
516
517
  }
@@ -520,7 +521,7 @@ class FirstName extends Name {
520
521
  constructor(value, ...more) {
521
522
  super(value, types_1.Namon.FIRST_NAME);
522
523
  _FirstName_more.set(this, void 0);
523
- more.forEach((n) => this.validate(n));
524
+ more.forEach(this.validate);
524
525
  __classPrivateFieldSet(this, _FirstName_more, more, "f");
525
526
  }
526
527
  get hasMore() {
@@ -531,9 +532,8 @@ class FirstName extends Name {
531
532
  }
532
533
  get asNames() {
533
534
  const names = [Name.first(this.value)];
534
- if (this.hasMore) {
535
- names.push(...__classPrivateFieldGet(this, _FirstName_more, "f").map((n) => Name.first(n)));
536
- }
535
+ if (this.hasMore)
536
+ names.push(...__classPrivateFieldGet(this, _FirstName_more, "f").map(Name.first));
537
537
  return names;
538
538
  }
539
539
  get more() {
@@ -544,9 +544,8 @@ class FirstName extends Name {
544
544
  }
545
545
  initials(withMore = false) {
546
546
  const inits = [this.initial];
547
- if (withMore && this.hasMore) {
547
+ if (withMore && this.hasMore)
548
548
  inits.push(...__classPrivateFieldGet(this, _FirstName_more, "f").map((n) => n[0]));
549
- }
550
549
  return inits;
551
550
  }
552
551
  caps(range) {
@@ -565,7 +564,7 @@ class FirstName extends Name {
565
564
  }
566
565
  copyWith(values) {
567
566
  var _a, _b;
568
- return new FirstName((_a = values.first) !== null && _a !== void 0 ? _a : this.value, ...((_b = values.more) !== null && _b !== void 0 ? _b : __classPrivateFieldGet(this, _FirstName_more, "f")));
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")));
569
568
  }
570
569
  }
571
570
  exports.FirstName = FirstName;
@@ -593,9 +592,8 @@ class LastName extends Name {
593
592
  }
594
593
  get asNames() {
595
594
  const names = [Name.last(this.value)];
596
- if (this.hasMother) {
595
+ if (__classPrivateFieldGet(this, _LastName_mother, "f"))
597
596
  names.push(Name.last(__classPrivateFieldGet(this, _LastName_mother, "f")));
598
- }
599
597
  return names;
600
598
  }
601
599
  toString(format) {
@@ -608,39 +606,37 @@ class LastName extends Name {
608
606
  return (_a = this.mother) !== null && _a !== void 0 ? _a : '';
609
607
  case types_1.Surname.HYPHENATED:
610
608
  return this.hasMother ? `${this.value}-${__classPrivateFieldGet(this, _LastName_mother, "f")}` : this.value;
611
- case types_1.Surname.ALL:
609
+ default:
612
610
  return this.hasMother ? `${this.value} ${__classPrivateFieldGet(this, _LastName_mother, "f")}` : this.value;
613
611
  }
614
612
  }
615
613
  initials(format) {
616
- format = format || this.format;
617
614
  const inits = [];
618
- switch (format) {
619
- case types_1.Surname.MOTHER:
620
- if (this.hasMother)
621
- inits.push(__classPrivateFieldGet(this, _LastName_mother, "f")[0]);
622
- break;
615
+ switch (format !== null && format !== void 0 ? format : this.format) {
623
616
  case types_1.Surname.HYPHENATED:
624
617
  case types_1.Surname.ALL:
625
618
  inits.push(this.initial);
626
- if (this.hasMother)
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"))
627
624
  inits.push(__classPrivateFieldGet(this, _LastName_mother, "f")[0]);
628
625
  break;
629
- case types_1.Surname.FATHER:
630
626
  default:
631
627
  inits.push(this.initial);
632
628
  }
633
629
  return inits;
634
630
  }
635
631
  caps(range) {
636
- range = range || this.capsRange;
632
+ range !== null && range !== void 0 ? range : (range = this.capsRange);
637
633
  this.value = (0, utils_1.capitalize)(this.value, range);
638
634
  if (this.hasMother)
639
635
  __classPrivateFieldSet(this, _LastName_mother, (0, utils_1.capitalize)(__classPrivateFieldGet(this, _LastName_mother, "f"), range), "f");
640
636
  return this;
641
637
  }
642
638
  decaps(range) {
643
- range = range || this.capsRange;
639
+ range !== null && range !== void 0 ? range : (range = this.capsRange);
644
640
  this.value = (0, utils_1.decapitalize)(this.value, range);
645
641
  if (this.hasMother)
646
642
  __classPrivateFieldSet(this, _LastName_mother, (0, utils_1.decapitalize)(__classPrivateFieldGet(this, _LastName_mother, "f"), range), "f");
@@ -648,11 +644,15 @@ class LastName extends Name {
648
644
  }
649
645
  copyWith(values) {
650
646
  var _a, _b, _c;
651
- return new LastName((_a = values.father) !== null && _a !== void 0 ? _a : this.value, (_b = values.mother) !== null && _b !== void 0 ? _b : this.mother, (_c = values.format) !== null && _c !== void 0 ? _c : this.format);
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);
652
648
  }
653
649
  }
654
650
  exports.LastName = LastName;
655
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;
656
656
 
657
657
 
658
658
  /***/ }),
@@ -662,34 +662,11 @@ _LastName_mother = new WeakMap();
662
662
  "use strict";
663
663
 
664
664
  Object.defineProperty(exports, "__esModule", { value: true });
665
- exports.ALLOWED_TOKENS = exports.MAX_NUMBER_OF_NAME_PARTS = exports.MIN_NUMBER_OF_NAME_PARTS = exports.VERSION = void 0;
666
- exports.VERSION = '1.3.0';
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';
667
667
  exports.MIN_NUMBER_OF_NAME_PARTS = 2;
668
668
  exports.MAX_NUMBER_OF_NAME_PARTS = 5;
669
- exports.ALLOWED_TOKENS = [
670
- '.',
671
- ',',
672
- ' ',
673
- '-',
674
- '_',
675
- 'b',
676
- 'B',
677
- 'f',
678
- 'F',
679
- 'l',
680
- 'L',
681
- 'm',
682
- 'M',
683
- 'n',
684
- 'N',
685
- 'o',
686
- 'O',
687
- 'p',
688
- 'P',
689
- 's',
690
- 'S',
691
- '$',
692
- ];
669
+ exports.ALLOWED_FORMAT_TOKENS = ` .,_-()[]<>'"bBfFlLmMnNoOpPsS$`;
693
670
 
694
671
 
695
672
  /***/ }),
@@ -722,14 +699,16 @@ var _Namefully_instances, _Namefully_fullName, _Namefully_toParser, _Namefully_m
722
699
  Object.defineProperty(exports, "__esModule", { value: true });
723
700
  exports.Namefully = void 0;
724
701
  const constants_1 = __webpack_require__(4);
702
+ const name_1 = __webpack_require__(3);
725
703
  const error_1 = __webpack_require__(1);
726
- const parser_1 = __webpack_require__(8);
727
- const types_1 = __webpack_require__(0);
728
704
  const utils_1 = __webpack_require__(2);
705
+ const types_1 = __webpack_require__(0);
706
+ const parser_1 = __webpack_require__(8);
729
707
  class Namefully {
730
708
  constructor(names, options) {
731
709
  _Namefully_instances.add(this);
732
710
  _Namefully_fullName.set(this, void 0);
711
+ this.json = this.toJson;
733
712
  __classPrivateFieldSet(this, _Namefully_fullName, __classPrivateFieldGet(this, _Namefully_instances, "m", _Namefully_toParser).call(this, names).parse(options), "f");
734
713
  }
735
714
  static tryParse(text, index) {
@@ -789,25 +768,43 @@ class Namefully {
789
768
  get salutation() {
790
769
  return this.format('p l');
791
770
  }
771
+ get parts() {
772
+ return __classPrivateFieldGet(this, _Namefully_fullName, "f").toIterable();
773
+ }
774
+ get size() {
775
+ return Array.from(this.parts).length;
776
+ }
777
+ *[(_Namefully_fullName = new WeakMap(), _Namefully_instances = new WeakSet(), Symbol.iterator)]() {
778
+ yield* __classPrivateFieldGet(this, _Namefully_fullName, "f").toIterable(true);
779
+ }
792
780
  toString() {
793
781
  return this.full;
794
782
  }
795
- get(namon) {
796
- if (namon.equal(types_1.Namon.PREFIX))
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))
797
786
  return __classPrivateFieldGet(this, _Namefully_fullName, "f").prefix;
798
- if (namon.equal(types_1.Namon.FIRST_NAME))
787
+ if (namon === null || namon === void 0 ? void 0 : namon.equal(types_1.Namon.FIRST_NAME))
799
788
  return __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName;
800
- if (namon.equal(types_1.Namon.MIDDLE_NAME))
789
+ if (namon === null || namon === void 0 ? void 0 : namon.equal(types_1.Namon.MIDDLE_NAME))
801
790
  return __classPrivateFieldGet(this, _Namefully_fullName, "f").middleName;
802
- if (namon.equal(types_1.Namon.LAST_NAME))
791
+ if (namon === null || namon === void 0 ? void 0 : namon.equal(types_1.Namon.LAST_NAME))
803
792
  return __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName;
804
- if (namon.equal(types_1.Namon.SUFFIX))
793
+ if (namon === null || namon === void 0 ? void 0 : namon.equal(types_1.Namon.SUFFIX))
805
794
  return __classPrivateFieldGet(this, _Namefully_fullName, "f").suffix;
806
795
  return undefined;
807
796
  }
808
797
  equal(other) {
809
798
  return this.toString() === other.toString();
810
799
  }
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;
807
+ }
811
808
  toJson() {
812
809
  return {
813
810
  prefix: this.prefix,
@@ -823,21 +820,26 @@ class Namefully {
823
820
  fullName(orderedBy) {
824
821
  const sep = this.config.ending ? ',' : '';
825
822
  const names = [];
826
- orderedBy = orderedBy || this.config.orderedBy;
827
823
  if (this.prefix)
828
824
  names.push(this.prefix);
829
- if (orderedBy === types_1.NameOrder.FIRST_NAME) {
825
+ if ((orderedBy !== null && orderedBy !== void 0 ? orderedBy : this.config.orderedBy) === types_1.NameOrder.FIRST_NAME) {
830
826
  names.push(this.first, ...this.middleName(), this.last + sep);
831
827
  }
832
828
  else {
833
- names.push(this.last, this.first, this.middleName().join(' ') + sep);
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
+ }
834
836
  }
835
837
  if (this.suffix)
836
838
  names.push(this.suffix);
837
839
  return names.join(' ').trim();
838
840
  }
839
841
  birthName(orderedBy) {
840
- orderedBy = orderedBy || this.config.orderedBy;
842
+ orderedBy !== null && orderedBy !== void 0 ? orderedBy : (orderedBy = this.config.orderedBy);
841
843
  return orderedBy === types_1.NameOrder.FIRST_NAME
842
844
  ? [this.first, ...this.middleName(), this.last].join(' ')
843
845
  : [this.last, this.first, ...this.middleName()].join(' ');
@@ -852,50 +854,42 @@ class Namefully {
852
854
  return __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.toString(format);
853
855
  }
854
856
  initials(options) {
857
+ const { orderedBy = this.config.orderedBy, only = types_1.NameType.BIRTH_NAME, asJson } = options !== null && options !== void 0 ? options : {};
855
858
  const firstInits = __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.initials();
856
- const midInits = __classPrivateFieldGet(this, _Namefully_fullName, "f").middleName.map((n) => n.initials()[0]);
859
+ const midInits = __classPrivateFieldGet(this, _Namefully_fullName, "f").middleName.map((n) => n.value[0]);
857
860
  const lastInits = __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.initials();
858
- if (options === null || options === void 0 ? void 0 : options.asJson)
861
+ if (asJson)
859
862
  return { firstName: firstInits, middleName: midInits, lastName: lastInits };
860
- const initials = [];
861
- const { orderedBy = this.config.orderedBy, only = types_1.NameType.BIRTH_NAME } = options !== null && options !== void 0 ? options : {};
862
863
  if (only !== types_1.NameType.BIRTH_NAME) {
863
- if (only === types_1.NameType.FIRST_NAME) {
864
- initials.push(...firstInits);
865
- }
866
- else if (only === types_1.NameType.MIDDLE_NAME) {
867
- initials.push(...midInits);
868
- }
869
- else {
870
- initials.push(...lastInits);
871
- }
864
+ return only === types_1.NameType.FIRST_NAME ? firstInits : only === types_1.NameType.MIDDLE_NAME ? midInits : lastInits;
872
865
  }
873
866
  else if (orderedBy === types_1.NameOrder.FIRST_NAME) {
874
- initials.push(...firstInits, ...midInits, ...lastInits);
867
+ return [...firstInits, ...midInits, ...lastInits];
875
868
  }
876
869
  else {
877
- initials.push(...lastInits, ...firstInits, ...midInits);
870
+ return [...lastInits, ...firstInits, ...midInits];
878
871
  }
879
- return initials;
880
872
  }
881
873
  shorten(orderedBy) {
882
- orderedBy = orderedBy || this.config.orderedBy;
874
+ orderedBy !== null && orderedBy !== void 0 ? orderedBy : (orderedBy = this.config.orderedBy);
875
+ const { firstName, lastName } = __classPrivateFieldGet(this, _Namefully_fullName, "f");
883
876
  return orderedBy === types_1.NameOrder.FIRST_NAME
884
- ? [__classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.value, __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.toString()].join(' ')
885
- : [__classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.toString(), __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.value].join(' ');
877
+ ? [firstName.value, lastName.toString()].join(' ')
878
+ : [lastName.toString(), firstName.value].join(' ');
886
879
  }
887
880
  flatten(options) {
888
- if (this.length <= options.limit)
889
- return this.full;
890
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");
891
885
  const sep = withPeriod ? '.' : '';
892
- const fn = __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.toString();
893
- const mn = this.middleName().join(' ');
894
- const ln = __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.toString();
895
886
  const hasMid = this.hasMiddle;
896
- const f = __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.initials(withMore).join(sep + ' ') + sep;
897
- const l = __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.initials(surname).join(sep + ' ') + sep;
898
- const m = hasMid ? __classPrivateFieldGet(this, _Namefully_fullName, "f").middleName.map((n) => n.initials()[0]).join(sep + ' ') + sep : '';
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 : '';
899
893
  let name = [];
900
894
  if (this.config.orderedBy === types_1.NameOrder.FIRST_NAME) {
901
895
  switch (by) {
@@ -914,7 +908,7 @@ class Namefully {
914
908
  case types_1.Flat.MID_LAST:
915
909
  name = hasMid ? [fn, m, l] : [fn, l];
916
910
  break;
917
- case types_1.Flat.ALL:
911
+ default:
918
912
  name = hasMid ? [f, m, l] : [f, l];
919
913
  break;
920
914
  }
@@ -936,7 +930,7 @@ class Namefully {
936
930
  case types_1.Flat.MID_LAST:
937
931
  name = hasMid ? [l, fn, m] : [l, fn];
938
932
  break;
939
- case types_1.Flat.ALL:
933
+ default:
940
934
  name = hasMid ? [l, f, m] : [l, f];
941
935
  break;
942
936
  }
@@ -977,8 +971,8 @@ class Namefully {
977
971
  pattern = 'o';
978
972
  let group = '';
979
973
  const formatted = [];
980
- for (const char of pattern.split('')) {
981
- if (constants_1.ALLOWED_TOKENS.indexOf(char) === -1) {
974
+ for (const char of pattern) {
975
+ if (!constants_1.ALLOWED_FORMAT_TOKENS.includes(char)) {
982
976
  throw new error_1.NotAllowedError({
983
977
  source: this.full,
984
978
  operation: 'format',
@@ -994,7 +988,8 @@ class Namefully {
994
988
  return formatted.join('').trim();
995
989
  }
996
990
  flip() {
997
- this.config.updateOrder(this.config.orderedBy === types_1.NameOrder.FIRST_NAME ? types_1.NameOrder.LAST_NAME : types_1.NameOrder.FIRST_NAME);
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 });
998
993
  }
999
994
  split(separator = /[' -]/g) {
1000
995
  return this.birth.replace(separator, ' ').split(' ');
@@ -1036,27 +1031,21 @@ class Namefully {
1036
1031
  }
1037
1032
  }
1038
1033
  exports.Namefully = Namefully;
1039
- _Namefully_fullName = new WeakMap(), _Namefully_instances = new WeakSet(), _Namefully_toParser = function _Namefully_toParser(raw) {
1034
+ _Namefully_toParser = function _Namefully_toParser(raw) {
1040
1035
  if (raw instanceof parser_1.Parser)
1041
1036
  return raw;
1042
1037
  if (typeof raw === 'string')
1043
1038
  return new parser_1.StringParser(raw);
1044
1039
  if ((0, utils_1.isStringArray)(raw))
1045
1040
  return new parser_1.ArrayStringParser(raw);
1046
- if ((0, utils_1.isNameArray)(raw))
1041
+ if ((0, name_1.isNameArray)(raw))
1047
1042
  return new parser_1.ArrayNameParser(raw);
1048
1043
  if (typeof raw === 'object')
1049
1044
  return new parser_1.NamaParser(raw);
1050
- throw new error_1.InputError({ source: raw, message: 'Cannot parse raw data. Review expected data types.' });
1045
+ throw new error_1.InputError({ source: raw, message: 'Cannot parse raw data; review expected data types.' });
1051
1046
  }, _Namefully_map = function _Namefully_map(char) {
1052
1047
  var _a, _b;
1053
1048
  switch (char) {
1054
- case '.':
1055
- case ',':
1056
- case ' ':
1057
- case '-':
1058
- case '_':
1059
- return char;
1060
1049
  case 'b':
1061
1050
  return this.birth;
1062
1051
  case 'B':
@@ -1075,16 +1064,15 @@ _Namefully_fullName = new WeakMap(), _Namefully_instances = new WeakSet(), _Name
1075
1064
  case 'o':
1076
1065
  case 'O':
1077
1066
  return ((character) => {
1078
- const sep = this.config.ending ? ',' : '', names = [];
1067
+ const sep = this.config.ending ? ',' : '';
1068
+ const names = [];
1079
1069
  if (this.prefix)
1080
1070
  names.push(this.prefix);
1081
1071
  names.push(`${this.last},`.toUpperCase());
1082
- if (this.hasMiddle) {
1072
+ if (this.hasMiddle)
1083
1073
  names.push(this.first, this.middleName().join(' ') + sep);
1084
- }
1085
- else {
1074
+ else
1086
1075
  names.push(this.first + sep);
1087
- }
1088
1076
  if (this.suffix)
1089
1077
  names.push(this.suffix);
1090
1078
  const nama = names.join(' ').trim();
@@ -1099,16 +1087,19 @@ _Namefully_fullName = new WeakMap(), _Namefully_instances = new WeakSet(), _Name
1099
1087
  case 'S':
1100
1088
  return (_b = this.suffix) === null || _b === void 0 ? void 0 : _b.toUpperCase();
1101
1089
  case '$f':
1090
+ return __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.value[0];
1102
1091
  case '$F':
1103
- return __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.initials()[0];
1092
+ return __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.initials(true).join('');
1104
1093
  case '$l':
1094
+ return __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.value[0];
1105
1095
  case '$L':
1106
- return __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.initials()[0];
1096
+ return __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.initials().join('');
1107
1097
  case '$m':
1108
- case '$M':
1109
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;
1110
1101
  default:
1111
- return undefined;
1102
+ return constants_1.ALLOWED_FORMAT_TOKENS.includes(char) ? char : undefined;
1112
1103
  }
1113
1104
  };
1114
1105
  exports.default = (names, options) => {
@@ -1222,10 +1213,16 @@ class Config {
1222
1213
  __classPrivateFieldSet(this, _Config_surname, types_1.Surname.FATHER, "f");
1223
1214
  _a.cache.set(this.name, this);
1224
1215
  }
1225
- updateOrder(order) {
1226
- if (order && order !== __classPrivateFieldGet(this, _Config_orderedBy, "f")) {
1227
- __classPrivateFieldSet(_a.cache.get(this.name), _Config_orderedBy, order, "f");
1228
- }
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");
1229
1226
  }
1230
1227
  }
1231
1228
  exports.Config = Config;
@@ -1255,11 +1252,11 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
1255
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;
1256
1253
  Object.defineProperty(exports, "__esModule", { value: true });
1257
1254
  exports.Validators = exports.ArrayNameValidator = exports.ArrayStringValidator = exports.NamaValidator = void 0;
1258
- const constants_1 = __webpack_require__(4);
1259
- const error_1 = __webpack_require__(1);
1260
- const name_1 = __webpack_require__(3);
1261
1255
  const types_1 = __webpack_require__(0);
1262
1256
  const utils_1 = __webpack_require__(2);
1257
+ const name_1 = __webpack_require__(3);
1258
+ const error_1 = __webpack_require__(1);
1259
+ const constants_1 = __webpack_require__(4);
1263
1260
  class ValidationRule {
1264
1261
  }
1265
1262
  ValidationRule.base = /[a-zA-Z\u00C0-\u00D6\u00D8-\u00f6\u00f8-\u00ff\u0400-\u04FFΆ-ωΑ-ώ]/;
@@ -1267,19 +1264,22 @@ ValidationRule.namon = new RegExp(`^${ValidationRule.base.source}+(([' -]${Valid
1267
1264
  ValidationRule.firstName = ValidationRule.namon;
1268
1265
  ValidationRule.middleName = new RegExp(`^${ValidationRule.base.source}+(([' -]${ValidationRule.base.source})?${ValidationRule.base.source}*)*$`);
1269
1266
  ValidationRule.lastName = ValidationRule.namon;
1267
+ const toNameSource = (values) => {
1268
+ return (0, name_1.isNameArray)(values) ? values.map((n) => n.toString()).join(' ') : '';
1269
+ };
1270
1270
  class ArrayValidator {
1271
1271
  validate(values) {
1272
1272
  if (values.length === 0 || values.length < constants_1.MIN_NUMBER_OF_NAME_PARTS || values.length > constants_1.MAX_NUMBER_OF_NAME_PARTS) {
1273
1273
  throw new error_1.InputError({
1274
1274
  source: values.map((n) => n.toString()),
1275
- message: `expecting a list of ${constants_1.MIN_NUMBER_OF_NAME_PARTS}-${constants_1.MIN_NUMBER_OF_NAME_PARTS} elements`,
1275
+ message: `expecting a list of ${constants_1.MIN_NUMBER_OF_NAME_PARTS}-${constants_1.MAX_NUMBER_OF_NAME_PARTS} elements`,
1276
1276
  });
1277
1277
  }
1278
1278
  }
1279
1279
  }
1280
1280
  class NamonValidator {
1281
1281
  static create() {
1282
- return __classPrivateFieldGet(this, _a, "f", _NamonValidator_validator) || (__classPrivateFieldSet(this, _a, new this(), "f", _NamonValidator_validator));
1282
+ return __classPrivateFieldGet(this, _a, "f", _NamonValidator_validator) || (__classPrivateFieldSet(this, _a, new _a(), "f", _NamonValidator_validator));
1283
1283
  }
1284
1284
  validate(value, type) {
1285
1285
  if (value instanceof name_1.Name) {
@@ -1290,15 +1290,12 @@ class NamonValidator {
1290
1290
  throw new error_1.ValidationError({
1291
1291
  source: value,
1292
1292
  nameType: 'namon',
1293
- message: 'invalid content',
1293
+ message: 'invalid name content failing namon regex',
1294
1294
  });
1295
1295
  }
1296
1296
  }
1297
1297
  else {
1298
- throw new error_1.InputError({
1299
- source: typeof value,
1300
- message: 'expecting types of string | Name',
1301
- });
1298
+ throw new error_1.InputError({ source: typeof value, message: 'expecting types of string or Name' });
1302
1299
  }
1303
1300
  }
1304
1301
  }
@@ -1306,7 +1303,7 @@ _a = NamonValidator;
1306
1303
  _NamonValidator_validator = { value: void 0 };
1307
1304
  class FirstNameValidator {
1308
1305
  static create() {
1309
- return __classPrivateFieldGet(this, _b, "f", _FirstNameValidator_validator) || (__classPrivateFieldSet(this, _b, new this(), "f", _FirstNameValidator_validator));
1306
+ return __classPrivateFieldGet(this, _b, "f", _FirstNameValidator_validator) || (__classPrivateFieldSet(this, _b, new _b(), "f", _FirstNameValidator_validator));
1310
1307
  }
1311
1308
  validate(value) {
1312
1309
  if (value instanceof name_1.FirstName) {
@@ -1317,15 +1314,12 @@ class FirstNameValidator {
1317
1314
  throw new error_1.ValidationError({
1318
1315
  source: value,
1319
1316
  nameType: 'firstName',
1320
- message: 'invalid content',
1317
+ message: 'invalid name content failing firstName regex',
1321
1318
  });
1322
1319
  }
1323
1320
  }
1324
1321
  else {
1325
- throw new error_1.InputError({
1326
- source: typeof value,
1327
- message: 'expecting types string | FirstName',
1328
- });
1322
+ throw new error_1.InputError({ source: typeof value, message: 'expecting types string or FirstName' });
1329
1323
  }
1330
1324
  }
1331
1325
  }
@@ -1333,7 +1327,7 @@ _b = FirstNameValidator;
1333
1327
  _FirstNameValidator_validator = { value: void 0 };
1334
1328
  class MiddleNameValidator {
1335
1329
  static create() {
1336
- return __classPrivateFieldGet(this, _c, "f", _MiddleNameValidator_validator) || (__classPrivateFieldSet(this, _c, new this(), "f", _MiddleNameValidator_validator));
1330
+ return __classPrivateFieldGet(this, _c, "f", _MiddleNameValidator_validator) || (__classPrivateFieldSet(this, _c, new _c(), "f", _MiddleNameValidator_validator));
1337
1331
  }
1338
1332
  validate(value) {
1339
1333
  if (typeof value === 'string') {
@@ -1341,7 +1335,7 @@ class MiddleNameValidator {
1341
1335
  throw new error_1.ValidationError({
1342
1336
  source: value,
1343
1337
  nameType: 'middleName',
1344
- message: 'invalid content',
1338
+ message: 'invalid name content failing middleName regex',
1345
1339
  });
1346
1340
  }
1347
1341
  }
@@ -1353,7 +1347,7 @@ class MiddleNameValidator {
1353
1347
  }
1354
1348
  catch (error) {
1355
1349
  throw new error_1.ValidationError({
1356
- source: value,
1350
+ source: toNameSource(value),
1357
1351
  nameType: 'middleName',
1358
1352
  message: error === null || error === void 0 ? void 0 : error.message,
1359
1353
  });
@@ -1362,7 +1356,7 @@ class MiddleNameValidator {
1362
1356
  else {
1363
1357
  throw new error_1.InputError({
1364
1358
  source: typeof value,
1365
- message: 'expecting types of string | string[] | Name[]',
1359
+ message: 'expecting types of string, string[] or Name[]',
1366
1360
  });
1367
1361
  }
1368
1362
  }
@@ -1371,7 +1365,7 @@ _c = MiddleNameValidator;
1371
1365
  _MiddleNameValidator_validator = { value: void 0 };
1372
1366
  class LastNameValidator {
1373
1367
  static create() {
1374
- return __classPrivateFieldGet(this, _d, "f", _LastNameValidator_validator) || (__classPrivateFieldSet(this, _d, new this(), "f", _LastNameValidator_validator));
1368
+ return __classPrivateFieldGet(this, _d, "f", _LastNameValidator_validator) || (__classPrivateFieldSet(this, _d, new _d(), "f", _LastNameValidator_validator));
1375
1369
  }
1376
1370
  validate(value) {
1377
1371
  if (value instanceof name_1.LastName) {
@@ -1382,15 +1376,12 @@ class LastNameValidator {
1382
1376
  throw new error_1.ValidationError({
1383
1377
  source: value,
1384
1378
  nameType: 'lastName',
1385
- message: 'invalid content',
1379
+ message: 'invalid name content failing lastName regex',
1386
1380
  });
1387
1381
  }
1388
1382
  }
1389
1383
  else {
1390
- throw new error_1.InputError({
1391
- source: typeof value,
1392
- message: 'expecting types string | LastName',
1393
- });
1384
+ throw new error_1.InputError({ source: typeof value, message: 'expecting types string or LastName' });
1394
1385
  }
1395
1386
  }
1396
1387
  }
@@ -1398,21 +1389,21 @@ _d = LastNameValidator;
1398
1389
  _LastNameValidator_validator = { value: void 0 };
1399
1390
  class NameValidator {
1400
1391
  static create() {
1401
- return __classPrivateFieldGet(this, _e, "f", _NameValidator_validator) || (__classPrivateFieldSet(this, _e, new this(), "f", _NameValidator_validator));
1392
+ return __classPrivateFieldGet(this, _e, "f", _NameValidator_validator) || (__classPrivateFieldSet(this, _e, new _e(), "f", _NameValidator_validator));
1402
1393
  }
1403
1394
  validate(name, type) {
1404
1395
  if (type && name.type !== type) {
1405
1396
  throw new error_1.ValidationError({
1406
- source: [name],
1397
+ source: name.toString(),
1407
1398
  nameType: name.type.toString(),
1408
- message: 'wrong type',
1399
+ message: 'wrong name type; only Namon types are supported',
1409
1400
  });
1410
1401
  }
1411
1402
  if (!ValidationRule.namon.test(name.value)) {
1412
1403
  throw new error_1.ValidationError({
1413
- source: [name],
1404
+ source: name.toString(),
1414
1405
  nameType: name.type.toString(),
1415
- message: 'invalid content',
1406
+ message: 'invalid name content failing namon regex',
1416
1407
  });
1417
1408
  }
1418
1409
  }
@@ -1421,18 +1412,16 @@ _e = NameValidator;
1421
1412
  _NameValidator_validator = { value: void 0 };
1422
1413
  class NamaValidator {
1423
1414
  static create() {
1424
- return __classPrivateFieldGet(this, _f, "f", _NamaValidator_validator) || (__classPrivateFieldSet(this, _f, new this(), "f", _NamaValidator_validator));
1415
+ return __classPrivateFieldGet(this, _f, "f", _NamaValidator_validator) || (__classPrivateFieldSet(this, _f, new _f(), "f", _NamaValidator_validator));
1425
1416
  }
1426
1417
  validate(value) {
1427
1418
  this.validateKeys(value);
1428
1419
  Validators.firstName.validate(value.get(types_1.Namon.FIRST_NAME));
1429
1420
  Validators.lastName.validate(value.get(types_1.Namon.LAST_NAME));
1430
- if (value.has(types_1.Namon.PREFIX)) {
1421
+ if (value.has(types_1.Namon.PREFIX))
1431
1422
  Validators.namon.validate(value.get(types_1.Namon.PREFIX));
1432
- }
1433
- if (value.has(types_1.Namon.SUFFIX)) {
1423
+ if (value.has(types_1.Namon.SUFFIX))
1434
1424
  Validators.namon.validate(value.get(types_1.Namon.SUFFIX));
1435
- }
1436
1425
  }
1437
1426
  validateKeys(nama) {
1438
1427
  if (!nama.size) {
@@ -1441,20 +1430,14 @@ class NamaValidator {
1441
1430
  else if (nama.size < constants_1.MIN_NUMBER_OF_NAME_PARTS || nama.size > constants_1.MAX_NUMBER_OF_NAME_PARTS) {
1442
1431
  throw new error_1.InputError({
1443
1432
  source: [...nama.values()],
1444
- message: `expecting ${constants_1.MIN_NUMBER_OF_NAME_PARTS}-${constants_1.MIN_NUMBER_OF_NAME_PARTS} fields`,
1433
+ message: `expecting ${constants_1.MIN_NUMBER_OF_NAME_PARTS}-${constants_1.MAX_NUMBER_OF_NAME_PARTS} fields`,
1445
1434
  });
1446
1435
  }
1447
1436
  if (!nama.has(types_1.Namon.FIRST_NAME)) {
1448
- throw new error_1.InputError({
1449
- source: [...nama.values()],
1450
- message: '"firstName" is a required key',
1451
- });
1437
+ throw new error_1.InputError({ source: [...nama.values()], message: '"firstName" is a required key' });
1452
1438
  }
1453
1439
  if (!nama.has(types_1.Namon.LAST_NAME)) {
1454
- throw new error_1.InputError({
1455
- source: [...nama.values()],
1456
- message: '"lastName" is a required key',
1457
- });
1440
+ throw new error_1.InputError({ source: [...nama.values()], message: '"lastName" is a required key' });
1458
1441
  }
1459
1442
  }
1460
1443
  }
@@ -1487,18 +1470,18 @@ class ArrayNameValidator {
1487
1470
  _ArrayNameValidator_instances.add(this);
1488
1471
  }
1489
1472
  static create() {
1490
- return __classPrivateFieldGet(this, _g, "f", _ArrayNameValidator_validator) || (__classPrivateFieldSet(this, _g, new this(), "f", _ArrayNameValidator_validator));
1473
+ return __classPrivateFieldGet(this, _g, "f", _ArrayNameValidator_validator) || (__classPrivateFieldSet(this, _g, new _g(), "f", _ArrayNameValidator_validator));
1491
1474
  }
1492
1475
  validate(value) {
1493
1476
  if (value.length < constants_1.MIN_NUMBER_OF_NAME_PARTS) {
1494
1477
  throw new error_1.InputError({
1495
- source: value,
1478
+ source: toNameSource(value),
1496
1479
  message: `expecting at least ${constants_1.MIN_NUMBER_OF_NAME_PARTS} elements`,
1497
1480
  });
1498
1481
  }
1499
1482
  if (!__classPrivateFieldGet(this, _ArrayNameValidator_instances, "m", _ArrayNameValidator_hasBasicNames).call(this, value)) {
1500
1483
  throw new error_1.InputError({
1501
- source: value,
1484
+ source: toNameSource(value),
1502
1485
  message: 'both first and last names are required',
1503
1486
  });
1504
1487
  }
@@ -1533,21 +1516,15 @@ Validators.suffix = NamonValidator.create();
1533
1516
 
1534
1517
  "use strict";
1535
1518
 
1536
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
1537
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
1538
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
1539
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1540
- };
1541
- var _NamaParser_instances, _NamaParser_asNama;
1542
1519
  Object.defineProperty(exports, "__esModule", { value: true });
1543
1520
  exports.ArrayNameParser = exports.NamaParser = exports.ArrayStringParser = exports.StringParser = exports.Parser = void 0;
1544
- const full_name_1 = __webpack_require__(9);
1545
1521
  const config_1 = __webpack_require__(6);
1546
1522
  const utils_1 = __webpack_require__(2);
1547
- const validator_1 = __webpack_require__(7);
1548
- const name_1 = __webpack_require__(3);
1549
- const types_1 = __webpack_require__(0);
1550
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);
1551
1528
  class Parser {
1552
1529
  constructor(raw) {
1553
1530
  this.raw = raw;
@@ -1556,16 +1533,13 @@ class Parser {
1556
1533
  const parts = text.trim().split(types_1.Separator.SPACE.token);
1557
1534
  const length = parts.length;
1558
1535
  if (index instanceof utils_1.NameIndex) {
1559
- const names = Object.entries(index.toJson())
1536
+ const names = Object.entries(index.json())
1560
1537
  .filter(([, position]) => position > -1 && position < length)
1561
1538
  .map(([key, position]) => new name_1.Name(parts[position], types_1.Namon.all.get(key)));
1562
1539
  return new ArrayNameParser(names);
1563
1540
  }
1564
1541
  if (length < 2) {
1565
- throw new error_1.InputError({
1566
- source: text,
1567
- message: 'cannot build from invalid input',
1568
- });
1542
+ throw new error_1.InputError({ source: text, message: 'expecting at least 2 name parts' });
1569
1543
  }
1570
1544
  else if (length === 2 || length === 3) {
1571
1545
  return new StringParser(text);
@@ -1590,14 +1564,13 @@ class StringParser extends Parser {
1590
1564
  parse(options) {
1591
1565
  const config = config_1.Config.merge(options);
1592
1566
  const names = this.raw.split(config.separator.token);
1593
- return new ArrayStringParser(names).parse(options);
1567
+ return new ArrayStringParser(names).parse(config);
1594
1568
  }
1595
1569
  }
1596
1570
  exports.StringParser = StringParser;
1597
1571
  class ArrayStringParser extends Parser {
1598
1572
  parse(options) {
1599
1573
  const config = config_1.Config.merge(options);
1600
- const fullName = new full_name_1.FullName(config);
1601
1574
  const raw = this.raw.map((n) => n.trim());
1602
1575
  const index = utils_1.NameIndex.when(config.orderedBy, raw.length);
1603
1576
  const validator = new validator_1.ArrayStringValidator(index);
@@ -1608,8 +1581,9 @@ class ArrayStringParser extends Parser {
1608
1581
  validator.validate(raw);
1609
1582
  }
1610
1583
  const { firstName, lastName, middleName, prefix, suffix } = index;
1611
- fullName.setFirstName(new name_1.FirstName(raw[firstName]));
1612
- fullName.setLastName(new name_1.LastName(raw[lastName]));
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]));
1613
1587
  if (raw.length >= 3)
1614
1588
  fullName.setMiddleName(raw[middleName].split(config.separator.token));
1615
1589
  if (raw.length >= 4)
@@ -1621,39 +1595,32 @@ class ArrayStringParser extends Parser {
1621
1595
  }
1622
1596
  exports.ArrayStringParser = ArrayStringParser;
1623
1597
  class NamaParser extends Parser {
1624
- constructor() {
1625
- super(...arguments);
1626
- _NamaParser_instances.add(this);
1627
- }
1628
1598
  parse(options) {
1629
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
+ });
1607
+ }
1608
+ return [namon, value];
1609
+ }));
1630
1610
  if (config.bypass) {
1631
- validator_1.NamaValidator.create().validateKeys(__classPrivateFieldGet(this, _NamaParser_instances, "m", _NamaParser_asNama).call(this));
1611
+ validator_1.Validators.nama.validateKeys(names);
1632
1612
  }
1633
1613
  else {
1634
- validator_1.NamaValidator.create().validate(__classPrivateFieldGet(this, _NamaParser_instances, "m", _NamaParser_asNama).call(this));
1614
+ validator_1.Validators.nama.validate(names);
1635
1615
  }
1636
1616
  return full_name_1.FullName.parse(this.raw, config);
1637
1617
  }
1638
1618
  }
1639
1619
  exports.NamaParser = NamaParser;
1640
- _NamaParser_instances = new WeakSet(), _NamaParser_asNama = function _NamaParser_asNama() {
1641
- return new Map(Object.entries(this.raw).map(([key, value]) => {
1642
- const namon = types_1.Namon.cast(key);
1643
- if (!namon) {
1644
- throw new error_1.InputError({
1645
- source: Object.values(this.raw).join(' '),
1646
- message: `unsupported key "${key}"`,
1647
- });
1648
- }
1649
- return [namon, value];
1650
- }));
1651
- };
1652
1620
  class ArrayNameParser extends Parser {
1653
1621
  parse(options) {
1654
- const config = config_1.Config.merge(options);
1655
- const fullName = new full_name_1.FullName(config);
1656
1622
  validator_1.ArrayNameValidator.create().validate(this.raw);
1623
+ const fullName = new full_name_1.FullName(options);
1657
1624
  for (const name of this.raw) {
1658
1625
  if (name.isPrefix) {
1659
1626
  fullName.setPrefix(name);
@@ -1668,8 +1635,8 @@ class ArrayNameParser extends Parser {
1668
1635
  fullName.middleName.push(name);
1669
1636
  }
1670
1637
  else if (name.isLastName) {
1671
- const lastName = new name_1.LastName(name.value, name instanceof name_1.LastName ? name.mother : undefined, config.surname);
1672
- fullName.setLastName(lastName);
1638
+ const mother = name instanceof name_1.LastName ? name.mother : undefined;
1639
+ fullName.setLastName(new name_1.LastName(name.value, mother, fullName.config.surname));
1673
1640
  }
1674
1641
  }
1675
1642
  return fullName;
@@ -1699,10 +1666,10 @@ var _FullName_prefix, _FullName_firstName, _FullName_middleName, _FullName_lastN
1699
1666
  Object.defineProperty(exports, "__esModule", { value: true });
1700
1667
  exports.FullName = void 0;
1701
1668
  const config_1 = __webpack_require__(6);
1669
+ const validator_1 = __webpack_require__(7);
1670
+ const types_1 = __webpack_require__(0);
1702
1671
  const error_1 = __webpack_require__(1);
1703
1672
  const name_1 = __webpack_require__(3);
1704
- const types_1 = __webpack_require__(0);
1705
- const validator_1 = __webpack_require__(7);
1706
1673
  class FullName {
1707
1674
  constructor(options) {
1708
1675
  _FullName_prefix.set(this, void 0);
@@ -1732,14 +1699,15 @@ class FullName {
1732
1699
  return __classPrivateFieldGet(this, _FullName_suffix, "f");
1733
1700
  }
1734
1701
  static parse(json, config) {
1702
+ var _a;
1735
1703
  try {
1736
- const fullName = new FullName(config);
1737
- fullName.setPrefix(json.prefix);
1738
- fullName.setFirstName(json.firstName);
1739
- fullName.setMiddleName(json.middleName);
1740
- fullName.setLastName(json.lastName);
1741
- fullName.setSuffix(json.suffix);
1742
- return fullName;
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);
1743
1711
  }
1744
1712
  catch (error) {
1745
1713
  if (error instanceof error_1.NameError)
@@ -1747,7 +1715,7 @@ class FullName {
1747
1715
  throw new error_1.UnknownError({
1748
1716
  source: Object.values(json).join(' '),
1749
1717
  message: 'could not parse JSON content',
1750
- error,
1718
+ origin: error instanceof Error ? error : new Error(String(error)),
1751
1719
  });
1752
1720
  }
1753
1721
  }
@@ -1757,7 +1725,7 @@ class FullName {
1757
1725
  if (!__classPrivateFieldGet(this, _FullName_config, "f").bypass)
1758
1726
  validator_1.Validators.prefix.validate(name);
1759
1727
  const prefix = name instanceof name_1.Name ? name.value : name;
1760
- __classPrivateFieldSet(this, _FullName_prefix, name_1.Name.prefix(__classPrivateFieldGet(this, _FullName_config, "f").title === types_1.Title.US ? `${prefix}.` : prefix), "f");
1728
+ __classPrivateFieldSet(this, _FullName_prefix, name_1.Name.prefix(__classPrivateFieldGet(this, _FullName_config, "f").title === types_1.Title.US && !prefix.endsWith('.') ? `${prefix}.` : prefix), "f");
1761
1729
  return this;
1762
1730
  }
1763
1731
  setFirstName(name) {
@@ -1777,7 +1745,7 @@ class FullName {
1777
1745
  return this;
1778
1746
  if (!__classPrivateFieldGet(this, _FullName_config, "f").bypass)
1779
1747
  validator_1.Validators.middleName.validate(names);
1780
- __classPrivateFieldSet(this, _FullName_middleName, names.map((name) => (name instanceof name_1.Name ? name : name_1.Name.middle(name))), "f");
1748
+ __classPrivateFieldSet(this, _FullName_middleName, names.map((n) => (n instanceof name_1.Name ? n : name_1.Name.middle(n))), "f");
1781
1749
  return this;
1782
1750
  }
1783
1751
  setSuffix(name) {
@@ -1788,16 +1756,40 @@ class FullName {
1788
1756
  __classPrivateFieldSet(this, _FullName_suffix, name_1.Name.suffix(name instanceof name_1.Name ? name.value : name), "f");
1789
1757
  return this;
1790
1758
  }
1791
- has(namon) {
1759
+ has(key) {
1760
+ const namon = typeof key === 'string' ? types_1.Namon.cast(key) : key;
1761
+ if (!namon)
1762
+ return false;
1792
1763
  if (namon.equal(types_1.Namon.PREFIX))
1793
1764
  return !!__classPrivateFieldGet(this, _FullName_prefix, "f");
1794
1765
  if (namon.equal(types_1.Namon.SUFFIX))
1795
1766
  return !!__classPrivateFieldGet(this, _FullName_suffix, "f");
1796
1767
  return namon.equal(types_1.Namon.MIDDLE_NAME) ? __classPrivateFieldGet(this, _FullName_middleName, "f").length > 0 : true;
1797
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);
1790
+ }
1798
1791
  }
1799
1792
  exports.FullName = FullName;
1800
- _FullName_prefix = new WeakMap(), _FullName_firstName = new WeakMap(), _FullName_middleName = new WeakMap(), _FullName_lastName = new WeakMap(), _FullName_suffix = new WeakMap(), _FullName_config = new WeakMap();
1801
1793
 
1802
1794
 
1803
1795
  /***/ }),