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