namefully 1.1.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 +112 -0
- package/dist/lib/constants.js +30 -0
- package/dist/lib/error.js +92 -0
- package/dist/lib/full-name.js +115 -0
- package/dist/lib/index.js +27 -12
- package/dist/lib/name.js +230 -0
- package/dist/lib/namefully.js +368 -681
- package/dist/lib/parser.js +138 -0
- package/dist/lib/types.js +107 -0
- package/dist/lib/utils.js +92 -0
- package/dist/lib/validator.js +301 -0
- package/dist/types/config.d.ts +97 -0
- package/dist/types/constants.d.ts +4 -0
- package/dist/types/error.d.ts +158 -0
- package/dist/types/full-name.d.ts +54 -0
- package/dist/types/index.d.ts +21 -0
- package/dist/types/name.d.ts +126 -0
- package/dist/types/namefully.d.ts +313 -0
- package/dist/types/parser.d.ts +41 -0
- package/dist/types/types.d.ts +127 -0
- package/dist/types/utils.d.ts +53 -0
- package/dist/types/validator.d.ts +57 -0
- package/dist/umd/namefully.js +1503 -2900
- package/dist/umd/namefully.min.js +1 -3
- package/package.json +28 -38
- package/readme.md +138 -167
- package/changelog.md +0 -134
- package/dist/lib/core/constants.d.ts +0 -48
- package/dist/lib/core/constants.js +0 -101
- package/dist/lib/core/constants.js.map +0 -1
- package/dist/lib/core/core.d.ts +0 -17
- package/dist/lib/core/core.js +0 -24
- package/dist/lib/core/core.js.map +0 -1
- package/dist/lib/core/index.d.ts +0 -9
- package/dist/lib/core/index.js +0 -13
- package/dist/lib/core/index.js.map +0 -1
- package/dist/lib/core/parsers/array-name.parser.d.ts +0 -41
- package/dist/lib/core/parsers/array-name.parser.js +0 -86
- package/dist/lib/core/parsers/array-name.parser.js.map +0 -1
- package/dist/lib/core/parsers/array-string.parser.d.ts +0 -47
- package/dist/lib/core/parsers/array-string.parser.js +0 -95
- package/dist/lib/core/parsers/array-string.parser.js.map +0 -1
- package/dist/lib/core/parsers/index.d.ts +0 -11
- package/dist/lib/core/parsers/index.js +0 -11
- package/dist/lib/core/parsers/index.js.map +0 -1
- package/dist/lib/core/parsers/nama.parser.d.ts +0 -33
- package/dist/lib/core/parsers/nama.parser.js +0 -74
- package/dist/lib/core/parsers/nama.parser.js.map +0 -1
- package/dist/lib/core/parsers/parser.d.ts +0 -28
- package/dist/lib/core/parsers/parser.js +0 -3
- package/dist/lib/core/parsers/parser.js.map +0 -1
- package/dist/lib/core/parsers/string.parser.d.ts +0 -60
- package/dist/lib/core/parsers/string.parser.js +0 -62
- package/dist/lib/core/parsers/string.parser.js.map +0 -1
- package/dist/lib/core/utils.d.ts +0 -52
- package/dist/lib/core/utils.js +0 -178
- package/dist/lib/core/utils.js.map +0 -1
- package/dist/lib/index.d.ts +0 -10
- package/dist/lib/index.js.map +0 -1
- package/dist/lib/models/enums.d.ts +0 -106
- package/dist/lib/models/enums.js +0 -114
- package/dist/lib/models/enums.js.map +0 -1
- package/dist/lib/models/firstname.d.ts +0 -77
- package/dist/lib/models/firstname.js +0 -131
- package/dist/lib/models/firstname.js.map +0 -1
- package/dist/lib/models/fullname.d.ts +0 -73
- package/dist/lib/models/fullname.js +0 -99
- package/dist/lib/models/fullname.js.map +0 -1
- package/dist/lib/models/index.d.ts +0 -13
- package/dist/lib/models/index.js +0 -16
- package/dist/lib/models/index.js.map +0 -1
- package/dist/lib/models/lastname.d.ts +0 -80
- package/dist/lib/models/lastname.js +0 -157
- package/dist/lib/models/lastname.js.map +0 -1
- package/dist/lib/models/misc.d.ts +0 -108
- package/dist/lib/models/misc.js +0 -3
- package/dist/lib/models/misc.js.map +0 -1
- package/dist/lib/models/name.d.ts +0 -76
- package/dist/lib/models/name.js +0 -115
- package/dist/lib/models/name.js.map +0 -1
- package/dist/lib/models/summary.d.ts +0 -26
- package/dist/lib/models/summary.js +0 -61
- package/dist/lib/models/summary.js.map +0 -1
- package/dist/lib/namefully.d.ts +0 -302
- package/dist/lib/namefully.js.map +0 -1
- package/dist/lib/validators/array-name.validator.d.ts +0 -25
- package/dist/lib/validators/array-name.validator.js +0 -75
- package/dist/lib/validators/array-name.validator.js.map +0 -1
- package/dist/lib/validators/array-string.validator.d.ts +0 -43
- package/dist/lib/validators/array-string.validator.js +0 -76
- package/dist/lib/validators/array-string.validator.js.map +0 -1
- package/dist/lib/validators/common/validation-error.d.ts +0 -19
- package/dist/lib/validators/common/validation-error.js +0 -26
- package/dist/lib/validators/common/validation-error.js.map +0 -1
- package/dist/lib/validators/common/validation-rule.d.ts +0 -72
- package/dist/lib/validators/common/validation-rule.js +0 -76
- package/dist/lib/validators/common/validation-rule.js.map +0 -1
- package/dist/lib/validators/common/validation-type.d.ts +0 -24
- package/dist/lib/validators/common/validation-type.js +0 -28
- package/dist/lib/validators/common/validation-type.js.map +0 -1
- package/dist/lib/validators/firstname.validator.d.ts +0 -20
- package/dist/lib/validators/firstname.validator.js +0 -29
- package/dist/lib/validators/firstname.validator.js.map +0 -1
- package/dist/lib/validators/fullname.validator.d.ts +0 -21
- package/dist/lib/validators/fullname.validator.js +0 -38
- package/dist/lib/validators/fullname.validator.js.map +0 -1
- package/dist/lib/validators/index.d.ts +0 -21
- package/dist/lib/validators/index.js +0 -35
- package/dist/lib/validators/index.js.map +0 -1
- package/dist/lib/validators/lastname.validator.d.ts +0 -20
- package/dist/lib/validators/lastname.validator.js +0 -29
- package/dist/lib/validators/lastname.validator.js.map +0 -1
- package/dist/lib/validators/middlename.validator.d.ts +0 -20
- package/dist/lib/validators/middlename.validator.js +0 -38
- package/dist/lib/validators/middlename.validator.js.map +0 -1
- package/dist/lib/validators/nama.validator.d.ts +0 -21
- package/dist/lib/validators/nama.validator.js +0 -44
- package/dist/lib/validators/nama.validator.js.map +0 -1
- package/dist/lib/validators/namon.validator.d.ts +0 -20
- package/dist/lib/validators/namon.validator.js +0 -29
- package/dist/lib/validators/namon.validator.js.map +0 -1
- package/dist/lib/validators/prefix.validator.d.ts +0 -14
- package/dist/lib/validators/prefix.validator.js +0 -31
- package/dist/lib/validators/prefix.validator.js.map +0 -1
- package/dist/lib/validators/string-name.validator.d.ts +0 -20
- package/dist/lib/validators/string-name.validator.js +0 -29
- package/dist/lib/validators/string-name.validator.js.map +0 -1
- package/dist/lib/validators/suffix.validator.d.ts +0 -14
- package/dist/lib/validators/suffix.validator.js +0 -31
- package/dist/lib/validators/suffix.validator.js.map +0 -1
- package/dist/lib/validators/validator.d.ts +0 -13
- package/dist/lib/validators/validator.js +0 -9
- package/dist/lib/validators/validator.js.map +0 -1
- package/dist/umd/namefully.js.map +0 -1
- package/dist/umd/namefully.min.js.LICENSE.txt +0 -29
- package/dist/umd/namefully.min.js.map +0 -1
package/dist/umd/namefully.js
CHANGED
|
@@ -91,7 +91,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
91
91
|
/******/
|
|
92
92
|
/******/
|
|
93
93
|
/******/ // Load entry module and return exports
|
|
94
|
-
/******/ return __webpack_require__(__webpack_require__.s =
|
|
94
|
+
/******/ return __webpack_require__(__webpack_require__.s = 9);
|
|
95
95
|
/******/ })
|
|
96
96
|
/************************************************************************/
|
|
97
97
|
/******/ ([
|
|
@@ -101,19 +101,111 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
101
101
|
"use strict";
|
|
102
102
|
|
|
103
103
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
104
|
+
exports.Separator = exports.Namon = exports.CapsRange = exports.Flat = exports.NameType = exports.NameOrder = exports.Surname = exports.Title = void 0;
|
|
105
|
+
var Title;
|
|
106
|
+
(function (Title) {
|
|
107
|
+
Title["US"] = "US";
|
|
108
|
+
Title["UK"] = "UK";
|
|
109
|
+
})(Title || (exports.Title = Title = {}));
|
|
110
|
+
var Surname;
|
|
111
|
+
(function (Surname) {
|
|
112
|
+
Surname["FATHER"] = "father";
|
|
113
|
+
Surname["MOTHER"] = "mother";
|
|
114
|
+
Surname["HYPHENATED"] = "hyphenated";
|
|
115
|
+
Surname["ALL"] = "all";
|
|
116
|
+
})(Surname || (exports.Surname = Surname = {}));
|
|
117
|
+
var NameOrder;
|
|
118
|
+
(function (NameOrder) {
|
|
119
|
+
NameOrder["FIRST_NAME"] = "firstName";
|
|
120
|
+
NameOrder["LAST_NAME"] = "lastName";
|
|
121
|
+
})(NameOrder || (exports.NameOrder = NameOrder = {}));
|
|
122
|
+
var NameType;
|
|
123
|
+
(function (NameType) {
|
|
124
|
+
NameType["FIRST_NAME"] = "firstName";
|
|
125
|
+
NameType["MIDDLE_NAME"] = "middleName";
|
|
126
|
+
NameType["LAST_NAME"] = "lastName";
|
|
127
|
+
NameType["BIRTH_NAME"] = "birthName";
|
|
128
|
+
})(NameType || (exports.NameType = NameType = {}));
|
|
129
|
+
var Flat;
|
|
130
|
+
(function (Flat) {
|
|
131
|
+
Flat["FIRST_NAME"] = "firstName";
|
|
132
|
+
Flat["MIDDLE_NAME"] = "middleName";
|
|
133
|
+
Flat["LAST_NAME"] = "lastName";
|
|
134
|
+
Flat["FIRST_MID"] = "firstMid";
|
|
135
|
+
Flat["MID_LAST"] = "midLast";
|
|
136
|
+
Flat["ALL"] = "all";
|
|
137
|
+
})(Flat || (exports.Flat = Flat = {}));
|
|
138
|
+
var CapsRange;
|
|
139
|
+
(function (CapsRange) {
|
|
140
|
+
CapsRange[CapsRange["NONE"] = 0] = "NONE";
|
|
141
|
+
CapsRange[CapsRange["INITIAL"] = 1] = "INITIAL";
|
|
142
|
+
CapsRange[CapsRange["ALL"] = 2] = "ALL";
|
|
143
|
+
})(CapsRange || (exports.CapsRange = CapsRange = {}));
|
|
144
|
+
class Namon {
|
|
145
|
+
constructor(index, key) {
|
|
146
|
+
this.index = index;
|
|
147
|
+
this.key = key;
|
|
148
|
+
}
|
|
149
|
+
static has(key) {
|
|
150
|
+
return Namon.all.has(key);
|
|
151
|
+
}
|
|
152
|
+
static cast(key) {
|
|
153
|
+
return Namon.has(key) ? Namon.all.get(key) : undefined;
|
|
154
|
+
}
|
|
155
|
+
toString() {
|
|
156
|
+
return `Namon.${this.key}`;
|
|
157
|
+
}
|
|
158
|
+
equal(other) {
|
|
159
|
+
return other instanceof Namon && other.index === this.index && other.key === this.key;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
exports.Namon = Namon;
|
|
163
|
+
Namon.PREFIX = new Namon(0, 'prefix');
|
|
164
|
+
Namon.FIRST_NAME = new Namon(1, 'firstName');
|
|
165
|
+
Namon.MIDDLE_NAME = new Namon(2, 'middleName');
|
|
166
|
+
Namon.LAST_NAME = new Namon(3, 'lastName');
|
|
167
|
+
Namon.SUFFIX = new Namon(4, 'suffix');
|
|
168
|
+
Namon.values = [Namon.PREFIX, Namon.FIRST_NAME, Namon.MIDDLE_NAME, Namon.LAST_NAME, Namon.SUFFIX];
|
|
169
|
+
Namon.all = new Map([
|
|
170
|
+
[Namon.PREFIX.key, Namon.PREFIX],
|
|
171
|
+
[Namon.FIRST_NAME.key, Namon.FIRST_NAME],
|
|
172
|
+
[Namon.MIDDLE_NAME.key, Namon.MIDDLE_NAME],
|
|
173
|
+
[Namon.LAST_NAME.key, Namon.LAST_NAME],
|
|
174
|
+
[Namon.SUFFIX.key, Namon.SUFFIX],
|
|
175
|
+
]);
|
|
176
|
+
class Separator {
|
|
177
|
+
constructor(name, token) {
|
|
178
|
+
this.name = name;
|
|
179
|
+
this.token = token;
|
|
180
|
+
}
|
|
181
|
+
toString() {
|
|
182
|
+
return `Separator.${this.name}`;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
exports.Separator = Separator;
|
|
186
|
+
Separator.COMMA = new Separator('comma', ',');
|
|
187
|
+
Separator.COLON = new Separator('colon', ':');
|
|
188
|
+
Separator.DOUBLE_QUOTE = new Separator('doubleQuote', '"');
|
|
189
|
+
Separator.EMPTY = new Separator('empty', '');
|
|
190
|
+
Separator.HYPHEN = new Separator('hyphen', '-');
|
|
191
|
+
Separator.PERIOD = new Separator('period', '.');
|
|
192
|
+
Separator.SEMI_COLON = new Separator('semiColon', ';');
|
|
193
|
+
Separator.SINGLE_QUOTE = new Separator('singleQuote', `'`);
|
|
194
|
+
Separator.SPACE = new Separator('space', ' ');
|
|
195
|
+
Separator.UNDERSCORE = new Separator('underscore', '_');
|
|
196
|
+
Separator.all = new Map([
|
|
197
|
+
[Separator.COMMA.name, Separator.COMMA],
|
|
198
|
+
[Separator.COLON.name, Separator.COLON],
|
|
199
|
+
[Separator.DOUBLE_QUOTE.name, Separator.DOUBLE_QUOTE],
|
|
200
|
+
[Separator.EMPTY.name, Separator.EMPTY],
|
|
201
|
+
[Separator.HYPHEN.name, Separator.HYPHEN],
|
|
202
|
+
[Separator.PERIOD.name, Separator.PERIOD],
|
|
203
|
+
[Separator.SEMI_COLON.name, Separator.SEMI_COLON],
|
|
204
|
+
[Separator.SINGLE_QUOTE.name, Separator.SINGLE_QUOTE],
|
|
205
|
+
[Separator.SPACE.name, Separator.SPACE],
|
|
206
|
+
[Separator.UNDERSCORE.name, Separator.UNDERSCORE],
|
|
207
|
+
]);
|
|
208
|
+
Separator.tokens = [...Separator.all.values()].map((s) => s.token);
|
|
117
209
|
|
|
118
210
|
|
|
119
211
|
/***/ }),
|
|
@@ -123,38 +215,96 @@ tslib_1.__exportStar(__webpack_require__(14), exports);
|
|
|
123
215
|
"use strict";
|
|
124
216
|
|
|
125
217
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
218
|
+
exports.UnknownError = exports.NotAllowedError = exports.ValidationError = exports.InputError = exports.NameError = exports.NameErrorType = void 0;
|
|
219
|
+
const utils_1 = __webpack_require__(2);
|
|
220
|
+
var NameErrorType;
|
|
221
|
+
(function (NameErrorType) {
|
|
222
|
+
NameErrorType[NameErrorType["INPUT"] = 0] = "INPUT";
|
|
223
|
+
NameErrorType[NameErrorType["VALIDATION"] = 1] = "VALIDATION";
|
|
224
|
+
NameErrorType[NameErrorType["NOT_ALLOWED"] = 2] = "NOT_ALLOWED";
|
|
225
|
+
NameErrorType[NameErrorType["UNKNOWN"] = 3] = "UNKNOWN";
|
|
226
|
+
})(NameErrorType || (exports.NameErrorType = NameErrorType = {}));
|
|
227
|
+
class NameError extends Error {
|
|
228
|
+
constructor(source, message, type = NameErrorType.UNKNOWN) {
|
|
229
|
+
super(message);
|
|
230
|
+
this.source = source;
|
|
231
|
+
this.type = type;
|
|
232
|
+
this.name = 'NameError';
|
|
233
|
+
}
|
|
234
|
+
get sourceAsString() {
|
|
235
|
+
let input = '';
|
|
236
|
+
if (!this.source)
|
|
237
|
+
input = '<undefined>';
|
|
238
|
+
if (typeof this.source === 'string')
|
|
239
|
+
input = this.source;
|
|
240
|
+
if ((0, utils_1.isNameArray)(this.source))
|
|
241
|
+
input = this.source.map((n) => n.toString()).join(' ');
|
|
242
|
+
if ((0, utils_1.isStringArray)(this.source))
|
|
243
|
+
input = this.source.join(' ');
|
|
244
|
+
return input;
|
|
245
|
+
}
|
|
246
|
+
get hasMessage() {
|
|
247
|
+
return this.message && this.message.trim().length > 0;
|
|
248
|
+
}
|
|
249
|
+
toString() {
|
|
250
|
+
let report = `${this.name} (${this.sourceAsString})`;
|
|
251
|
+
if (this.hasMessage)
|
|
252
|
+
report = `${report}: ${this.message}`;
|
|
253
|
+
return report;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
exports.NameError = NameError;
|
|
257
|
+
class InputError extends NameError {
|
|
258
|
+
constructor(error) {
|
|
259
|
+
super(error.source, error.message, NameErrorType.INPUT);
|
|
260
|
+
this.name = 'InputError';
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
exports.InputError = InputError;
|
|
264
|
+
class ValidationError extends NameError {
|
|
265
|
+
constructor(error) {
|
|
266
|
+
super(error.source, error.message, NameErrorType.VALIDATION);
|
|
267
|
+
this.nameType = error.nameType;
|
|
268
|
+
this.name = 'ValidationError';
|
|
269
|
+
}
|
|
270
|
+
toString() {
|
|
271
|
+
let report = `${this.name} (${this.nameType}='${this.sourceAsString}')`;
|
|
272
|
+
if (this.hasMessage)
|
|
273
|
+
report = `${report}: ${this.message}`;
|
|
274
|
+
return report;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
exports.ValidationError = ValidationError;
|
|
278
|
+
class NotAllowedError extends NameError {
|
|
279
|
+
constructor(error) {
|
|
280
|
+
super(error.source, error.message, NameErrorType.NOT_ALLOWED);
|
|
281
|
+
this.operation = error.operation;
|
|
282
|
+
this.name = 'NotAllowedError';
|
|
283
|
+
}
|
|
284
|
+
toString() {
|
|
285
|
+
let report = `${this.name} (${this.sourceAsString})`;
|
|
286
|
+
if (this.operation && this.operation.trim().length > 0)
|
|
287
|
+
report = `${report} - ${this.operation}`;
|
|
288
|
+
if (this.hasMessage)
|
|
289
|
+
report = `${report}: ${this.message}`;
|
|
290
|
+
return report;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
exports.NotAllowedError = NotAllowedError;
|
|
294
|
+
class UnknownError extends NameError {
|
|
295
|
+
constructor(error) {
|
|
296
|
+
super(error.source, error.message, NameErrorType.UNKNOWN);
|
|
297
|
+
this.origin = error.error;
|
|
298
|
+
this.name = 'UnknownError';
|
|
299
|
+
}
|
|
300
|
+
toString() {
|
|
301
|
+
let report = super.toString();
|
|
302
|
+
if (this.origin)
|
|
303
|
+
report += `\n${this.origin.toString()}`;
|
|
304
|
+
return report;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
exports.UnknownError = UnknownError;
|
|
158
308
|
|
|
159
309
|
|
|
160
310
|
/***/ }),
|
|
@@ -164,3066 +314,1519 @@ exports.StringNameValidator = string_name_validator_1.default;
|
|
|
164
314
|
"use strict";
|
|
165
315
|
|
|
166
316
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncValues", function() { return __asyncValues; });
|
|
202
|
-
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__makeTemplateObject", function() { return __makeTemplateObject; });
|
|
203
|
-
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importStar", function() { return __importStar; });
|
|
204
|
-
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importDefault", function() { return __importDefault; });
|
|
205
|
-
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__classPrivateFieldGet", function() { return __classPrivateFieldGet; });
|
|
206
|
-
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__classPrivateFieldSet", function() { return __classPrivateFieldSet; });
|
|
207
|
-
/*! *****************************************************************************
|
|
208
|
-
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
209
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
210
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
211
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
212
|
-
|
|
213
|
-
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
214
|
-
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
215
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
216
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
217
|
-
|
|
218
|
-
See the Apache Version 2.0 License for specific language governing permissions
|
|
219
|
-
and limitations under the License.
|
|
220
|
-
***************************************************************************** */
|
|
221
|
-
/* global Reflect, Promise */
|
|
222
|
-
|
|
223
|
-
var extendStatics = function(d, b) {
|
|
224
|
-
extendStatics = Object.setPrototypeOf ||
|
|
225
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
226
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
227
|
-
return extendStatics(d, b);
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
function __extends(d, b) {
|
|
231
|
-
extendStatics(d, b);
|
|
232
|
-
function __() { this.constructor = d; }
|
|
233
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
var __assign = function() {
|
|
237
|
-
__assign = Object.assign || function __assign(t) {
|
|
238
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
239
|
-
s = arguments[i];
|
|
240
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
241
|
-
}
|
|
242
|
-
return t;
|
|
243
|
-
}
|
|
244
|
-
return __assign.apply(this, arguments);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
function __rest(s, e) {
|
|
248
|
-
var t = {};
|
|
249
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
250
|
-
t[p] = s[p];
|
|
251
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
252
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
253
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
254
|
-
t[p[i]] = s[p[i]];
|
|
255
|
-
}
|
|
256
|
-
return t;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
function __decorate(decorators, target, key, desc) {
|
|
260
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
261
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
262
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
263
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
function __param(paramIndex, decorator) {
|
|
267
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function __metadata(metadataKey, metadataValue) {
|
|
271
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
275
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
276
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
277
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
278
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
279
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
280
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
function __generator(thisArg, body) {
|
|
285
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
286
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
287
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
288
|
-
function step(op) {
|
|
289
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
290
|
-
while (_) try {
|
|
291
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
292
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
293
|
-
switch (op[0]) {
|
|
294
|
-
case 0: case 1: t = op; break;
|
|
295
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
296
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
297
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
298
|
-
default:
|
|
299
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
300
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
301
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
302
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
303
|
-
if (t[2]) _.ops.pop();
|
|
304
|
-
_.trys.pop(); continue;
|
|
305
|
-
}
|
|
306
|
-
op = body.call(thisArg, _);
|
|
307
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
308
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
function __exportStar(m, exports) {
|
|
313
|
-
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
function __values(o) {
|
|
317
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
318
|
-
if (m) return m.call(o);
|
|
319
|
-
if (o && typeof o.length === "number") return {
|
|
320
|
-
next: function () {
|
|
321
|
-
if (o && i >= o.length) o = void 0;
|
|
322
|
-
return { value: o && o[i++], done: !o };
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
function __read(o, n) {
|
|
329
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
330
|
-
if (!m) return o;
|
|
331
|
-
var i = m.call(o), r, ar = [], e;
|
|
332
|
-
try {
|
|
333
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
334
|
-
}
|
|
335
|
-
catch (error) { e = { error: error }; }
|
|
336
|
-
finally {
|
|
337
|
-
try {
|
|
338
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
339
|
-
}
|
|
340
|
-
finally { if (e) throw e.error; }
|
|
341
|
-
}
|
|
342
|
-
return ar;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
function __spread() {
|
|
346
|
-
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
347
|
-
ar = ar.concat(__read(arguments[i]));
|
|
348
|
-
return ar;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
function __spreadArrays() {
|
|
352
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
353
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
354
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
355
|
-
r[k] = a[j];
|
|
356
|
-
return r;
|
|
357
|
-
};
|
|
358
|
-
|
|
359
|
-
function __await(v) {
|
|
360
|
-
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
364
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
365
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
366
|
-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
367
|
-
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
368
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
369
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
370
|
-
function fulfill(value) { resume("next", value); }
|
|
371
|
-
function reject(value) { resume("throw", value); }
|
|
372
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
function __asyncDelegator(o) {
|
|
376
|
-
var i, p;
|
|
377
|
-
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
378
|
-
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
function __asyncValues(o) {
|
|
382
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
383
|
-
var m = o[Symbol.asyncIterator], i;
|
|
384
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
385
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
386
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
function __makeTemplateObject(cooked, raw) {
|
|
390
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
391
|
-
return cooked;
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
function __importStar(mod) {
|
|
395
|
-
if (mod && mod.__esModule) return mod;
|
|
396
|
-
var result = {};
|
|
397
|
-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
398
|
-
result.default = mod;
|
|
399
|
-
return result;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
function __importDefault(mod) {
|
|
403
|
-
return (mod && mod.__esModule) ? mod : { default: mod };
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
function __classPrivateFieldGet(receiver, privateMap) {
|
|
407
|
-
if (!privateMap.has(receiver)) {
|
|
408
|
-
throw new TypeError("attempted to get private field on non-instance");
|
|
409
|
-
}
|
|
410
|
-
return privateMap.get(receiver);
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
function __classPrivateFieldSet(receiver, privateMap, value) {
|
|
414
|
-
if (!privateMap.has(receiver)) {
|
|
415
|
-
throw new TypeError("attempted to set private field on non-instance");
|
|
416
|
-
}
|
|
417
|
-
privateMap.set(receiver, value);
|
|
418
|
-
return value;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
/***/ }),
|
|
423
|
-
/* 4 */
|
|
424
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
425
|
-
|
|
426
|
-
"use strict";
|
|
427
|
-
|
|
428
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
429
|
-
/**
|
|
430
|
-
* Constants
|
|
431
|
-
*
|
|
432
|
-
* Created on March 07, 2020
|
|
433
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
434
|
-
*/
|
|
435
|
-
const index_1 = __webpack_require__(0);
|
|
436
|
-
const core_1 = __webpack_require__(26);
|
|
437
|
-
/**
|
|
438
|
-
* The current version of `Namefully`.
|
|
439
|
-
* @constant
|
|
440
|
-
*/
|
|
441
|
-
exports.version = '1.1.0';
|
|
442
|
-
/**
|
|
443
|
-
* CONFIG
|
|
444
|
-
* @constant
|
|
445
|
-
* @type {Config}
|
|
446
|
-
* @default
|
|
447
|
-
*/
|
|
448
|
-
exports.CONFIG = {
|
|
449
|
-
orderedBy: 'firstname',
|
|
450
|
-
separator: index_1.Separator.SPACE,
|
|
451
|
-
titling: 'uk',
|
|
452
|
-
ending: false,
|
|
453
|
-
bypass: false,
|
|
454
|
-
lastnameFormat: 'father',
|
|
455
|
-
};
|
|
456
|
-
/**
|
|
457
|
-
* NAME_INDEX
|
|
458
|
-
* @constant
|
|
459
|
-
* @type {NameIndex}
|
|
460
|
-
* @default
|
|
461
|
-
*/
|
|
462
|
-
exports.NAME_INDEX = {
|
|
463
|
-
prefix: 0,
|
|
464
|
-
firstname: 1,
|
|
465
|
-
middlename: 2,
|
|
466
|
-
lastname: 3,
|
|
467
|
-
suffix: 4,
|
|
468
|
-
};
|
|
469
|
-
exports.FIRST_LAST_NAME_INDEX = 2;
|
|
470
|
-
exports.LAST_FIRST_NAME_INDEX = 2;
|
|
471
|
-
exports.FIRST_MIDDLE_LAST_NAME_INDEX = 3;
|
|
472
|
-
exports.LAST_FIRST_MIDDLE_NAME_INDEX = 3;
|
|
473
|
-
exports.PREFIX_FIRST_MIDDLE_LAST_NAME_INDEX = 4;
|
|
474
|
-
exports.PREFIX_LAST_FIRST_MIDDLE_NAME_INDEX = 4;
|
|
475
|
-
exports.PREFIX_FIRST_MIDDLE_LAST_SUFFIX_NAME_INDEX = 5;
|
|
476
|
-
exports.PREFIX_LAST_FIRST_MIDDLE_SUFFIX_NAME_INDEX = 5;
|
|
477
|
-
exports.MIN_NUMBER_NAME_PART = 2;
|
|
478
|
-
exports.MAX_NUMBER_NAME_PART = 5;
|
|
479
|
-
/**
|
|
480
|
-
* RESTRICTED_CHARS
|
|
481
|
-
* @constant
|
|
482
|
-
* @default
|
|
483
|
-
*/
|
|
484
|
-
exports.RESTRICTED_CHARS = [
|
|
485
|
-
index_1.Separator.SPACE,
|
|
486
|
-
index_1.Separator.SINGLE_QUOTE,
|
|
487
|
-
index_1.Separator.HYPHEN,
|
|
488
|
-
index_1.Separator.PERIOD,
|
|
489
|
-
index_1.Separator.COMMA,
|
|
490
|
-
];
|
|
491
|
-
/**
|
|
492
|
-
* PASSWORD_MAPPER
|
|
493
|
-
* @constant
|
|
494
|
-
*/
|
|
495
|
-
exports.PASSWORD_MAPPER = new Map([
|
|
496
|
-
['a', new core_1.CharSet(['a', 'A', '@', '4'])],
|
|
497
|
-
['b', new core_1.CharSet(['b', 'B', '6', '|)', '|3', '|>'])],
|
|
498
|
-
['c', new core_1.CharSet(['c', 'C', '(', '<'])],
|
|
499
|
-
['d', new core_1.CharSet(['d', 'D', '(|', '<|'])],
|
|
500
|
-
['e', new core_1.CharSet(['e', 'E', '3', '*'])],
|
|
501
|
-
['f', new core_1.CharSet(['f', 'F', '7', '(-'])],
|
|
502
|
-
['g', new core_1.CharSet(['g', 'G', '8', '&', '**'])],
|
|
503
|
-
['h', new core_1.CharSet(['h', 'H', '#', '|-|'])],
|
|
504
|
-
['i', new core_1.CharSet(['i', 'I', '!', '1', '|', '--'])],
|
|
505
|
-
['j', new core_1.CharSet(['j', 'J', ')', '1'])],
|
|
506
|
-
['k', new core_1.CharSet(['k', 'K', '%', '|<'])],
|
|
507
|
-
['l', new core_1.CharSet(['l', 'L', '1', '!', '|_'])],
|
|
508
|
-
['m', new core_1.CharSet(['m', 'M', '^^', '>>'])],
|
|
509
|
-
['n', new core_1.CharSet(['n', 'N', '!=', '++'])],
|
|
510
|
-
['o', new core_1.CharSet(['o', 'O', '0', '.', '*'])],
|
|
511
|
-
['p', new core_1.CharSet(['p', 'P', '|3', '|)', '|>'])],
|
|
512
|
-
['q', new core_1.CharSet(['q', 'Q', '&', '9', '<|'])],
|
|
513
|
-
['r', new core_1.CharSet(['r', 'R', '7', '&'])],
|
|
514
|
-
['s', new core_1.CharSet(['s', 'S', '5', '$'])],
|
|
515
|
-
['t', new core_1.CharSet(['t', 'T', '7', '['])],
|
|
516
|
-
['u', new core_1.CharSet(['u', 'U', '|_|', 'v'])],
|
|
517
|
-
['v', new core_1.CharSet(['v', 'V', '>', '<', '^'])],
|
|
518
|
-
['w', new core_1.CharSet(['w', 'W', '[|]', 'vv'])],
|
|
519
|
-
['x', new core_1.CharSet(['x', 'X', '%', '#'])],
|
|
520
|
-
['z', new core_1.CharSet(['z', 'Z', '2', '!='])],
|
|
521
|
-
['$', new core_1.CharSet([
|
|
522
|
-
'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '[',
|
|
523
|
-
'_', '=', '{', '}', ':', ';', ',', '.', '<', '>', '|', '~', ']',
|
|
524
|
-
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
|
|
525
|
-
])],
|
|
526
|
-
]);
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
/***/ }),
|
|
530
|
-
/* 5 */
|
|
531
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
532
|
-
|
|
533
|
-
"use strict";
|
|
534
|
-
|
|
535
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
536
|
-
var array_name_parser_1 = __webpack_require__(8);
|
|
537
|
-
exports.ArrayNameParser = array_name_parser_1.default;
|
|
538
|
-
var array_string_parser_1 = __webpack_require__(30);
|
|
539
|
-
exports.ArrayStringParser = array_string_parser_1.default;
|
|
540
|
-
var nama_parser_1 = __webpack_require__(31);
|
|
541
|
-
exports.NamaParser = nama_parser_1.default;
|
|
542
|
-
var string_parser_1 = __webpack_require__(32);
|
|
543
|
-
exports.StringParser = string_parser_1.default;
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
/***/ }),
|
|
547
|
-
/* 6 */
|
|
548
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
549
|
-
|
|
550
|
-
"use strict";
|
|
551
|
-
|
|
552
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
553
|
-
const tslib_1 = __webpack_require__(3);
|
|
554
|
-
/**
|
|
555
|
-
* Main entry to `Namefully`
|
|
556
|
-
*
|
|
557
|
-
* Created on March 03, 2020
|
|
558
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
559
|
-
*/
|
|
560
|
-
tslib_1.__exportStar(__webpack_require__(7), exports);
|
|
561
|
-
tslib_1.__exportStar(__webpack_require__(2), exports);
|
|
562
|
-
tslib_1.__exportStar(__webpack_require__(0), exports);
|
|
563
|
-
tslib_1.__exportStar(__webpack_require__(1), exports);
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
/***/ }),
|
|
567
|
-
/* 7 */
|
|
568
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
569
|
-
|
|
570
|
-
"use strict";
|
|
571
|
-
|
|
572
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
573
|
-
/**
|
|
574
|
-
* Welcome to namefully!
|
|
575
|
-
*
|
|
576
|
-
* namefully is a JS utility for handing person names.
|
|
577
|
-
*
|
|
578
|
-
* Sources
|
|
579
|
-
* - repo: https://github.com/ralflorent/namefully
|
|
580
|
-
* - docs: https://namefully.netlify.app
|
|
581
|
-
* - npm: https://npmjs.com/package/namefully
|
|
582
|
-
*
|
|
583
|
-
* Created on March 03, 2020
|
|
584
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
585
|
-
* @license MIT
|
|
586
|
-
*/
|
|
587
|
-
const core_1 = __webpack_require__(2);
|
|
588
|
-
const models_1 = __webpack_require__(0);
|
|
589
|
-
const validators_1 = __webpack_require__(1);
|
|
590
|
-
/**
|
|
591
|
-
* Person name handler
|
|
592
|
-
* @class
|
|
593
|
-
*
|
|
594
|
-
* `Namefully` does not magically guess which part of the name is what. It relies
|
|
595
|
-
* actually on how the developer indicates the roles of the name parts so that
|
|
596
|
-
* it, internally, can perform certain operations and saves the developer some
|
|
597
|
-
* calculations/processings. Nevertheless, Namefully can be constructed using
|
|
598
|
-
* distinct raw data shape. This is intended to give some flexibility to the
|
|
599
|
-
* developer so that he or she is not bound to a particular data format. Please,
|
|
600
|
-
* do follow closely the APIs to know how to properly use it in order to avoid
|
|
601
|
-
* some errors (mainly validation's).
|
|
602
|
-
*
|
|
603
|
-
* `Namefully` also works like a trap door. Once a raw data is provided and
|
|
604
|
-
* validated, a developer can only ACCESS in a vast amount of, yet effective ways
|
|
605
|
-
* the name info. NO EDITING is possible. If the name is mistaken, a new instance
|
|
606
|
-
* of `Namefully` must be created. Remember, this utility's primary objective is
|
|
607
|
-
* to help to **handle** a person name.
|
|
608
|
-
*
|
|
609
|
-
* Note that the name standards used for the current version of this library are
|
|
610
|
-
* as follows:
|
|
611
|
-
* [Prefix] Firstname [Middlename] Lastname [Suffix]
|
|
612
|
-
* The opening `[` and closing `]` brackets mean that these parts are optional.
|
|
613
|
-
* In other words, the most basic and typical case is a name that looks like this:
|
|
614
|
-
* `John Smith`, where `John` is the first name and `Smith`, the last name.
|
|
615
|
-
* @see https://departments.weber.edu/qsupport&training/Data_Standards/Name.htm
|
|
616
|
-
* for more info on name standards.
|
|
617
|
-
*
|
|
618
|
-
* **IMPORTANT**: Keep in mind that the order of appearance matters and can be
|
|
619
|
-
* altered through configured parameters, which we will be seeing later on. By
|
|
620
|
-
* default, the order of appearance is as shown above and will be used as a basis
|
|
621
|
-
* for future examples and use cases.
|
|
622
|
-
*
|
|
623
|
-
* Once imported, all that is required to do is to create an instance of
|
|
624
|
-
* `Namefully` and the rest will follow.
|
|
625
|
-
*
|
|
626
|
-
* Some terminologies used across the library are:
|
|
627
|
-
* - namon: 1 piece of a name (e.g., firstname)
|
|
628
|
-
* - nama: 2+ pieces of a name (e.g., firstname + lastname)
|
|
629
|
-
*
|
|
630
|
-
* Happy handling!
|
|
631
|
-
*/
|
|
632
|
-
class Namefully {
|
|
633
|
-
/**
|
|
634
|
-
* Constructs an instance of the utility and helps to benefit from many helpers
|
|
635
|
-
* @param {string | string[] | Name[] | Nama | Fullname} raw element to parse or
|
|
636
|
-
* construct the pieces of the name
|
|
637
|
-
* @param {Config} options to configure how to run the utility
|
|
638
|
-
*/
|
|
639
|
-
constructor(raw, options) {
|
|
640
|
-
// well, first thing first
|
|
641
|
-
this.configure(options);
|
|
642
|
-
// let's try to parse this, baby!
|
|
643
|
-
this.build(raw);
|
|
644
|
-
}
|
|
645
|
-
/**
|
|
646
|
-
* Gets the full name ordered as configured
|
|
647
|
-
* @param {NameOrder} orderedBy force to order by first or last
|
|
648
|
-
* name by overriding the preset configuration
|
|
649
|
-
*
|
|
650
|
-
* @see {format} to alter manually the order of appearance of the full name.
|
|
651
|
-
* For example, ::format('l f m') outputs `lastname firstname middlename`.
|
|
652
|
-
*/
|
|
653
|
-
getFullname(orderedBy) {
|
|
654
|
-
orderedBy = this.parseNameOrder(orderedBy);
|
|
655
|
-
const { titling, ending } = this.config;
|
|
656
|
-
const pxSep = titling === 'us' ? models_1.Separator.PERIOD : models_1.Separator.EMPTY; // Mr[.]
|
|
657
|
-
const sxSep = ending ? ',' : models_1.Separator.EMPTY; // [,] PhD
|
|
658
|
-
const nama = [];
|
|
659
|
-
if (this.fullname.prefix)
|
|
660
|
-
nama.push(models_1.Separator.EMPTY.concat(this.fullname.prefix, pxSep));
|
|
661
|
-
if (orderedBy === 'firstname') {
|
|
662
|
-
nama.push(this.getFirstname());
|
|
663
|
-
nama.push(...this.getMiddlenames());
|
|
664
|
-
nama.push(models_1.Separator.EMPTY.concat(this.getLastname(), sxSep));
|
|
665
|
-
}
|
|
666
|
-
else {
|
|
667
|
-
nama.push(this.getLastname());
|
|
668
|
-
nama.push(this.getFirstname());
|
|
669
|
-
nama.push(this.getMiddlenames().join(models_1.Separator.SPACE).concat(sxSep));
|
|
670
|
-
}
|
|
671
|
-
if (this.fullname.suffix)
|
|
672
|
-
nama.push(this.fullname.suffix);
|
|
673
|
-
return nama.join(models_1.Separator.SPACE);
|
|
674
|
-
}
|
|
675
|
-
/**
|
|
676
|
-
* Gets the birth name ordered as configured, no prefix or suffix
|
|
677
|
-
* @param {NameOrder} orderedBy force to order by first or last
|
|
678
|
-
* name by overriding the preset configuration
|
|
679
|
-
*/
|
|
680
|
-
getBirthname(orderedBy) {
|
|
681
|
-
orderedBy = this.parseNameOrder(orderedBy);
|
|
682
|
-
const nama = [];
|
|
683
|
-
if (orderedBy === 'firstname') {
|
|
684
|
-
nama.push(this.getFirstname());
|
|
685
|
-
nama.push(...this.getMiddlenames());
|
|
686
|
-
nama.push(this.getLastname());
|
|
687
|
-
}
|
|
688
|
-
else {
|
|
689
|
-
nama.push(this.getLastname());
|
|
690
|
-
nama.push(this.getFirstname());
|
|
691
|
-
nama.push(...this.getMiddlenames());
|
|
692
|
-
}
|
|
693
|
-
return nama.join(models_1.Separator.SPACE);
|
|
694
|
-
}
|
|
695
|
-
/**
|
|
696
|
-
* Gets the first name part of the full name
|
|
697
|
-
* @param {boolean} includeAll whether to include other pieces of the first
|
|
698
|
-
* name
|
|
699
|
-
*/
|
|
700
|
-
getFirstname(includeAll = true) {
|
|
701
|
-
return this.fullname.firstname.tostring(includeAll);
|
|
702
|
-
}
|
|
703
|
-
/**
|
|
704
|
-
* Gets the last name part of the full name
|
|
705
|
-
* @param {LastnameFormat} [format] overrides the how-to format of a surname
|
|
706
|
-
* output, considering its subparts.
|
|
707
|
-
*/
|
|
708
|
-
getLastname(format) {
|
|
709
|
-
return this.fullname.lastname.tostring(format);
|
|
710
|
-
}
|
|
711
|
-
/**
|
|
712
|
-
* Gets the middle names part of the full name
|
|
713
|
-
*/
|
|
714
|
-
getMiddlenames() {
|
|
715
|
-
return this.hasMiddlename() ? this.fullname.middlename.map(n => n.namon) : [];
|
|
716
|
-
}
|
|
717
|
-
/**
|
|
718
|
-
* Gets the prefix part of the full name
|
|
719
|
-
*/
|
|
720
|
-
getPrefix() {
|
|
721
|
-
return this.fullname.prefix
|
|
722
|
-
? this.fullname.prefix.concat(this.config.titling === 'us'
|
|
723
|
-
? models_1.Separator.PERIOD
|
|
724
|
-
: models_1.Separator.EMPTY) : models_1.Separator.EMPTY;
|
|
725
|
-
}
|
|
726
|
-
/**
|
|
727
|
-
* Gets the suffix part of the full name
|
|
728
|
-
*/
|
|
729
|
-
getSuffix() {
|
|
730
|
-
return this.fullname.suffix || models_1.Separator.EMPTY;
|
|
731
|
-
}
|
|
732
|
-
/**
|
|
733
|
-
* Gets the initials of the full name
|
|
734
|
-
* @param {NameOrder} orderedBy force to order by first or last name by
|
|
735
|
-
* overriding the preset configuration
|
|
736
|
-
* @param {boolean} [withMid] whether to include middle names's
|
|
737
|
-
*
|
|
738
|
-
* @example
|
|
739
|
-
* Given the names:
|
|
740
|
-
* - `John Smith` => ['J', 'S']
|
|
741
|
-
* - `John Ben Smith` => ['J', 'S']
|
|
742
|
-
* when `withMid` is set to true:
|
|
743
|
-
* - `John Ben Smith` => ['J', 'B', 'S']
|
|
744
|
-
*
|
|
745
|
-
* **NOTE**:
|
|
746
|
-
* Ordered by last name obeys the following format:
|
|
747
|
-
* `lastname firstname [middlename]`
|
|
748
|
-
* which means that if no middle name was set, setting `withMid` to true
|
|
749
|
-
* will output nothing and warn the end user about it.
|
|
750
|
-
*/
|
|
751
|
-
getInitials(orderedBy, withMid = false) {
|
|
752
|
-
orderedBy = this.parseNameOrder(orderedBy);
|
|
753
|
-
const midInits = this.fullname.middlename ?
|
|
754
|
-
this.fullname.middlename.map(n => n.getInitials()) : [];
|
|
755
|
-
if (withMid && !this.hasMiddlename()) {
|
|
756
|
-
console.warn('No initials for middle names since none was set.');
|
|
757
|
-
}
|
|
758
|
-
const initials = [];
|
|
759
|
-
if (orderedBy === 'firstname') {
|
|
760
|
-
initials.push(...this.fullname.firstname.getInitials());
|
|
761
|
-
if (withMid)
|
|
762
|
-
midInits.forEach(m => initials.push(...m));
|
|
763
|
-
initials.push(...this.fullname.lastname.getInitials());
|
|
764
|
-
}
|
|
765
|
-
else {
|
|
766
|
-
initials.push(...this.fullname.lastname.getInitials());
|
|
767
|
-
initials.push(...this.fullname.firstname.getInitials());
|
|
768
|
-
if (withMid)
|
|
769
|
-
midInits.forEach(m => initials.push(...m));
|
|
770
|
-
}
|
|
771
|
-
return initials;
|
|
772
|
-
}
|
|
773
|
-
/**
|
|
774
|
-
* Gives some descriptive statistics that summarize the central tendency,
|
|
775
|
-
* dispersion and shape of the characters' distribution.
|
|
776
|
-
* @param what which variant to use when describe a name part
|
|
777
|
-
*
|
|
778
|
-
* Treated as a categorical dataset, the summary contains the following info:
|
|
779
|
-
* `count` : the number of *unrestricted* characters of the name;
|
|
780
|
-
* `frequency` : the highest frequency within the characters;
|
|
781
|
-
* `top` : the character with the highest frequency;
|
|
782
|
-
* `unique` : the count of unique characters of the name;
|
|
783
|
-
* `distribution` : the characters' distribution.
|
|
784
|
-
*
|
|
785
|
-
* @example
|
|
786
|
-
* Given the name "Thomas Alva Edison", the summary will output as follows:
|
|
787
|
-
*
|
|
788
|
-
* Descriptive statistics for "Thomas Alva Edison"
|
|
789
|
-
* count : 16
|
|
790
|
-
* frequency: 3
|
|
791
|
-
* top : A
|
|
792
|
-
* unique : 12
|
|
793
|
-
* distribution: { T: 1, H: 1, O: 2, M: 1, A: 2, S: 2, ' ': 2, L: 1, V: 1,
|
|
794
|
-
* E: 1, D: 1, I: 1, N: 1 }
|
|
795
|
-
*
|
|
796
|
-
* **NOTE:**
|
|
797
|
-
* During the setup, a set of restricted characters can be defined to be removed
|
|
798
|
-
* from the stats. By default, the only restricted character is the `space`.
|
|
799
|
-
* That is why the `count` for the example below result in `16` instead of
|
|
800
|
-
* `16`.
|
|
801
|
-
* Another thing to consider is that the summary is case *insensitive*. Note
|
|
802
|
-
* that the letter `a` has the top frequency, be it `3`.
|
|
803
|
-
*/
|
|
804
|
-
describe(what) {
|
|
805
|
-
what = core_1.allowShortNameType(what);
|
|
806
|
-
switch (what) {
|
|
807
|
-
case 'firstname':
|
|
808
|
-
return this.fullname.firstname.describe();
|
|
809
|
-
case 'lastname':
|
|
810
|
-
return this.fullname.lastname.describe();
|
|
811
|
-
case 'middlename':
|
|
812
|
-
if (!this.hasMiddlename()) {
|
|
813
|
-
console.warn('No Summary for middle names since none was set.');
|
|
814
|
-
return null;
|
|
815
|
-
}
|
|
816
|
-
return new models_1.Summary(this.fullname.middlename
|
|
817
|
-
.map(n => n.namon)
|
|
818
|
-
.join(models_1.Separator.SPACE));
|
|
819
|
-
default:
|
|
820
|
-
return this.summary;
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
/**
|
|
824
|
-
* Shortens a complex full name to a simple typical name, a combination of
|
|
825
|
-
* first name and last name.
|
|
826
|
-
* @param {NameOrder} orderedBy force to order by first or last
|
|
827
|
-
* name by overriding the preset configuration
|
|
828
|
-
*
|
|
829
|
-
* @example
|
|
830
|
-
* For a given name such as `Mr Keanu Charles Reeves`, shortening this name
|
|
831
|
-
* is equivalent to making it `Keanu Reeves`.
|
|
832
|
-
*
|
|
833
|
-
* As a shortened name, the namon of the first name is favored over the other
|
|
834
|
-
* names forming part of the entire first names, if any. Meanwhile, for
|
|
835
|
-
* the last name, the configured `lastnameFormat` is prioritized.
|
|
836
|
-
*
|
|
837
|
-
* @example
|
|
838
|
-
* For a given `Firstname Fathername Mothername`, shortening this name when
|
|
839
|
-
* the lastnameFormat is set as `mother` is equivalent to making it:
|
|
840
|
-
* `Firstname Mothername`.
|
|
841
|
-
*/
|
|
842
|
-
shorten(orderedBy) {
|
|
843
|
-
orderedBy = orderedBy || this.config.orderedBy; // override config
|
|
844
|
-
const { firstname, lastname } = this.fullname;
|
|
845
|
-
return orderedBy === 'firstname'
|
|
846
|
-
? [firstname.namon, lastname.tostring()].join(models_1.Separator.SPACE)
|
|
847
|
-
: [lastname.tostring(), firstname.namon].join(models_1.Separator.SPACE);
|
|
848
|
-
}
|
|
849
|
-
/**
|
|
850
|
-
* Compresses a name by using different forms of variants
|
|
851
|
-
* @param {number} [limit] a threshold to limit the number of characters
|
|
852
|
-
* @param {'firstname'|'lastname'|'middlename'|'firstmid'|'midlast'} [by]
|
|
853
|
-
* a variant to use when compressing the long name. The last two variants
|
|
854
|
-
* represent respectively the combination of `firstname + middlename` and
|
|
855
|
-
* `middlename + lastname`.
|
|
856
|
-
* @param {boolean} [warning] should warn when the set limit is violated
|
|
857
|
-
*
|
|
858
|
-
* @example
|
|
859
|
-
* The compressing operation is only executed iff there is valid entry and it
|
|
860
|
-
* surpasses the limit set. In the examples below, let us assume that the
|
|
861
|
-
* name goes beyond the limit value.
|
|
862
|
-
*
|
|
863
|
-
* Compressing a long name refers to reducing the name to the following forms:
|
|
864
|
-
* 1. by firstname: 'John Moe Beau Lennon' => 'J. Moe Beau Lennon'
|
|
865
|
-
* 2. by middlename: 'John Moe Beau Lennon' => 'John M. B. Lennon'
|
|
866
|
-
* 3. by lastname: 'John Moe Beau Lennon' => 'John Moe Beau L.'
|
|
867
|
-
* 4. by firstmid: 'John Moe Beau Lennon' => 'J. M. B. Lennon'
|
|
868
|
-
* 5. by midlast: 'John Moe Beau Lennon' => 'John M. B. L.'
|
|
869
|
-
*
|
|
870
|
-
* By default, it compresses by 'firstmid' variant: 'J. M. B. Lennon'.
|
|
871
|
-
*/
|
|
872
|
-
compress(limit = 20, by = 'mn', warning = true) {
|
|
873
|
-
if (this.getFullname().length <= limit) // no need to compress
|
|
874
|
-
return this.getFullname();
|
|
875
|
-
const { firstname: fn, lastname: ln, middlename } = this.fullname;
|
|
876
|
-
const mn = this.getMiddlenames().join(models_1.Separator.SPACE);
|
|
877
|
-
const hasmid = Array.isArray(middlename) && middlename.length > 0;
|
|
878
|
-
const sep = models_1.Separator.PERIOD;
|
|
879
|
-
const firsts = fn.getInitials().join(sep).concat(sep);
|
|
880
|
-
const lasts = ln.getInitials().join(sep).concat(sep);
|
|
881
|
-
const mids = hasmid
|
|
882
|
-
? middlename.map(n => n.getInitials()).join(sep).concat(sep)
|
|
883
|
-
: models_1.Separator.EMPTY;
|
|
884
|
-
let cname = '';
|
|
885
|
-
if (this.config.orderedBy === 'firstname') {
|
|
886
|
-
switch (by) {
|
|
887
|
-
case 'firstname':
|
|
888
|
-
case 'fn':
|
|
889
|
-
cname = hasmid ?
|
|
890
|
-
[firsts, mn, ln.tostring()].join(models_1.Separator.SPACE) :
|
|
891
|
-
[firsts, ln.tostring()].join(models_1.Separator.SPACE);
|
|
892
|
-
break;
|
|
893
|
-
case 'lastname':
|
|
894
|
-
case 'ln':
|
|
895
|
-
cname = hasmid ?
|
|
896
|
-
[fn.tostring(), mn, lasts].join(models_1.Separator.SPACE) :
|
|
897
|
-
[fn.tostring(), lasts].join(models_1.Separator.SPACE);
|
|
898
|
-
break;
|
|
899
|
-
case 'middlename':
|
|
900
|
-
case 'mn':
|
|
901
|
-
cname = hasmid ?
|
|
902
|
-
[fn.tostring(), mids, ln.tostring()].join(models_1.Separator.SPACE) :
|
|
903
|
-
[fn.tostring(), ln.tostring()].join(models_1.Separator.SPACE);
|
|
904
|
-
break;
|
|
905
|
-
case 'firstmid':
|
|
906
|
-
case 'fm':
|
|
907
|
-
cname = hasmid ?
|
|
908
|
-
[firsts, mids, ln.tostring()].join(models_1.Separator.SPACE) :
|
|
909
|
-
[firsts, ln.tostring()].join(models_1.Separator.SPACE);
|
|
910
|
-
break;
|
|
911
|
-
case 'midlast':
|
|
912
|
-
case 'ml':
|
|
913
|
-
cname = hasmid ?
|
|
914
|
-
[fn.tostring(), mids, lasts].join(models_1.Separator.SPACE) :
|
|
915
|
-
[fn.tostring(), lasts].join(models_1.Separator.SPACE);
|
|
916
|
-
break;
|
|
317
|
+
exports.isNameArray = exports.isStringArray = exports.toggleCase = exports.decapitalize = exports.capitalize = exports.NameIndex = void 0;
|
|
318
|
+
const constants_1 = __webpack_require__(4);
|
|
319
|
+
const name_1 = __webpack_require__(3);
|
|
320
|
+
const types_1 = __webpack_require__(0);
|
|
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
|
+
}
|
|
328
|
+
constructor(prefix, firstName, middleName, lastName, suffix) {
|
|
329
|
+
this.prefix = prefix;
|
|
330
|
+
this.firstName = firstName;
|
|
331
|
+
this.middleName = middleName;
|
|
332
|
+
this.lastName = lastName;
|
|
333
|
+
this.suffix = suffix;
|
|
334
|
+
}
|
|
335
|
+
static base() {
|
|
336
|
+
return new this(-1, 0, -1, 1, -1);
|
|
337
|
+
}
|
|
338
|
+
static when(order, count = 2) {
|
|
339
|
+
if (order === types_1.NameOrder.FIRST_NAME) {
|
|
340
|
+
switch (count) {
|
|
341
|
+
case 2:
|
|
342
|
+
return new this(-1, 0, -1, 1, -1);
|
|
343
|
+
case 3:
|
|
344
|
+
return new this(-1, 0, 1, 2, -1);
|
|
345
|
+
case 4:
|
|
346
|
+
return new this(0, 1, 2, 3, -1);
|
|
347
|
+
case 5:
|
|
348
|
+
return new this(0, 1, 2, 3, 4);
|
|
349
|
+
default:
|
|
350
|
+
return NameIndex.base();
|
|
917
351
|
}
|
|
918
352
|
}
|
|
919
353
|
else {
|
|
920
|
-
switch (
|
|
921
|
-
case
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
case
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
[lasts, fn.tostring()].join(models_1.Separator.SPACE);
|
|
932
|
-
break;
|
|
933
|
-
case 'middlename':
|
|
934
|
-
case 'mn':
|
|
935
|
-
cname = hasmid ?
|
|
936
|
-
[ln.tostring(), fn.tostring(), mids].join(models_1.Separator.SPACE) :
|
|
937
|
-
[ln.tostring(), fn.tostring()].join(models_1.Separator.SPACE);
|
|
938
|
-
break;
|
|
939
|
-
case 'firstmid':
|
|
940
|
-
case 'fm':
|
|
941
|
-
cname = hasmid ?
|
|
942
|
-
[ln.tostring(), firsts, mids].join(models_1.Separator.SPACE) :
|
|
943
|
-
[ln.tostring(), firsts].join(models_1.Separator.SPACE);
|
|
944
|
-
break;
|
|
945
|
-
case 'midlast':
|
|
946
|
-
case 'ml':
|
|
947
|
-
cname = hasmid ?
|
|
948
|
-
[lasts, fn.tostring(), mids].join(models_1.Separator.SPACE) :
|
|
949
|
-
[lasts, fn.tostring()].join(models_1.Separator.SPACE);
|
|
950
|
-
break;
|
|
354
|
+
switch (count) {
|
|
355
|
+
case 2:
|
|
356
|
+
return new this(-1, 1, -1, 0, -1);
|
|
357
|
+
case 3:
|
|
358
|
+
return new this(-1, 1, 2, 0, -1);
|
|
359
|
+
case 4:
|
|
360
|
+
return new this(0, 2, 3, 1, -1);
|
|
361
|
+
case 5:
|
|
362
|
+
return new this(0, 2, 3, 1, 4);
|
|
363
|
+
default:
|
|
364
|
+
return NameIndex.base();
|
|
951
365
|
}
|
|
952
366
|
}
|
|
953
|
-
if (warning && cname.length > limit)
|
|
954
|
-
console.warn(`The compressed name <${cname}> still surpasses the set limit ${limit}`);
|
|
955
|
-
return cname;
|
|
956
|
-
}
|
|
957
|
-
/**
|
|
958
|
-
* Zips or compresses a name by using different forms of variants
|
|
959
|
-
* @param by a variant to use when compressing the long name. The last two
|
|
960
|
-
* variants represent respectively the combination of `firstname + middlename`
|
|
961
|
-
* and `middlename + lastname`.
|
|
962
|
-
*/
|
|
963
|
-
zip(by = 'mn') {
|
|
964
|
-
let v;
|
|
965
|
-
if (by === 'fn' || by === 'firstname')
|
|
966
|
-
v = 'firstname';
|
|
967
|
-
if (by === 'mn' || by === 'middlename')
|
|
968
|
-
v = 'middlename';
|
|
969
|
-
if (by === 'ln' || by === 'lastname')
|
|
970
|
-
v = 'lastname';
|
|
971
|
-
if (by === 'fm' || by === 'firstmid')
|
|
972
|
-
v = 'firstmid';
|
|
973
|
-
if (by === 'ml' || by === 'midlast')
|
|
974
|
-
v = 'midlast';
|
|
975
|
-
return this.compress(0, v, false);
|
|
976
|
-
}
|
|
977
|
-
/**
|
|
978
|
-
* Suggests possible (randomly) usernames closest to the name
|
|
979
|
-
*
|
|
980
|
-
* **NOTE**
|
|
981
|
-
* The validity of these usernames are not checked against any social media
|
|
982
|
-
* or web app online.
|
|
983
|
-
*/
|
|
984
|
-
username() {
|
|
985
|
-
const unames = [];
|
|
986
|
-
const { firstname, lastname } = this.fullname;
|
|
987
|
-
const p = models_1.Separator.PERIOD;
|
|
988
|
-
const fn = firstname.tostring().toLowerCase();
|
|
989
|
-
const ln = lastname.father.toLowerCase();
|
|
990
|
-
// Given `John Smith`
|
|
991
|
-
unames.push(fn + ln); // johnsmith
|
|
992
|
-
unames.push(ln + fn); // smithjohn
|
|
993
|
-
unames.push(fn[0] + ln); // jsmith
|
|
994
|
-
unames.push(ln[0] + fn); // sjohn
|
|
995
|
-
unames.push(fn[0] + p + ln); // j.smith
|
|
996
|
-
unames.push(ln[0] + p + fn); // s.john
|
|
997
|
-
unames.push(fn.slice(0, 2) + ln); // josmith
|
|
998
|
-
unames.push(ln.slice(0, 2) + fn); // smjohn
|
|
999
|
-
unames.push(fn.slice(0, 2) + p + ln); // jo.smith
|
|
1000
|
-
unames.push(ln.slice(0, 2) + p + fn); // sm.john
|
|
1001
|
-
return unames;
|
|
1002
|
-
}
|
|
1003
|
-
/**
|
|
1004
|
-
* Formats the name as desired
|
|
1005
|
-
* @param {string} how to format the full name
|
|
1006
|
-
*
|
|
1007
|
-
* How to format it?
|
|
1008
|
-
* string format
|
|
1009
|
-
* -------------
|
|
1010
|
-
* 'short': typical first + last name
|
|
1011
|
-
* 'long': birth name (without prefix and suffix)
|
|
1012
|
-
*
|
|
1013
|
-
* char format
|
|
1014
|
-
* -----------
|
|
1015
|
-
* 'b': birth name
|
|
1016
|
-
* 'B': capitalized birth name
|
|
1017
|
-
* 'f': first name
|
|
1018
|
-
* 'F': capitalized first name
|
|
1019
|
-
* 'l': last name (official)
|
|
1020
|
-
* 'L': capitalized last name
|
|
1021
|
-
* 'm': middle names
|
|
1022
|
-
* 'M': capitalized middle names
|
|
1023
|
-
* 'o': official document format
|
|
1024
|
-
* 'O': official document format in capital letters
|
|
1025
|
-
* 'p': prefix
|
|
1026
|
-
* 'P': capitalized prefix
|
|
1027
|
-
* 's': suffix
|
|
1028
|
-
* 'S': capitalized suffix
|
|
1029
|
-
*
|
|
1030
|
-
* punctuations
|
|
1031
|
-
* ------------
|
|
1032
|
-
* '.': period
|
|
1033
|
-
* ',': comma
|
|
1034
|
-
* ' ': space
|
|
1035
|
-
* '-': hyphen
|
|
1036
|
-
* '_': underscore
|
|
1037
|
-
*
|
|
1038
|
-
* @example
|
|
1039
|
-
* Given the name `Joe Jim Smith`, call the `format` with the how string.
|
|
1040
|
-
* - format('l f') => 'Smith Joe'
|
|
1041
|
-
* - format('L, f') => 'SMITH, Joe'
|
|
1042
|
-
* - format('short') => 'Joe Smith'
|
|
1043
|
-
* - format() => 'SMITH, Joe Jim'
|
|
1044
|
-
*/
|
|
1045
|
-
format(how = 'official') {
|
|
1046
|
-
if (how === 'short')
|
|
1047
|
-
return this.shorten();
|
|
1048
|
-
if (how === 'long')
|
|
1049
|
-
return this.getBirthname();
|
|
1050
|
-
if (how === 'official')
|
|
1051
|
-
how = 'o';
|
|
1052
|
-
const formatted = [];
|
|
1053
|
-
const tokens = [
|
|
1054
|
-
'.', ',', ' ', '-', '_', 'b', 'B', 'f', 'F', 'l', 'L', 'm', 'M',
|
|
1055
|
-
'n', 'N', 'o', 'O', 'p', 'P', 's', 'S'
|
|
1056
|
-
];
|
|
1057
|
-
for (const c of how) {
|
|
1058
|
-
if (tokens.indexOf(c) === -1)
|
|
1059
|
-
throw new Error(`<${c}> is an invalid character for the formatting.`);
|
|
1060
|
-
formatted.push(this.map(c));
|
|
1061
|
-
}
|
|
1062
|
-
return formatted.join(models_1.Separator.EMPTY).trim();
|
|
1063
|
-
}
|
|
1064
|
-
/**
|
|
1065
|
-
* Returns the count of characters of the birth name, excluding punctuations
|
|
1066
|
-
*/
|
|
1067
|
-
size() {
|
|
1068
|
-
return new models_1.Summary(this.getBirthname(), [...core_1.RESTRICTED_CHARS]).count;
|
|
1069
|
-
}
|
|
1070
|
-
/**
|
|
1071
|
-
* Returns an ascii representation of each characters of a name as specified
|
|
1072
|
-
* @param options use specifics to shape conversion
|
|
1073
|
-
*/
|
|
1074
|
-
ascii(options = {}) {
|
|
1075
|
-
const { exceptions: restrictions } = options;
|
|
1076
|
-
const nameType = core_1.allowShortNameType(options.nameType);
|
|
1077
|
-
const { firstname, lastname, middlename } = this.fullname;
|
|
1078
|
-
switch (nameType) {
|
|
1079
|
-
case 'firstname':
|
|
1080
|
-
return firstname.ascii(restrictions);
|
|
1081
|
-
case 'lastname':
|
|
1082
|
-
return lastname.ascii(restrictions);
|
|
1083
|
-
case 'middlename':
|
|
1084
|
-
if (!this.hasMiddlename())
|
|
1085
|
-
console.warn(`No ASCII conversion for middle names since none was set.`);
|
|
1086
|
-
return middlename
|
|
1087
|
-
.map(n => n.ascii(restrictions)) // convert
|
|
1088
|
-
.reduce((acc, value) => acc.concat(value), []); // then flatten
|
|
1089
|
-
default:
|
|
1090
|
-
const firsts = firstname.ascii(restrictions);
|
|
1091
|
-
const mids = middlename
|
|
1092
|
-
.map(n => n.ascii(restrictions))
|
|
1093
|
-
.reduce((acc, value) => acc.concat(value), []);
|
|
1094
|
-
const lasts = lastname.ascii(restrictions);
|
|
1095
|
-
if (this.config.orderedBy === 'firstname') {
|
|
1096
|
-
return firsts.concat(mids, lasts);
|
|
1097
|
-
}
|
|
1098
|
-
return lasts.concat(firsts, mids);
|
|
1099
|
-
}
|
|
1100
|
-
}
|
|
1101
|
-
/**
|
|
1102
|
-
* Transforms a birth name to a specific case
|
|
1103
|
-
* @param case which case to convert a birth name to
|
|
1104
|
-
*/
|
|
1105
|
-
to(_case) {
|
|
1106
|
-
const birthname = this.getBirthname();
|
|
1107
|
-
const nama = birthname
|
|
1108
|
-
.replace(/[' -]/g, models_1.Separator.SPACE)
|
|
1109
|
-
.split(models_1.Separator.SPACE);
|
|
1110
|
-
switch (_case) {
|
|
1111
|
-
case 'upper':
|
|
1112
|
-
return birthname.toUpperCase();
|
|
1113
|
-
case 'lower':
|
|
1114
|
-
return birthname.toLowerCase();
|
|
1115
|
-
case 'camel':
|
|
1116
|
-
case 'pascal':
|
|
1117
|
-
const pascalCase = nama.map(n => core_1.capitalize(n)).join(models_1.Separator.EMPTY);
|
|
1118
|
-
return _case === 'camel' ? core_1.decapitalize(pascalCase) : pascalCase;
|
|
1119
|
-
case 'snake':
|
|
1120
|
-
return nama.map(n => n.toLowerCase()).join(models_1.Separator.UNDERSCORE);
|
|
1121
|
-
case 'hyphen':
|
|
1122
|
-
return nama.map(n => n.toLowerCase()).join(models_1.Separator.HYPHEN);
|
|
1123
|
-
case 'dot':
|
|
1124
|
-
return nama.map(n => n.toLowerCase()).join(models_1.Separator.PERIOD);
|
|
1125
|
-
case 'toggle':
|
|
1126
|
-
return core_1.toggleCase(birthname);
|
|
1127
|
-
default:
|
|
1128
|
-
return models_1.Separator.EMPTY;
|
|
1129
|
-
}
|
|
1130
|
-
}
|
|
1131
|
-
/**
|
|
1132
|
-
* Returns a password-like representation of a name
|
|
1133
|
-
* @param {NameType} [what] which name part
|
|
1134
|
-
*/
|
|
1135
|
-
passwd(what) {
|
|
1136
|
-
what = core_1.allowShortNameType(what);
|
|
1137
|
-
switch (what) {
|
|
1138
|
-
case 'firstname':
|
|
1139
|
-
return this.fullname.firstname.passwd();
|
|
1140
|
-
case 'lastname':
|
|
1141
|
-
return this.fullname.lastname.passwd();
|
|
1142
|
-
case 'middlename':
|
|
1143
|
-
if (!this.hasMiddlename())
|
|
1144
|
-
console.warn('No password for middle names since none was set.');
|
|
1145
|
-
return this.fullname.middlename
|
|
1146
|
-
.map(n => n.passwd())
|
|
1147
|
-
.join(models_1.Separator.EMPTY);
|
|
1148
|
-
default:
|
|
1149
|
-
return core_1.generatePassword(this.getBirthname());
|
|
1150
|
-
}
|
|
1151
367
|
}
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
case ' ':
|
|
1176
|
-
return models_1.Separator.SPACE;
|
|
1177
|
-
case '-':
|
|
1178
|
-
return models_1.Separator.HYPHEN;
|
|
1179
|
-
case '_':
|
|
1180
|
-
return models_1.Separator.UNDERSCORE;
|
|
1181
|
-
case 'b':
|
|
1182
|
-
return this.getBirthname();
|
|
1183
|
-
case 'B':
|
|
1184
|
-
return this.getBirthname().toUpperCase();
|
|
1185
|
-
case 'f':
|
|
1186
|
-
return firstname.tostring();
|
|
1187
|
-
case 'F':
|
|
1188
|
-
return firstname.tostring().toUpperCase();
|
|
1189
|
-
case 'l':
|
|
1190
|
-
return lastname.tostring();
|
|
1191
|
-
case 'L':
|
|
1192
|
-
return lastname.tostring().toUpperCase();
|
|
1193
|
-
case 'm':
|
|
1194
|
-
if (!this.hasMiddlename()) {
|
|
1195
|
-
console.warn('No formatting for middle names since none was set.');
|
|
1196
|
-
return models_1.Separator.EMPTY;
|
|
1197
|
-
}
|
|
1198
|
-
return this.fullname.middlename.map(n => n.namon).join(models_1.Separator.SPACE);
|
|
1199
|
-
case 'M':
|
|
1200
|
-
if (!this.hasMiddlename()) {
|
|
1201
|
-
console.warn('No formatting for middle names since none was set.');
|
|
1202
|
-
return models_1.Separator.EMPTY;
|
|
1203
|
-
}
|
|
1204
|
-
return middlename.map(n => n.namon.toUpperCase()).join(models_1.Separator.SPACE);
|
|
1205
|
-
case 'o':
|
|
1206
|
-
case 'O':
|
|
1207
|
-
const { titling, ending } = this.config;
|
|
1208
|
-
const pxSep = titling === 'us' ? models_1.Separator.PERIOD : models_1.Separator.EMPTY;
|
|
1209
|
-
const sxSep = ending ? ',' : models_1.Separator.EMPTY;
|
|
1210
|
-
const nama = [];
|
|
1211
|
-
if (prefix)
|
|
1212
|
-
nama.push(prefix.concat(pxSep));
|
|
1213
|
-
nama.push(lastname.tostring().concat(models_1.Separator.COMMA).toUpperCase());
|
|
1214
|
-
if (this.hasMiddlename()) {
|
|
1215
|
-
nama.push(firstname.tostring());
|
|
1216
|
-
nama.push(middlename.map(n => n.namon).join(models_1.Separator.SPACE).concat(sxSep));
|
|
1217
|
-
}
|
|
1218
|
-
else {
|
|
1219
|
-
nama.push(firstname.tostring().concat(sxSep));
|
|
1220
|
-
}
|
|
1221
|
-
nama.push(suffix || models_1.Separator.EMPTY);
|
|
1222
|
-
const official = nama.join(models_1.Separator.SPACE).trim();
|
|
1223
|
-
return c === 'o' ? official : official.toUpperCase();
|
|
1224
|
-
case 'p':
|
|
1225
|
-
return prefix || models_1.Separator.EMPTY;
|
|
1226
|
-
case 'P':
|
|
1227
|
-
return prefix ? prefix.toUpperCase() : models_1.Separator.EMPTY;
|
|
1228
|
-
case 's':
|
|
1229
|
-
return suffix || models_1.Separator.EMPTY;
|
|
1230
|
-
case 'S':
|
|
1231
|
-
return suffix ? suffix.toUpperCase() : models_1.Separator.EMPTY;
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
build(raw) {
|
|
1235
|
-
if (this.config.parser) {
|
|
1236
|
-
this.initialize(this.config.parser);
|
|
1237
|
-
}
|
|
1238
|
-
else if (typeof raw === 'string') { // check for string type
|
|
1239
|
-
this.initialize(new core_1.StringParser(raw));
|
|
1240
|
-
}
|
|
1241
|
-
else if (Array.isArray(raw) && raw.length) { // check for T[]
|
|
1242
|
-
if (typeof raw[0] === 'string') { // check for string[]
|
|
1243
|
-
for (const key of raw)
|
|
1244
|
-
if (typeof key !== 'string')
|
|
1245
|
-
throw new Error(`Cannot parse raw data as array of 'string'`);
|
|
1246
|
-
this.initialize(new core_1.ArrayStringParser(raw));
|
|
1247
|
-
}
|
|
1248
|
-
else if (raw[0] instanceof models_1.Name) { // check for Name[]
|
|
1249
|
-
for (const obj of raw)
|
|
1250
|
-
if (!(obj instanceof models_1.Name))
|
|
1251
|
-
throw new Error(`Cannot parse raw data as array of 'Name'`);
|
|
1252
|
-
this.initialize(new core_1.ArrayNameParser(raw));
|
|
1253
|
-
}
|
|
1254
|
-
else {
|
|
1255
|
-
// typescript should stop them, but let's be paranoid (for JS developers)
|
|
1256
|
-
throw new Error(`Cannot parse raw data as arrays that are not of 'Name' or string`);
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
|
-
else if (raw instanceof Object) { // check for json object
|
|
1260
|
-
for (const [key, value] of Object.entries(raw)) { // make sure keys are correct
|
|
1261
|
-
if (['firstname', 'lastname', 'middlename', 'prefix', 'suffix'].indexOf(key) === -1)
|
|
1262
|
-
throw new Error(`Cannot parse raw data as json object that does not contains keys of` +
|
|
1263
|
-
`'${Object.keys(models_1.Namon)}'`);
|
|
1264
|
-
// make sure the values are proper string or object
|
|
1265
|
-
if (typeof value !== 'string' && typeof value !== 'object')
|
|
1266
|
-
throw new Error(`Cannot parse raw data. The key <${key}> should be a 'string|object' type`);
|
|
1267
|
-
}
|
|
1268
|
-
if (typeof raw['firstname'] === 'string') // this key must always exist
|
|
1269
|
-
this.initialize(new core_1.NamaParser(raw));
|
|
1270
|
-
else
|
|
1271
|
-
this.fullname = raw;
|
|
368
|
+
}
|
|
369
|
+
exports.NameIndex = NameIndex;
|
|
370
|
+
function capitalize(str, range = types_1.CapsRange.INITIAL) {
|
|
371
|
+
if (!str || range === types_1.CapsRange.NONE)
|
|
372
|
+
return str;
|
|
373
|
+
const initial = str[0].toUpperCase();
|
|
374
|
+
const rest = str.slice(1).toLowerCase();
|
|
375
|
+
return range === types_1.CapsRange.INITIAL ? initial.concat(rest) : str.toUpperCase();
|
|
376
|
+
}
|
|
377
|
+
exports.capitalize = capitalize;
|
|
378
|
+
function decapitalize(str, range = types_1.CapsRange.INITIAL) {
|
|
379
|
+
if (!str || range === types_1.CapsRange.NONE)
|
|
380
|
+
return str;
|
|
381
|
+
const initial = str[0].toLowerCase();
|
|
382
|
+
const rest = str.slice(1);
|
|
383
|
+
return range === types_1.CapsRange.INITIAL ? initial.concat(rest) : str.toLowerCase();
|
|
384
|
+
}
|
|
385
|
+
exports.decapitalize = decapitalize;
|
|
386
|
+
function toggleCase(str) {
|
|
387
|
+
const chars = [];
|
|
388
|
+
for (const c of str) {
|
|
389
|
+
if (c === c.toUpperCase()) {
|
|
390
|
+
chars.push(c.toLowerCase());
|
|
1272
391
|
}
|
|
1273
392
|
else {
|
|
1274
|
-
|
|
1275
|
-
throw new Error(`Cannot parse raw data. Review the data type expected.`);
|
|
393
|
+
chars.push(c.toUpperCase());
|
|
1276
394
|
}
|
|
1277
|
-
// paranoid coder mode: on :P
|
|
1278
|
-
if (!this.config.bypass)
|
|
1279
|
-
new validators_1.FullnameValidator().validate(this.fullname);
|
|
1280
|
-
this.summary = new models_1.Summary(this.getFullname());
|
|
1281
395
|
}
|
|
396
|
+
return chars.join('');
|
|
1282
397
|
}
|
|
1283
|
-
exports.
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
Namefully.prototype.sx = Namefully.prototype.getSuffix;
|
|
1291
|
-
Namefully.prototype.inits = Namefully.prototype.getInitials;
|
|
1292
|
-
Namefully.prototype.stats = Namefully.prototype.describe;
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
/***/ }),
|
|
1296
|
-
/* 8 */
|
|
1297
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
1298
|
-
|
|
1299
|
-
"use strict";
|
|
1300
|
-
|
|
1301
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1302
|
-
/**
|
|
1303
|
-
* An array `Name` parser
|
|
1304
|
-
*
|
|
1305
|
-
* Created on March 15, 2020
|
|
1306
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
1307
|
-
*/
|
|
1308
|
-
const models_1 = __webpack_require__(0);
|
|
1309
|
-
const index_1 = __webpack_require__(1);
|
|
1310
|
-
/**
|
|
1311
|
-
* Represents a `Name[]` parser
|
|
1312
|
-
* @class
|
|
1313
|
-
* @implements {Parser<Name[]>}
|
|
1314
|
-
*
|
|
1315
|
-
* This parser parses an array of the class `Name` while checking that every part
|
|
1316
|
-
* plays the role they are supposed to play. The class `Name` is a ready-made
|
|
1317
|
-
* recipe that saves the how-to parsing for a raw data input.
|
|
1318
|
-
*
|
|
1319
|
-
* **NOTE**:
|
|
1320
|
-
* In this specific case, the user is expected to carefully set each name part
|
|
1321
|
-
* and submit a high-quality data. Why is this parser if the data is already
|
|
1322
|
-
* shaped as wanted? Well, it is better to be safe than sorry, so we implement a
|
|
1323
|
-
* double-check of these values and reconfirm a cleaner data. Remember, namefully
|
|
1324
|
-
* works like a trapdoor, once the data is set and confirmed safe, no editing is
|
|
1325
|
-
* possible.
|
|
1326
|
-
*/
|
|
1327
|
-
class ArrayNameParser {
|
|
1328
|
-
/**
|
|
1329
|
-
* Create a parser ready to parse the raw data
|
|
1330
|
-
* @param {Name[]} raw data
|
|
1331
|
-
*/
|
|
1332
|
-
constructor(raw) {
|
|
1333
|
-
this.raw = raw;
|
|
1334
|
-
}
|
|
1335
|
-
/**
|
|
1336
|
-
* Parses the raw data into a full name
|
|
1337
|
-
*/
|
|
1338
|
-
parse(options) {
|
|
1339
|
-
const { bypass, lastnameFormat } = options;
|
|
1340
|
-
// validate first
|
|
1341
|
-
if (!bypass)
|
|
1342
|
-
new index_1.ArrayNameValidator().validate(this.raw);
|
|
1343
|
-
// then distribute all the elements accordingly
|
|
1344
|
-
const fullname = this.distribute(lastnameFormat);
|
|
1345
|
-
// finally return high quality of data
|
|
1346
|
-
return fullname;
|
|
1347
|
-
}
|
|
1348
|
-
distribute(lastnameFormat) {
|
|
1349
|
-
const fullname = {
|
|
1350
|
-
firstname: null,
|
|
1351
|
-
lastname: null,
|
|
1352
|
-
middlename: [],
|
|
1353
|
-
prefix: null,
|
|
1354
|
-
suffix: null,
|
|
1355
|
-
};
|
|
1356
|
-
this.raw.forEach(name => {
|
|
1357
|
-
switch (name.type) {
|
|
1358
|
-
case models_1.Namon.PREFIX:
|
|
1359
|
-
fullname.prefix = name.namon;
|
|
1360
|
-
break;
|
|
1361
|
-
case models_1.Namon.FIRST_NAME:
|
|
1362
|
-
if (name instanceof models_1.Firstname)
|
|
1363
|
-
fullname.firstname = new models_1.Firstname(name.namon, ...name.more);
|
|
1364
|
-
else
|
|
1365
|
-
fullname.firstname = new models_1.Firstname(name.namon);
|
|
1366
|
-
break;
|
|
1367
|
-
case models_1.Namon.LAST_NAME:
|
|
1368
|
-
if (name instanceof models_1.Lastname)
|
|
1369
|
-
fullname.lastname = new models_1.Lastname(name.father, name.mother, lastnameFormat);
|
|
1370
|
-
else
|
|
1371
|
-
fullname.lastname = new models_1.Lastname(name.namon, null, lastnameFormat);
|
|
1372
|
-
break;
|
|
1373
|
-
case models_1.Namon.MIDDLE_NAME:
|
|
1374
|
-
fullname.middlename.push(name);
|
|
1375
|
-
break;
|
|
1376
|
-
case models_1.Namon.SUFFIX:
|
|
1377
|
-
fullname.suffix = name.namon;
|
|
1378
|
-
break;
|
|
1379
|
-
}
|
|
1380
|
-
});
|
|
1381
|
-
return fullname;
|
|
1382
|
-
}
|
|
398
|
+
exports.toggleCase = toggleCase;
|
|
399
|
+
function isStringArray(value) {
|
|
400
|
+
return Array.isArray(value) && value.length > 0 && value.every((e) => typeof e === 'string');
|
|
401
|
+
}
|
|
402
|
+
exports.isStringArray = isStringArray;
|
|
403
|
+
function isNameArray(value) {
|
|
404
|
+
return Array.isArray(value) && value.length > 0 && value.every((e) => e instanceof name_1.Name);
|
|
1383
405
|
}
|
|
1384
|
-
exports.
|
|
406
|
+
exports.isNameArray = isNameArray;
|
|
1385
407
|
|
|
1386
408
|
|
|
1387
409
|
/***/ }),
|
|
1388
|
-
/*
|
|
410
|
+
/* 3 */
|
|
1389
411
|
/***/ (function(module, exports, __webpack_require__) {
|
|
1390
412
|
|
|
1391
413
|
"use strict";
|
|
1392
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;
|
|
1393
427
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
1399
|
-
*/
|
|
1400
|
-
const index_1 = __webpack_require__(0);
|
|
1401
|
-
const core_1 = __webpack_require__(2);
|
|
1402
|
-
/**
|
|
1403
|
-
* Represents a namon with some extra functionalities
|
|
1404
|
-
* @class
|
|
1405
|
-
* @see {@link Namon} interface to understand the concept of namon/nama.
|
|
1406
|
-
*/
|
|
428
|
+
exports.LastName = exports.FirstName = exports.Name = void 0;
|
|
429
|
+
const error_1 = __webpack_require__(1);
|
|
430
|
+
const types_1 = __webpack_require__(0);
|
|
431
|
+
const utils_1 = __webpack_require__(2);
|
|
1407
432
|
class Name {
|
|
1408
|
-
|
|
1409
|
-
* Constructs a `Name`
|
|
1410
|
-
* @param namon a piece of string that will be defined as a namon
|
|
1411
|
-
* @param type which namon that is
|
|
1412
|
-
* @param cap which kind of capitalizations
|
|
1413
|
-
*/
|
|
1414
|
-
constructor(namon, type, cap) {
|
|
1415
|
-
this.namon = namon;
|
|
433
|
+
constructor(value, type, capsRange) {
|
|
1416
434
|
this.type = type;
|
|
1417
|
-
this
|
|
1418
|
-
this.
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
/**
|
|
1423
|
-
* Gives some descriptive statistics that summarize the central tendency,
|
|
1424
|
-
* dispersion and shape of the characters' distribution.
|
|
1425
|
-
* @see {@link describe} in `Namefully` class for further information
|
|
1426
|
-
*/
|
|
1427
|
-
describe() {
|
|
1428
|
-
return new index_1.Summary(this.namon);
|
|
1429
|
-
}
|
|
1430
|
-
/**
|
|
1431
|
-
* Returns a string representation of the namon
|
|
1432
|
-
*/
|
|
1433
|
-
tostring() {
|
|
1434
|
-
return this.namon;
|
|
1435
|
-
}
|
|
1436
|
-
/**
|
|
1437
|
-
* Gets the initials of the name
|
|
1438
|
-
*/
|
|
1439
|
-
getInitials() {
|
|
1440
|
-
return [this.namon[0]];
|
|
1441
|
-
}
|
|
1442
|
-
/**
|
|
1443
|
-
* Capitalizes a name
|
|
1444
|
-
* @param {'initial' | 'all'} option how to capitalize it
|
|
1445
|
-
*/
|
|
1446
|
-
capitalize(option = 'initial') {
|
|
1447
|
-
const initial = this.initial.toUpperCase();
|
|
1448
|
-
if (option === 'initial') {
|
|
1449
|
-
this.namon = initial.concat(this.body);
|
|
1450
|
-
}
|
|
1451
|
-
else {
|
|
1452
|
-
this.namon = this.namon.toUpperCase();
|
|
1453
|
-
}
|
|
1454
|
-
return this;
|
|
435
|
+
_Name_namon.set(this, void 0);
|
|
436
|
+
this.capsRange = capsRange !== null && capsRange !== void 0 ? capsRange : types_1.CapsRange.INITIAL;
|
|
437
|
+
this.value = value;
|
|
438
|
+
if (capsRange)
|
|
439
|
+
this.caps(capsRange);
|
|
1455
440
|
}
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
decapitalize(option = 'initial') {
|
|
1461
|
-
const initial = this.initial.toLowerCase();
|
|
1462
|
-
if (option === 'initial') {
|
|
1463
|
-
this.namon = initial.concat(this.body);
|
|
1464
|
-
}
|
|
1465
|
-
else {
|
|
1466
|
-
this.namon = initial.concat(this.body.toLowerCase());
|
|
1467
|
-
}
|
|
1468
|
-
return this;
|
|
441
|
+
set value(newValue) {
|
|
442
|
+
this.validate(newValue);
|
|
443
|
+
__classPrivateFieldSet(this, _Name_namon, newValue, "f");
|
|
444
|
+
this.initial = newValue[0];
|
|
1469
445
|
}
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
*/
|
|
1473
|
-
normalize() {
|
|
1474
|
-
this.namon = this.namon[0]
|
|
1475
|
-
.toUpperCase()
|
|
1476
|
-
.concat(this.namon.slice(1).toLowerCase());
|
|
1477
|
-
return this;
|
|
446
|
+
get value() {
|
|
447
|
+
return __classPrivateFieldGet(this, _Name_namon, "f");
|
|
1478
448
|
}
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
this.
|
|
449
|
+
get length() {
|
|
450
|
+
return __classPrivateFieldGet(this, _Name_namon, "f").length;
|
|
451
|
+
}
|
|
452
|
+
get isPrefix() {
|
|
453
|
+
return this.type === types_1.Namon.PREFIX;
|
|
454
|
+
}
|
|
455
|
+
get isFirstName() {
|
|
456
|
+
return this.type === types_1.Namon.FIRST_NAME;
|
|
457
|
+
}
|
|
458
|
+
get isMiddleName() {
|
|
459
|
+
return this.type === types_1.Namon.MIDDLE_NAME;
|
|
460
|
+
}
|
|
461
|
+
get isLastName() {
|
|
462
|
+
return this.type === types_1.Namon.LAST_NAME;
|
|
463
|
+
}
|
|
464
|
+
get isSuffix() {
|
|
465
|
+
return this.type === types_1.Namon.SUFFIX;
|
|
466
|
+
}
|
|
467
|
+
static prefix(value) {
|
|
468
|
+
return new this(value, types_1.Namon.PREFIX);
|
|
469
|
+
}
|
|
470
|
+
static first(value) {
|
|
471
|
+
return new this(value, types_1.Namon.FIRST_NAME);
|
|
472
|
+
}
|
|
473
|
+
static middle(value) {
|
|
474
|
+
return new this(value, types_1.Namon.MIDDLE_NAME);
|
|
475
|
+
}
|
|
476
|
+
static last(value) {
|
|
477
|
+
return new this(value, types_1.Namon.LAST_NAME);
|
|
478
|
+
}
|
|
479
|
+
static suffix(value) {
|
|
480
|
+
return new this(value, types_1.Namon.SUFFIX);
|
|
481
|
+
}
|
|
482
|
+
initials() {
|
|
483
|
+
return [this.initial];
|
|
484
|
+
}
|
|
485
|
+
toString() {
|
|
486
|
+
return __classPrivateFieldGet(this, _Name_namon, "f");
|
|
487
|
+
}
|
|
488
|
+
equal(other) {
|
|
489
|
+
return other instanceof Name && other.value === this.value && other.type === this.type;
|
|
490
|
+
}
|
|
491
|
+
caps(range) {
|
|
492
|
+
this.value = (0, utils_1.capitalize)(__classPrivateFieldGet(this, _Name_namon, "f"), range !== null && range !== void 0 ? range : this.capsRange);
|
|
1484
493
|
return this;
|
|
1485
494
|
}
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
*/
|
|
1490
|
-
ascii(restrictions) {
|
|
1491
|
-
return core_1.convertToAscii(this.namon, restrictions);
|
|
495
|
+
decaps(range) {
|
|
496
|
+
this.value = (0, utils_1.decapitalize)(__classPrivateFieldGet(this, _Name_namon, "f"), range !== null && range !== void 0 ? range : this.capsRange);
|
|
497
|
+
return this;
|
|
1492
498
|
}
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
return core_1.generatePassword(this.namon);
|
|
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
|
+
}
|
|
1498
503
|
}
|
|
1499
504
|
}
|
|
1500
505
|
exports.Name = Name;
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
1520
|
-
*/
|
|
1521
|
-
const index_1 = __webpack_require__(0);
|
|
1522
|
-
const core_1 = __webpack_require__(2);
|
|
1523
|
-
/**
|
|
1524
|
-
* Represents a first name with some extra functionalities
|
|
1525
|
-
* @class
|
|
1526
|
-
* @extends Name
|
|
1527
|
-
*/
|
|
1528
|
-
class Firstname extends index_1.Name {
|
|
1529
|
-
/**
|
|
1530
|
-
* Constructs a `Firstname`
|
|
1531
|
-
* @param {string} namon a piece of string that will be defined as a namon
|
|
1532
|
-
* @param {string[]} [more] additional pieces considered as a given name
|
|
1533
|
-
*/
|
|
1534
|
-
constructor(namon, ...more) {
|
|
1535
|
-
super(namon, index_1.Namon.FIRST_NAME);
|
|
1536
|
-
this.namon = namon;
|
|
1537
|
-
this.more = [];
|
|
1538
|
-
this.more = more;
|
|
1539
|
-
}
|
|
1540
|
-
/**
|
|
1541
|
-
* Determines whether a first name has more name parts
|
|
1542
|
-
*/
|
|
1543
|
-
hasMore() {
|
|
1544
|
-
return Array.isArray(this.more) && this.more.length > 0;
|
|
1545
|
-
}
|
|
1546
|
-
/**
|
|
1547
|
-
* Gives some descriptive statistics that summarize the central tendency,
|
|
1548
|
-
* dispersion and shape of the characters' distribution.
|
|
1549
|
-
* @param {boolean} includeAll whether to include other pieces of the first
|
|
1550
|
-
* name in the summary
|
|
1551
|
-
* @see {@link describe} in `Namefully` class for further information
|
|
1552
|
-
*/
|
|
1553
|
-
describe(includeAll = false) {
|
|
1554
|
-
return new index_1.Summary(this.tostring(includeAll));
|
|
1555
|
-
}
|
|
1556
|
-
/**
|
|
1557
|
-
* Returns a string representation of the first name
|
|
1558
|
-
* @param {boolean} includeAll whether to include other pieces of the first
|
|
1559
|
-
* name
|
|
1560
|
-
*/
|
|
1561
|
-
tostring(includeAll = true) {
|
|
1562
|
-
return !includeAll
|
|
1563
|
-
? this.namon
|
|
1564
|
-
: this.namon.concat(index_1.Separator.SPACE, this.more.join(index_1.Separator.SPACE)).trim();
|
|
1565
|
-
}
|
|
1566
|
-
/**
|
|
1567
|
-
* Gets the initials of the first name
|
|
1568
|
-
*/
|
|
1569
|
-
getInitials(includeAll = false) {
|
|
1570
|
-
const initials = [this.namon[0]];
|
|
1571
|
-
if (includeAll && this.hasMore()) {
|
|
1572
|
-
initials.push(...this.more.map(n => n[0]));
|
|
506
|
+
_Name_namon = new WeakMap();
|
|
507
|
+
class FirstName extends Name {
|
|
508
|
+
constructor(value, ...more) {
|
|
509
|
+
super(value, types_1.Namon.FIRST_NAME);
|
|
510
|
+
_FirstName_more.set(this, void 0);
|
|
511
|
+
more.forEach((n) => this.validate(n));
|
|
512
|
+
__classPrivateFieldSet(this, _FirstName_more, more, "f");
|
|
513
|
+
}
|
|
514
|
+
get hasMore() {
|
|
515
|
+
return __classPrivateFieldGet(this, _FirstName_more, "f").length > 0;
|
|
516
|
+
}
|
|
517
|
+
get length() {
|
|
518
|
+
return super.length + (this.hasMore ? __classPrivateFieldGet(this, _FirstName_more, "f").reduce((acc, n) => acc + n).length : 0);
|
|
519
|
+
}
|
|
520
|
+
get asNames() {
|
|
521
|
+
const names = [Name.first(this.value)];
|
|
522
|
+
if (this.hasMore) {
|
|
523
|
+
names.push(...__classPrivateFieldGet(this, _FirstName_more, "f").map((n) => Name.first(n)));
|
|
1573
524
|
}
|
|
1574
|
-
return
|
|
525
|
+
return names;
|
|
1575
526
|
}
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
* @param {'initial' | 'all'} option how to capitalize its subparts
|
|
1579
|
-
*/
|
|
1580
|
-
capitalize(option = 'initial') {
|
|
1581
|
-
if (option === 'initial') {
|
|
1582
|
-
this.namon = this.namon[0].toUpperCase().concat(this.namon.slice(1));
|
|
1583
|
-
if (this.hasMore())
|
|
1584
|
-
this.more = this.more.map(n => n[0].toUpperCase().concat(n.slice(1)));
|
|
1585
|
-
}
|
|
1586
|
-
else {
|
|
1587
|
-
this.namon = this.namon.toUpperCase();
|
|
1588
|
-
if (this.hasMore())
|
|
1589
|
-
this.more = this.more.map(n => n.toUpperCase());
|
|
1590
|
-
}
|
|
1591
|
-
return this;
|
|
527
|
+
get more() {
|
|
528
|
+
return __classPrivateFieldGet(this, _FirstName_more, "f");
|
|
1592
529
|
}
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
if (
|
|
1599
|
-
this.
|
|
1600
|
-
if (this.hasMore())
|
|
1601
|
-
this.more = this.more.map(n => n[0].toLowerCase().concat(n.slice(1)));
|
|
1602
|
-
}
|
|
1603
|
-
else {
|
|
1604
|
-
this.namon = this.namon.toLowerCase();
|
|
1605
|
-
if (this.hasMore())
|
|
1606
|
-
this.more = this.more.map(n => n.toLowerCase());
|
|
530
|
+
toString(withMore = false) {
|
|
531
|
+
return withMore && this.hasMore ? `${this.value} ${__classPrivateFieldGet(this, _FirstName_more, "f").join(' ')}`.trim() : this.value;
|
|
532
|
+
}
|
|
533
|
+
initials(withMore = false) {
|
|
534
|
+
const inits = [this.initial];
|
|
535
|
+
if (withMore && this.hasMore) {
|
|
536
|
+
inits.push(...__classPrivateFieldGet(this, _FirstName_more, "f").map((n) => n[0]));
|
|
1607
537
|
}
|
|
1608
|
-
return
|
|
538
|
+
return inits;
|
|
1609
539
|
}
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
.toUpperCase()
|
|
1616
|
-
.concat(this.namon.slice(1).toLowerCase());
|
|
1617
|
-
if (this.hasMore())
|
|
1618
|
-
this.more = this.more.map(n => n[0]
|
|
1619
|
-
.toUpperCase()
|
|
1620
|
-
.concat(n.slice(1).toLowerCase()));
|
|
540
|
+
caps(range) {
|
|
541
|
+
range = range || this.capsRange;
|
|
542
|
+
this.value = (0, utils_1.capitalize)(this.value, range);
|
|
543
|
+
if (this.hasMore)
|
|
544
|
+
__classPrivateFieldSet(this, _FirstName_more, __classPrivateFieldGet(this, _FirstName_more, "f").map((n) => (0, utils_1.capitalize)(n, range)), "f");
|
|
1621
545
|
return this;
|
|
1622
546
|
}
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
return
|
|
547
|
+
decaps(range) {
|
|
548
|
+
range = range || this.capsRange;
|
|
549
|
+
this.value = (0, utils_1.decapitalize)(this.value, range);
|
|
550
|
+
if (this.hasMore)
|
|
551
|
+
__classPrivateFieldSet(this, _FirstName_more, __classPrivateFieldGet(this, _FirstName_more, "f").map((n) => (0, utils_1.decapitalize)(n, range)), "f");
|
|
552
|
+
return this;
|
|
1629
553
|
}
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
passwd() {
|
|
1634
|
-
return core_1.generatePassword(this.tostring(true));
|
|
554
|
+
copyWith(values) {
|
|
555
|
+
var _a, _b;
|
|
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")));
|
|
1635
557
|
}
|
|
1636
558
|
}
|
|
1637
|
-
exports.
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
Firstname.prototype.inits = Firstname.prototype.getInitials;
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
/***/ }),
|
|
1646
|
-
/* 11 */
|
|
1647
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
1648
|
-
|
|
1649
|
-
"use strict";
|
|
1650
|
-
|
|
1651
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1652
|
-
/**
|
|
1653
|
-
* Last name class definition
|
|
1654
|
-
*
|
|
1655
|
-
* Created on March 06, 2020
|
|
1656
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
1657
|
-
*/
|
|
1658
|
-
const index_1 = __webpack_require__(0);
|
|
1659
|
-
const core_1 = __webpack_require__(2);
|
|
1660
|
-
/**
|
|
1661
|
-
* Represents a last name with some extra functionalities
|
|
1662
|
-
* @class
|
|
1663
|
-
* @extends Name
|
|
1664
|
-
*/
|
|
1665
|
-
class Lastname extends index_1.Name {
|
|
1666
|
-
/**
|
|
1667
|
-
* Constructs a `Lastname`
|
|
1668
|
-
* @param {string} father a piece of string that will be defined as a namon
|
|
1669
|
-
* @param {string} [mother] additional pieces considered as a last name
|
|
1670
|
-
* @param {LastnameFormat} [format] how to output a surname considering its
|
|
1671
|
-
* subparts
|
|
1672
|
-
*/
|
|
1673
|
-
constructor(father, mother, format = 'father') {
|
|
1674
|
-
super(father, index_1.Namon.LAST_NAME);
|
|
1675
|
-
this.father = father;
|
|
1676
|
-
this.mother = mother;
|
|
559
|
+
exports.FirstName = FirstName;
|
|
560
|
+
_FirstName_more = new WeakMap();
|
|
561
|
+
class LastName extends Name {
|
|
562
|
+
constructor(father, mother, format = types_1.Surname.FATHER) {
|
|
563
|
+
super(father, types_1.Namon.LAST_NAME);
|
|
1677
564
|
this.format = format;
|
|
565
|
+
_LastName_mother.set(this, void 0);
|
|
566
|
+
this.validate(mother);
|
|
567
|
+
__classPrivateFieldSet(this, _LastName_mother, mother, "f");
|
|
1678
568
|
}
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
return
|
|
1684
|
-
}
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
format = format || this.format;
|
|
569
|
+
get father() {
|
|
570
|
+
return this.value;
|
|
571
|
+
}
|
|
572
|
+
get mother() {
|
|
573
|
+
return __classPrivateFieldGet(this, _LastName_mother, "f");
|
|
574
|
+
}
|
|
575
|
+
get hasMother() {
|
|
576
|
+
return !!__classPrivateFieldGet(this, _LastName_mother, "f");
|
|
577
|
+
}
|
|
578
|
+
get length() {
|
|
579
|
+
var _a, _b;
|
|
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);
|
|
581
|
+
}
|
|
582
|
+
get asNames() {
|
|
583
|
+
const names = [Name.last(this.value)];
|
|
584
|
+
if (this.hasMother) {
|
|
585
|
+
names.push(Name.last(__classPrivateFieldGet(this, _LastName_mother, "f")));
|
|
586
|
+
}
|
|
587
|
+
return names;
|
|
588
|
+
}
|
|
589
|
+
toString(format) {
|
|
590
|
+
var _a;
|
|
591
|
+
format = format !== null && format !== void 0 ? format : this.format;
|
|
1703
592
|
switch (format) {
|
|
1704
|
-
case
|
|
1705
|
-
return this.
|
|
1706
|
-
case
|
|
1707
|
-
return this.mother
|
|
1708
|
-
case
|
|
1709
|
-
return this.
|
|
1710
|
-
case
|
|
1711
|
-
return this.
|
|
593
|
+
case types_1.Surname.FATHER:
|
|
594
|
+
return this.value;
|
|
595
|
+
case types_1.Surname.MOTHER:
|
|
596
|
+
return (_a = this.mother) !== null && _a !== void 0 ? _a : '';
|
|
597
|
+
case types_1.Surname.HYPHENATED:
|
|
598
|
+
return this.hasMother ? `${this.value}-${__classPrivateFieldGet(this, _LastName_mother, "f")}` : this.value;
|
|
599
|
+
case types_1.Surname.ALL:
|
|
600
|
+
return this.hasMother ? `${this.value} ${__classPrivateFieldGet(this, _LastName_mother, "f")}` : this.value;
|
|
1712
601
|
}
|
|
1713
602
|
}
|
|
1714
|
-
|
|
1715
|
-
* Gets the initials of the last name
|
|
1716
|
-
*/
|
|
1717
|
-
getInitials(format) {
|
|
603
|
+
initials(format) {
|
|
1718
604
|
format = format || this.format;
|
|
1719
|
-
const
|
|
605
|
+
const inits = [];
|
|
1720
606
|
switch (format) {
|
|
1721
|
-
case
|
|
1722
|
-
|
|
607
|
+
case types_1.Surname.MOTHER:
|
|
608
|
+
if (this.hasMother)
|
|
609
|
+
inits.push(__classPrivateFieldGet(this, _LastName_mother, "f")[0]);
|
|
1723
610
|
break;
|
|
1724
|
-
case
|
|
1725
|
-
|
|
1726
|
-
|
|
611
|
+
case types_1.Surname.HYPHENATED:
|
|
612
|
+
case types_1.Surname.ALL:
|
|
613
|
+
inits.push(this.initial);
|
|
614
|
+
if (this.hasMother)
|
|
615
|
+
inits.push(__classPrivateFieldGet(this, _LastName_mother, "f")[0]);
|
|
1727
616
|
break;
|
|
1728
|
-
case
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
if (this.hasMother())
|
|
1732
|
-
initials.push(this.mother[0]);
|
|
1733
|
-
break;
|
|
1734
|
-
}
|
|
1735
|
-
return initials;
|
|
1736
|
-
}
|
|
1737
|
-
/**
|
|
1738
|
-
* Capitalizes a last name
|
|
1739
|
-
* @param {'initial' | 'all'} option how to capitalize its subparts
|
|
1740
|
-
*/
|
|
1741
|
-
capitalize(option = 'initial') {
|
|
1742
|
-
super.capitalize(option);
|
|
1743
|
-
if (option === 'initial') {
|
|
1744
|
-
this.father = this.father[0].toUpperCase().concat(this.father.slice(1));
|
|
1745
|
-
if (this.hasMother())
|
|
1746
|
-
this.mother = this.mother[0].toUpperCase().concat(this.mother.slice(1));
|
|
1747
|
-
}
|
|
1748
|
-
else {
|
|
1749
|
-
this.father = this.father.toUpperCase();
|
|
1750
|
-
if (this.hasMother())
|
|
1751
|
-
this.mother = this.mother.toUpperCase();
|
|
617
|
+
case types_1.Surname.FATHER:
|
|
618
|
+
default:
|
|
619
|
+
inits.push(this.initial);
|
|
1752
620
|
}
|
|
1753
|
-
return
|
|
621
|
+
return inits;
|
|
1754
622
|
}
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
super.capitalize(option);
|
|
1761
|
-
if (option === 'initial') {
|
|
1762
|
-
this.father = this.father[0].toLowerCase().concat(this.father.slice(1));
|
|
1763
|
-
if (this.hasMother())
|
|
1764
|
-
this.mother = this.mother[0].toLowerCase().concat(this.mother.slice(1));
|
|
1765
|
-
}
|
|
1766
|
-
else {
|
|
1767
|
-
this.father = this.father.toLowerCase();
|
|
1768
|
-
if (this.hasMother())
|
|
1769
|
-
this.mother = this.mother.toLowerCase();
|
|
1770
|
-
}
|
|
623
|
+
caps(range) {
|
|
624
|
+
range = range || this.capsRange;
|
|
625
|
+
this.value = (0, utils_1.capitalize)(this.value, range);
|
|
626
|
+
if (this.hasMother)
|
|
627
|
+
__classPrivateFieldSet(this, _LastName_mother, (0, utils_1.capitalize)(__classPrivateFieldGet(this, _LastName_mother, "f"), range), "f");
|
|
1771
628
|
return this;
|
|
1772
629
|
}
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
.toUpperCase()
|
|
1779
|
-
.concat(this.father.slice(1).toLowerCase());
|
|
1780
|
-
if (this.hasMother())
|
|
1781
|
-
this.mother = this.mother[0]
|
|
1782
|
-
.toUpperCase()
|
|
1783
|
-
.concat(this.mother.slice(1).toLowerCase());
|
|
630
|
+
decaps(range) {
|
|
631
|
+
range = range || this.capsRange;
|
|
632
|
+
this.value = (0, utils_1.decapitalize)(this.value, range);
|
|
633
|
+
if (this.hasMother)
|
|
634
|
+
__classPrivateFieldSet(this, _LastName_mother, (0, utils_1.decapitalize)(__classPrivateFieldGet(this, _LastName_mother, "f"), range), "f");
|
|
1784
635
|
return this;
|
|
1785
636
|
}
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
*/
|
|
1790
|
-
ascii(restrictions) {
|
|
1791
|
-
return core_1.convertToAscii(this.tostring(), restrictions);
|
|
1792
|
-
}
|
|
1793
|
-
/**
|
|
1794
|
-
* Returns a password-like representation of a last name
|
|
1795
|
-
*/
|
|
1796
|
-
passwd() {
|
|
1797
|
-
return core_1.generatePassword(this.tostring());
|
|
637
|
+
copyWith(values) {
|
|
638
|
+
var _a, _b, _c;
|
|
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);
|
|
1798
640
|
}
|
|
1799
641
|
}
|
|
1800
|
-
exports.
|
|
1801
|
-
|
|
1802
|
-
Lastname.prototype.decap = Lastname.prototype.decapitalize;
|
|
1803
|
-
Lastname.prototype.norm = Lastname.prototype.normalize;
|
|
1804
|
-
Lastname.prototype.stats = Lastname.prototype.describe;
|
|
1805
|
-
Lastname.prototype.inits = Lastname.prototype.getInitials;
|
|
642
|
+
exports.LastName = LastName;
|
|
643
|
+
_LastName_mother = new WeakMap();
|
|
1806
644
|
|
|
1807
645
|
|
|
1808
646
|
/***/ }),
|
|
1809
|
-
/*
|
|
647
|
+
/* 4 */
|
|
1810
648
|
/***/ (function(module, exports, __webpack_require__) {
|
|
1811
649
|
|
|
1812
650
|
"use strict";
|
|
1813
651
|
|
|
1814
|
-
/**
|
|
1815
|
-
* All the enums are listed here
|
|
1816
|
-
*
|
|
1817
|
-
* Created on March 06, 2020
|
|
1818
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
1819
|
-
*/
|
|
1820
652
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
})(Alphabet = exports.Alphabet || (exports.Alphabet = {}));
|
|
1850
|
-
/**
|
|
1851
|
-
* Enum for the prefix values
|
|
1852
|
-
* @readonly
|
|
1853
|
-
* @enum {string}
|
|
1854
|
-
* American and Canadian English follow slightly different rules for abbreviated
|
|
1855
|
-
* titles than British and Australian English. In North American English, titles
|
|
1856
|
-
* before a name require a period: `Mr., Mrs., Ms., Dr.` In British and Australian
|
|
1857
|
-
* English, no full stops are used in these abbreviations.
|
|
1858
|
-
*/
|
|
1859
|
-
var Prefix;
|
|
1860
|
-
(function (Prefix) {
|
|
1861
|
-
Prefix["FIRT_LIEUTENANT"] = "1st Lt";
|
|
1862
|
-
Prefix["ADMIRAL"] = "Adm";
|
|
1863
|
-
Prefix["ATTORNEY"] = "Atty";
|
|
1864
|
-
Prefix["BROTHER"] = "Brother";
|
|
1865
|
-
Prefix["CAPTAIN"] = "Capt";
|
|
1866
|
-
Prefix["CHIEF"] = "Chief";
|
|
1867
|
-
Prefix["COMMANDER"] = "Cmdr";
|
|
1868
|
-
Prefix["COLONEL"] = "Col";
|
|
1869
|
-
Prefix["UNI_DEAN"] = "Dean";
|
|
1870
|
-
Prefix["DOCTOR"] = "Dr";
|
|
1871
|
-
Prefix["ELDER"] = "Elder";
|
|
1872
|
-
Prefix["FATHER"] = "Father";
|
|
1873
|
-
Prefix["GENERAL"] = "Gen";
|
|
1874
|
-
Prefix["HONORABLE"] = "Hon";
|
|
1875
|
-
Prefix["LIEUTENANT_COLONEL"] = "Lt Col";
|
|
1876
|
-
Prefix["MAJOR"] = "Maj";
|
|
1877
|
-
Prefix["MASTER_SERGEANT"] = "MSgt";
|
|
1878
|
-
Prefix["MISTER"] = "Mr";
|
|
1879
|
-
Prefix["MARRIED_WOMAN"] = "Mrs";
|
|
1880
|
-
Prefix["SINGLE_WOMAN"] = "Ms";
|
|
1881
|
-
Prefix["PRINCE"] = "Prince";
|
|
1882
|
-
Prefix["PROFESSOR"] = "Prof";
|
|
1883
|
-
Prefix["RABBI"] = "Rabbi";
|
|
1884
|
-
Prefix["REVEREND"] = "Rev";
|
|
1885
|
-
Prefix["SISTER"] = "Sister";
|
|
1886
|
-
})(Prefix = exports.Prefix || (exports.Prefix = {}));
|
|
1887
|
-
/**
|
|
1888
|
-
* Enum for the suffix values
|
|
1889
|
-
* @readonly
|
|
1890
|
-
* @enum {string}
|
|
1891
|
-
*/
|
|
1892
|
-
var Suffix;
|
|
1893
|
-
(function (Suffix) {
|
|
1894
|
-
Suffix["THE_SECOND"] = "II";
|
|
1895
|
-
Suffix["THE_THIRD"] = "III";
|
|
1896
|
-
Suffix["THE_FOURTH"] = "IV";
|
|
1897
|
-
Suffix["CERT_PUB_ACCOUNTANT"] = "CPA";
|
|
1898
|
-
Suffix["DOCTOR_DENTAL_MED"] = "DDS";
|
|
1899
|
-
Suffix["ESQUIRE"] = "Esq";
|
|
1900
|
-
Suffix["JURIST_DOCTOR"] = "JD";
|
|
1901
|
-
Suffix["JUNIOR"] = "Jr";
|
|
1902
|
-
Suffix["DOCTOR_OF_LAWS"] = "LLD";
|
|
1903
|
-
Suffix["DOCTORATE"] = "PhD";
|
|
1904
|
-
Suffix["RETIRED_ARMED_FORCES"] = "Ret";
|
|
1905
|
-
Suffix["REGISTERED_NURSE"] = "RN";
|
|
1906
|
-
Suffix["SENIOR"] = "Sr";
|
|
1907
|
-
Suffix["DOCTOR_OF_OSTEO"] = "DO";
|
|
1908
|
-
})(Suffix = exports.Suffix || (exports.Suffix = {}));
|
|
1909
|
-
/**
|
|
1910
|
-
* Enum for the separator values representing some of the ASCII characters
|
|
1911
|
-
* @readonly
|
|
1912
|
-
* @enum {string}
|
|
1913
|
-
*/
|
|
1914
|
-
var Separator;
|
|
1915
|
-
(function (Separator) {
|
|
1916
|
-
Separator["COLON"] = ":";
|
|
1917
|
-
Separator["COMMA"] = ",";
|
|
1918
|
-
Separator["EMPTY"] = "";
|
|
1919
|
-
Separator["HYPHEN"] = "-";
|
|
1920
|
-
Separator["PERIOD"] = ".";
|
|
1921
|
-
Separator["SPACE"] = " ";
|
|
1922
|
-
Separator["SINGLE_QUOTE"] = "'";
|
|
1923
|
-
Separator["DOUBLE_QUOTE"] = "\"";
|
|
1924
|
-
Separator["UNDERSCORE"] = "_";
|
|
1925
|
-
})(Separator = exports.Separator || (exports.Separator = {}));
|
|
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
|
+
];
|
|
1926
681
|
|
|
1927
682
|
|
|
1928
683
|
/***/ }),
|
|
1929
|
-
/*
|
|
684
|
+
/* 5 */
|
|
1930
685
|
/***/ (function(module, exports, __webpack_require__) {
|
|
1931
686
|
|
|
1932
687
|
"use strict";
|
|
1933
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;
|
|
1934
701
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
this
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
702
|
+
exports.Config = void 0;
|
|
703
|
+
const types_1 = __webpack_require__(0);
|
|
704
|
+
const defaultName = 'default';
|
|
705
|
+
const copyAlias = '_copy';
|
|
706
|
+
class Config {
|
|
707
|
+
get orderedBy() {
|
|
708
|
+
return __classPrivateFieldGet(this, _Config_orderedBy, "f");
|
|
709
|
+
}
|
|
710
|
+
get separator() {
|
|
711
|
+
return __classPrivateFieldGet(this, _Config_separator, "f");
|
|
712
|
+
}
|
|
713
|
+
get title() {
|
|
714
|
+
return __classPrivateFieldGet(this, _Config_title, "f");
|
|
715
|
+
}
|
|
716
|
+
get ending() {
|
|
717
|
+
return __classPrivateFieldGet(this, _Config_ending, "f");
|
|
718
|
+
}
|
|
719
|
+
get bypass() {
|
|
720
|
+
return __classPrivateFieldGet(this, _Config_bypass, "f");
|
|
721
|
+
}
|
|
722
|
+
get surname() {
|
|
723
|
+
return __classPrivateFieldGet(this, _Config_surname, "f");
|
|
724
|
+
}
|
|
725
|
+
get name() {
|
|
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");
|
|
744
|
+
}
|
|
745
|
+
static create(name = defaultName) {
|
|
746
|
+
if (!_a.cache.has(name))
|
|
747
|
+
_a.cache.set(name, new this(name));
|
|
748
|
+
return _a.cache.get(name);
|
|
749
|
+
}
|
|
750
|
+
static merge(other) {
|
|
751
|
+
var _b, _c, _d, _e, _f, _g;
|
|
752
|
+
if (!other) {
|
|
753
|
+
return _a.create();
|
|
754
|
+
}
|
|
755
|
+
else {
|
|
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");
|
|
763
|
+
return config;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
copyWith(options = {}) {
|
|
767
|
+
const { name, orderedBy, separator, title, ending, bypass, surname } = options;
|
|
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");
|
|
775
|
+
return config;
|
|
776
|
+
}
|
|
777
|
+
clone() {
|
|
778
|
+
return this.copyWith();
|
|
779
|
+
}
|
|
780
|
+
reset() {
|
|
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
|
+
}
|
|
789
|
+
updateOrder(order) {
|
|
790
|
+
if (order && order !== __classPrivateFieldGet(this, _Config_orderedBy, "f")) {
|
|
791
|
+
__classPrivateFieldSet(_a.cache.get(this.name), _Config_orderedBy, order, "f");
|
|
1975
792
|
}
|
|
1976
|
-
this.distribution = freqs;
|
|
1977
|
-
this.count = count;
|
|
1978
|
-
this.frequency = maxfreq;
|
|
1979
|
-
this.top = top;
|
|
1980
|
-
this.unique = uniq;
|
|
1981
|
-
}
|
|
1982
|
-
groupByChar() {
|
|
1983
|
-
const frequencies = {};
|
|
1984
|
-
for (const char of this.namon.toUpperCase())
|
|
1985
|
-
if (Object.keys(frequencies).includes(char))
|
|
1986
|
-
frequencies[char] += 1;
|
|
1987
|
-
else
|
|
1988
|
-
frequencies[char] = 1;
|
|
1989
|
-
return frequencies;
|
|
1990
793
|
}
|
|
1991
794
|
}
|
|
1992
|
-
exports.
|
|
795
|
+
exports.Config = Config;
|
|
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
|
+
};
|
|
799
|
+
Config.cache = new Map();
|
|
1993
800
|
|
|
1994
801
|
|
|
1995
802
|
/***/ }),
|
|
1996
|
-
/*
|
|
803
|
+
/* 6 */
|
|
1997
804
|
/***/ (function(module, exports, __webpack_require__) {
|
|
1998
805
|
|
|
1999
806
|
"use strict";
|
|
2000
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;
|
|
2001
820
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
this
|
|
2016
|
-
this.
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
this
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
821
|
+
exports.FullName = void 0;
|
|
822
|
+
const config_1 = __webpack_require__(5);
|
|
823
|
+
const error_1 = __webpack_require__(1);
|
|
824
|
+
const name_1 = __webpack_require__(3);
|
|
825
|
+
const types_1 = __webpack_require__(0);
|
|
826
|
+
const validator_1 = __webpack_require__(7);
|
|
827
|
+
class FullName {
|
|
828
|
+
constructor(options) {
|
|
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");
|
|
836
|
+
}
|
|
837
|
+
get config() {
|
|
838
|
+
return __classPrivateFieldGet(this, _FullName_config, "f");
|
|
839
|
+
}
|
|
840
|
+
get prefix() {
|
|
841
|
+
return __classPrivateFieldGet(this, _FullName_prefix, "f");
|
|
842
|
+
}
|
|
843
|
+
get firstName() {
|
|
844
|
+
return __classPrivateFieldGet(this, _FullName_firstName, "f");
|
|
845
|
+
}
|
|
846
|
+
get lastName() {
|
|
847
|
+
return __classPrivateFieldGet(this, _FullName_lastName, "f");
|
|
848
|
+
}
|
|
849
|
+
get middleName() {
|
|
850
|
+
return __classPrivateFieldGet(this, _FullName_middleName, "f");
|
|
851
|
+
}
|
|
852
|
+
get suffix() {
|
|
853
|
+
return __classPrivateFieldGet(this, _FullName_suffix, "f");
|
|
854
|
+
}
|
|
855
|
+
static parse(json, config) {
|
|
856
|
+
try {
|
|
857
|
+
const fullName = new FullName(config);
|
|
858
|
+
fullName.setPrefix(json.prefix);
|
|
859
|
+
fullName.setFirstName(json.firstName);
|
|
860
|
+
fullName.setMiddleName(json.middleName);
|
|
861
|
+
fullName.setLastName(json.lastName);
|
|
862
|
+
fullName.setSuffix(json.suffix);
|
|
863
|
+
return fullName;
|
|
864
|
+
}
|
|
865
|
+
catch (error) {
|
|
866
|
+
if (error instanceof error_1.NameError)
|
|
867
|
+
throw error;
|
|
868
|
+
throw new error_1.UnknownError({
|
|
869
|
+
source: Object.values(json).join(' '),
|
|
870
|
+
message: 'could not parse JSON content',
|
|
871
|
+
error,
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
setPrefix(name) {
|
|
876
|
+
if (!name)
|
|
877
|
+
return this;
|
|
878
|
+
if (!__classPrivateFieldGet(this, _FullName_config, "f").bypass)
|
|
879
|
+
validator_1.Validators.prefix.validate(name);
|
|
880
|
+
const prefix = name instanceof name_1.Name ? name.value : name;
|
|
881
|
+
__classPrivateFieldSet(this, _FullName_prefix, name_1.Name.prefix(__classPrivateFieldGet(this, _FullName_config, "f").title === types_1.Title.US ? `${prefix}.` : prefix), "f");
|
|
2030
882
|
return this;
|
|
2031
883
|
}
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
*/
|
|
2037
|
-
firstname(namon, ...more) {
|
|
2038
|
-
this._fn = new index_1.Firstname(namon, ...more);
|
|
2039
|
-
if (!this.bypass)
|
|
2040
|
-
new validators_1.FirstnameValidator().validate(this._fn.tostring());
|
|
884
|
+
setFirstName(name) {
|
|
885
|
+
if (!__classPrivateFieldGet(this, _FullName_config, "f").bypass)
|
|
886
|
+
validator_1.Validators.firstName.validate(name);
|
|
887
|
+
__classPrivateFieldSet(this, _FullName_firstName, name instanceof name_1.FirstName ? name : new name_1.FirstName(name), "f");
|
|
2041
888
|
return this;
|
|
2042
889
|
}
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
middlename(...nama) {
|
|
2048
|
-
const validator = new validators_1.NamonValidator();
|
|
2049
|
-
this._mn = nama.map(namon => {
|
|
2050
|
-
if (!this.bypass)
|
|
2051
|
-
validator.validate(namon);
|
|
2052
|
-
return new index_1.Name(namon, index_1.Namon.MIDDLE_NAME);
|
|
2053
|
-
});
|
|
890
|
+
setLastName(name) {
|
|
891
|
+
if (!__classPrivateFieldGet(this, _FullName_config, "f").bypass)
|
|
892
|
+
validator_1.Validators.lastName.validate(name);
|
|
893
|
+
__classPrivateFieldSet(this, _FullName_lastName, name instanceof name_1.LastName ? name : new name_1.LastName(name), "f");
|
|
2054
894
|
return this;
|
|
2055
895
|
}
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
lastname(father, mother, format = 'father') {
|
|
2063
|
-
this._ln = new index_1.Lastname(father, mother, format);
|
|
2064
|
-
if (!this.bypass)
|
|
2065
|
-
new validators_1.LastnameValidator().validate(this._ln.tostring());
|
|
896
|
+
setMiddleName(names) {
|
|
897
|
+
if (!Array.isArray(names))
|
|
898
|
+
return this;
|
|
899
|
+
if (!__classPrivateFieldGet(this, _FullName_config, "f").bypass)
|
|
900
|
+
validator_1.Validators.middleName.validate(names);
|
|
901
|
+
__classPrivateFieldSet(this, _FullName_middleName, names.map((name) => (name instanceof name_1.Name ? name : name_1.Name.middle(name))), "f");
|
|
2066
902
|
return this;
|
|
2067
903
|
}
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
new validators_1.SuffixValidator().validate(namon);
|
|
2075
|
-
this._sx = namon;
|
|
904
|
+
setSuffix(name) {
|
|
905
|
+
if (!name)
|
|
906
|
+
return this;
|
|
907
|
+
if (!__classPrivateFieldGet(this, _FullName_config, "f").bypass)
|
|
908
|
+
validator_1.Validators.suffix.validate(name);
|
|
909
|
+
__classPrivateFieldSet(this, _FullName_suffix, name_1.Name.suffix(name instanceof name_1.Name ? name.value : name), "f");
|
|
2076
910
|
return this;
|
|
2077
911
|
}
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
lastname: this._ln,
|
|
2085
|
-
middlename: this._mn,
|
|
2086
|
-
prefix: this._px,
|
|
2087
|
-
suffix: this._sx
|
|
2088
|
-
};
|
|
2089
|
-
return fullname;
|
|
912
|
+
has(namon) {
|
|
913
|
+
if (namon.equal(types_1.Namon.PREFIX))
|
|
914
|
+
return !!__classPrivateFieldGet(this, _FullName_prefix, "f");
|
|
915
|
+
if (namon.equal(types_1.Namon.SUFFIX))
|
|
916
|
+
return !!__classPrivateFieldGet(this, _FullName_suffix, "f");
|
|
917
|
+
return namon.equal(types_1.Namon.MIDDLE_NAME) ? __classPrivateFieldGet(this, _FullName_middleName, "f").length > 0 : true;
|
|
2090
918
|
}
|
|
2091
919
|
}
|
|
2092
|
-
exports.
|
|
2093
|
-
|
|
2094
|
-
FullnameBuilder.prototype.fn = FullnameBuilder.prototype.firstname;
|
|
2095
|
-
FullnameBuilder.prototype.mn = FullnameBuilder.prototype.middlename;
|
|
2096
|
-
FullnameBuilder.prototype.ln = FullnameBuilder.prototype.lastname;
|
|
2097
|
-
FullnameBuilder.prototype.sx = FullnameBuilder.prototype.sx;
|
|
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();
|
|
2098
922
|
|
|
2099
923
|
|
|
2100
924
|
/***/ }),
|
|
2101
|
-
/*
|
|
925
|
+
/* 7 */
|
|
2102
926
|
/***/ (function(module, exports, __webpack_require__) {
|
|
2103
927
|
|
|
2104
928
|
"use strict";
|
|
2105
929
|
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
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;
|
|
2112
942
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
* not contain special characters. `\w` does not cover non-Latin characters. So,
|
|
2120
|
-
* it is extended using unicode chars to cover more cases (e.g., Icelandic).
|
|
2121
|
-
* It matches as follows:
|
|
2122
|
-
* [a-z]: Latin alphabet from a (index 97) to z (index 122)
|
|
2123
|
-
* [A-Z]: Latin alphabet from A (index 65) to Z (index 90)
|
|
2124
|
-
* [\u00C0-\u00D6]: Latin/German chars from À (index 192) to Ö (index 214)
|
|
2125
|
-
* [\u00D8-\u00f6]: German/Icelandic chars from Ø (index 216) to ö (index 246)
|
|
2126
|
-
* [\u00f8-\u00ff]: German/Icelandic chars from ø (index 248) to ÿ (index 255)
|
|
2127
|
-
* [\u0400-\u04FF]: Cyrillic alphabet from Ѐ (index 1024) to ӿ (index 1279)
|
|
2128
|
-
* [Ά-ωΑ-ώ]: Greek alphabet from Ά (index 902) to ω (index 969)
|
|
2129
|
-
*/
|
|
943
|
+
exports.Validators = exports.ArrayNameValidator = exports.ArrayStringValidator = exports.NamaValidator = void 0;
|
|
944
|
+
const constants_1 = __webpack_require__(4);
|
|
945
|
+
const error_1 = __webpack_require__(1);
|
|
946
|
+
const name_1 = __webpack_require__(3);
|
|
947
|
+
const types_1 = __webpack_require__(0);
|
|
948
|
+
const utils_1 = __webpack_require__(2);
|
|
2130
949
|
class ValidationRule {
|
|
2131
950
|
}
|
|
2132
|
-
exports.ValidationRule = ValidationRule;
|
|
2133
951
|
ValidationRule.base = /[a-zA-Z\u00C0-\u00D6\u00D8-\u00f6\u00f8-\u00ff\u0400-\u04FFΆ-ωΑ-ώ]/;
|
|
2134
|
-
/**
|
|
2135
|
-
* Matches one name part (namon) that is of nature:
|
|
2136
|
-
* - Latin (English, Spanish, French, etc.)
|
|
2137
|
-
* - European (Greek, Cyrillic, Icelandic, German)
|
|
2138
|
-
* - hyphenated
|
|
2139
|
-
* - with apostrophe
|
|
2140
|
-
* - with space
|
|
2141
|
-
*/
|
|
2142
952
|
ValidationRule.namon = new RegExp(`^${ValidationRule.base.source}+(([' -]${ValidationRule.base.source})?${ValidationRule.base.source}*)*$`);
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
/**
|
|
2155
|
-
* Matches one name part (namon) that is of nature:
|
|
2156
|
-
* - Latin (English, Spanish, French, etc.)
|
|
2157
|
-
* - European (Greek, Cyrillic, Icelandic, German)
|
|
2158
|
-
* - hyphenated
|
|
2159
|
-
* - with apostrophe
|
|
2160
|
-
*/
|
|
2161
|
-
ValidationRule.firstname = ValidationRule.namon;
|
|
2162
|
-
/**
|
|
2163
|
-
* Matches 1+ names part (namon) that are of nature:
|
|
2164
|
-
* - Latin (English, Spanish, French, etc.)
|
|
2165
|
-
* - European (Greek, Cyrillic, Icelandic, German)
|
|
2166
|
-
* - hyphenated
|
|
2167
|
-
* - with apostrophe
|
|
2168
|
-
* - with space
|
|
2169
|
-
*/
|
|
2170
|
-
ValidationRule.middlename = new RegExp(`^${ValidationRule.base.source}+(([' -]${ValidationRule.base.source})?${ValidationRule.base.source}*)*$`);
|
|
2171
|
-
/**
|
|
2172
|
-
* Matches one name part (namon) that is of nature:
|
|
2173
|
-
* - Latin (English, Spanish, French, etc.)
|
|
2174
|
-
* - European (Greek, Cyrillic, Icelandic, German)
|
|
2175
|
-
* - hyphenated
|
|
2176
|
-
* - with apostrophe
|
|
2177
|
-
* - with space
|
|
2178
|
-
*/
|
|
2179
|
-
ValidationRule.lastname = ValidationRule.namon;
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
/***/ }),
|
|
2183
|
-
/* 16 */
|
|
2184
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
2185
|
-
|
|
2186
|
-
"use strict";
|
|
2187
|
-
|
|
2188
|
-
/**
|
|
2189
|
-
* Validation types
|
|
2190
|
-
*
|
|
2191
|
-
* Created on March 06, 2020
|
|
2192
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
2193
|
-
*/
|
|
2194
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2195
|
-
/**
|
|
2196
|
-
* Enum for the validation types
|
|
2197
|
-
* @enum
|
|
2198
|
-
*/
|
|
2199
|
-
var ValidatorType;
|
|
2200
|
-
(function (ValidatorType) {
|
|
2201
|
-
ValidatorType[ValidatorType["NONE"] = 0] = "NONE";
|
|
2202
|
-
ValidatorType[ValidatorType["NAMON"] = 1] = "NAMON";
|
|
2203
|
-
ValidatorType[ValidatorType["NAMA"] = 2] = "NAMA";
|
|
2204
|
-
ValidatorType[ValidatorType["ARR_NAMES"] = 3] = "ARR_NAMES";
|
|
2205
|
-
ValidatorType[ValidatorType["ARR_STRING"] = 4] = "ARR_STRING";
|
|
2206
|
-
ValidatorType[ValidatorType["FULL_NAME"] = 5] = "FULL_NAME";
|
|
2207
|
-
ValidatorType[ValidatorType["PREFIX"] = 6] = "PREFIX";
|
|
2208
|
-
ValidatorType[ValidatorType["FIRST_NAME"] = 7] = "FIRST_NAME";
|
|
2209
|
-
ValidatorType[ValidatorType["MIDDLE_NAME"] = 8] = "MIDDLE_NAME";
|
|
2210
|
-
ValidatorType[ValidatorType["LAST_NAME"] = 9] = "LAST_NAME";
|
|
2211
|
-
ValidatorType[ValidatorType["SUFFIX"] = 10] = "SUFFIX";
|
|
2212
|
-
ValidatorType[ValidatorType["CUSTOM"] = 11] = "CUSTOM";
|
|
2213
|
-
})(ValidatorType = exports.ValidatorType || (exports.ValidatorType = {}));
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
/***/ }),
|
|
2217
|
-
/* 17 */
|
|
2218
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
2219
|
-
|
|
2220
|
-
"use strict";
|
|
2221
|
-
|
|
2222
|
-
/**
|
|
2223
|
-
* Validation error
|
|
2224
|
-
*
|
|
2225
|
-
* Created on March 06, 2020
|
|
2226
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
2227
|
-
*/
|
|
2228
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2229
|
-
/**
|
|
2230
|
-
* Represents a validation error
|
|
2231
|
-
* @class
|
|
2232
|
-
* @extends Error
|
|
2233
|
-
*/
|
|
2234
|
-
class ValidationError extends Error {
|
|
2235
|
-
/**
|
|
2236
|
-
* Create a validation `Error`
|
|
2237
|
-
* @param message of error to display
|
|
2238
|
-
* @param type categorizes the error
|
|
2239
|
-
*/
|
|
2240
|
-
constructor(message, type) {
|
|
2241
|
-
super(`${type ? type + ' :: ' + message : message}`);
|
|
2242
|
-
this.name = 'ValidationError';
|
|
953
|
+
ValidationRule.firstName = ValidationRule.namon;
|
|
954
|
+
ValidationRule.middleName = new RegExp(`^${ValidationRule.base.source}+(([' -]${ValidationRule.base.source})?${ValidationRule.base.source}*)*$`);
|
|
955
|
+
ValidationRule.lastName = ValidationRule.namon;
|
|
956
|
+
class ArrayValidator {
|
|
957
|
+
validate(values) {
|
|
958
|
+
if (values.length === 0 || values.length < constants_1.MIN_NUMBER_OF_NAME_PARTS || values.length > constants_1.MAX_NUMBER_OF_NAME_PARTS) {
|
|
959
|
+
throw new error_1.InputError({
|
|
960
|
+
source: values.map((n) => n.toString()),
|
|
961
|
+
message: `expecting a list of ${constants_1.MIN_NUMBER_OF_NAME_PARTS}-${constants_1.MIN_NUMBER_OF_NAME_PARTS} elements`,
|
|
962
|
+
});
|
|
963
|
+
}
|
|
2243
964
|
}
|
|
2244
965
|
}
|
|
2245
|
-
exports.ValidationError = ValidationError;
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
/***/ }),
|
|
2249
|
-
/* 18 */
|
|
2250
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
2251
|
-
|
|
2252
|
-
"use strict";
|
|
2253
|
-
|
|
2254
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2255
|
-
/**
|
|
2256
|
-
* Namon validator
|
|
2257
|
-
*
|
|
2258
|
-
* Created on March 15, 2020
|
|
2259
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
2260
|
-
*/
|
|
2261
|
-
const index_1 = __webpack_require__(1);
|
|
2262
|
-
/**
|
|
2263
|
-
* Represents a namon validator to help to parse single pieces of string
|
|
2264
|
-
* @class
|
|
2265
|
-
* @implements {Validator}
|
|
2266
|
-
*/
|
|
2267
966
|
class NamonValidator {
|
|
2268
|
-
|
|
2269
|
-
this
|
|
967
|
+
static create() {
|
|
968
|
+
return __classPrivateFieldGet(this, _a, "f", _NamonValidator_validator) || (__classPrivateFieldSet(this, _a, new this(), "f", _NamonValidator_validator));
|
|
2270
969
|
}
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
970
|
+
validate(value, type) {
|
|
971
|
+
if (value instanceof name_1.Name) {
|
|
972
|
+
NameValidator.create().validate(value, type);
|
|
973
|
+
}
|
|
974
|
+
else if (typeof value === 'string') {
|
|
975
|
+
if (!ValidationRule.namon.test(value)) {
|
|
976
|
+
throw new error_1.ValidationError({
|
|
977
|
+
source: value,
|
|
978
|
+
nameType: 'namon',
|
|
979
|
+
message: 'invalid content',
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
else {
|
|
984
|
+
throw new error_1.InputError({
|
|
985
|
+
source: typeof value,
|
|
986
|
+
message: 'expecting types of string | Name',
|
|
987
|
+
});
|
|
988
|
+
}
|
|
2278
989
|
}
|
|
2279
990
|
}
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
2286
|
-
|
|
2287
|
-
"use strict";
|
|
2288
|
-
|
|
2289
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2290
|
-
/**
|
|
2291
|
-
* Prefix validator
|
|
2292
|
-
*
|
|
2293
|
-
* Created on March 15, 2020
|
|
2294
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
2295
|
-
*/
|
|
2296
|
-
const index_1 = __webpack_require__(0);
|
|
2297
|
-
const index_2 = __webpack_require__(1);
|
|
2298
|
-
/**
|
|
2299
|
-
* Represents a prefix validator
|
|
2300
|
-
* @class
|
|
2301
|
-
* @implements {Validator}
|
|
2302
|
-
*/
|
|
2303
|
-
class PrefixValidator {
|
|
2304
|
-
constructor() {
|
|
2305
|
-
this.type = index_2.ValidatorType.PREFIX;
|
|
991
|
+
_a = NamonValidator;
|
|
992
|
+
_NamonValidator_validator = { value: void 0 };
|
|
993
|
+
class FirstNameValidator {
|
|
994
|
+
static create() {
|
|
995
|
+
return __classPrivateFieldGet(this, _b, "f", _FirstNameValidator_validator) || (__classPrivateFieldSet(this, _b, new this(), "f", _FirstNameValidator_validator));
|
|
2306
996
|
}
|
|
2307
|
-
/**
|
|
2308
|
-
* Validates the content of a prefix name
|
|
2309
|
-
* @param {string} value data to validate
|
|
2310
|
-
*/
|
|
2311
997
|
validate(value) {
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
998
|
+
if (value instanceof name_1.FirstName) {
|
|
999
|
+
value.asNames.forEach((name) => this.validate(name.value));
|
|
1000
|
+
}
|
|
1001
|
+
else if (typeof value === 'string') {
|
|
1002
|
+
if (!ValidationRule.firstName.test(value)) {
|
|
1003
|
+
throw new error_1.ValidationError({
|
|
1004
|
+
source: value,
|
|
1005
|
+
nameType: 'firstName',
|
|
1006
|
+
message: 'invalid content',
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
else {
|
|
1011
|
+
throw new error_1.InputError({
|
|
1012
|
+
source: typeof value,
|
|
1013
|
+
message: 'expecting types string | FirstName',
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
2315
1016
|
}
|
|
2316
1017
|
}
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
2323
|
-
|
|
2324
|
-
"use strict";
|
|
2325
|
-
|
|
2326
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2327
|
-
/**
|
|
2328
|
-
* Suffix validator
|
|
2329
|
-
*
|
|
2330
|
-
* Created on March 15, 2020
|
|
2331
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
2332
|
-
*/
|
|
2333
|
-
const index_1 = __webpack_require__(0);
|
|
2334
|
-
const index_2 = __webpack_require__(1);
|
|
2335
|
-
/**
|
|
2336
|
-
* Represents a suffix validator
|
|
2337
|
-
* @class
|
|
2338
|
-
* @implements {Validator}
|
|
2339
|
-
*/
|
|
2340
|
-
class SuffixValidator {
|
|
2341
|
-
constructor() {
|
|
2342
|
-
this.type = index_2.ValidatorType.SUFFIX;
|
|
1018
|
+
_b = FirstNameValidator;
|
|
1019
|
+
_FirstNameValidator_validator = { value: void 0 };
|
|
1020
|
+
class MiddleNameValidator {
|
|
1021
|
+
static create() {
|
|
1022
|
+
return __classPrivateFieldGet(this, _c, "f", _MiddleNameValidator_validator) || (__classPrivateFieldSet(this, _c, new this(), "f", _MiddleNameValidator_validator));
|
|
2343
1023
|
}
|
|
2344
|
-
/**
|
|
2345
|
-
* Validates the content of a suffix name
|
|
2346
|
-
* @param {string} value data to validate
|
|
2347
|
-
*/
|
|
2348
1024
|
validate(value) {
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
1025
|
+
if (typeof value === 'string') {
|
|
1026
|
+
if (!ValidationRule.middleName.test(value)) {
|
|
1027
|
+
throw new error_1.ValidationError({
|
|
1028
|
+
source: value,
|
|
1029
|
+
nameType: 'middleName',
|
|
1030
|
+
message: 'invalid content',
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
else if (Array.isArray(value)) {
|
|
1035
|
+
try {
|
|
1036
|
+
const validator = NamonValidator.create();
|
|
1037
|
+
for (const name of value)
|
|
1038
|
+
validator.validate(name, types_1.Namon.MIDDLE_NAME);
|
|
1039
|
+
}
|
|
1040
|
+
catch (error) {
|
|
1041
|
+
throw new error_1.ValidationError({
|
|
1042
|
+
source: value,
|
|
1043
|
+
nameType: 'middleName',
|
|
1044
|
+
message: error === null || error === void 0 ? void 0 : error.message,
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
else {
|
|
1049
|
+
throw new error_1.InputError({
|
|
1050
|
+
source: typeof value,
|
|
1051
|
+
message: 'expecting types of string | string[] | Name[]',
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
2352
1054
|
}
|
|
2353
1055
|
}
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
2360
|
-
|
|
2361
|
-
"use strict";
|
|
2362
|
-
|
|
2363
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2364
|
-
/**
|
|
2365
|
-
* First name validator
|
|
2366
|
-
*
|
|
2367
|
-
* Created on March 15, 2020
|
|
2368
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
2369
|
-
*/
|
|
2370
|
-
const index_1 = __webpack_require__(1);
|
|
2371
|
-
/**
|
|
2372
|
-
* Represents a first name validator
|
|
2373
|
-
* @class
|
|
2374
|
-
* @implements {Validator}
|
|
2375
|
-
*/
|
|
2376
|
-
class FirstnameValidator {
|
|
2377
|
-
constructor() {
|
|
2378
|
-
this.type = index_1.ValidatorType.FIRST_NAME;
|
|
1056
|
+
_c = MiddleNameValidator;
|
|
1057
|
+
_MiddleNameValidator_validator = { value: void 0 };
|
|
1058
|
+
class LastNameValidator {
|
|
1059
|
+
static create() {
|
|
1060
|
+
return __classPrivateFieldGet(this, _d, "f", _LastNameValidator_validator) || (__classPrivateFieldSet(this, _d, new this(), "f", _LastNameValidator_validator));
|
|
2379
1061
|
}
|
|
2380
|
-
/**
|
|
2381
|
-
* Validates the content of a first name
|
|
2382
|
-
* @param {string} value data to validate
|
|
2383
|
-
*/
|
|
2384
1062
|
validate(value) {
|
|
2385
|
-
if (
|
|
2386
|
-
|
|
2387
|
-
}
|
|
2388
|
-
}
|
|
2389
|
-
exports.default = FirstnameValidator;
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
/***/ }),
|
|
2393
|
-
/* 22 */
|
|
2394
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
2395
|
-
|
|
2396
|
-
"use strict";
|
|
2397
|
-
|
|
2398
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2399
|
-
/**
|
|
2400
|
-
* Last name validator
|
|
2401
|
-
*
|
|
2402
|
-
* Created on March 15, 2020
|
|
2403
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
2404
|
-
*/
|
|
2405
|
-
const index_1 = __webpack_require__(1);
|
|
2406
|
-
/**
|
|
2407
|
-
* Represents a last name validator
|
|
2408
|
-
* @class
|
|
2409
|
-
* @implements {Validator}
|
|
2410
|
-
*/
|
|
2411
|
-
class LastnameValidator {
|
|
2412
|
-
constructor() {
|
|
2413
|
-
this.type = index_1.ValidatorType.LAST_NAME;
|
|
2414
|
-
}
|
|
2415
|
-
/**
|
|
2416
|
-
* Validates the content of a last name
|
|
2417
|
-
* @param {string} value data to validate
|
|
2418
|
-
*/
|
|
2419
|
-
validate(value) {
|
|
2420
|
-
if (!index_1.ValidationRule.lastname.test(value))
|
|
2421
|
-
throw new index_1.ValidationError(`invalid string content '${value}'`, 'Last name');
|
|
2422
|
-
}
|
|
2423
|
-
}
|
|
2424
|
-
exports.default = LastnameValidator;
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
/***/ }),
|
|
2428
|
-
/* 23 */
|
|
2429
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
2430
|
-
|
|
2431
|
-
"use strict";
|
|
2432
|
-
|
|
2433
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2434
|
-
/**
|
|
2435
|
-
* Middle name validator
|
|
2436
|
-
*
|
|
2437
|
-
* Created on March 15, 2020
|
|
2438
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
2439
|
-
*/
|
|
2440
|
-
const index_1 = __webpack_require__(1);
|
|
2441
|
-
/**
|
|
2442
|
-
* Represents a middle name validator
|
|
2443
|
-
* @class
|
|
2444
|
-
* @implements {Validator}
|
|
2445
|
-
*/
|
|
2446
|
-
class MiddlenameValidator {
|
|
2447
|
-
constructor() {
|
|
2448
|
-
this.type = index_1.ValidatorType.MIDDLE_NAME;
|
|
2449
|
-
}
|
|
2450
|
-
/**
|
|
2451
|
-
* Validates the content of a list of middle names
|
|
2452
|
-
* @param {string | string[]} values to validate
|
|
2453
|
-
*/
|
|
2454
|
-
validate(values) {
|
|
2455
|
-
if (typeof values === 'string') {
|
|
2456
|
-
if (!index_1.ValidationRule.middlename.test(values))
|
|
2457
|
-
throw new index_1.ValidationError(`invalid string content '${values}'`, 'Middle name');
|
|
1063
|
+
if (value instanceof name_1.LastName) {
|
|
1064
|
+
value.asNames.forEach((name) => this.validate(name.value));
|
|
2458
1065
|
}
|
|
2459
|
-
else if (
|
|
2460
|
-
|
|
2461
|
-
|
|
1066
|
+
else if (typeof value === 'string') {
|
|
1067
|
+
if (!ValidationRule.lastName.test(value)) {
|
|
1068
|
+
throw new error_1.ValidationError({
|
|
1069
|
+
source: value,
|
|
1070
|
+
nameType: 'lastName',
|
|
1071
|
+
message: 'invalid content',
|
|
1072
|
+
});
|
|
1073
|
+
}
|
|
2462
1074
|
}
|
|
2463
1075
|
else {
|
|
2464
|
-
throw new
|
|
1076
|
+
throw new error_1.InputError({
|
|
1077
|
+
source: typeof value,
|
|
1078
|
+
message: 'expecting types string | LastName',
|
|
1079
|
+
});
|
|
2465
1080
|
}
|
|
2466
1081
|
}
|
|
2467
1082
|
}
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
* @implements {Validator}
|
|
2490
|
-
*/
|
|
2491
|
-
class FullnameValidator {
|
|
2492
|
-
constructor() {
|
|
2493
|
-
this.type = index_2.ValidatorType.FULL_NAME;
|
|
2494
|
-
}
|
|
2495
|
-
/**
|
|
2496
|
-
* Validates that the `Fullname` contract is met
|
|
2497
|
-
* @param {Fullname} value data to validate
|
|
2498
|
-
*/
|
|
2499
|
-
validate(v) {
|
|
2500
|
-
if (!v.firstname || !(v.firstname instanceof index_1.Firstname))
|
|
2501
|
-
throw new index_2.ValidationError('first name is corrupted', 'Fullname');
|
|
2502
|
-
if (!v.lastname || !(v.lastname instanceof index_1.Lastname))
|
|
2503
|
-
throw new index_2.ValidationError('last name is corrupted', 'Fullname');
|
|
2504
|
-
if (v.middlename && !(v.middlename instanceof Array))
|
|
2505
|
-
throw new index_2.ValidationError('middle name is corrupted', 'Fullname');
|
|
2506
|
-
if (v.prefix)
|
|
2507
|
-
new index_2.PrefixValidator().validate(v.prefix);
|
|
2508
|
-
if (v.suffix)
|
|
2509
|
-
new index_2.SuffixValidator().validate(v.suffix);
|
|
1083
|
+
_d = LastNameValidator;
|
|
1084
|
+
_LastNameValidator_validator = { value: void 0 };
|
|
1085
|
+
class NameValidator {
|
|
1086
|
+
static create() {
|
|
1087
|
+
return __classPrivateFieldGet(this, _e, "f", _NameValidator_validator) || (__classPrivateFieldSet(this, _e, new this(), "f", _NameValidator_validator));
|
|
1088
|
+
}
|
|
1089
|
+
validate(name, type) {
|
|
1090
|
+
if (type && name.type !== type) {
|
|
1091
|
+
throw new error_1.ValidationError({
|
|
1092
|
+
source: [name],
|
|
1093
|
+
nameType: name.type.toString(),
|
|
1094
|
+
message: 'wrong type',
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1097
|
+
if (!ValidationRule.namon.test(name.value)) {
|
|
1098
|
+
throw new error_1.ValidationError({
|
|
1099
|
+
source: [name],
|
|
1100
|
+
nameType: name.type.toString(),
|
|
1101
|
+
message: 'invalid content',
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
2510
1104
|
}
|
|
2511
1105
|
}
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
/***/ }),
|
|
2516
|
-
/* 25 */
|
|
2517
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
2518
|
-
|
|
2519
|
-
"use strict";
|
|
2520
|
-
|
|
2521
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2522
|
-
/**
|
|
2523
|
-
* Nama validator
|
|
2524
|
-
*
|
|
2525
|
-
* Created on March 15, 2020
|
|
2526
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
2527
|
-
*/
|
|
2528
|
-
const models_1 = __webpack_require__(0);
|
|
2529
|
-
const constants_1 = __webpack_require__(4);
|
|
2530
|
-
const index_1 = __webpack_require__(1);
|
|
2531
|
-
/**
|
|
2532
|
-
* Represents a `Nama` validator to help the nama parser
|
|
2533
|
-
* @class
|
|
2534
|
-
* @implements {Validator}
|
|
2535
|
-
*/
|
|
1106
|
+
_e = NameValidator;
|
|
1107
|
+
_NameValidator_validator = { value: void 0 };
|
|
2536
1108
|
class NamaValidator {
|
|
2537
|
-
|
|
2538
|
-
this
|
|
1109
|
+
static create() {
|
|
1110
|
+
return __classPrivateFieldGet(this, _f, "f", _NamaValidator_validator) || (__classPrivateFieldSet(this, _f, new this(), "f", _NamaValidator_validator));
|
|
2539
1111
|
}
|
|
2540
|
-
/**
|
|
2541
|
-
* Validates the content of a JSON-formatted names
|
|
2542
|
-
* @param {string} value data to validate
|
|
2543
|
-
*/
|
|
2544
1112
|
validate(value) {
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
[models_1.Namon.SUFFIX]: new index_1.SuffixValidator(),
|
|
2554
|
-
};
|
|
2555
|
-
for (const entry of entries) {
|
|
2556
|
-
const k = entry[0];
|
|
2557
|
-
const v = entry[1];
|
|
2558
|
-
validators[k].validate(v);
|
|
1113
|
+
this.validateKeys(value);
|
|
1114
|
+
Validators.firstName.validate(value.get(types_1.Namon.FIRST_NAME));
|
|
1115
|
+
Validators.lastName.validate(value.get(types_1.Namon.LAST_NAME));
|
|
1116
|
+
if (value.has(types_1.Namon.PREFIX)) {
|
|
1117
|
+
Validators.namon.validate(value.get(types_1.Namon.PREFIX));
|
|
1118
|
+
}
|
|
1119
|
+
if (value.has(types_1.Namon.SUFFIX)) {
|
|
1120
|
+
Validators.namon.validate(value.get(types_1.Namon.SUFFIX));
|
|
2559
1121
|
}
|
|
2560
1122
|
}
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
return Array.from(this)[Math.floor(Math.random() * this.size)];
|
|
1123
|
+
validateKeys(nama) {
|
|
1124
|
+
if (!nama.size) {
|
|
1125
|
+
throw new error_1.InputError({ source: undefined, message: 'Map<k,v> must not be empty' });
|
|
1126
|
+
}
|
|
1127
|
+
else if (nama.size < constants_1.MIN_NUMBER_OF_NAME_PARTS || nama.size > constants_1.MAX_NUMBER_OF_NAME_PARTS) {
|
|
1128
|
+
throw new error_1.InputError({
|
|
1129
|
+
source: [...nama.values()],
|
|
1130
|
+
message: `expecting ${constants_1.MIN_NUMBER_OF_NAME_PARTS}-${constants_1.MIN_NUMBER_OF_NAME_PARTS} fields`,
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
if (!nama.has(types_1.Namon.FIRST_NAME)) {
|
|
1134
|
+
throw new error_1.InputError({
|
|
1135
|
+
source: [...nama.values()],
|
|
1136
|
+
message: '"firstName" is a required key',
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
if (!nama.has(types_1.Namon.LAST_NAME)) {
|
|
1140
|
+
throw new error_1.InputError({
|
|
1141
|
+
source: [...nama.values()],
|
|
1142
|
+
message: '"lastName" is a required key',
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
2584
1145
|
}
|
|
2585
1146
|
}
|
|
2586
|
-
exports.
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
/***/ }),
|
|
2596
|
-
/* 27 */
|
|
2597
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
2598
|
-
|
|
2599
|
-
"use strict";
|
|
2600
|
-
|
|
2601
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2602
|
-
/**
|
|
2603
|
-
* Array of `Name` validator
|
|
2604
|
-
*
|
|
2605
|
-
* Created on March 15, 2020
|
|
2606
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
2607
|
-
*/
|
|
2608
|
-
const models_1 = __webpack_require__(0);
|
|
2609
|
-
const index_1 = __webpack_require__(1);
|
|
2610
|
-
const constants_1 = __webpack_require__(4);
|
|
2611
|
-
/**
|
|
2612
|
-
* Represents a validator to help the array `Name` parser
|
|
2613
|
-
* @class
|
|
2614
|
-
* @classdesc
|
|
2615
|
-
* This validator validates a array of `Name` objects following a specific order
|
|
2616
|
-
* based on the count of elements. It is expected that the array has to be
|
|
2617
|
-
* between two and five elements.
|
|
2618
|
-
*
|
|
2619
|
-
*/
|
|
2620
|
-
class ArrayNameValidator {
|
|
2621
|
-
constructor() {
|
|
2622
|
-
this.type = index_1.ValidatorType.ARR_NAMES;
|
|
1147
|
+
exports.NamaValidator = NamaValidator;
|
|
1148
|
+
_f = NamaValidator;
|
|
1149
|
+
_NamaValidator_validator = { value: void 0 };
|
|
1150
|
+
class ArrayStringValidator extends ArrayValidator {
|
|
1151
|
+
constructor(index = utils_1.NameIndex.base()) {
|
|
1152
|
+
super();
|
|
1153
|
+
this.index = index;
|
|
2623
1154
|
}
|
|
2624
|
-
/**
|
|
2625
|
-
* Validates the content of a set of custom `Name`s
|
|
2626
|
-
* @param {Name[]} value data to validate
|
|
2627
|
-
*/
|
|
2628
1155
|
validate(values) {
|
|
2629
|
-
|
|
2630
|
-
throw new index_1.ValidationError(`must be an array of ${constants_1.MIN_NUMBER_NAME_PART} - ` +
|
|
2631
|
-
`${constants_1.MAX_NUMBER_NAME_PART} 'Name's`, 'Array of Names');
|
|
2632
|
-
const validators = {
|
|
2633
|
-
[models_1.Namon.PREFIX]: new index_1.PrefixValidator(),
|
|
2634
|
-
[models_1.Namon.FIRST_NAME]: new index_1.FirstnameValidator(),
|
|
2635
|
-
[models_1.Namon.MIDDLE_NAME]: new index_1.MiddlenameValidator(),
|
|
2636
|
-
[models_1.Namon.LAST_NAME]: new index_1.LastnameValidator(),
|
|
2637
|
-
[models_1.Namon.SUFFIX]: new index_1.SuffixValidator(),
|
|
2638
|
-
};
|
|
1156
|
+
this.validateIndex(values);
|
|
2639
1157
|
switch (values.length) {
|
|
2640
|
-
case
|
|
2641
|
-
values.
|
|
2642
|
-
|
|
2643
|
-
throw new index_1.ValidationError('Both first and last names are required');
|
|
2644
|
-
validators[n.type].validate(n.tostring());
|
|
2645
|
-
});
|
|
1158
|
+
case 2:
|
|
1159
|
+
Validators.firstName.validate(values[this.index.firstName]);
|
|
1160
|
+
Validators.lastName.validate(values[this.index.lastName]);
|
|
2646
1161
|
break;
|
|
2647
|
-
case
|
|
2648
|
-
values.
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
validators[n.type].validate(n.tostring());
|
|
2652
|
-
});
|
|
1162
|
+
case 3:
|
|
1163
|
+
Validators.firstName.validate(values[this.index.firstName]);
|
|
1164
|
+
Validators.middleName.validate(values[this.index.middleName]);
|
|
1165
|
+
Validators.lastName.validate(values[this.index.lastName]);
|
|
2653
1166
|
break;
|
|
2654
|
-
case
|
|
2655
|
-
values.
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
validators[n.type].validate(n.tostring());
|
|
2660
|
-
});
|
|
1167
|
+
case 4:
|
|
1168
|
+
Validators.namon.validate(values[this.index.prefix]);
|
|
1169
|
+
Validators.firstName.validate(values[this.index.firstName]);
|
|
1170
|
+
Validators.middleName.validate(values[this.index.middleName]);
|
|
1171
|
+
Validators.lastName.validate(values[this.index.lastName]);
|
|
2661
1172
|
break;
|
|
2662
|
-
case
|
|
2663
|
-
values.
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
});
|
|
1173
|
+
case 5:
|
|
1174
|
+
Validators.namon.validate(values[this.index.prefix]);
|
|
1175
|
+
Validators.firstName.validate(values[this.index.firstName]);
|
|
1176
|
+
Validators.middleName.validate(values[this.index.middleName]);
|
|
1177
|
+
Validators.lastName.validate(values[this.index.lastName]);
|
|
1178
|
+
Validators.namon.validate(values[this.index.suffix]);
|
|
2669
1179
|
break;
|
|
2670
1180
|
}
|
|
2671
1181
|
}
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
/***/ }),
|
|
2677
|
-
/* 28 */
|
|
2678
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
2679
|
-
|
|
2680
|
-
"use strict";
|
|
2681
|
-
|
|
2682
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2683
|
-
const constants_1 = __webpack_require__(4);
|
|
2684
|
-
const index_1 = __webpack_require__(1);
|
|
2685
|
-
/**
|
|
2686
|
-
* Represents a validator to help the array string parser
|
|
2687
|
-
* @class
|
|
2688
|
-
* @classdesc
|
|
2689
|
-
* This validator validates an array of string name following a specific order
|
|
2690
|
-
* based on the count of elements. It is expected that the array has to be between
|
|
2691
|
-
* two and five elements. Also, the order of appearance set in the configuration
|
|
2692
|
-
* influences how this validation is carried out.
|
|
2693
|
-
*
|
|
2694
|
-
* Ordered by first name, the validator validates the following:
|
|
2695
|
-
* - 2 elements: firstname lastname
|
|
2696
|
-
* - 3 elements: firstname middlename lastname
|
|
2697
|
-
* - 4 elements: prefix firstname middlename lastname
|
|
2698
|
-
* - 5 elements: prefix firstname middlename lastname suffix
|
|
2699
|
-
*
|
|
2700
|
-
* Ordered by last name, the validator validates the following:
|
|
2701
|
-
* - 2 elements: lastname firstname
|
|
2702
|
-
* - 3 elements: lastname firstname middlename
|
|
2703
|
-
* - 4 elements: prefix lastname firstname middlename
|
|
2704
|
-
* - 5 elements: prefix lastname firstname middlename suffix
|
|
2705
|
-
*/
|
|
2706
|
-
class ArrayStringValidator {
|
|
2707
|
-
/**
|
|
2708
|
-
* Creates an instance of the validator
|
|
2709
|
-
* @param indexing how to index the name parts
|
|
2710
|
-
*/
|
|
2711
|
-
constructor(indexing) {
|
|
2712
|
-
this.indexing = indexing;
|
|
2713
|
-
this.type = index_1.ValidatorType.ARR_STRING;
|
|
2714
|
-
}
|
|
2715
|
-
/**
|
|
2716
|
-
* Validates the content of a name
|
|
2717
|
-
* @param {string} value data to validate
|
|
2718
|
-
*/
|
|
2719
|
-
validate(values) {
|
|
2720
|
-
if (values.length < constants_1.MIN_NUMBER_NAME_PART || values.length > constants_1.MAX_NUMBER_NAME_PART)
|
|
2721
|
-
throw new index_1.ValidationError(`must be an array of ${constants_1.MIN_NUMBER_NAME_PART} - ` +
|
|
2722
|
-
`${constants_1.MAX_NUMBER_NAME_PART} elements`, 'Array of names');
|
|
2723
|
-
const pf = new index_1.PrefixValidator();
|
|
2724
|
-
const sf = new index_1.SuffixValidator();
|
|
2725
|
-
const fn = new index_1.FirstnameValidator();
|
|
2726
|
-
const ln = new index_1.LastnameValidator();
|
|
2727
|
-
const mn = new index_1.MiddlenameValidator();
|
|
2728
|
-
const index = this.indexing;
|
|
2729
|
-
switch (values.length) {
|
|
2730
|
-
case constants_1.FIRST_LAST_NAME_INDEX:
|
|
2731
|
-
fn.validate(values[index.firstname]);
|
|
2732
|
-
ln.validate(values[index.lastname]);
|
|
2733
|
-
break;
|
|
2734
|
-
case constants_1.FIRST_MIDDLE_LAST_NAME_INDEX:
|
|
2735
|
-
fn.validate(values[index.firstname]);
|
|
2736
|
-
mn.validate(values[index.middlename]);
|
|
2737
|
-
ln.validate(values[index.lastname]);
|
|
2738
|
-
break;
|
|
2739
|
-
case constants_1.PREFIX_FIRST_MIDDLE_LAST_NAME_INDEX:
|
|
2740
|
-
pf.validate(values[index.prefix]);
|
|
2741
|
-
fn.validate(values[index.firstname]);
|
|
2742
|
-
mn.validate(values[index.middlename]);
|
|
2743
|
-
ln.validate(values[index.lastname]);
|
|
2744
|
-
break;
|
|
2745
|
-
case constants_1.PREFIX_FIRST_MIDDLE_LAST_SUFFIX_NAME_INDEX:
|
|
2746
|
-
pf.validate(values[index.prefix]);
|
|
2747
|
-
fn.validate(values[index.firstname]);
|
|
2748
|
-
mn.validate(values[index.middlename]);
|
|
2749
|
-
ln.validate(values[index.lastname]);
|
|
2750
|
-
sf.validate(values[index.suffix]);
|
|
2751
|
-
break;
|
|
2752
|
-
}
|
|
1182
|
+
validateIndex(values) {
|
|
1183
|
+
super.validate(values);
|
|
2753
1184
|
}
|
|
2754
1185
|
}
|
|
2755
|
-
exports.
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
/***/ }),
|
|
2759
|
-
/* 29 */
|
|
2760
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
2761
|
-
|
|
2762
|
-
"use strict";
|
|
2763
|
-
|
|
2764
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2765
|
-
/**
|
|
2766
|
-
* String of full name validator
|
|
2767
|
-
*
|
|
2768
|
-
* Created on March 15, 2020
|
|
2769
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
2770
|
-
*/
|
|
2771
|
-
const index_1 = __webpack_require__(1);
|
|
2772
|
-
/**
|
|
2773
|
-
* Represents a string full name validator
|
|
2774
|
-
* @class
|
|
2775
|
-
* @implements {Validator}
|
|
2776
|
-
*/
|
|
2777
|
-
class StringNameValidator {
|
|
1186
|
+
exports.ArrayStringValidator = ArrayStringValidator;
|
|
1187
|
+
class ArrayNameValidator {
|
|
2778
1188
|
constructor() {
|
|
2779
|
-
this
|
|
1189
|
+
_ArrayNameValidator_instances.add(this);
|
|
1190
|
+
}
|
|
1191
|
+
static create() {
|
|
1192
|
+
return __classPrivateFieldGet(this, _g, "f", _ArrayNameValidator_validator) || (__classPrivateFieldSet(this, _g, new this(), "f", _ArrayNameValidator_validator));
|
|
2780
1193
|
}
|
|
2781
|
-
/**
|
|
2782
|
-
* Validates the content of a name
|
|
2783
|
-
* @param {string} value data to validate
|
|
2784
|
-
*/
|
|
2785
1194
|
validate(value) {
|
|
2786
|
-
if (
|
|
2787
|
-
throw new
|
|
1195
|
+
if (value.length < constants_1.MIN_NUMBER_OF_NAME_PARTS) {
|
|
1196
|
+
throw new error_1.InputError({
|
|
1197
|
+
source: value,
|
|
1198
|
+
message: `expecting at least ${constants_1.MIN_NUMBER_OF_NAME_PARTS} elements`,
|
|
1199
|
+
});
|
|
1200
|
+
}
|
|
1201
|
+
if (!__classPrivateFieldGet(this, _ArrayNameValidator_instances, "m", _ArrayNameValidator_hasBasicNames).call(this, value)) {
|
|
1202
|
+
throw new error_1.InputError({
|
|
1203
|
+
source: value,
|
|
1204
|
+
message: 'both first and last names are required',
|
|
1205
|
+
});
|
|
1206
|
+
}
|
|
2788
1207
|
}
|
|
2789
1208
|
}
|
|
2790
|
-
exports.
|
|
1209
|
+
exports.ArrayNameValidator = ArrayNameValidator;
|
|
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 };
|
|
1220
|
+
class Validators {
|
|
1221
|
+
}
|
|
1222
|
+
exports.Validators = Validators;
|
|
1223
|
+
Validators.namon = NamonValidator.create();
|
|
1224
|
+
Validators.nama = NamaValidator.create();
|
|
1225
|
+
Validators.prefix = NamonValidator.create();
|
|
1226
|
+
Validators.firstName = FirstNameValidator.create();
|
|
1227
|
+
Validators.middleName = MiddleNameValidator.create();
|
|
1228
|
+
Validators.lastName = LastNameValidator.create();
|
|
1229
|
+
Validators.suffix = NamonValidator.create();
|
|
2791
1230
|
|
|
2792
1231
|
|
|
2793
1232
|
/***/ }),
|
|
2794
|
-
/*
|
|
1233
|
+
/* 8 */
|
|
2795
1234
|
/***/ (function(module, exports, __webpack_require__) {
|
|
2796
1235
|
|
|
2797
1236
|
"use strict";
|
|
2798
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;
|
|
2799
1244
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
const
|
|
2807
|
-
const
|
|
2808
|
-
|
|
2809
|
-
/**
|
|
2810
|
-
* Represents an array string parser
|
|
2811
|
-
* @class
|
|
2812
|
-
* @implements {Parser<string[]>}
|
|
2813
|
-
*
|
|
2814
|
-
* This parser parses an array of string name following a specific order based
|
|
2815
|
-
* on the count of elements. It is expected that the array has to be between two
|
|
2816
|
-
* and five elements. Also, the order of appearance set in the configuration
|
|
2817
|
-
* influences how this parsing is carried out.
|
|
2818
|
-
*
|
|
2819
|
-
* Ordered by first name, the parser works as follows:
|
|
2820
|
-
* - 2 elements: firstname lastname
|
|
2821
|
-
* - 3 elements: firstname middlename lastname
|
|
2822
|
-
* - 4 elements: prefix firstname middlename lastname
|
|
2823
|
-
* - 5 elements: prefix firstname middlename lastname suffix
|
|
2824
|
-
*
|
|
2825
|
-
* Ordered by last name, the parser works as follows:
|
|
2826
|
-
* - 2 elements: lastname firstname
|
|
2827
|
-
* - 3 elements: lastname firstname middlename
|
|
2828
|
-
* - 4 elements: prefix lastname firstname middlename
|
|
2829
|
-
* - 5 elements: prefix lastname firstname middlename suffix
|
|
2830
|
-
*
|
|
2831
|
-
*/
|
|
2832
|
-
class ArrayStringParser {
|
|
2833
|
-
/**
|
|
2834
|
-
* Create a parser ready to parse the raw data
|
|
2835
|
-
* @param {string[]} raw data
|
|
2836
|
-
*/
|
|
1245
|
+
exports.ArrayNameParser = exports.NamaParser = exports.ArrayStringParser = exports.StringParser = exports.Parser = void 0;
|
|
1246
|
+
const full_name_1 = __webpack_require__(6);
|
|
1247
|
+
const config_1 = __webpack_require__(5);
|
|
1248
|
+
const utils_1 = __webpack_require__(2);
|
|
1249
|
+
const validator_1 = __webpack_require__(7);
|
|
1250
|
+
const name_1 = __webpack_require__(3);
|
|
1251
|
+
const types_1 = __webpack_require__(0);
|
|
1252
|
+
const error_1 = __webpack_require__(1);
|
|
1253
|
+
class Parser {
|
|
2837
1254
|
constructor(raw) {
|
|
2838
1255
|
this.raw = raw;
|
|
2839
1256
|
}
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
1257
|
+
static build(text) {
|
|
1258
|
+
const parts = text.trim().split(types_1.Separator.SPACE.token);
|
|
1259
|
+
const length = parts.length;
|
|
1260
|
+
if (length < 2) {
|
|
1261
|
+
throw new error_1.InputError({
|
|
1262
|
+
source: text,
|
|
1263
|
+
message: 'cannot build from invalid input',
|
|
1264
|
+
});
|
|
1265
|
+
}
|
|
1266
|
+
else if (length === 2 || length === 3) {
|
|
1267
|
+
return new StringParser(text);
|
|
1268
|
+
}
|
|
1269
|
+
else {
|
|
1270
|
+
const last = parts.pop();
|
|
1271
|
+
const [first, ...middles] = parts;
|
|
1272
|
+
return new ArrayStringParser([first, middles.join(' '), last]);
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
static buildAsync(text) {
|
|
1276
|
+
try {
|
|
1277
|
+
return Promise.resolve(Parser.build(text));
|
|
1278
|
+
}
|
|
1279
|
+
catch (error) {
|
|
1280
|
+
return Promise.reject(error);
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
exports.Parser = Parser;
|
|
1285
|
+
class StringParser extends Parser {
|
|
2843
1286
|
parse(options) {
|
|
2844
|
-
|
|
2845
|
-
const
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
const
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
lastname: null,
|
|
2860
|
-
middlename: [],
|
|
2861
|
-
prefix: null,
|
|
2862
|
-
suffix: null,
|
|
2863
|
-
};
|
|
2864
|
-
switch (raw.length) {
|
|
2865
|
-
case 2: // first name + last name
|
|
2866
|
-
fullname.firstname = new models_1.Firstname(raw[index.firstname]);
|
|
2867
|
-
fullname.lastname = new models_1.Lastname(raw[index.lastname]);
|
|
2868
|
-
break;
|
|
2869
|
-
case 3: // first name + middle name + last name
|
|
2870
|
-
fullname.firstname = new models_1.Firstname(raw[index.firstname]);
|
|
2871
|
-
fullname.middlename.push(new models_1.Name(raw[index.middlename], models_1.Namon.MIDDLE_NAME));
|
|
2872
|
-
fullname.lastname = new models_1.Lastname(raw[index.lastname]);
|
|
2873
|
-
break;
|
|
2874
|
-
case 4: // prefix + first name + middle name + last name
|
|
2875
|
-
fullname.prefix = raw[index.prefix];
|
|
2876
|
-
fullname.firstname = new models_1.Firstname(raw[index.firstname]);
|
|
2877
|
-
fullname.middlename.push(new models_1.Name(raw[index.middlename], models_1.Namon.MIDDLE_NAME));
|
|
2878
|
-
fullname.lastname = new models_1.Lastname(raw[index.lastname]);
|
|
2879
|
-
break;
|
|
2880
|
-
case 5: // prefix + first name + middle name + last name + suffix
|
|
2881
|
-
fullname.prefix = raw[index.prefix];
|
|
2882
|
-
fullname.firstname = new models_1.Firstname(raw[index.firstname]);
|
|
2883
|
-
fullname.middlename.push(new models_1.Name(raw[index.middlename], models_1.Namon.MIDDLE_NAME));
|
|
2884
|
-
fullname.lastname = new models_1.Lastname(raw[index.lastname]);
|
|
2885
|
-
fullname.suffix = raw[index.suffix];
|
|
2886
|
-
break;
|
|
1287
|
+
const config = config_1.Config.merge(options);
|
|
1288
|
+
const names = this.raw.split(config.separator.token);
|
|
1289
|
+
return new ArrayStringParser(names).parse(options);
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
exports.StringParser = StringParser;
|
|
1293
|
+
class ArrayStringParser extends Parser {
|
|
1294
|
+
parse(options) {
|
|
1295
|
+
const config = config_1.Config.merge(options);
|
|
1296
|
+
const fullName = new full_name_1.FullName(config);
|
|
1297
|
+
const raw = this.raw.map((n) => n.trim());
|
|
1298
|
+
const index = utils_1.NameIndex.when(config.orderedBy, raw.length);
|
|
1299
|
+
const validator = new validator_1.ArrayStringValidator(index);
|
|
1300
|
+
if (config.bypass) {
|
|
1301
|
+
validator.validateIndex(raw);
|
|
2887
1302
|
}
|
|
2888
|
-
|
|
1303
|
+
else {
|
|
1304
|
+
validator.validate(raw);
|
|
1305
|
+
}
|
|
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]));
|
|
1315
|
+
return fullName;
|
|
2889
1316
|
}
|
|
2890
1317
|
}
|
|
2891
|
-
exports.
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
2897
|
-
|
|
2898
|
-
"use strict";
|
|
2899
|
-
|
|
2900
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2901
|
-
/**
|
|
2902
|
-
* A `Nama` (JSON signature) parser
|
|
2903
|
-
*
|
|
2904
|
-
* Created on March 15, 2020
|
|
2905
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
2906
|
-
*/
|
|
2907
|
-
const index_1 = __webpack_require__(0);
|
|
2908
|
-
const index_2 = __webpack_require__(1);
|
|
2909
|
-
/**
|
|
2910
|
-
* Represents a `Nama` parser
|
|
2911
|
-
* @class
|
|
2912
|
-
* @implements {Parser<Nama>}
|
|
2913
|
-
*
|
|
2914
|
-
* This parser parses a JSON signature of the name parts provided as string
|
|
2915
|
-
* values. This is to facilitate a developer's life that holds users' info in a
|
|
2916
|
-
* JSON format. In other words, the developer only needs to provide similar info
|
|
2917
|
-
* and the rest will follow.
|
|
2918
|
-
*/
|
|
2919
|
-
class NamaParser {
|
|
2920
|
-
/**
|
|
2921
|
-
* Create a parser ready to parse the raw data
|
|
2922
|
-
* @param {Nama} raw data as JSON object
|
|
2923
|
-
*/
|
|
2924
|
-
constructor(raw) {
|
|
2925
|
-
this.raw = raw;
|
|
1318
|
+
exports.ArrayStringParser = ArrayStringParser;
|
|
1319
|
+
class NamaParser extends Parser {
|
|
1320
|
+
constructor() {
|
|
1321
|
+
super(...arguments);
|
|
1322
|
+
_NamaParser_instances.add(this);
|
|
2926
1323
|
}
|
|
2927
|
-
/**
|
|
2928
|
-
* Parses the raw data into a full name
|
|
2929
|
-
*/
|
|
2930
1324
|
parse(options) {
|
|
2931
|
-
|
|
2932
|
-
if (
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
1325
|
+
const config = config_1.Config.merge(options);
|
|
1326
|
+
if (config.bypass) {
|
|
1327
|
+
validator_1.NamaValidator.create().validateKeys(__classPrivateFieldGet(this, _NamaParser_instances, "m", _NamaParser_asNama).call(this));
|
|
1328
|
+
}
|
|
1329
|
+
else {
|
|
1330
|
+
validator_1.NamaValidator.create().validate(__classPrivateFieldGet(this, _NamaParser_instances, "m", _NamaParser_asNama).call(this));
|
|
1331
|
+
}
|
|
1332
|
+
return full_name_1.FullName.parse(this.raw, config);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
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
|
+
};
|
|
1348
|
+
class ArrayNameParser extends Parser {
|
|
1349
|
+
parse(options) {
|
|
1350
|
+
const config = config_1.Config.merge(options);
|
|
1351
|
+
const fullName = new full_name_1.FullName(config);
|
|
1352
|
+
validator_1.ArrayNameValidator.create().validate(this.raw);
|
|
1353
|
+
for (const name of this.raw) {
|
|
1354
|
+
if (name.isPrefix) {
|
|
1355
|
+
fullName.setPrefix(name);
|
|
1356
|
+
}
|
|
1357
|
+
else if (name.isSuffix) {
|
|
1358
|
+
fullName.setSuffix(name);
|
|
1359
|
+
}
|
|
1360
|
+
else if (name.isFirstName) {
|
|
1361
|
+
fullName.setFirstName(name instanceof name_1.FirstName ? name : new name_1.FirstName(name.value));
|
|
1362
|
+
}
|
|
1363
|
+
else if (name.isMiddleName) {
|
|
1364
|
+
fullName.middleName.push(name);
|
|
1365
|
+
}
|
|
1366
|
+
else if (name.isLastName) {
|
|
1367
|
+
const lastName = new name_1.LastName(name.value, name instanceof name_1.LastName ? name.mother : undefined, config.surname);
|
|
1368
|
+
fullName.setLastName(lastName);
|
|
2966
1369
|
}
|
|
2967
1370
|
}
|
|
2968
|
-
return
|
|
1371
|
+
return fullName;
|
|
2969
1372
|
}
|
|
2970
1373
|
}
|
|
2971
|
-
exports.
|
|
1374
|
+
exports.ArrayNameParser = ArrayNameParser;
|
|
2972
1375
|
|
|
2973
1376
|
|
|
2974
1377
|
/***/ }),
|
|
2975
|
-
/*
|
|
1378
|
+
/* 9 */
|
|
2976
1379
|
/***/ (function(module, exports, __webpack_require__) {
|
|
2977
1380
|
|
|
2978
1381
|
"use strict";
|
|
2979
1382
|
|
|
1383
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
1384
|
+
if (k2 === undefined) k2 = k;
|
|
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);
|
|
1390
|
+
}) : (function(o, m, k, k2) {
|
|
1391
|
+
if (k2 === undefined) k2 = k;
|
|
1392
|
+
o[k2] = m[k];
|
|
1393
|
+
}));
|
|
1394
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
1395
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
1396
|
+
};
|
|
2980
1397
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
* (e.g., a colon <:>) to handle multiple names for a `Namon`. That is to say,
|
|
2995
|
-
* a piece of name shaped as `De La Cruz` is a last name that needs to be handled
|
|
2996
|
-
* as a whole, and therefore requires that a different type of separator to split
|
|
2997
|
-
* up the name parts. Alternatively, the `ArrayStringParser` can be used by indicating
|
|
2998
|
-
* specifically which part of the name is what. Do note that this parser is actually
|
|
2999
|
-
* a wrapper of the `ArrayStringParser`.
|
|
3000
|
-
*
|
|
3001
|
-
* @example
|
|
3002
|
-
* Given the name `Maria De La Cruz`, using this parser without indicating a
|
|
3003
|
-
* separator different than <space> will definitely throw an error. So, if the proper
|
|
3004
|
-
* proper of doing when `De La Cruz` is the last name:
|
|
3005
|
-
* ```
|
|
3006
|
-
* > const name = new Namefully('Maria:De La Cruz', { separator: Separator.COLON })
|
|
3007
|
-
* > console.log(name.getLastname())
|
|
3008
|
-
* De La Cruz
|
|
3009
|
-
* ```
|
|
3010
|
-
* Or
|
|
3011
|
-
* ```
|
|
3012
|
-
* > const name = new Namefully(['Maria', 'De La Cruz'])
|
|
3013
|
-
* > console.log(name.getLastname())
|
|
3014
|
-
* De La Cruz
|
|
3015
|
-
* ```
|
|
3016
|
-
*/
|
|
3017
|
-
class StringParser {
|
|
3018
|
-
/**
|
|
3019
|
-
* Create a parser ready to parse the raw data
|
|
3020
|
-
* @param {string} raw data as a string representation
|
|
3021
|
-
*/
|
|
3022
|
-
constructor(raw) {
|
|
3023
|
-
this.raw = raw;
|
|
3024
|
-
}
|
|
3025
|
-
/**
|
|
3026
|
-
* Parses the raw data into a full name
|
|
3027
|
-
* @param options how to parse
|
|
3028
|
-
*/
|
|
3029
|
-
parse(options) {
|
|
3030
|
-
// given this setting
|
|
3031
|
-
const { orderedBy, separator, bypass } = options;
|
|
3032
|
-
// then distribute all the elements accordingly
|
|
3033
|
-
const nama = this.raw.split(separator);
|
|
3034
|
-
const fullname = new index_1.ArrayStringParser(nama).parse({ orderedBy, bypass });
|
|
3035
|
-
// finally return high quality of data
|
|
3036
|
-
return fullname;
|
|
3037
|
-
}
|
|
3038
|
-
}
|
|
3039
|
-
exports.default = StringParser;
|
|
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; } });
|
|
1402
|
+
__exportStar(__webpack_require__(1), exports);
|
|
1403
|
+
__exportStar(__webpack_require__(6), exports);
|
|
1404
|
+
__exportStar(__webpack_require__(3), exports);
|
|
1405
|
+
__exportStar(__webpack_require__(10), exports);
|
|
1406
|
+
var parser_1 = __webpack_require__(8);
|
|
1407
|
+
Object.defineProperty(exports, "Parser", { enumerable: true, get: function () { return parser_1.Parser; } });
|
|
1408
|
+
__exportStar(__webpack_require__(0), exports);
|
|
1409
|
+
var utils_1 = __webpack_require__(2);
|
|
1410
|
+
Object.defineProperty(exports, "NameIndex", { enumerable: true, get: function () { return utils_1.NameIndex; } });
|
|
3040
1411
|
|
|
3041
1412
|
|
|
3042
1413
|
/***/ }),
|
|
3043
|
-
/*
|
|
1414
|
+
/* 10 */
|
|
3044
1415
|
/***/ (function(module, exports, __webpack_require__) {
|
|
3045
1416
|
|
|
3046
1417
|
"use strict";
|
|
3047
1418
|
|
|
1419
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1420
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1421
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1422
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
1423
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
1424
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1425
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1426
|
+
});
|
|
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;
|
|
3048
1440
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
}
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
1441
|
+
exports.Namefully = void 0;
|
|
1442
|
+
const constants_1 = __webpack_require__(4);
|
|
1443
|
+
const error_1 = __webpack_require__(1);
|
|
1444
|
+
const parser_1 = __webpack_require__(8);
|
|
1445
|
+
const types_1 = __webpack_require__(0);
|
|
1446
|
+
const utils_1 = __webpack_require__(2);
|
|
1447
|
+
class Namefully {
|
|
1448
|
+
constructor(names, options) {
|
|
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
|
+
}
|
|
1453
|
+
static tryParse(text) {
|
|
1454
|
+
try {
|
|
1455
|
+
return new this(parser_1.Parser.build(text));
|
|
1456
|
+
}
|
|
1457
|
+
catch (error) {
|
|
1458
|
+
return undefined;
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
static parse(text) {
|
|
1462
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1463
|
+
return parser_1.Parser.buildAsync(text).then((parser) => new Namefully(parser));
|
|
1464
|
+
});
|
|
1465
|
+
}
|
|
1466
|
+
get config() {
|
|
1467
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").config;
|
|
1468
|
+
}
|
|
1469
|
+
get length() {
|
|
1470
|
+
return this.birth.length;
|
|
1471
|
+
}
|
|
1472
|
+
get prefix() {
|
|
1473
|
+
var _a;
|
|
1474
|
+
return (_a = __classPrivateFieldGet(this, _Namefully_fullName, "f").prefix) === null || _a === void 0 ? void 0 : _a.toString();
|
|
1475
|
+
}
|
|
1476
|
+
get first() {
|
|
1477
|
+
return this.firstName();
|
|
1478
|
+
}
|
|
1479
|
+
get middle() {
|
|
1480
|
+
return this.hasMiddle ? this.middleName()[0] : undefined;
|
|
1481
|
+
}
|
|
1482
|
+
get hasMiddle() {
|
|
1483
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").has(types_1.Namon.MIDDLE_NAME);
|
|
1484
|
+
}
|
|
1485
|
+
get last() {
|
|
1486
|
+
return this.lastName();
|
|
1487
|
+
}
|
|
1488
|
+
get suffix() {
|
|
1489
|
+
var _a;
|
|
1490
|
+
return (_a = __classPrivateFieldGet(this, _Namefully_fullName, "f").suffix) === null || _a === void 0 ? void 0 : _a.toString();
|
|
1491
|
+
}
|
|
1492
|
+
get birth() {
|
|
1493
|
+
return this.birthName();
|
|
1494
|
+
}
|
|
1495
|
+
get short() {
|
|
1496
|
+
return this.shorten();
|
|
1497
|
+
}
|
|
1498
|
+
get long() {
|
|
1499
|
+
return this.birth;
|
|
1500
|
+
}
|
|
1501
|
+
get full() {
|
|
1502
|
+
return this.fullName();
|
|
1503
|
+
}
|
|
1504
|
+
get public() {
|
|
1505
|
+
return this.format('f $l');
|
|
1506
|
+
}
|
|
1507
|
+
toString() {
|
|
1508
|
+
return this.full;
|
|
1509
|
+
}
|
|
1510
|
+
get(namon) {
|
|
1511
|
+
if (namon.equal(types_1.Namon.PREFIX))
|
|
1512
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").prefix;
|
|
1513
|
+
if (namon.equal(types_1.Namon.FIRST_NAME))
|
|
1514
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName;
|
|
1515
|
+
if (namon.equal(types_1.Namon.MIDDLE_NAME))
|
|
1516
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").middleName;
|
|
1517
|
+
if (namon.equal(types_1.Namon.LAST_NAME))
|
|
1518
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName;
|
|
1519
|
+
if (namon.equal(types_1.Namon.SUFFIX))
|
|
1520
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").suffix;
|
|
1521
|
+
return undefined;
|
|
1522
|
+
}
|
|
1523
|
+
equal(other) {
|
|
1524
|
+
return this.toString() === other.toString();
|
|
1525
|
+
}
|
|
1526
|
+
toJson() {
|
|
1527
|
+
return {
|
|
1528
|
+
prefix: this.prefix,
|
|
1529
|
+
firstName: this.first,
|
|
1530
|
+
middleName: this.middleName(),
|
|
1531
|
+
lastName: this.last,
|
|
1532
|
+
suffix: this.suffix,
|
|
1533
|
+
};
|
|
1534
|
+
}
|
|
1535
|
+
has(namon) {
|
|
1536
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").has(namon);
|
|
1537
|
+
}
|
|
1538
|
+
fullName(orderedBy) {
|
|
1539
|
+
const sep = this.config.ending ? ',' : '';
|
|
1540
|
+
const names = [];
|
|
1541
|
+
orderedBy = orderedBy || this.config.orderedBy;
|
|
1542
|
+
if (this.prefix)
|
|
1543
|
+
names.push(this.prefix);
|
|
1544
|
+
if (orderedBy === types_1.NameOrder.FIRST_NAME) {
|
|
1545
|
+
names.push(this.first, ...this.middleName(), this.last + sep);
|
|
3092
1546
|
}
|
|
3093
1547
|
else {
|
|
3094
|
-
|
|
1548
|
+
names.push(this.last, this.first, this.middleName().join(' ') + sep);
|
|
3095
1549
|
}
|
|
1550
|
+
if (this.suffix)
|
|
1551
|
+
names.push(this.suffix);
|
|
1552
|
+
return names.join(' ').trim();
|
|
3096
1553
|
}
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
1554
|
+
birthName(orderedBy) {
|
|
1555
|
+
orderedBy = orderedBy || this.config.orderedBy;
|
|
1556
|
+
return orderedBy === types_1.NameOrder.FIRST_NAME
|
|
1557
|
+
? [this.first, ...this.middleName(), this.last].join(' ')
|
|
1558
|
+
: [this.last, this.first, ...this.middleName()].join(' ');
|
|
1559
|
+
}
|
|
1560
|
+
firstName(withMore = true) {
|
|
1561
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.toString(withMore);
|
|
1562
|
+
}
|
|
1563
|
+
middleName() {
|
|
1564
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").middleName.map((n) => n.value);
|
|
1565
|
+
}
|
|
1566
|
+
lastName(format) {
|
|
1567
|
+
return __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.toString(format);
|
|
1568
|
+
}
|
|
1569
|
+
initials(options) {
|
|
1570
|
+
const initials = [];
|
|
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);
|
|
1575
|
+
const { orderedBy, only } = mergedOptions;
|
|
1576
|
+
if (only !== types_1.NameType.BIRTH_NAME) {
|
|
1577
|
+
if (only === types_1.NameType.FIRST_NAME) {
|
|
1578
|
+
initials.push(...firstInits);
|
|
1579
|
+
}
|
|
1580
|
+
else if (only === types_1.NameType.MIDDLE_NAME) {
|
|
1581
|
+
initials.push(...midInits);
|
|
1582
|
+
}
|
|
1583
|
+
else {
|
|
1584
|
+
initials.push(...lastInits);
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
else if (orderedBy === types_1.NameOrder.FIRST_NAME) {
|
|
1588
|
+
initials.push(...firstInits, ...midInits, ...lastInits);
|
|
3132
1589
|
}
|
|
1590
|
+
else {
|
|
1591
|
+
initials.push(...lastInits, ...firstInits, ...midInits);
|
|
1592
|
+
}
|
|
1593
|
+
return initials;
|
|
3133
1594
|
}
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
1595
|
+
shorten(orderedBy) {
|
|
1596
|
+
orderedBy = orderedBy || this.config.orderedBy;
|
|
1597
|
+
return orderedBy === types_1.NameOrder.FIRST_NAME
|
|
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
|
+
}
|
|
1601
|
+
flatten(options) {
|
|
1602
|
+
if (this.length <= options.limit)
|
|
1603
|
+
return this.full;
|
|
1604
|
+
const mergedOptions = Object.assign({ limit: 20, by: types_1.Flat.MIDDLE_NAME, withPeriod: true, recursive: false, withMore: false }, options);
|
|
1605
|
+
const { by, limit, recursive, withMore, withPeriod, surname } = mergedOptions;
|
|
1606
|
+
const sep = withPeriod ? '.' : '';
|
|
1607
|
+
const fn = __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.toString();
|
|
1608
|
+
const mn = this.middleName().join(' ');
|
|
1609
|
+
const ln = __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.toString();
|
|
1610
|
+
const hasMid = this.hasMiddle;
|
|
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 : '';
|
|
1614
|
+
let name = [];
|
|
1615
|
+
if (this.config.orderedBy === types_1.NameOrder.FIRST_NAME) {
|
|
1616
|
+
switch (by) {
|
|
1617
|
+
case types_1.Flat.FIRST_NAME:
|
|
1618
|
+
name = hasMid ? [f, mn, ln] : [f, ln];
|
|
1619
|
+
break;
|
|
1620
|
+
case types_1.Flat.LAST_NAME:
|
|
1621
|
+
name = hasMid ? [fn, mn, l] : [fn, l];
|
|
1622
|
+
break;
|
|
1623
|
+
case types_1.Flat.MIDDLE_NAME:
|
|
1624
|
+
name = hasMid ? [fn, m, ln] : [fn, ln];
|
|
1625
|
+
break;
|
|
1626
|
+
case types_1.Flat.FIRST_MID:
|
|
1627
|
+
name = hasMid ? [f, m, ln] : [f, ln];
|
|
1628
|
+
break;
|
|
1629
|
+
case types_1.Flat.MID_LAST:
|
|
1630
|
+
name = hasMid ? [fn, m, l] : [fn, l];
|
|
1631
|
+
break;
|
|
1632
|
+
case types_1.Flat.ALL:
|
|
1633
|
+
name = hasMid ? [f, m, l] : [f, l];
|
|
1634
|
+
break;
|
|
1635
|
+
}
|
|
3158
1636
|
}
|
|
1637
|
+
else {
|
|
1638
|
+
switch (by) {
|
|
1639
|
+
case types_1.Flat.FIRST_NAME:
|
|
1640
|
+
name = hasMid ? [ln, f, mn] : [ln, f];
|
|
1641
|
+
break;
|
|
1642
|
+
case types_1.Flat.LAST_NAME:
|
|
1643
|
+
name = hasMid ? [l, fn, mn] : [l, fn];
|
|
1644
|
+
break;
|
|
1645
|
+
case types_1.Flat.MIDDLE_NAME:
|
|
1646
|
+
name = hasMid ? [ln, fn, m] : [ln, fn];
|
|
1647
|
+
break;
|
|
1648
|
+
case types_1.Flat.FIRST_MID:
|
|
1649
|
+
name = hasMid ? [ln, f, m] : [ln, f];
|
|
1650
|
+
break;
|
|
1651
|
+
case types_1.Flat.MID_LAST:
|
|
1652
|
+
name = hasMid ? [l, fn, m] : [l, fn];
|
|
1653
|
+
break;
|
|
1654
|
+
case types_1.Flat.ALL:
|
|
1655
|
+
name = hasMid ? [l, f, m] : [l, f];
|
|
1656
|
+
break;
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
const flat = name.join(' ');
|
|
1660
|
+
if (recursive && flat.length > limit) {
|
|
1661
|
+
const next = by === types_1.Flat.FIRST_NAME
|
|
1662
|
+
? types_1.Flat.MIDDLE_NAME
|
|
1663
|
+
: by === types_1.Flat.MIDDLE_NAME
|
|
1664
|
+
? types_1.Flat.LAST_NAME
|
|
1665
|
+
: by === types_1.Flat.LAST_NAME
|
|
1666
|
+
? types_1.Flat.FIRST_MID
|
|
1667
|
+
: by === types_1.Flat.FIRST_MID
|
|
1668
|
+
? types_1.Flat.MID_LAST
|
|
1669
|
+
: by === types_1.Flat.MID_LAST
|
|
1670
|
+
? types_1.Flat.ALL
|
|
1671
|
+
: by === types_1.Flat.ALL
|
|
1672
|
+
? types_1.Flat.ALL
|
|
1673
|
+
: by;
|
|
1674
|
+
if (next === by)
|
|
1675
|
+
return flat;
|
|
1676
|
+
return this.flatten(Object.assign(Object.assign({}, options), { by: next }));
|
|
1677
|
+
}
|
|
1678
|
+
return flat;
|
|
1679
|
+
}
|
|
1680
|
+
zip(by = types_1.Flat.MID_LAST, withPeriod = true) {
|
|
1681
|
+
return this.flatten({ limit: 0, by, withPeriod });
|
|
1682
|
+
}
|
|
1683
|
+
format(pattern) {
|
|
1684
|
+
var _a;
|
|
1685
|
+
if (pattern === 'short')
|
|
1686
|
+
return this.short;
|
|
1687
|
+
if (pattern === 'long')
|
|
1688
|
+
return this.long;
|
|
1689
|
+
if (pattern === 'public')
|
|
1690
|
+
return this.public;
|
|
1691
|
+
if (pattern === 'official')
|
|
1692
|
+
pattern = 'o';
|
|
1693
|
+
let group = '';
|
|
1694
|
+
const formatted = [];
|
|
1695
|
+
for (const char of pattern.split('')) {
|
|
1696
|
+
if (constants_1.ALLOWED_TOKENS.indexOf(char) === -1) {
|
|
1697
|
+
throw new error_1.NotAllowedError({
|
|
1698
|
+
source: this.full,
|
|
1699
|
+
operation: 'format',
|
|
1700
|
+
message: `unsupported character <${char}> from ${pattern}.`,
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1703
|
+
group += char;
|
|
1704
|
+
if (char === '$')
|
|
1705
|
+
continue;
|
|
1706
|
+
formatted.push((_a = __classPrivateFieldGet(this, _Namefully_instances, "m", _Namefully_map).call(this, group)) !== null && _a !== void 0 ? _a : '');
|
|
1707
|
+
group = '';
|
|
1708
|
+
}
|
|
1709
|
+
return formatted.join('').trim();
|
|
3159
1710
|
}
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
1711
|
+
flip() {
|
|
1712
|
+
this.config.updateOrder(this.config.orderedBy === types_1.NameOrder.FIRST_NAME ? types_1.NameOrder.LAST_NAME : types_1.NameOrder.FIRST_NAME);
|
|
1713
|
+
}
|
|
1714
|
+
split(separator = /[' -]/g) {
|
|
1715
|
+
return this.birth.replace(separator, ' ').split(' ');
|
|
1716
|
+
}
|
|
1717
|
+
join(separator = '') {
|
|
1718
|
+
return this.split().join(separator);
|
|
1719
|
+
}
|
|
1720
|
+
toUpperCase() {
|
|
1721
|
+
return this.birth.toUpperCase();
|
|
1722
|
+
}
|
|
1723
|
+
toLowerCase() {
|
|
1724
|
+
return this.birth.toLowerCase();
|
|
1725
|
+
}
|
|
1726
|
+
toCamelCase() {
|
|
1727
|
+
return (0, utils_1.decapitalize)(this.toPascalCase());
|
|
1728
|
+
}
|
|
1729
|
+
toPascalCase() {
|
|
1730
|
+
return this.split()
|
|
1731
|
+
.map((n) => (0, utils_1.capitalize)(n))
|
|
1732
|
+
.join('');
|
|
1733
|
+
}
|
|
1734
|
+
toSnakeCase() {
|
|
1735
|
+
return this.split()
|
|
1736
|
+
.map((n) => n.toLowerCase())
|
|
1737
|
+
.join('_');
|
|
1738
|
+
}
|
|
1739
|
+
toHyphenCase() {
|
|
1740
|
+
return this.split()
|
|
1741
|
+
.map((n) => n.toLowerCase())
|
|
1742
|
+
.join('-');
|
|
1743
|
+
}
|
|
1744
|
+
toDotCase() {
|
|
1745
|
+
return this.split()
|
|
1746
|
+
.map((n) => n.toLowerCase())
|
|
1747
|
+
.join('.');
|
|
1748
|
+
}
|
|
1749
|
+
toToggleCase() {
|
|
1750
|
+
return (0, utils_1.toggleCase)(this.birth);
|
|
3177
1751
|
}
|
|
3178
1752
|
}
|
|
3179
|
-
exports.
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
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;
|
|
3190
1824
|
default:
|
|
3191
|
-
return
|
|
1825
|
+
return undefined;
|
|
3192
1826
|
}
|
|
3193
|
-
}
|
|
3194
|
-
exports.allowShortNameOrder = allowShortNameOrder;
|
|
3195
|
-
/**
|
|
3196
|
-
* Converts to ascii characters (using UTF-16)
|
|
3197
|
-
* @param str string content
|
|
3198
|
-
* @param restrictions unneeded content to skip
|
|
3199
|
-
*/
|
|
3200
|
-
function convertToAscii(str, restrictions = [...core_1.RESTRICTED_CHARS]) {
|
|
3201
|
-
return str
|
|
3202
|
-
.split(models_1.Separator.EMPTY)
|
|
3203
|
-
.filter(c => restrictions.indexOf(c) === -1)
|
|
3204
|
-
.map(c => c.charCodeAt(0));
|
|
3205
|
-
}
|
|
3206
|
-
exports.convertToAscii = convertToAscii;
|
|
3207
|
-
/**
|
|
3208
|
-
* Generates a password
|
|
3209
|
-
* @param str string content
|
|
3210
|
-
*/
|
|
3211
|
-
function generatePassword(str) {
|
|
3212
|
-
const mapper = core_1.PASSWORD_MAPPER;
|
|
3213
|
-
const password = str
|
|
3214
|
-
.split(models_1.Separator.EMPTY)
|
|
3215
|
-
.map(char => {
|
|
3216
|
-
if (mapper.has(char.toLowerCase()))
|
|
3217
|
-
return mapper.get(char.toLowerCase()).random();
|
|
3218
|
-
return mapper.get('$').random();
|
|
3219
|
-
})
|
|
3220
|
-
.join(models_1.Separator.EMPTY);
|
|
3221
|
-
return password;
|
|
3222
|
-
}
|
|
3223
|
-
exports.generatePassword = generatePassword;
|
|
1827
|
+
};
|
|
3224
1828
|
|
|
3225
1829
|
|
|
3226
1830
|
/***/ })
|
|
3227
1831
|
/******/ ]);
|
|
3228
|
-
});
|
|
3229
|
-
//# sourceMappingURL=namefully.js.map
|
|
1832
|
+
});
|