namefully 1.3.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/{lib → cjs}/builder.js +15 -13
  2. package/dist/cjs/config.js +100 -0
  3. package/dist/{lib → cjs}/constants.js +1 -1
  4. package/dist/{lib → cjs}/error.js +8 -5
  5. package/dist/cjs/fullname.js +102 -0
  6. package/dist/{lib → cjs}/index.js +18 -15
  7. package/dist/cjs/name.js +218 -0
  8. package/dist/cjs/namefully.js +391 -0
  9. package/dist/cjs/package.json +1 -0
  10. package/dist/cjs/parser.js +135 -0
  11. package/dist/{lib → cjs}/types.js +40 -36
  12. package/dist/{lib → cjs}/utils.js +17 -17
  13. package/dist/cjs/validator.js +266 -0
  14. package/dist/{types → esm}/builder.d.ts +8 -8
  15. package/dist/esm/builder.js +78 -0
  16. package/dist/{types → esm}/config.d.ts +1 -1
  17. package/dist/esm/config.js +96 -0
  18. package/dist/{types → esm}/constants.d.ts +1 -1
  19. package/dist/esm/constants.js +27 -0
  20. package/dist/{types → esm}/error.d.ts +2 -3
  21. package/dist/esm/error.js +87 -0
  22. package/dist/{types/full-name.d.ts → esm/fullname.d.ts} +3 -3
  23. package/dist/esm/fullname.js +98 -0
  24. package/dist/esm/index.d.ts +25 -0
  25. package/dist/esm/index.js +12 -0
  26. package/dist/{types → esm}/name.d.ts +2 -1
  27. package/dist/esm/name.js +211 -0
  28. package/dist/{types → esm}/namefully.d.ts +8 -8
  29. package/dist/esm/namefully.js +387 -0
  30. package/dist/esm/package.json +1 -0
  31. package/dist/{types → esm}/parser.d.ts +4 -4
  32. package/dist/esm/parser.js +127 -0
  33. package/dist/esm/types.js +106 -0
  34. package/dist/{types → esm}/utils.d.ts +1 -2
  35. package/dist/esm/utils.js +96 -0
  36. package/dist/{types → esm}/validator.d.ts +3 -3
  37. package/dist/esm/validator.js +259 -0
  38. package/dist/namefully.js +1580 -0
  39. package/dist/namefully.min.js +1 -0
  40. package/package.json +44 -27
  41. package/readme.md +1 -1
  42. package/dist/lib/config.js +0 -112
  43. package/dist/lib/full-name.js +0 -115
  44. package/dist/lib/name.js +0 -230
  45. package/dist/lib/namefully.js +0 -417
  46. package/dist/lib/parser.js +0 -144
  47. package/dist/lib/validator.js +0 -285
  48. package/dist/types/index.d.ts +0 -25
  49. package/dist/umd/namefully.js +0 -1931
  50. package/dist/umd/namefully.min.js +0 -1
  51. /package/dist/{types → esm}/types.d.ts +0 -0
