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.
@@ -1,19 +1,13 @@
1
1
  "use strict";
2
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
- 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");
5
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
- };
7
- var _NamaParser_instances, _NamaParser_asNama;
8
2
  Object.defineProperty(exports, "__esModule", { value: true });
9
3
  exports.ArrayNameParser = exports.NamaParser = exports.ArrayStringParser = exports.StringParser = exports.Parser = void 0;
10
- const full_name_1 = require("./full-name");
11
4
  const config_1 = require("./config");
12
5
  const utils_1 = require("./utils");
13
- const validator_1 = require("./validator");
14
- const name_1 = require("./name");
15
- const types_1 = require("./types");
16
6
  const error_1 = require("./error");
7
+ const full_name_1 = require("./full-name");
8
+ const types_1 = require("./types");
9
+ const name_1 = require("./name");
10
+ const validator_1 = require("./validator");
17
11
  class Parser {
18
12
  constructor(raw) {
19
13
  this.raw = raw;
@@ -22,16 +16,13 @@ class Parser {
22
16
  const parts = text.trim().split(types_1.Separator.SPACE.token);
23
17
  const length = parts.length;
24
18
  if (index instanceof utils_1.NameIndex) {
25
- const names = Object.entries(index.toJson())
19
+ const names = Object.entries(index.json())
26
20
  .filter(([, position]) => position > -1 && position < length)
27
21
  .map(([key, position]) => new name_1.Name(parts[position], types_1.Namon.all.get(key)));
28
22
  return new ArrayNameParser(names);
29
23
  }
30
24
  if (length < 2) {
31
- throw new error_1.InputError({
32
- source: text,
33
- message: 'cannot build from invalid input',
34
- });
25
+ throw new error_1.InputError({ source: text, message: 'expecting at least 2 name parts' });
35
26
  }
36
27
  else if (length === 2 || length === 3) {
37
28
  return new StringParser(text);
@@ -56,14 +47,13 @@ class StringParser extends Parser {
56
47
  parse(options) {
57
48
  const config = config_1.Config.merge(options);
58
49
  const names = this.raw.split(config.separator.token);
59
- return new ArrayStringParser(names).parse(options);
50
+ return new ArrayStringParser(names).parse(config);
60
51
  }
61
52
  }
62
53
  exports.StringParser = StringParser;
63
54
  class ArrayStringParser extends Parser {
64
55
  parse(options) {
65
56
  const config = config_1.Config.merge(options);
66
- const fullName = new full_name_1.FullName(config);
67
57
  const raw = this.raw.map((n) => n.trim());
68
58
  const index = utils_1.NameIndex.when(config.orderedBy, raw.length);
69
59
  const validator = new validator_1.ArrayStringValidator(index);
@@ -74,8 +64,9 @@ class ArrayStringParser extends Parser {
74
64
  validator.validate(raw);
75
65
  }
76
66
  const { firstName, lastName, middleName, prefix, suffix } = index;
77
- fullName.setFirstName(new name_1.FirstName(raw[firstName]));
78
- fullName.setLastName(new name_1.LastName(raw[lastName]));
67
+ const fullName = new full_name_1.FullName(config)
68
+ .setFirstName(new name_1.FirstName(raw[firstName]))
69
+ .setLastName(new name_1.LastName(raw[lastName]));
79
70
  if (raw.length >= 3)
80
71
  fullName.setMiddleName(raw[middleName].split(config.separator.token));
81
72
  if (raw.length >= 4)
@@ -87,39 +78,32 @@ class ArrayStringParser extends Parser {
87
78
  }
88
79
  exports.ArrayStringParser = ArrayStringParser;
89
80
  class NamaParser extends Parser {
90
- constructor() {
91
- super(...arguments);
92
- _NamaParser_instances.add(this);
93
- }
94
81
  parse(options) {
95
82
  const config = config_1.Config.merge(options);
83
+ const names = new Map(Object.entries(this.raw).map(([key, value]) => {
84
+ const namon = types_1.Namon.cast(key);
85
+ if (!namon) {
86
+ throw new error_1.InputError({
87
+ source: Object.values(this.raw).join(' '),
88
+ message: `unsupported key "${key}"`,
89
+ });
90
+ }
91
+ return [namon, value];
92
+ }));
96
93
  if (config.bypass) {
97
- validator_1.NamaValidator.create().validateKeys(__classPrivateFieldGet(this, _NamaParser_instances, "m", _NamaParser_asNama).call(this));
94
+ validator_1.Validators.nama.validateKeys(names);
98
95
  }
99
96
  else {
100
- validator_1.NamaValidator.create().validate(__classPrivateFieldGet(this, _NamaParser_instances, "m", _NamaParser_asNama).call(this));
97
+ validator_1.Validators.nama.validate(names);
101
98
  }
102
99
  return full_name_1.FullName.parse(this.raw, config);
103
100
  }
104
101
  }
105
102
  exports.NamaParser = NamaParser;
106
- _NamaParser_instances = new WeakSet(), _NamaParser_asNama = function _NamaParser_asNama() {
107
- return new Map(Object.entries(this.raw).map(([key, value]) => {
108
- const namon = types_1.Namon.cast(key);
109
- if (!namon) {
110
- throw new error_1.InputError({
111
- source: Object.values(this.raw).join(' '),
112
- message: `unsupported key "${key}"`,
113
- });
114
- }
115
- return [namon, value];
116
- }));
117
- };
118
103
  class ArrayNameParser extends Parser {
119
104
  parse(options) {
120
- const config = config_1.Config.merge(options);
121
- const fullName = new full_name_1.FullName(config);
122
105
  validator_1.ArrayNameValidator.create().validate(this.raw);
106
+ const fullName = new full_name_1.FullName(options);
123
107
  for (const name of this.raw) {
124
108
  if (name.isPrefix) {
125
109
  fullName.setPrefix(name);
@@ -134,8 +118,8 @@ class ArrayNameParser extends Parser {
134
118
  fullName.middleName.push(name);
135
119
  }
136
120
  else if (name.isLastName) {
137
- const lastName = new name_1.LastName(name.value, name instanceof name_1.LastName ? name.mother : undefined, config.surname);
138
- fullName.setLastName(lastName);
121
+ const mother = name instanceof name_1.LastName ? name.mother : undefined;
122
+ fullName.setLastName(new name_1.LastName(name.value, mother, fullName.config.surname));
139
123
  }
140
124
  }
141
125
  return fullName;
package/dist/lib/types.js CHANGED
@@ -49,7 +49,10 @@ class Namon {
49
49
  return Namon.all.has(key);
50
50
  }
51
51
  static cast(key) {
52
- return Namon.has(key) ? Namon.all.get(key) : undefined;
52
+ var _a;
53
+ const searchValue = String(key).toLowerCase();
54
+ const namon = (_a = Object.entries(Namon.aliases).find(([, list]) => list.includes(searchValue))) === null || _a === void 0 ? void 0 : _a[0];
55
+ return Namon.has(namon !== null && namon !== void 0 ? namon : '') ? Namon.all.get(key) : undefined;
53
56
  }
54
57
  toString() {
55
58
  return `Namon.${this.key}`;
@@ -72,11 +75,26 @@ Namon.all = new Map([
72
75
  [Namon.LAST_NAME.key, Namon.LAST_NAME],
73
76
  [Namon.SUFFIX.key, Namon.SUFFIX],
74
77
  ]);
78
+ Namon.aliases = {
79
+ [Namon.PREFIX.key]: ['prefix', 'px', 'p'],
80
+ [Namon.FIRST_NAME.key]: ['firstname', 'first', 'fn', 'f'],
81
+ [Namon.MIDDLE_NAME.key]: ['middlename', 'middle', 'mid', 'mn', 'm'],
82
+ [Namon.LAST_NAME.key]: ['lastname', 'last', 'ln', 'l'],
83
+ [Namon.SUFFIX.key]: ['suffix', 'sx', 's'],
84
+ };
75
85
  class Separator {
76
86
  constructor(name, token) {
77
87
  this.name = name;
78
88
  this.token = token;
79
89
  }
90
+ static cast(key) {
91
+ for (const [name, separator] of Separator.all) {
92
+ if (separator.token === key || name.toLowerCase() === key.toLowerCase()) {
93
+ return separator;
94
+ }
95
+ }
96
+ return undefined;
97
+ }
80
98
  toString() {
81
99
  return `Separator.${this.name}`;
82
100
  }
package/dist/lib/utils.js CHANGED
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNameArray = exports.isStringArray = exports.toggleCase = exports.decapitalize = exports.capitalize = exports.NameIndex = void 0;
4
- const constants_1 = require("./constants");
5
- const name_1 = require("./name");
3
+ exports.isStringArray = exports.toggleCase = exports.decapitalize = exports.capitalize = exports.NameIndex = void 0;
6
4
  const types_1 = require("./types");
5
+ const constants_1 = require("./constants");
7
6
  class NameIndex {
8
7
  static get min() {
9
8
  return constants_1.MIN_NUMBER_OF_NAME_PARTS;
@@ -17,21 +16,22 @@ class NameIndex {
17
16
  this.middleName = middleName;
18
17
  this.lastName = lastName;
19
18
  this.suffix = suffix;
19
+ this.json = this.toJson;
20
20
  }
21
21
  static base() {
22
- return new this(-1, 0, -1, 1, -1);
22
+ return new NameIndex(-1, 0, -1, 1, -1);
23
23
  }
24
24
  static when(order, count = 2) {
25
25
  if (order === types_1.NameOrder.FIRST_NAME) {
26
26
  switch (count) {
27
27
  case 2:
28
- return new this(-1, 0, -1, 1, -1);
28
+ return new NameIndex(-1, 0, -1, 1, -1);
29
29
  case 3:
30
- return new this(-1, 0, 1, 2, -1);
30
+ return new NameIndex(-1, 0, 1, 2, -1);
31
31
  case 4:
32
- return new this(0, 1, 2, 3, -1);
32
+ return new NameIndex(0, 1, 2, 3, -1);
33
33
  case 5:
34
- return new this(0, 1, 2, 3, 4);
34
+ return new NameIndex(0, 1, 2, 3, 4);
35
35
  default:
36
36
  return NameIndex.base();
37
37
  }
@@ -39,20 +39,20 @@ class NameIndex {
39
39
  else {
40
40
  switch (count) {
41
41
  case 2:
42
- return new this(-1, 1, -1, 0, -1);
42
+ return new NameIndex(-1, 1, -1, 0, -1);
43
43
  case 3:
44
- return new this(-1, 1, 2, 0, -1);
44
+ return new NameIndex(-1, 1, 2, 0, -1);
45
45
  case 4:
46
- return new this(0, 2, 3, 1, -1);
46
+ return new NameIndex(0, 2, 3, 1, -1);
47
47
  case 5:
48
- return new this(0, 2, 3, 1, 4);
48
+ return new NameIndex(0, 2, 3, 1, 4);
49
49
  default:
50
50
  return NameIndex.base();
51
51
  }
52
52
  }
53
53
  }
54
54
  static only({ prefix = -1, firstName, middleName = -1, lastName, suffix = -1 }) {
55
- return new this(prefix, firstName, middleName, lastName, suffix);
55
+ return new NameIndex(prefix, firstName, middleName, lastName, suffix);
56
56
  }
57
57
  toJson() {
58
58
  return {
@@ -68,37 +68,25 @@ exports.NameIndex = NameIndex;
68
68
  function capitalize(str, range = types_1.CapsRange.INITIAL) {
69
69
  if (!str || range === types_1.CapsRange.NONE)
70
70
  return str;
71
- const initial = str[0].toUpperCase();
72
- const rest = str.slice(1).toLowerCase();
71
+ const [initial, rest] = [str[0].toUpperCase(), str.slice(1).toLowerCase()];
73
72
  return range === types_1.CapsRange.INITIAL ? initial.concat(rest) : str.toUpperCase();
74
73
  }
75
74
  exports.capitalize = capitalize;
76
75
  function decapitalize(str, range = types_1.CapsRange.INITIAL) {
77
76
  if (!str || range === types_1.CapsRange.NONE)
78
77
  return str;
79
- const initial = str[0].toLowerCase();
80
- const rest = str.slice(1);
78
+ const [initial, rest] = [str[0].toLowerCase(), str.slice(1)];
81
79
  return range === types_1.CapsRange.INITIAL ? initial.concat(rest) : str.toLowerCase();
82
80
  }
83
81
  exports.decapitalize = decapitalize;
84
82
  function toggleCase(str) {
85
- const chars = [];
86
- for (const c of str) {
87
- if (c === c.toUpperCase()) {
88
- chars.push(c.toLowerCase());
89
- }
90
- else {
91
- chars.push(c.toUpperCase());
92
- }
93
- }
94
- return chars.join('');
83
+ return str
84
+ .split('')
85
+ .map((c) => (c === c.toUpperCase() ? c.toLowerCase() : c.toUpperCase()))
86
+ .join('');
95
87
  }
96
88
  exports.toggleCase = toggleCase;
97
89
  function isStringArray(value) {
98
90
  return Array.isArray(value) && value.length > 0 && value.every((e) => typeof e === 'string');
99
91
  }
100
92
  exports.isStringArray = isStringArray;
101
- function isNameArray(value) {
102
- return Array.isArray(value) && value.length > 0 && value.every((e) => e instanceof name_1.Name);
103
- }
104
- exports.isNameArray = isNameArray;
@@ -13,11 +13,11 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
13
13
  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;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.Validators = exports.ArrayNameValidator = exports.ArrayStringValidator = exports.NamaValidator = void 0;
16
- const constants_1 = require("./constants");
17
- const error_1 = require("./error");
18
- const name_1 = require("./name");
19
16
  const types_1 = require("./types");
20
17
  const utils_1 = require("./utils");
18
+ const name_1 = require("./name");
19
+ const error_1 = require("./error");
20
+ const constants_1 = require("./constants");
21
21
  class ValidationRule {
22
22
  }
23
23
  ValidationRule.base = /[a-zA-Z\u00C0-\u00D6\u00D8-\u00f6\u00f8-\u00ff\u0400-\u04FFΆ-ωΑ-ώ]/;
@@ -25,19 +25,22 @@ ValidationRule.namon = new RegExp(`^${ValidationRule.base.source}+(([' -]${Valid
25
25
  ValidationRule.firstName = ValidationRule.namon;
26
26
  ValidationRule.middleName = new RegExp(`^${ValidationRule.base.source}+(([' -]${ValidationRule.base.source})?${ValidationRule.base.source}*)*$`);
27
27
  ValidationRule.lastName = ValidationRule.namon;
28
+ const toNameSource = (values) => {
29
+ return (0, name_1.isNameArray)(values) ? values.map((n) => n.toString()).join(' ') : '';
30
+ };
28
31
  class ArrayValidator {
29
32
  validate(values) {
30
33
  if (values.length === 0 || values.length < constants_1.MIN_NUMBER_OF_NAME_PARTS || values.length > constants_1.MAX_NUMBER_OF_NAME_PARTS) {
31
34
  throw new error_1.InputError({
32
35
  source: values.map((n) => n.toString()),
33
- message: `expecting a list of ${constants_1.MIN_NUMBER_OF_NAME_PARTS}-${constants_1.MIN_NUMBER_OF_NAME_PARTS} elements`,
36
+ message: `expecting a list of ${constants_1.MIN_NUMBER_OF_NAME_PARTS}-${constants_1.MAX_NUMBER_OF_NAME_PARTS} elements`,
34
37
  });
35
38
  }
36
39
  }
37
40
  }
38
41
  class NamonValidator {
39
42
  static create() {
40
- return __classPrivateFieldGet(this, _a, "f", _NamonValidator_validator) || (__classPrivateFieldSet(this, _a, new this(), "f", _NamonValidator_validator));
43
+ return __classPrivateFieldGet(this, _a, "f", _NamonValidator_validator) || (__classPrivateFieldSet(this, _a, new _a(), "f", _NamonValidator_validator));
41
44
  }
42
45
  validate(value, type) {
43
46
  if (value instanceof name_1.Name) {
@@ -48,15 +51,12 @@ class NamonValidator {
48
51
  throw new error_1.ValidationError({
49
52
  source: value,
50
53
  nameType: 'namon',
51
- message: 'invalid content',
54
+ message: 'invalid name content failing namon regex',
52
55
  });
53
56
  }
54
57
  }
55
58
  else {
56
- throw new error_1.InputError({
57
- source: typeof value,
58
- message: 'expecting types of string | Name',
59
- });
59
+ throw new error_1.InputError({ source: typeof value, message: 'expecting types of string or Name' });
60
60
  }
61
61
  }
62
62
  }
@@ -64,7 +64,7 @@ _a = NamonValidator;
64
64
  _NamonValidator_validator = { value: void 0 };
65
65
  class FirstNameValidator {
66
66
  static create() {
67
- return __classPrivateFieldGet(this, _b, "f", _FirstNameValidator_validator) || (__classPrivateFieldSet(this, _b, new this(), "f", _FirstNameValidator_validator));
67
+ return __classPrivateFieldGet(this, _b, "f", _FirstNameValidator_validator) || (__classPrivateFieldSet(this, _b, new _b(), "f", _FirstNameValidator_validator));
68
68
  }
69
69
  validate(value) {
70
70
  if (value instanceof name_1.FirstName) {
@@ -75,15 +75,12 @@ class FirstNameValidator {
75
75
  throw new error_1.ValidationError({
76
76
  source: value,
77
77
  nameType: 'firstName',
78
- message: 'invalid content',
78
+ message: 'invalid name content failing firstName regex',
79
79
  });
80
80
  }
81
81
  }
82
82
  else {
83
- throw new error_1.InputError({
84
- source: typeof value,
85
- message: 'expecting types string | FirstName',
86
- });
83
+ throw new error_1.InputError({ source: typeof value, message: 'expecting types string or FirstName' });
87
84
  }
88
85
  }
89
86
  }
@@ -91,7 +88,7 @@ _b = FirstNameValidator;
91
88
  _FirstNameValidator_validator = { value: void 0 };
92
89
  class MiddleNameValidator {
93
90
  static create() {
94
- return __classPrivateFieldGet(this, _c, "f", _MiddleNameValidator_validator) || (__classPrivateFieldSet(this, _c, new this(), "f", _MiddleNameValidator_validator));
91
+ return __classPrivateFieldGet(this, _c, "f", _MiddleNameValidator_validator) || (__classPrivateFieldSet(this, _c, new _c(), "f", _MiddleNameValidator_validator));
95
92
  }
96
93
  validate(value) {
97
94
  if (typeof value === 'string') {
@@ -99,7 +96,7 @@ class MiddleNameValidator {
99
96
  throw new error_1.ValidationError({
100
97
  source: value,
101
98
  nameType: 'middleName',
102
- message: 'invalid content',
99
+ message: 'invalid name content failing middleName regex',
103
100
  });
104
101
  }
105
102
  }
@@ -111,7 +108,7 @@ class MiddleNameValidator {
111
108
  }
112
109
  catch (error) {
113
110
  throw new error_1.ValidationError({
114
- source: value,
111
+ source: toNameSource(value),
115
112
  nameType: 'middleName',
116
113
  message: error === null || error === void 0 ? void 0 : error.message,
117
114
  });
@@ -120,7 +117,7 @@ class MiddleNameValidator {
120
117
  else {
121
118
  throw new error_1.InputError({
122
119
  source: typeof value,
123
- message: 'expecting types of string | string[] | Name[]',
120
+ message: 'expecting types of string, string[] or Name[]',
124
121
  });
125
122
  }
126
123
  }
@@ -129,7 +126,7 @@ _c = MiddleNameValidator;
129
126
  _MiddleNameValidator_validator = { value: void 0 };
130
127
  class LastNameValidator {
131
128
  static create() {
132
- return __classPrivateFieldGet(this, _d, "f", _LastNameValidator_validator) || (__classPrivateFieldSet(this, _d, new this(), "f", _LastNameValidator_validator));
129
+ return __classPrivateFieldGet(this, _d, "f", _LastNameValidator_validator) || (__classPrivateFieldSet(this, _d, new _d(), "f", _LastNameValidator_validator));
133
130
  }
134
131
  validate(value) {
135
132
  if (value instanceof name_1.LastName) {
@@ -140,15 +137,12 @@ class LastNameValidator {
140
137
  throw new error_1.ValidationError({
141
138
  source: value,
142
139
  nameType: 'lastName',
143
- message: 'invalid content',
140
+ message: 'invalid name content failing lastName regex',
144
141
  });
145
142
  }
146
143
  }
147
144
  else {
148
- throw new error_1.InputError({
149
- source: typeof value,
150
- message: 'expecting types string | LastName',
151
- });
145
+ throw new error_1.InputError({ source: typeof value, message: 'expecting types string or LastName' });
152
146
  }
153
147
  }
154
148
  }
@@ -156,21 +150,21 @@ _d = LastNameValidator;
156
150
  _LastNameValidator_validator = { value: void 0 };
157
151
  class NameValidator {
158
152
  static create() {
159
- return __classPrivateFieldGet(this, _e, "f", _NameValidator_validator) || (__classPrivateFieldSet(this, _e, new this(), "f", _NameValidator_validator));
153
+ return __classPrivateFieldGet(this, _e, "f", _NameValidator_validator) || (__classPrivateFieldSet(this, _e, new _e(), "f", _NameValidator_validator));
160
154
  }
161
155
  validate(name, type) {
162
156
  if (type && name.type !== type) {
163
157
  throw new error_1.ValidationError({
164
- source: [name],
158
+ source: name.toString(),
165
159
  nameType: name.type.toString(),
166
- message: 'wrong type',
160
+ message: 'wrong name type; only Namon types are supported',
167
161
  });
168
162
  }
169
163
  if (!ValidationRule.namon.test(name.value)) {
170
164
  throw new error_1.ValidationError({
171
- source: [name],
165
+ source: name.toString(),
172
166
  nameType: name.type.toString(),
173
- message: 'invalid content',
167
+ message: 'invalid name content failing namon regex',
174
168
  });
175
169
  }
176
170
  }
@@ -179,18 +173,16 @@ _e = NameValidator;
179
173
  _NameValidator_validator = { value: void 0 };
180
174
  class NamaValidator {
181
175
  static create() {
182
- return __classPrivateFieldGet(this, _f, "f", _NamaValidator_validator) || (__classPrivateFieldSet(this, _f, new this(), "f", _NamaValidator_validator));
176
+ return __classPrivateFieldGet(this, _f, "f", _NamaValidator_validator) || (__classPrivateFieldSet(this, _f, new _f(), "f", _NamaValidator_validator));
183
177
  }
184
178
  validate(value) {
185
179
  this.validateKeys(value);
186
180
  Validators.firstName.validate(value.get(types_1.Namon.FIRST_NAME));
187
181
  Validators.lastName.validate(value.get(types_1.Namon.LAST_NAME));
188
- if (value.has(types_1.Namon.PREFIX)) {
182
+ if (value.has(types_1.Namon.PREFIX))
189
183
  Validators.namon.validate(value.get(types_1.Namon.PREFIX));
190
- }
191
- if (value.has(types_1.Namon.SUFFIX)) {
184
+ if (value.has(types_1.Namon.SUFFIX))
192
185
  Validators.namon.validate(value.get(types_1.Namon.SUFFIX));
193
- }
194
186
  }
195
187
  validateKeys(nama) {
196
188
  if (!nama.size) {
@@ -199,20 +191,14 @@ class NamaValidator {
199
191
  else if (nama.size < constants_1.MIN_NUMBER_OF_NAME_PARTS || nama.size > constants_1.MAX_NUMBER_OF_NAME_PARTS) {
200
192
  throw new error_1.InputError({
201
193
  source: [...nama.values()],
202
- message: `expecting ${constants_1.MIN_NUMBER_OF_NAME_PARTS}-${constants_1.MIN_NUMBER_OF_NAME_PARTS} fields`,
194
+ message: `expecting ${constants_1.MIN_NUMBER_OF_NAME_PARTS}-${constants_1.MAX_NUMBER_OF_NAME_PARTS} fields`,
203
195
  });
204
196
  }
205
197
  if (!nama.has(types_1.Namon.FIRST_NAME)) {
206
- throw new error_1.InputError({
207
- source: [...nama.values()],
208
- message: '"firstName" is a required key',
209
- });
198
+ throw new error_1.InputError({ source: [...nama.values()], message: '"firstName" is a required key' });
210
199
  }
211
200
  if (!nama.has(types_1.Namon.LAST_NAME)) {
212
- throw new error_1.InputError({
213
- source: [...nama.values()],
214
- message: '"lastName" is a required key',
215
- });
201
+ throw new error_1.InputError({ source: [...nama.values()], message: '"lastName" is a required key' });
216
202
  }
217
203
  }
218
204
  }
@@ -245,18 +231,18 @@ class ArrayNameValidator {
245
231
  _ArrayNameValidator_instances.add(this);
246
232
  }
247
233
  static create() {
248
- return __classPrivateFieldGet(this, _g, "f", _ArrayNameValidator_validator) || (__classPrivateFieldSet(this, _g, new this(), "f", _ArrayNameValidator_validator));
234
+ return __classPrivateFieldGet(this, _g, "f", _ArrayNameValidator_validator) || (__classPrivateFieldSet(this, _g, new _g(), "f", _ArrayNameValidator_validator));
249
235
  }
250
236
  validate(value) {
251
237
  if (value.length < constants_1.MIN_NUMBER_OF_NAME_PARTS) {
252
238
  throw new error_1.InputError({
253
- source: value,
239
+ source: toNameSource(value),
254
240
  message: `expecting at least ${constants_1.MIN_NUMBER_OF_NAME_PARTS} elements`,
255
241
  });
256
242
  }
257
243
  if (!__classPrivateFieldGet(this, _ArrayNameValidator_instances, "m", _ArrayNameValidator_hasBasicNames).call(this, value)) {
258
244
  throw new error_1.InputError({
259
- source: value,
245
+ source: toNameSource(value),
260
246
  message: 'both first and last names are required',
261
247
  });
262
248
  }
@@ -1,6 +1,6 @@
1
1
  import { Name } from './name';
2
- import { Namefully } from './namefully';
3
2
  import { Config } from './config';
3
+ import { Namefully } from './namefully';
4
4
  type VoidCallback = () => void;
5
5
  type Callback<Type, Return> = (value: Type) => Return;
6
6
  /**
@@ -44,9 +44,11 @@ declare abstract class Builder<T, I> {
44
44
  * to finally construct a complete Namefully instance.
45
45
  *
46
46
  * @example
47
+ * ```js
47
48
  * const builder = NameBuilder.of([Name.first('Thomas'), Name.last('Edison')]);
48
49
  * builder.add(Name.middle('Alva'));
49
50
  * console.log(builder.build()); // 'Thomas Alva Edison'
51
+ * ```
50
52
  */
51
53
  export declare class NameBuilder extends Builder<Name, Namefully> {
52
54
  private constructor();
@@ -66,7 +68,7 @@ export declare class NameBuilder extends Builder<Name, Namefully> {
66
68
  * Builds an instance of Namefully from the previously collected names.
67
69
  *
68
70
  * Regardless of how the names are added, both first and last names must exist
69
- * to complete a fine build. Otherwise, it throws a NameException.
71
+ * to complete a fine build. Otherwise, it throws a NameError.
70
72
  */
71
73
  build(config?: Partial<Config>): Namefully;
72
74
  }
@@ -89,9 +89,6 @@ export declare class Config {
89
89
  clone(): Config;
90
90
  /** Resets the configuration by setting it back to its default values. */
91
91
  reset(): void;
92
- /**
93
- * Alters the name order between the first and last name, and rearrange the
94
- * order of appearance of a name set.
95
- */
96
- updateOrder(order: NameOrder): void;
92
+ /** Allows the possibility to alter behavior-related options after creating a name set. */
93
+ update({ orderedBy, title, ending }: Partial<Pick<Config, 'orderedBy' | 'title' | 'ending'>>): void;
97
94
  }
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "1.3.0";
1
+ export declare const VERSION = "1.3.1";
2
2
  export declare const MIN_NUMBER_OF_NAME_PARTS = 2;
3
3
  export declare const MAX_NUMBER_OF_NAME_PARTS = 5;
4
- export declare const ALLOWED_TOKENS: string[];
4
+ export declare const ALLOWED_FORMAT_TOKENS = " .,_-()[]<>'\"bBfFlLmMnNoOpPsS$";
@@ -1,13 +1,10 @@
1
- import { Name } from './name';
2
1
  import { Nullable } from './types';
3
- type NameSource = Nullable<string | string[] | Name[]>;
2
+ type NameSource = Nullable<string | string[]>;
4
3
  interface ErrorMessage {
5
4
  source: NameSource;
6
5
  message?: string;
7
6
  }
8
- /**
9
- * The error types supported by `Namefully`.
10
- */
7
+ /** The error types supported by `Namefully`. */
11
8
  export declare enum NameErrorType {
12
9
  /**
13
10
  * Thrown when a name entry/argument is incorrect.
@@ -30,9 +27,7 @@ export declare enum NameErrorType {
30
27
  * See also: `NotAllowedError`, `Namefully.format`.
31
28
  */
32
29
  NOT_ALLOWED = 2,
33
- /**
34
- * Thrown by any other unknown sources or unexpected situation.
35
- */
30
+ /** Thrown by any other unknown sources or unexpected situation. */
36
31
  UNKNOWN = 3
37
32
  }
38
33
  /**
@@ -45,8 +40,8 @@ export declare enum NameErrorType {
45
40
  * program failure. Au contraire, it is expected that a programmer using this utility
46
41
  * would consider validating a name using its own business rules. That is not
47
42
  * this utility's job to guess those rules. So, the predefined `ValidationRules`
48
- * obey some common validation techniques when it comes to sanitizing a person
49
- * name. For this reason, the [Config.bypass] is set to `true` by default,
43
+ * obey some common validation techniques when it comes to sanitizing a personal
44
+ * name. For this reason, the `Config.bypass` is set to `true` by default,
50
45
  * indicating that those predefined rules should be skipped for the sake of the
51
46
  * program.
52
47
  *
@@ -55,7 +50,7 @@ export declare enum NameErrorType {
55
50
  *
56
51
  * A name error intends to provide useful information about what causes the error
57
52
  * and let the user take initiative on what happens next to the given name:
58
- * reconstructing it or skipping it.
53
+ * reconstructing it or discarding it.
59
54
  */
60
55
  export declare class NameError extends Error {
61
56
  readonly source: NameSource;
@@ -63,8 +58,8 @@ export declare class NameError extends Error {
63
58
  /**
64
59
  * Creates an error with a message describing the issue for a name source.
65
60
  * @param source name input that caused the error
66
- * @param message a message describing the failure.
67
- * @param type of `NameErrorType`
61
+ * @param message describing the failure.
62
+ * @param type of error via `NameErrorType`
68
63
  */
69
64
  constructor(source: NameSource, message?: string, type?: NameErrorType);
70
65
  /** The actual source input which caused the error. */
@@ -77,9 +72,9 @@ export declare class NameError extends Error {
77
72
  /**
78
73
  * An error thrown when a name source input is incorrect.
79
74
  *
80
- * A `Name` is a name for this utility under certain criteria (i.e., 2+ chars),
75
+ * A `Name` is a name for this utility under certain criteria (i.e., 1+ chars),
81
76
  * hence, a wrong input will cause this kind of error. Another common reason
82
- * may be a wrong key in a Json name parsing mechanism.
77
+ * may be a wrong key in a JSON name parsing mechanism.
83
78
  *
84
79
  * Keep in mind that this error is different from a `ValidationError`.
85
80
  */
@@ -151,7 +146,7 @@ export declare class UnknownError extends NameError {
151
146
  * Optionally, the original error revealing the true nature of the failure.
152
147
  */
153
148
  constructor(error: ErrorMessage & {
154
- error?: Error;
149
+ origin?: Error;
155
150
  });
156
151
  toString(): string;
157
152
  }