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/lib/validator.js
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10
|
+
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");
|
|
11
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
|
+
};
|
|
13
|
+
var _a, _NamonValidator_validator, _b, _FirstNameValidator_validator, _c, _MiddleNameValidator_validator, _d, _LastNameValidator_validator, _e, _NameValidator_validator, _f, _NamaValidator_validator, _ArrayNameValidator_instances, _g, _ArrayNameValidator_validator, _ArrayNameValidator_hasBasicNames;
|
|
2
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
15
|
exports.Validators = exports.ArrayNameValidator = exports.ArrayStringValidator = exports.NamaValidator = void 0;
|
|
4
16
|
const constants_1 = require("./constants");
|
|
@@ -6,64 +18,16 @@ const error_1 = require("./error");
|
|
|
6
18
|
const name_1 = require("./name");
|
|
7
19
|
const types_1 = require("./types");
|
|
8
20
|
const utils_1 = require("./utils");
|
|
9
|
-
/**
|
|
10
|
-
* Represents a set of validation rules (regex)
|
|
11
|
-
*
|
|
12
|
-
* This regex is intented to match specific alphabets only as a person name does
|
|
13
|
-
* not contain special characters. `\w` does not cover non-Latin characters. So,
|
|
14
|
-
* it is extended using unicode chars to cover more cases (e.g., Icelandic).
|
|
15
|
-
* It matches as follows:
|
|
16
|
-
* [a-z]: Latin alphabet from a (index 97) to z (index 122)
|
|
17
|
-
* [A-Z]: Latin alphabet from A (index 65) to Z (index 90)
|
|
18
|
-
* [\u00C0-\u00D6]: Latin/German chars from À (index 192) to Ö (index 214)
|
|
19
|
-
* [\u00D8-\u00f6]: German/Icelandic chars from Ø (index 216) to ö (index 246)
|
|
20
|
-
* [\u00f8-\u00ff]: German/Icelandic chars from ø (index 248) to ÿ (index 255)
|
|
21
|
-
* [\u0400-\u04FF]: Cyrillic alphabet from Ѐ (index 1024) to ӿ (index 1279)
|
|
22
|
-
* [Ά-ωΑ-ώ]: Greek alphabet from Ά (index 902) to ω (index 969)
|
|
23
|
-
*/
|
|
24
21
|
class ValidationRule {
|
|
25
22
|
}
|
|
26
23
|
ValidationRule.base = /[a-zA-Z\u00C0-\u00D6\u00D8-\u00f6\u00f8-\u00ff\u0400-\u04FFΆ-ωΑ-ώ]/;
|
|
27
|
-
/**
|
|
28
|
-
* Matches one name part (namon) that is of nature:
|
|
29
|
-
* - Latin (English, Spanish, French, etc.)
|
|
30
|
-
* - European (Greek, Cyrillic, Icelandic, German)
|
|
31
|
-
* - hyphenated
|
|
32
|
-
* - with apostrophe
|
|
33
|
-
* - with space
|
|
34
|
-
*/
|
|
35
24
|
ValidationRule.namon = new RegExp(`^${ValidationRule.base.source}+(([' -]${ValidationRule.base.source})?${ValidationRule.base.source}*)*$`);
|
|
36
|
-
/**
|
|
37
|
-
* Matches one name part (namon) that is of nature:
|
|
38
|
-
* - Latin (English, Spanish, French, etc.)
|
|
39
|
-
* - European (Greek, Cyrillic, Icelandic, German)
|
|
40
|
-
* - hyphenated
|
|
41
|
-
* - with apostrophe
|
|
42
|
-
*/
|
|
43
25
|
ValidationRule.firstName = ValidationRule.namon;
|
|
44
|
-
/**
|
|
45
|
-
* Matches 1+ names part (namon) that are of nature:
|
|
46
|
-
* - Latin (English, Spanish, French, etc.)
|
|
47
|
-
* - European (Greek, Cyrillic, Icelandic, German)
|
|
48
|
-
* - hyphenated
|
|
49
|
-
* - with apostrophe
|
|
50
|
-
* - with space
|
|
51
|
-
*/
|
|
52
26
|
ValidationRule.middleName = new RegExp(`^${ValidationRule.base.source}+(([' -]${ValidationRule.base.source})?${ValidationRule.base.source}*)*$`);
|
|
53
|
-
/**
|
|
54
|
-
* Matches one name part (namon) that is of nature:
|
|
55
|
-
* - Latin (English, Spanish, French, etc.)
|
|
56
|
-
* - European (Greek, Cyrillic, Icelandic, German)
|
|
57
|
-
* - hyphenated
|
|
58
|
-
* - with apostrophe
|
|
59
|
-
* - with space
|
|
60
|
-
*/
|
|
61
27
|
ValidationRule.lastName = ValidationRule.namon;
|
|
62
28
|
class ArrayValidator {
|
|
63
29
|
validate(values) {
|
|
64
|
-
if (values.length === 0 ||
|
|
65
|
-
values.length < constants_1.MIN_NUMBER_OF_NAME_PARTS ||
|
|
66
|
-
values.length > constants_1.MAX_NUMBER_OF_NAME_PARTS) {
|
|
30
|
+
if (values.length === 0 || values.length < constants_1.MIN_NUMBER_OF_NAME_PARTS || values.length > constants_1.MAX_NUMBER_OF_NAME_PARTS) {
|
|
67
31
|
throw new error_1.InputError({
|
|
68
32
|
source: values.map((n) => n.toString()),
|
|
69
33
|
message: `expecting a list of ${constants_1.MIN_NUMBER_OF_NAME_PARTS}-${constants_1.MIN_NUMBER_OF_NAME_PARTS} elements`,
|
|
@@ -72,9 +36,8 @@ class ArrayValidator {
|
|
|
72
36
|
}
|
|
73
37
|
}
|
|
74
38
|
class NamonValidator {
|
|
75
|
-
constructor() { }
|
|
76
39
|
static create() {
|
|
77
|
-
return this
|
|
40
|
+
return __classPrivateFieldGet(this, _a, "f", _NamonValidator_validator) || (__classPrivateFieldSet(this, _a, new this(), "f", _NamonValidator_validator));
|
|
78
41
|
}
|
|
79
42
|
validate(value, type) {
|
|
80
43
|
if (value instanceof name_1.Name) {
|
|
@@ -97,10 +60,11 @@ class NamonValidator {
|
|
|
97
60
|
}
|
|
98
61
|
}
|
|
99
62
|
}
|
|
63
|
+
_a = NamonValidator;
|
|
64
|
+
_NamonValidator_validator = { value: void 0 };
|
|
100
65
|
class FirstNameValidator {
|
|
101
|
-
constructor() { }
|
|
102
66
|
static create() {
|
|
103
|
-
return this
|
|
67
|
+
return __classPrivateFieldGet(this, _b, "f", _FirstNameValidator_validator) || (__classPrivateFieldSet(this, _b, new this(), "f", _FirstNameValidator_validator));
|
|
104
68
|
}
|
|
105
69
|
validate(value) {
|
|
106
70
|
if (value instanceof name_1.FirstName) {
|
|
@@ -123,10 +87,11 @@ class FirstNameValidator {
|
|
|
123
87
|
}
|
|
124
88
|
}
|
|
125
89
|
}
|
|
90
|
+
_b = FirstNameValidator;
|
|
91
|
+
_FirstNameValidator_validator = { value: void 0 };
|
|
126
92
|
class MiddleNameValidator {
|
|
127
|
-
constructor() { }
|
|
128
93
|
static create() {
|
|
129
|
-
return this
|
|
94
|
+
return __classPrivateFieldGet(this, _c, "f", _MiddleNameValidator_validator) || (__classPrivateFieldSet(this, _c, new this(), "f", _MiddleNameValidator_validator));
|
|
130
95
|
}
|
|
131
96
|
validate(value) {
|
|
132
97
|
if (typeof value === 'string') {
|
|
@@ -160,10 +125,11 @@ class MiddleNameValidator {
|
|
|
160
125
|
}
|
|
161
126
|
}
|
|
162
127
|
}
|
|
128
|
+
_c = MiddleNameValidator;
|
|
129
|
+
_MiddleNameValidator_validator = { value: void 0 };
|
|
163
130
|
class LastNameValidator {
|
|
164
|
-
constructor() { }
|
|
165
131
|
static create() {
|
|
166
|
-
return this
|
|
132
|
+
return __classPrivateFieldGet(this, _d, "f", _LastNameValidator_validator) || (__classPrivateFieldSet(this, _d, new this(), "f", _LastNameValidator_validator));
|
|
167
133
|
}
|
|
168
134
|
validate(value) {
|
|
169
135
|
if (value instanceof name_1.LastName) {
|
|
@@ -186,10 +152,11 @@ class LastNameValidator {
|
|
|
186
152
|
}
|
|
187
153
|
}
|
|
188
154
|
}
|
|
155
|
+
_d = LastNameValidator;
|
|
156
|
+
_LastNameValidator_validator = { value: void 0 };
|
|
189
157
|
class NameValidator {
|
|
190
|
-
constructor() { }
|
|
191
158
|
static create() {
|
|
192
|
-
return this
|
|
159
|
+
return __classPrivateFieldGet(this, _e, "f", _NameValidator_validator) || (__classPrivateFieldSet(this, _e, new this(), "f", _NameValidator_validator));
|
|
193
160
|
}
|
|
194
161
|
validate(name, type) {
|
|
195
162
|
if (type && name.type !== type) {
|
|
@@ -208,10 +175,11 @@ class NameValidator {
|
|
|
208
175
|
}
|
|
209
176
|
}
|
|
210
177
|
}
|
|
178
|
+
_e = NameValidator;
|
|
179
|
+
_NameValidator_validator = { value: void 0 };
|
|
211
180
|
class NamaValidator {
|
|
212
|
-
constructor() { }
|
|
213
181
|
static create() {
|
|
214
|
-
return this
|
|
182
|
+
return __classPrivateFieldGet(this, _f, "f", _NamaValidator_validator) || (__classPrivateFieldSet(this, _f, new this(), "f", _NamaValidator_validator));
|
|
215
183
|
}
|
|
216
184
|
validate(value) {
|
|
217
185
|
this.validateKeys(value);
|
|
@@ -249,6 +217,8 @@ class NamaValidator {
|
|
|
249
217
|
}
|
|
250
218
|
}
|
|
251
219
|
exports.NamaValidator = NamaValidator;
|
|
220
|
+
_f = NamaValidator;
|
|
221
|
+
_NamaValidator_validator = { value: void 0 };
|
|
252
222
|
class ArrayStringValidator extends ArrayValidator {
|
|
253
223
|
constructor(index = utils_1.NameIndex.base()) {
|
|
254
224
|
super();
|
|
@@ -287,9 +257,11 @@ class ArrayStringValidator extends ArrayValidator {
|
|
|
287
257
|
}
|
|
288
258
|
exports.ArrayStringValidator = ArrayStringValidator;
|
|
289
259
|
class ArrayNameValidator {
|
|
290
|
-
constructor() {
|
|
260
|
+
constructor() {
|
|
261
|
+
_ArrayNameValidator_instances.add(this);
|
|
262
|
+
}
|
|
291
263
|
static create() {
|
|
292
|
-
return this
|
|
264
|
+
return __classPrivateFieldGet(this, _g, "f", _ArrayNameValidator_validator) || (__classPrivateFieldSet(this, _g, new this(), "f", _ArrayNameValidator_validator));
|
|
293
265
|
}
|
|
294
266
|
validate(value) {
|
|
295
267
|
if (value.length < constants_1.MIN_NUMBER_OF_NAME_PARTS) {
|
|
@@ -298,27 +270,25 @@ class ArrayNameValidator {
|
|
|
298
270
|
message: `expecting at least ${constants_1.MIN_NUMBER_OF_NAME_PARTS} elements`,
|
|
299
271
|
});
|
|
300
272
|
}
|
|
301
|
-
if (!this.
|
|
273
|
+
if (!__classPrivateFieldGet(this, _ArrayNameValidator_instances, "m", _ArrayNameValidator_hasBasicNames).call(this, value)) {
|
|
302
274
|
throw new error_1.InputError({
|
|
303
275
|
source: value,
|
|
304
276
|
message: 'both first and last names are required',
|
|
305
277
|
});
|
|
306
278
|
}
|
|
307
279
|
}
|
|
308
|
-
hasBasicNames(names) {
|
|
309
|
-
const accumulator = {};
|
|
310
|
-
for (const name of names) {
|
|
311
|
-
if (name.isFirstName || name.isLastName) {
|
|
312
|
-
accumulator[name.type.key] = name.toString();
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
return Object.keys(accumulator).length === constants_1.MIN_NUMBER_OF_NAME_PARTS;
|
|
316
|
-
}
|
|
317
280
|
}
|
|
318
281
|
exports.ArrayNameValidator = ArrayNameValidator;
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
282
|
+
_g = ArrayNameValidator, _ArrayNameValidator_instances = new WeakSet(), _ArrayNameValidator_hasBasicNames = function _ArrayNameValidator_hasBasicNames(names) {
|
|
283
|
+
const accumulator = {};
|
|
284
|
+
for (const name of names) {
|
|
285
|
+
if (name.isFirstName || name.isLastName) {
|
|
286
|
+
accumulator[name.type.key] = name.toString();
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return Object.keys(accumulator).length === constants_1.MIN_NUMBER_OF_NAME_PARTS;
|
|
290
|
+
};
|
|
291
|
+
_ArrayNameValidator_validator = { value: void 0 };
|
|
322
292
|
class Validators {
|
|
323
293
|
}
|
|
324
294
|
exports.Validators = Validators;
|
|
@@ -329,4 +299,3 @@ Validators.firstName = FirstNameValidator.create();
|
|
|
329
299
|
Validators.middleName = MiddleNameValidator.create();
|
|
330
300
|
Validators.lastName = LastNameValidator.create();
|
|
331
301
|
Validators.suffix = NamonValidator.create();
|
|
332
|
-
//# sourceMappingURL=validator.js.map
|
|
@@ -28,29 +28,19 @@ import { NameOrder, Separator, Title, Surname } from './types';
|
|
|
28
28
|
* above.
|
|
29
29
|
*/
|
|
30
30
|
export declare class Config {
|
|
31
|
-
private
|
|
32
|
-
|
|
33
|
-
private
|
|
34
|
-
|
|
35
|
-
private _ending;
|
|
36
|
-
private _bypass;
|
|
37
|
-
private _surname;
|
|
38
|
-
/**
|
|
39
|
-
* The order of appearance of a full name.
|
|
40
|
-
*/
|
|
31
|
+
#private;
|
|
32
|
+
/** Cache for multiple instances. */
|
|
33
|
+
private static cache;
|
|
34
|
+
/** The order of appearance of a full name. */
|
|
41
35
|
get orderedBy(): NameOrder;
|
|
42
|
-
/**
|
|
43
|
-
* The token used to indicate how to split string values.
|
|
44
|
-
*/
|
|
36
|
+
/** The token used to indicate how to split string values. */
|
|
45
37
|
get separator(): Separator;
|
|
46
38
|
/**
|
|
47
39
|
* The abbreviation type to indicate whether or not to add period to a prefix
|
|
48
40
|
* using the American or British way.
|
|
49
41
|
*/
|
|
50
42
|
get title(): Title;
|
|
51
|
-
/**
|
|
52
|
-
* The option indicating if an ending suffix is used in a formal way.
|
|
53
|
-
*/
|
|
43
|
+
/** The option indicating if an ending suffix is used in a formal way. */
|
|
54
44
|
get ending(): boolean;
|
|
55
45
|
/**
|
|
56
46
|
* A bypass of the validation rules with this option. This option is ideal
|
|
@@ -71,14 +61,8 @@ export declare class Config {
|
|
|
71
61
|
* prioritized and viewed as the source of truth for future considerations.
|
|
72
62
|
*/
|
|
73
63
|
get surname(): Surname;
|
|
74
|
-
/**
|
|
75
|
-
* The name of the cached configuration.
|
|
76
|
-
*/
|
|
64
|
+
/** The name of the cached configuration. */
|
|
77
65
|
get name(): string;
|
|
78
|
-
/**
|
|
79
|
-
* Cache for multiple instances.
|
|
80
|
-
*/
|
|
81
|
-
private static cache;
|
|
82
66
|
private constructor();
|
|
83
67
|
/**
|
|
84
68
|
* Returns a named configuration with default values.
|
|
@@ -101,21 +85,13 @@ export declare class Config {
|
|
|
101
85
|
* be named `default_copy`.
|
|
102
86
|
*/
|
|
103
87
|
copyWith(options?: Partial<Config>): Config;
|
|
104
|
-
/**
|
|
105
|
-
* Makes an exact copy of the current configuration.
|
|
106
|
-
*/
|
|
88
|
+
/** Makes an exact copy of the current configuration. */
|
|
107
89
|
clone(): Config;
|
|
108
|
-
/**
|
|
109
|
-
* Resets the configuration by setting it back to its default values.
|
|
110
|
-
*/
|
|
90
|
+
/** Resets the configuration by setting it back to its default values. */
|
|
111
91
|
reset(): void;
|
|
112
92
|
/**
|
|
113
93
|
* Alters the name order between the first and last name, and rearrange the
|
|
114
94
|
* order of appearance of a name set.
|
|
115
95
|
*/
|
|
116
96
|
updateOrder(order: NameOrder): void;
|
|
117
|
-
/**
|
|
118
|
-
* Generates a unique new name.
|
|
119
|
-
*/
|
|
120
|
-
private genNewName;
|
|
121
97
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Name } from './name';
|
|
2
2
|
import { Nullable } from './types';
|
|
3
|
-
|
|
3
|
+
type NameSource = Nullable<string | string[] | Name[]>;
|
|
4
4
|
interface ErrorMessage {
|
|
5
5
|
source: NameSource;
|
|
6
6
|
message?: string;
|
|
@@ -67,17 +67,11 @@ export declare class NameError extends Error {
|
|
|
67
67
|
* @param type of `NameErrorType`
|
|
68
68
|
*/
|
|
69
69
|
constructor(source: NameSource, message?: string, type?: NameErrorType);
|
|
70
|
-
/**
|
|
71
|
-
* The actual source input which caused the error.
|
|
72
|
-
*/
|
|
70
|
+
/** The actual source input which caused the error. */
|
|
73
71
|
get sourceAsString(): string;
|
|
74
|
-
/**
|
|
75
|
-
* Whether a message describing the failure exists.
|
|
76
|
-
*/
|
|
72
|
+
/** Whether a message describing the failure exists. */
|
|
77
73
|
get hasMessage(): boolean;
|
|
78
|
-
/**
|
|
79
|
-
* Returns a string representation of the error.
|
|
80
|
-
*/
|
|
74
|
+
/** Returns a string representation of the error. */
|
|
81
75
|
toString(): string;
|
|
82
76
|
}
|
|
83
77
|
/**
|
|
@@ -100,13 +94,9 @@ export declare class InputError extends NameError {
|
|
|
100
94
|
*/
|
|
101
95
|
constructor(error: ErrorMessage);
|
|
102
96
|
}
|
|
103
|
-
/**
|
|
104
|
-
* An error thrown to indicate that a name fails the validation rules.
|
|
105
|
-
*/
|
|
97
|
+
/** An error thrown to indicate that a name fails the validation rules. */
|
|
106
98
|
export declare class ValidationError extends NameError {
|
|
107
|
-
/**
|
|
108
|
-
* Name of the invalid `nameType` if available.
|
|
109
|
-
*/
|
|
99
|
+
/** Name of the invalid `nameType` if available. */
|
|
110
100
|
readonly nameType: string;
|
|
111
101
|
/**
|
|
112
102
|
* Creates error containing the invalid `nameType` and a `message` that
|
|
@@ -128,9 +118,7 @@ export declare class ValidationError extends NameError {
|
|
|
128
118
|
* a non-supported key.
|
|
129
119
|
*/
|
|
130
120
|
export declare class NotAllowedError extends NameError {
|
|
131
|
-
/**
|
|
132
|
-
* The revoked operation name.
|
|
133
|
-
*/
|
|
121
|
+
/** The revoked operation name. */
|
|
134
122
|
readonly operation: string;
|
|
135
123
|
/**
|
|
136
124
|
* Creates a new `NotAllowedError` with an optional error `message` and the
|
|
@@ -156,9 +144,7 @@ export declare class NotAllowedError extends NameError {
|
|
|
156
144
|
* programmer.
|
|
157
145
|
*/
|
|
158
146
|
export declare class UnknownError extends NameError {
|
|
159
|
-
/**
|
|
160
|
-
* The possible unknown error, with trace revealing its source and reason.
|
|
161
|
-
*/
|
|
147
|
+
/** The possible unknown error, with trace revealing its source and reason. */
|
|
162
148
|
readonly origin?: Error;
|
|
163
149
|
/**
|
|
164
150
|
* Creates a new `UnknownError` with an optional error `message`.
|
|
@@ -18,40 +18,23 @@ import { Nullable, Namon } from './types';
|
|
|
18
18
|
* behaviors related to that name handling.
|
|
19
19
|
*/
|
|
20
20
|
export declare class FullName {
|
|
21
|
-
private
|
|
22
|
-
private _firstName;
|
|
23
|
-
private _middleName;
|
|
24
|
-
private _lastName;
|
|
25
|
-
private _suffix;
|
|
26
|
-
private _config;
|
|
21
|
+
#private;
|
|
27
22
|
/**
|
|
28
23
|
* Creates a full name as it goes
|
|
29
24
|
* @param options optional configuration for additional features.
|
|
30
25
|
*/
|
|
31
26
|
constructor(options?: Partial<Config>);
|
|
32
|
-
/**
|
|
33
|
-
* A snapshot of the configuration used to set up this full name.
|
|
34
|
-
*/
|
|
27
|
+
/** A snapshot of the configuration used to set up this full name. */
|
|
35
28
|
get config(): Config;
|
|
36
|
-
/**
|
|
37
|
-
* The prefix part of the full name.
|
|
38
|
-
*/
|
|
29
|
+
/** The prefix part of the full name. */
|
|
39
30
|
get prefix(): Nullable<Name>;
|
|
40
|
-
/**
|
|
41
|
-
* The first name part of the full name.
|
|
42
|
-
*/
|
|
31
|
+
/** The first name part of the full name. */
|
|
43
32
|
get firstName(): FirstName;
|
|
44
|
-
/**
|
|
45
|
-
* The last name part of the full name.
|
|
46
|
-
*/
|
|
33
|
+
/** The last name part of the full name. */
|
|
47
34
|
get lastName(): LastName;
|
|
48
|
-
/**
|
|
49
|
-
* The middle name part of the full name.
|
|
50
|
-
*/
|
|
35
|
+
/** The middle name part of the full name. */
|
|
51
36
|
get middleName(): Name[];
|
|
52
|
-
/**
|
|
53
|
-
* The suffix part of the full name.
|
|
54
|
-
*/
|
|
37
|
+
/** The suffix part of the full name. */
|
|
55
38
|
get suffix(): Nullable<Name>;
|
|
56
39
|
/**
|
|
57
40
|
* Parses a json name into a full name.
|
|
@@ -3,8 +3,8 @@ import { CapsRange, Namon, Surname } from './types';
|
|
|
3
3
|
* Representation of a string type name with some extra capabilities.
|
|
4
4
|
*/
|
|
5
5
|
export declare class Name {
|
|
6
|
+
#private;
|
|
6
7
|
readonly type: Namon;
|
|
7
|
-
private namon;
|
|
8
8
|
protected initial: string;
|
|
9
9
|
protected capsRange: CapsRange;
|
|
10
10
|
/**
|
|
@@ -15,80 +15,47 @@ export declare class Name {
|
|
|
15
15
|
*/
|
|
16
16
|
constructor(value: string, type: Namon, capsRange?: CapsRange);
|
|
17
17
|
set value(newValue: string);
|
|
18
|
-
/**
|
|
19
|
-
* The piece of string treated as a name.
|
|
20
|
-
*/
|
|
18
|
+
/** The piece of string treated as a name. */
|
|
21
19
|
get value(): string;
|
|
22
|
-
/**
|
|
23
|
-
* The length of the name.
|
|
24
|
-
*/
|
|
20
|
+
/** The length of the name. */
|
|
25
21
|
get length(): number;
|
|
26
|
-
/**
|
|
27
|
-
* Whether the name is a prefix.
|
|
28
|
-
*/
|
|
22
|
+
/** Whether the name is a prefix. */
|
|
29
23
|
get isPrefix(): boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Whether the name is a first name.
|
|
32
|
-
*/
|
|
24
|
+
/** Whether the name is a first name. */
|
|
33
25
|
get isFirstName(): boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Whether the name is a middle name.
|
|
36
|
-
*/
|
|
26
|
+
/** Whether the name is a middle name. */
|
|
37
27
|
get isMiddleName(): boolean;
|
|
38
|
-
/**
|
|
39
|
-
* Whether the name is a last name.
|
|
40
|
-
*/
|
|
28
|
+
/** Whether the name is a last name. */
|
|
41
29
|
get isLastName(): boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Whether the name is a suffix.
|
|
44
|
-
*/
|
|
30
|
+
/** Whether the name is a suffix. */
|
|
45
31
|
get isSuffix(): boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Creates a prefix.
|
|
48
|
-
*/
|
|
32
|
+
/** Creates a prefix. */
|
|
49
33
|
static prefix(value: string): Name;
|
|
50
|
-
/**
|
|
51
|
-
* Creates a first name.
|
|
52
|
-
*/
|
|
34
|
+
/** Creates a first name. */
|
|
53
35
|
static first(value: string): Name;
|
|
54
|
-
/**
|
|
55
|
-
* Creates a middle name.
|
|
56
|
-
*/
|
|
36
|
+
/** Creates a middle name. */
|
|
57
37
|
static middle(value: string): Name;
|
|
58
|
-
/**
|
|
59
|
-
* Creates a last name.
|
|
60
|
-
*/
|
|
38
|
+
/** Creates a last name. */
|
|
61
39
|
static last(value: string): Name;
|
|
62
|
-
/**
|
|
63
|
-
* Creates a suffix.
|
|
64
|
-
*/
|
|
40
|
+
/** Creates a suffix. */
|
|
65
41
|
static suffix(value: string): Name;
|
|
66
|
-
/**
|
|
67
|
-
* Gets the initials (first character) of this name.
|
|
68
|
-
*/
|
|
42
|
+
/** Gets the initials (first character) of this name. */
|
|
69
43
|
initials(): string[];
|
|
70
|
-
/**
|
|
71
|
-
* String representation of this object.
|
|
72
|
-
*/
|
|
44
|
+
/** String representation of this object. */
|
|
73
45
|
toString(): string;
|
|
74
|
-
/**
|
|
75
|
-
* Returns true if the other is equal to this name.
|
|
76
|
-
*/
|
|
46
|
+
/** Returns true if the other is equal to this name. */
|
|
77
47
|
equal(other: Name | unknown): boolean;
|
|
78
|
-
/**
|
|
79
|
-
* Capitalizes the name.
|
|
80
|
-
*/
|
|
48
|
+
/** Capitalizes the name. */
|
|
81
49
|
caps(range?: CapsRange): Name;
|
|
82
|
-
/**
|
|
83
|
-
* De-capitalizes the name.
|
|
84
|
-
*/
|
|
50
|
+
/** De-capitalizes the name. */
|
|
85
51
|
decaps(range?: CapsRange): Name;
|
|
52
|
+
protected validate(name?: string): void;
|
|
86
53
|
}
|
|
87
54
|
/**
|
|
88
55
|
* Representation of a first name with some extra functionality.
|
|
89
56
|
*/
|
|
90
57
|
export declare class FirstName extends Name {
|
|
91
|
-
private
|
|
58
|
+
#private;
|
|
92
59
|
/**
|
|
93
60
|
* Creates an extended version of `Name` and flags it as a first name `type`.
|
|
94
61
|
*
|
|
@@ -97,26 +64,18 @@ export declare class FirstName extends Name {
|
|
|
97
64
|
* `more` provides the freedom to do it as it pleases.
|
|
98
65
|
*/
|
|
99
66
|
constructor(value: string, ...more: string[]);
|
|
100
|
-
/**
|
|
101
|
-
* Determines whether a first name has `more` name parts.
|
|
102
|
-
*/
|
|
67
|
+
/** Determines whether a first name has `more` name parts. */
|
|
103
68
|
get hasMore(): boolean;
|
|
104
69
|
get length(): number;
|
|
105
|
-
/**
|
|
106
|
-
* Returns a combined version of the `value` and `more` if any.
|
|
107
|
-
*/
|
|
70
|
+
/** Returns a combined version of the `value` and `more` if any. */
|
|
108
71
|
get asNames(): Name[];
|
|
109
|
-
/**
|
|
110
|
-
* The additional name parts of the first name.
|
|
111
|
-
*/
|
|
72
|
+
/** The additional name parts of the first name. */
|
|
112
73
|
get more(): string[];
|
|
113
74
|
toString(withMore?: boolean): string;
|
|
114
75
|
initials(withMore?: boolean): string[];
|
|
115
76
|
caps(range?: CapsRange): FirstName;
|
|
116
77
|
decaps(range?: CapsRange): FirstName;
|
|
117
|
-
/**
|
|
118
|
-
* Makes a copy of the current name.
|
|
119
|
-
*/
|
|
78
|
+
/** Makes a copy of the current name. */
|
|
120
79
|
copyWith(values?: {
|
|
121
80
|
first?: string;
|
|
122
81
|
more?: string[];
|
|
@@ -126,8 +85,8 @@ export declare class FirstName extends Name {
|
|
|
126
85
|
* Representation of a last name with some extra functionality.
|
|
127
86
|
*/
|
|
128
87
|
export declare class LastName extends Name {
|
|
88
|
+
#private;
|
|
129
89
|
readonly format: Surname;
|
|
130
|
-
private _mother?;
|
|
131
90
|
/**
|
|
132
91
|
* Creates an extended version of `Name` and flags it as a last name `type`.
|
|
133
92
|
*
|
|
@@ -135,30 +94,20 @@ export declare class LastName extends Name {
|
|
|
135
94
|
* from their `father`'s surname. However, there are no clear rules about it.
|
|
136
95
|
*/
|
|
137
96
|
constructor(father: string, mother?: string, format?: Surname);
|
|
138
|
-
/**
|
|
139
|
-
* The surname inherited from a father side.
|
|
140
|
-
*/
|
|
97
|
+
/** The surname inherited from a father side. */
|
|
141
98
|
get father(): string;
|
|
142
|
-
/**
|
|
143
|
-
* The surname inherited from a mother side.
|
|
144
|
-
*/
|
|
99
|
+
/** The surname inherited from a mother side. */
|
|
145
100
|
get mother(): string | undefined;
|
|
146
|
-
/**
|
|
147
|
-
* Returns `true` if the mother's surname is defined.
|
|
148
|
-
*/
|
|
101
|
+
/** Returns `true` if the mother's surname is defined. */
|
|
149
102
|
get hasMother(): boolean;
|
|
150
103
|
get length(): number;
|
|
151
|
-
/**
|
|
152
|
-
* Returns a combined version of the `father` and `mother` if any.
|
|
153
|
-
*/
|
|
104
|
+
/** Returns a combined version of the `father` and `mother` if any. */
|
|
154
105
|
get asNames(): Name[];
|
|
155
106
|
toString(format?: Surname): string;
|
|
156
107
|
initials(format?: Surname): string[];
|
|
157
108
|
caps(range?: CapsRange): LastName;
|
|
158
109
|
decaps(range?: CapsRange): LastName;
|
|
159
|
-
/**
|
|
160
|
-
* Makes a copy of the current name.
|
|
161
|
-
*/
|
|
110
|
+
/** Makes a copy of the current name. */
|
|
162
111
|
copyWith(values?: {
|
|
163
112
|
father?: string;
|
|
164
113
|
mother?: string;
|