@@ -1,16 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NameBuilder = void 0;
4
- const namefully_1 = require("./namefully");
5
- const validator_1 = require("./validator");
4
+ const namefully_js_1 = require("./namefully.js");
5
+ const validator_js_1 = require("./validator.js");
6
6
  class Builder {
7
+ prebuild;
8
+ postbuild;
9
+ preclear;
10
+ postclear;
11
+ queue = [];
12
+ instance = null;
7
13
  constructor(prebuild, postbuild, preclear, postclear) {
8
14
  this.prebuild = prebuild;
9
15
  this.postbuild = postbuild;
10
16
  this.preclear = preclear;
11
17
  this.postclear = postclear;
12
- this.queue = [];
13
- this.instance = null;
14
18
  }
15
19
  get size() {
16
20
  return this.queue.length;
@@ -45,11 +49,10 @@ class Builder {
45
49
  this.queue = this.queue.filter(callback);
46
50
  }
47
51
  clear() {
48
- var _a, _b;
49
52
  if (this.instance !== null)
50
- (_a = this.preclear) === null || _a === void 0 ? void 0 : _a.call(this, this.instance);
53
+ this.preclear?.(this.instance);
51
54
  this.queue = [];
52
- (_b = this.postclear) === null || _b === void 0 ? void 0 : _b.call(this);
55
+ this.postclear?.();
53
56
  this.instance = null;
54
57
  }
55
58
  }
@@ -65,15 +68,14 @@ class NameBuilder extends Builder {
65
68
  return new NameBuilder(initialNames);
66
69
  }
67
70
  static use({ names, prebuild, postbuild, preclear, postclear, }) {
68
- return new NameBuilder(names !== null && names !== void 0 ? names : [], prebuild, postbuild, preclear, postclear);
71
+ return new NameBuilder(names ?? [], prebuild, postbuild, preclear, postclear);
69
72
  }
70
73
  build(config) {
71
- var _a, _b;
72
- (_a = this.prebuild) === null || _a === void 0 ? void 0 : _a.call(this);
74
+ this.prebuild?.();
73
75
  const names = [...this.queue];
74
- validator_1.ArrayNameValidator.create().validate(names);
75
- this.instance = new namefully_1.Namefully(names, config);
76
- (_b = this.postbuild) === null || _b === void 0 ? void 0 : _b.call(this, this.instance);
76
+ validator_js_1.ArrayNameValidator.create().validate(names);
77
+ this.instance = new namefully_js_1.Namefully(names, config);
78
+ this.postbuild?.(this.instance);
77
79
  return this.instance;
78
80
  }
79
81
  }
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Config = void 0;
5
+ const types_js_1 = require("./types.js");
6
+ const defaultName = 'default';
7
+ const copyAlias = '_copy';
8
+ class Config {
9
+ #name;
10
+ #orderedBy;
11
+ #separator;
12
+ #title;
13
+ #ending;
14
+ #bypass;
15
+ #surname;
16
+ static cache = new Map();
17
+ get orderedBy() {
18
+ return this.#orderedBy;
19
+ }
20
+ get separator() {
21
+ return this.#separator;
22
+ }
23
+ get title() {
24
+ return this.#title;
25
+ }
26
+ get ending() {
27
+ return this.#ending;
28
+ }
29
+ get bypass() {
30
+ return this.#bypass;
31
+ }
32
+ get surname() {
33
+ return this.#surname;
34
+ }
35
+ get name() {
36
+ return this.#name;
37
+ }
38
+ constructor(name, orderedBy = types_js_1.NameOrder.FIRST_NAME, separator = types_js_1.Separator.SPACE, title = types_js_1.Title.UK, ending = false, bypass = true, surname = types_js_1.Surname.FATHER) {
39
+ this.#name = name;
40
+ this.#orderedBy = orderedBy;
41
+ this.#separator = separator;
42
+ this.#title = title;
43
+ this.#ending = ending;
44
+ this.#bypass = bypass;
45
+ this.#surname = surname;
46
+ }
47
+ static create(name = defaultName) {
48
+ if (!_a.cache.has(name))
49
+ _a.cache.set(name, new this(name));
50
+ return _a.cache.get(name);
51
+ }
52
+ static merge(other) {
53
+ if (!other) {
54
+ return _a.create();
55
+ }
56
+ else {
57
+ const config = _a.create(other.name);
58
+ config.#orderedBy = other.orderedBy ?? config.orderedBy;
59
+ config.#separator = other.separator ?? config.separator;
60
+ config.#title = other.title ?? config.title;
61
+ config.#ending = other.ending ?? config.ending;
62
+ config.#bypass = other.bypass ?? config.bypass;
63
+ config.#surname = other.surname ?? config.surname;
64
+ return config;
65
+ }
66
+ }
67
+ copyWith(options = {}) {
68
+ const { name, orderedBy, separator, title, ending, bypass, surname } = options;
69
+ const config = _a.create(this.#genNewName(name ?? this.name + copyAlias));
70
+ config.#orderedBy = orderedBy ?? this.orderedBy;
71
+ config.#separator = separator ?? this.separator;
72
+ config.#title = title ?? this.title;
73
+ config.#ending = ending ?? this.ending;
74
+ config.#bypass = bypass ?? this.bypass;
75
+ config.#surname = surname ?? this.surname;
76
+ return config;
77
+ }
78
+ clone() {
79
+ return this.copyWith();
80
+ }
81
+ reset() {
82
+ this.#orderedBy = types_js_1.NameOrder.FIRST_NAME;
83
+ this.#separator = types_js_1.Separator.SPACE;
84
+ this.#title = types_js_1.Title.UK;
85
+ this.#ending = false;
86
+ this.#bypass = true;
87
+ this.#surname = types_js_1.Surname.FATHER;
88
+ _a.cache.set(this.name, this);
89
+ }
90
+ updateOrder(order) {
91
+ if (order && order !== this.#orderedBy) {
92
+ _a.cache.get(this.name).#orderedBy = order;
93
+ }
94
+ }
95
+ #genNewName(name) {
96
+ return name === this.name || _a.cache.has(name) ? this.#genNewName(name + copyAlias) : name;
97
+ }
98
+ }
99
+ exports.Config = Config;
100
+ _a = Config;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ALLOWED_TOKENS = exports.MAX_NUMBER_OF_NAME_PARTS = exports.MIN_NUMBER_OF_NAME_PARTS = exports.VERSION = void 0;
4
- exports.VERSION = '1.3.0';
4
+ exports.VERSION = '2.0.0';
5
5
  exports.MIN_NUMBER_OF_NAME_PARTS = 2;
6
6
  exports.MAX_NUMBER_OF_NAME_PARTS = 5;
7
7
  exports.ALLOWED_TOKENS = [
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UnknownError = exports.NotAllowedError = exports.ValidationError = exports.InputError = exports.NameError = exports.NameErrorType = void 0;
4
- const utils_1 = require("./utils");
4
+ const utils_js_1 = require("./utils.js");
5
5
  var NameErrorType;
6
6
  (function (NameErrorType) {
7
7
  NameErrorType[NameErrorType["INPUT"] = 0] = "INPUT";
@@ -10,6 +10,8 @@ var NameErrorType;
10
10
  NameErrorType[NameErrorType["UNKNOWN"] = 3] = "UNKNOWN";
11
11
  })(NameErrorType || (exports.NameErrorType = NameErrorType = {}));
12
12
  class NameError extends Error {
13
+ source;
14
+ type;
13
15
  constructor(source, message, type = NameErrorType.UNKNOWN) {
14
16
  super(message);
15
17
  this.source = source;
@@ -22,14 +24,12 @@ class NameError extends Error {
22
24
  input = '<undefined>';
23
25
  if (typeof this.source === 'string')
24
26
  input = this.source;
25
- if ((0, utils_1.isNameArray)(this.source))
26
- input = this.source.map((n) => n.toString()).join(' ');
27
- if ((0, utils_1.isStringArray)(this.source))
27
+ if ((0, utils_js_1.isStringArray)(this.source))
28
28
  input = this.source.join(' ');
29
29
  return input;
30
30
  }
31
31
  get hasMessage() {
32
- return this.message && this.message.trim().length > 0;
32
+ return this.message.trim().length > 0;
33
33
  }
34
34
  toString() {
35
35
  let report = `${this.name} (${this.sourceAsString})`;
@@ -47,6 +47,7 @@ class InputError extends NameError {
47
47
  }
48
48
  exports.InputError = InputError;
49
49
  class ValidationError extends NameError {
50
+ nameType;
50
51
  constructor(error) {
51
52
  super(error.source, error.message, NameErrorType.VALIDATION);
52
53
  this.nameType = error.nameType;
@@ -61,6 +62,7 @@ class ValidationError extends NameError {
61
62
  }
62
63
  exports.ValidationError = ValidationError;
63
64
  class NotAllowedError extends NameError {
65
+ operation;
64
66
  constructor(error) {
65
67
  super(error.source, error.message, NameErrorType.NOT_ALLOWED);
66
68
  this.operation = error.operation;
@@ -77,6 +79,7 @@ class NotAllowedError extends NameError {
77
79
  }
78
80
  exports.NotAllowedError = NotAllowedError;
79
81
  class UnknownError extends NameError {
82
+ origin;
80
83
  constructor(error) {
81
84
  super(error.source, error.message, NameErrorType.UNKNOWN);
82
85
  this.origin = error.error;
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FullName = void 0;
4
+ const config_js_1 = require("./config.js");
5
+ const error_js_1 = require("./error.js");
6
+ const name_js_1 = require("./name.js");
7
+ const types_js_1 = require("./types.js");
8
+ const validator_js_1 = require("./validator.js");
9
+ class FullName {
10
+ #prefix;
11
+ #firstName;
12
+ #middleName = [];
13
+ #lastName;
14
+ #suffix;
15
+ #config;
16
+ constructor(options) {
17
+ this.#config = config_js_1.Config.merge(options);
18
+ }
19
+ get config() {
20
+ return this.#config;
21
+ }
22
+ get prefix() {
23
+ return this.#prefix;
24
+ }
25
+ get firstName() {
26
+ return this.#firstName;
27
+ }
28
+ get lastName() {
29
+ return this.#lastName;
30
+ }
31
+ get middleName() {
32
+ return this.#middleName;
33
+ }
34
+ get suffix() {
35
+ return this.#suffix;
36
+ }
37
+ static parse(json, config) {
38
+ try {
39
+ const fullName = new FullName(config);
40
+ fullName.setPrefix(json.prefix);
41
+ fullName.setFirstName(json.firstName);
42
+ fullName.setMiddleName(json.middleName ?? []);
43
+ fullName.setLastName(json.lastName);
44
+ fullName.setSuffix(json.suffix);
45
+ return fullName;
46
+ }
47
+ catch (error) {
48
+ if (error instanceof error_js_1.NameError)
49
+ throw error;
50
+ throw new error_js_1.UnknownError({
51
+ source: Object.values(json).join(' '),
52
+ message: 'could not parse JSON content',
53
+ error: error instanceof Error ? error : new Error(String(error)),
54
+ });
55
+ }
56
+ }
57
+ setPrefix(name) {
58
+ if (!name)
59
+ return this;
60
+ if (!this.#config.bypass)
61
+ validator_js_1.Validators.prefix.validate(name);
62
+ const prefix = name instanceof name_js_1.Name ? name.value : name;
63
+ this.#prefix = name_js_1.Name.prefix(this.#config.title === types_js_1.Title.US ? `${prefix}.` : prefix);
64
+ return this;
65
+ }
66
+ setFirstName(name) {
67
+ if (!this.#config.bypass)
68
+ validator_js_1.Validators.firstName.validate(name);
69
+ this.#firstName = name instanceof name_js_1.FirstName ? name : new name_js_1.FirstName(name);
70
+ return this;
71
+ }
72
+ setLastName(name) {
73
+ if (!this.#config.bypass)
74
+ validator_js_1.Validators.lastName.validate(name);
75
+ this.#lastName = name instanceof name_js_1.LastName ? name : new name_js_1.LastName(name);
76
+ return this;
77
+ }
78
+ setMiddleName(names) {
79
+ if (!Array.isArray(names))
80
+ return this;
81
+ if (!this.#config.bypass)
82
+ validator_js_1.Validators.middleName.validate(names);
83
+ this.#middleName = names.map((name) => (name instanceof name_js_1.Name ? name : name_js_1.Name.middle(name)));
84
+ return this;
85
+ }
86
+ setSuffix(name) {
87
+ if (!name)
88
+ return this;
89
+ if (!this.#config.bypass)
90
+ validator_js_1.Validators.suffix.validate(name);
91
+ this.#suffix = name_js_1.Name.suffix(name instanceof name_js_1.Name ? name.value : name);
92
+ return this;
93
+ }
94
+ has(namon) {
95
+ if (namon.equal(types_js_1.Namon.PREFIX))
96
+ return !!this.#prefix;
97
+ if (namon.equal(types_js_1.Namon.SUFFIX))
98
+ return !!this.#suffix;
99
+ return namon.equal(types_js_1.Namon.MIDDLE_NAME) ? this.#middleName.length > 0 : true;
100
+ }
101
+ }
102
+ exports.FullName = FullName;
@@ -13,20 +13,23 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
16
19
  Object.defineProperty(exports, "__esModule", { value: true });
17
20
  exports.NameIndex = exports.Parser = exports.version = void 0;
18
- const namefully_1 = require("./namefully");
19
- __exportStar(require("./builder"), exports);
20
- __exportStar(require("./config"), exports);
21
- var constants_1 = require("./constants");
22
- Object.defineProperty(exports, "version", { enumerable: true, get: function () { return constants_1.VERSION; } });
23
- __exportStar(require("./error"), exports);
24
- __exportStar(require("./full-name"), exports);
25
- __exportStar(require("./name"), exports);
26
- __exportStar(require("./namefully"), exports);
27
- var parser_1 = require("./parser");
28
- Object.defineProperty(exports, "Parser", { enumerable: true, get: function () { return parser_1.Parser; } });
29
- __exportStar(require("./types"), exports);
30
- var utils_1 = require("./utils");
31
- Object.defineProperty(exports, "NameIndex", { enumerable: true, get: function () { return utils_1.NameIndex; } });
32
- exports.default = namefully_1.default;
21
+ const namefully_js_1 = __importDefault(require("./namefully.js"));
22
+ __exportStar(require("./builder.js"), exports);
23
+ __exportStar(require("./config.js"), exports);
24
+ var constants_js_1 = require("./constants.js");
25
+ Object.defineProperty(exports, "version", { enumerable: true, get: function () { return constants_js_1.VERSION; } });
26
+ __exportStar(require("./error.js"), exports);
27
+ __exportStar(require("./fullname.js"), exports);
28
+ __exportStar(require("./name.js"), exports);
29
+ __exportStar(require("./namefully.js"), exports);
30
+ var parser_js_1 = require("./parser.js");
31
+ Object.defineProperty(exports, "Parser", { enumerable: true, get: function () { return parser_js_1.Parser; } });
32
+ __exportStar(require("./types.js"), exports);
33
+ var utils_js_1 = require("./utils.js");
34
+ Object.defineProperty(exports, "NameIndex", { enumerable: true, get: function () { return utils_js_1.NameIndex; } });
35
+ exports.default = namefully_js_1.default;
@@ -0,0 +1,218 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNameArray = exports.LastName = exports.FirstName = exports.Name = void 0;
4
+ const error_js_1 = require("./error.js");
5
+ const types_js_1 = require("./types.js");
6
+ const utils_js_1 = require("./utils.js");
7
+ class Name {
8
+ type;
9
+ #namon;
10
+ initial;
11
+ capsRange;
12
+ constructor(value, type, capsRange) {
13
+ this.type = type;
14
+ this.capsRange = capsRange ?? types_js_1.CapsRange.INITIAL;
15
+ this.value = value;
16
+ if (capsRange)
17
+ this.caps(capsRange);
18
+ }
19
+ set value(newValue) {
20
+ this.validate(newValue);
21
+ this.#namon = newValue;
22
+ this.initial = newValue[0];
23
+ }
24
+ get value() {
25
+ return this.#namon;
26
+ }
27
+ get length() {
28
+ return this.#namon.length;
29
+ }
30
+ get isPrefix() {
31
+ return this.type === types_js_1.Namon.PREFIX;
32
+ }
33
+ get isFirstName() {
34
+ return this.type === types_js_1.Namon.FIRST_NAME;
35
+ }
36
+ get isMiddleName() {
37
+ return this.type === types_js_1.Namon.MIDDLE_NAME;
38
+ }
39
+ get isLastName() {
40
+ return this.type === types_js_1.Namon.LAST_NAME;
41
+ }
42
+ get isSuffix() {
43
+ return this.type === types_js_1.Namon.SUFFIX;
44
+ }
45
+ static prefix(value) {
46
+ return new this(value, types_js_1.Namon.PREFIX);
47
+ }
48
+ static first(value) {
49
+ return new this(value, types_js_1.Namon.FIRST_NAME);
50
+ }
51
+ static middle(value) {
52
+ return new this(value, types_js_1.Namon.MIDDLE_NAME);
53
+ }
54
+ static last(value) {
55
+ return new this(value, types_js_1.Namon.LAST_NAME);
56
+ }
57
+ static suffix(value) {
58
+ return new this(value, types_js_1.Namon.SUFFIX);
59
+ }
60
+ initials() {
61
+ return [this.initial];
62
+ }
63
+ toString() {
64
+ return this.#namon;
65
+ }
66
+ equal(other) {
67
+ return other instanceof Name && other.value === this.value && other.type === this.type;
68
+ }
69
+ caps(range) {
70
+ this.value = (0, utils_js_1.capitalize)(this.#namon, range ?? this.capsRange);
71
+ return this;
72
+ }
73
+ decaps(range) {
74
+ this.value = (0, utils_js_1.decapitalize)(this.#namon, range ?? this.capsRange);
75
+ return this;
76
+ }
77
+ validate(name) {
78
+ if (name && name?.trim()?.length < 2) {
79
+ throw new error_js_1.InputError({ source: name, message: 'must be 2+ characters' });
80
+ }
81
+ }
82
+ }
83
+ exports.Name = Name;
84
+ class FirstName extends Name {
85
+ #more;
86
+ constructor(value, ...more) {
87
+ super(value, types_js_1.Namon.FIRST_NAME);
88
+ more.forEach((n) => this.validate(n));
89
+ this.#more = more;
90
+ }
91
+ get hasMore() {
92
+ return this.#more.length > 0;
93
+ }
94
+ get length() {
95
+ return super.length + (this.hasMore ? this.#more.reduce((acc, n) => acc + n).length : 0);
96
+ }
97
+ get asNames() {
98
+ const names = [Name.first(this.value)];
99
+ if (this.hasMore) {
100
+ names.push(...this.#more.map((n) => Name.first(n)));
101
+ }
102
+ return names;
103
+ }
104
+ get more() {
105
+ return this.#more;
106
+ }
107
+ toString(withMore = false) {
108
+ return withMore && this.hasMore ? `${this.value} ${this.#more.join(' ')}`.trim() : this.value;
109
+ }
110
+ initials(withMore = false) {
111
+ const inits = [this.initial];
112
+ if (withMore && this.hasMore) {
113
+ inits.push(...this.#more.map((n) => n[0]));
114
+ }
115
+ return inits;
116
+ }
117
+ caps(range) {
118
+ range = range || this.capsRange;
119
+ this.value = (0, utils_js_1.capitalize)(this.value, range);
120
+ if (this.hasMore)
121
+ this.#more = this.#more.map((n) => (0, utils_js_1.capitalize)(n, range));
122
+ return this;
123
+ }
124
+ decaps(range) {
125
+ range = range || this.capsRange;
126
+ this.value = (0, utils_js_1.decapitalize)(this.value, range);
127
+ if (this.hasMore)
128
+ this.#more = this.#more.map((n) => (0, utils_js_1.decapitalize)(n, range));
129
+ return this;
130
+ }
131
+ copyWith(values) {
132
+ return new FirstName(values?.first ?? this.value, ...(values?.more ?? this.#more));
133
+ }
134
+ }
135
+ exports.FirstName = FirstName;
136
+ class LastName extends Name {
137
+ format;
138
+ #mother;
139
+ constructor(father, mother, format = types_js_1.Surname.FATHER) {
140
+ super(father, types_js_1.Namon.LAST_NAME);
141
+ this.format = format;
142
+ this.validate(mother);
143
+ this.#mother = mother;
144
+ }
145
+ get father() {
146
+ return this.value;
147
+ }
148
+ get mother() {
149
+ return this.#mother;
150
+ }
151
+ get hasMother() {
152
+ return !!this.#mother;
153
+ }
154
+ get length() {
155
+ return super.length + (this.#mother?.length ?? 0);
156
+ }
157
+ get asNames() {
158
+ const names = [Name.last(this.value)];
159
+ if (this.#mother)
160
+ names.push(Name.last(this.#mother));
161
+ return names;
162
+ }
163
+ toString(format) {
164
+ format = format ?? this.format;
165
+ switch (format) {
166
+ case types_js_1.Surname.FATHER:
167
+ return this.value;
168
+ case types_js_1.Surname.MOTHER:
169
+ return this.mother ?? '';
170
+ case types_js_1.Surname.HYPHENATED:
171
+ return this.hasMother ? `${this.value}-${this.#mother}` : this.value;
172
+ case types_js_1.Surname.ALL:
173
+ return this.hasMother ? `${this.value} ${this.#mother}` : this.value;
174
+ }
175
+ }
176
+ initials(format) {
177
+ format = format || this.format;
178
+ const inits = [];
179
+ switch (format) {
180
+ case types_js_1.Surname.MOTHER:
181
+ if (this.#mother)
182
+ inits.push(this.#mother[0]);
183
+ break;
184
+ case types_js_1.Surname.HYPHENATED:
185
+ case types_js_1.Surname.ALL:
186
+ inits.push(this.initial);
187
+ if (this.#mother)
188
+ inits.push(this.#mother[0]);
189
+ break;
190
+ case types_js_1.Surname.FATHER:
191
+ default:
192
+ inits.push(this.initial);
193
+ }
194
+ return inits;
195
+ }
196
+ caps(range) {
197
+ range = range || this.capsRange;
198
+ this.value = (0, utils_js_1.capitalize)(this.value, range);
199
+ if (this.hasMother)
200
+ this.#mother = (0, utils_js_1.capitalize)(this.#mother, range);
201
+ return this;
202
+ }
203
+ decaps(range) {
204
+ range = range || this.capsRange;
205
+ this.value = (0, utils_js_1.decapitalize)(this.value, range);
206
+ if (this.hasMother)
207
+ this.#mother = (0, utils_js_1.decapitalize)(this.#mother, range);
208
+ return this;
209
+ }
210
+ copyWith(values) {
211
+ return new LastName(values?.father ?? this.value, values?.mother ?? this.mother, values?.format ?? this.format);
212
+ }
213
+ }
214
+ exports.LastName = LastName;
215
+ function isNameArray(value) {
216
+ return Array.isArray(value) && value.length > 0 && value.every((e) => e instanceof Name);
217
+ }
218
+ exports.isNameArray = isNameArray;