namefully 1.2.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/builder.js +82 -0
- package/dist/cjs/config.js +100 -0
- package/dist/{lib → cjs}/constants.js +1 -1
- package/dist/{lib → cjs}/error.js +8 -5
- package/dist/cjs/fullname.js +102 -0
- package/dist/{lib → cjs}/index.js +18 -12
- package/dist/cjs/name.js +218 -0
- package/dist/cjs/namefully.js +391 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/parser.js +135 -0
- package/dist/{lib → cjs}/types.js +40 -36
- package/dist/{lib → cjs}/utils.js +29 -17
- package/dist/cjs/validator.js +266 -0
- package/dist/esm/builder.d.ts +73 -0
- package/dist/esm/builder.js +78 -0
- package/dist/{types → esm}/config.d.ts +1 -1
- package/dist/esm/config.js +96 -0
- package/dist/{types → esm}/constants.d.ts +1 -1
- package/dist/esm/constants.js +27 -0
- package/dist/{types → esm}/error.d.ts +2 -3
- package/dist/esm/error.js +87 -0
- package/dist/{types/full-name.d.ts → esm/fullname.d.ts} +3 -3
- package/dist/esm/fullname.js +98 -0
- package/dist/esm/index.d.ts +25 -0
- package/dist/esm/index.js +12 -0
- package/dist/{types → esm}/name.d.ts +2 -1
- package/dist/esm/name.js +211 -0
- package/dist/{types → esm}/namefully.d.ts +23 -13
- package/dist/esm/namefully.js +387 -0
- package/dist/esm/package.json +1 -0
- package/dist/{types → esm}/parser.d.ts +7 -6
- package/dist/esm/parser.js +127 -0
- package/dist/esm/types.js +106 -0
- package/dist/{types → esm}/utils.d.ts +4 -3
- package/dist/esm/utils.js +96 -0
- package/dist/{types → esm}/validator.d.ts +3 -3
- package/dist/esm/validator.js +259 -0
- package/dist/namefully.js +1580 -0
- package/dist/namefully.min.js +1 -0
- package/package.json +52 -32
- package/readme.md +63 -35
- package/dist/lib/config.js +0 -112
- package/dist/lib/full-name.js +0 -115
- package/dist/lib/name.js +0 -230
- package/dist/lib/namefully.js +0 -410
- package/dist/lib/parser.js +0 -138
- package/dist/lib/validator.js +0 -301
- package/dist/types/index.d.ts +0 -21
- package/dist/umd/namefully.js +0 -1832
- package/dist/umd/namefully.min.js +0 -1
- /package/dist/{types → esm}/types.d.ts +0 -0
package/dist/lib/name.js
DELETED
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
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");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
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");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _Name_namon, _FirstName_more, _LastName_mother;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.LastName = exports.FirstName = exports.Name = void 0;
|
|
16
|
-
const error_1 = require("./error");
|
|
17
|
-
const types_1 = require("./types");
|
|
18
|
-
const utils_1 = require("./utils");
|
|
19
|
-
class Name {
|
|
20
|
-
constructor(value, type, capsRange) {
|
|
21
|
-
this.type = type;
|
|
22
|
-
_Name_namon.set(this, void 0);
|
|
23
|
-
this.capsRange = capsRange !== null && capsRange !== void 0 ? capsRange : types_1.CapsRange.INITIAL;
|
|
24
|
-
this.value = value;
|
|
25
|
-
if (capsRange)
|
|
26
|
-
this.caps(capsRange);
|
|
27
|
-
}
|
|
28
|
-
set value(newValue) {
|
|
29
|
-
this.validate(newValue);
|
|
30
|
-
__classPrivateFieldSet(this, _Name_namon, newValue, "f");
|
|
31
|
-
this.initial = newValue[0];
|
|
32
|
-
}
|
|
33
|
-
get value() {
|
|
34
|
-
return __classPrivateFieldGet(this, _Name_namon, "f");
|
|
35
|
-
}
|
|
36
|
-
get length() {
|
|
37
|
-
return __classPrivateFieldGet(this, _Name_namon, "f").length;
|
|
38
|
-
}
|
|
39
|
-
get isPrefix() {
|
|
40
|
-
return this.type === types_1.Namon.PREFIX;
|
|
41
|
-
}
|
|
42
|
-
get isFirstName() {
|
|
43
|
-
return this.type === types_1.Namon.FIRST_NAME;
|
|
44
|
-
}
|
|
45
|
-
get isMiddleName() {
|
|
46
|
-
return this.type === types_1.Namon.MIDDLE_NAME;
|
|
47
|
-
}
|
|
48
|
-
get isLastName() {
|
|
49
|
-
return this.type === types_1.Namon.LAST_NAME;
|
|
50
|
-
}
|
|
51
|
-
get isSuffix() {
|
|
52
|
-
return this.type === types_1.Namon.SUFFIX;
|
|
53
|
-
}
|
|
54
|
-
static prefix(value) {
|
|
55
|
-
return new this(value, types_1.Namon.PREFIX);
|
|
56
|
-
}
|
|
57
|
-
static first(value) {
|
|
58
|
-
return new this(value, types_1.Namon.FIRST_NAME);
|
|
59
|
-
}
|
|
60
|
-
static middle(value) {
|
|
61
|
-
return new this(value, types_1.Namon.MIDDLE_NAME);
|
|
62
|
-
}
|
|
63
|
-
static last(value) {
|
|
64
|
-
return new this(value, types_1.Namon.LAST_NAME);
|
|
65
|
-
}
|
|
66
|
-
static suffix(value) {
|
|
67
|
-
return new this(value, types_1.Namon.SUFFIX);
|
|
68
|
-
}
|
|
69
|
-
initials() {
|
|
70
|
-
return [this.initial];
|
|
71
|
-
}
|
|
72
|
-
toString() {
|
|
73
|
-
return __classPrivateFieldGet(this, _Name_namon, "f");
|
|
74
|
-
}
|
|
75
|
-
equal(other) {
|
|
76
|
-
return other instanceof Name && other.value === this.value && other.type === this.type;
|
|
77
|
-
}
|
|
78
|
-
caps(range) {
|
|
79
|
-
this.value = (0, utils_1.capitalize)(__classPrivateFieldGet(this, _Name_namon, "f"), range !== null && range !== void 0 ? range : this.capsRange);
|
|
80
|
-
return this;
|
|
81
|
-
}
|
|
82
|
-
decaps(range) {
|
|
83
|
-
this.value = (0, utils_1.decapitalize)(__classPrivateFieldGet(this, _Name_namon, "f"), range !== null && range !== void 0 ? range : this.capsRange);
|
|
84
|
-
return this;
|
|
85
|
-
}
|
|
86
|
-
validate(name) {
|
|
87
|
-
if ((name === null || name === void 0 ? void 0 : name.trim().length) < 2) {
|
|
88
|
-
throw new error_1.InputError({ source: name, message: 'must be 2+ characters' });
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
exports.Name = Name;
|
|
93
|
-
_Name_namon = new WeakMap();
|
|
94
|
-
class FirstName extends Name {
|
|
95
|
-
constructor(value, ...more) {
|
|
96
|
-
super(value, types_1.Namon.FIRST_NAME);
|
|
97
|
-
_FirstName_more.set(this, void 0);
|
|
98
|
-
more.forEach((n) => this.validate(n));
|
|
99
|
-
__classPrivateFieldSet(this, _FirstName_more, more, "f");
|
|
100
|
-
}
|
|
101
|
-
get hasMore() {
|
|
102
|
-
return __classPrivateFieldGet(this, _FirstName_more, "f").length > 0;
|
|
103
|
-
}
|
|
104
|
-
get length() {
|
|
105
|
-
return super.length + (this.hasMore ? __classPrivateFieldGet(this, _FirstName_more, "f").reduce((acc, n) => acc + n).length : 0);
|
|
106
|
-
}
|
|
107
|
-
get asNames() {
|
|
108
|
-
const names = [Name.first(this.value)];
|
|
109
|
-
if (this.hasMore) {
|
|
110
|
-
names.push(...__classPrivateFieldGet(this, _FirstName_more, "f").map((n) => Name.first(n)));
|
|
111
|
-
}
|
|
112
|
-
return names;
|
|
113
|
-
}
|
|
114
|
-
get more() {
|
|
115
|
-
return __classPrivateFieldGet(this, _FirstName_more, "f");
|
|
116
|
-
}
|
|
117
|
-
toString(withMore = false) {
|
|
118
|
-
return withMore && this.hasMore ? `${this.value} ${__classPrivateFieldGet(this, _FirstName_more, "f").join(' ')}`.trim() : this.value;
|
|
119
|
-
}
|
|
120
|
-
initials(withMore = false) {
|
|
121
|
-
const inits = [this.initial];
|
|
122
|
-
if (withMore && this.hasMore) {
|
|
123
|
-
inits.push(...__classPrivateFieldGet(this, _FirstName_more, "f").map((n) => n[0]));
|
|
124
|
-
}
|
|
125
|
-
return inits;
|
|
126
|
-
}
|
|
127
|
-
caps(range) {
|
|
128
|
-
range = range || this.capsRange;
|
|
129
|
-
this.value = (0, utils_1.capitalize)(this.value, range);
|
|
130
|
-
if (this.hasMore)
|
|
131
|
-
__classPrivateFieldSet(this, _FirstName_more, __classPrivateFieldGet(this, _FirstName_more, "f").map((n) => (0, utils_1.capitalize)(n, range)), "f");
|
|
132
|
-
return this;
|
|
133
|
-
}
|
|
134
|
-
decaps(range) {
|
|
135
|
-
range = range || this.capsRange;
|
|
136
|
-
this.value = (0, utils_1.decapitalize)(this.value, range);
|
|
137
|
-
if (this.hasMore)
|
|
138
|
-
__classPrivateFieldSet(this, _FirstName_more, __classPrivateFieldGet(this, _FirstName_more, "f").map((n) => (0, utils_1.decapitalize)(n, range)), "f");
|
|
139
|
-
return this;
|
|
140
|
-
}
|
|
141
|
-
copyWith(values) {
|
|
142
|
-
var _a, _b;
|
|
143
|
-
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")));
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
exports.FirstName = FirstName;
|
|
147
|
-
_FirstName_more = new WeakMap();
|
|
148
|
-
class LastName extends Name {
|
|
149
|
-
constructor(father, mother, format = types_1.Surname.FATHER) {
|
|
150
|
-
super(father, types_1.Namon.LAST_NAME);
|
|
151
|
-
this.format = format;
|
|
152
|
-
_LastName_mother.set(this, void 0);
|
|
153
|
-
this.validate(mother);
|
|
154
|
-
__classPrivateFieldSet(this, _LastName_mother, mother, "f");
|
|
155
|
-
}
|
|
156
|
-
get father() {
|
|
157
|
-
return this.value;
|
|
158
|
-
}
|
|
159
|
-
get mother() {
|
|
160
|
-
return __classPrivateFieldGet(this, _LastName_mother, "f");
|
|
161
|
-
}
|
|
162
|
-
get hasMother() {
|
|
163
|
-
return !!__classPrivateFieldGet(this, _LastName_mother, "f");
|
|
164
|
-
}
|
|
165
|
-
get length() {
|
|
166
|
-
var _a, _b;
|
|
167
|
-
return super.length + ((_b = (_a = __classPrivateFieldGet(this, _LastName_mother, "f")) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0);
|
|
168
|
-
}
|
|
169
|
-
get asNames() {
|
|
170
|
-
const names = [Name.last(this.value)];
|
|
171
|
-
if (this.hasMother) {
|
|
172
|
-
names.push(Name.last(__classPrivateFieldGet(this, _LastName_mother, "f")));
|
|
173
|
-
}
|
|
174
|
-
return names;
|
|
175
|
-
}
|
|
176
|
-
toString(format) {
|
|
177
|
-
var _a;
|
|
178
|
-
format = format !== null && format !== void 0 ? format : this.format;
|
|
179
|
-
switch (format) {
|
|
180
|
-
case types_1.Surname.FATHER:
|
|
181
|
-
return this.value;
|
|
182
|
-
case types_1.Surname.MOTHER:
|
|
183
|
-
return (_a = this.mother) !== null && _a !== void 0 ? _a : '';
|
|
184
|
-
case types_1.Surname.HYPHENATED:
|
|
185
|
-
return this.hasMother ? `${this.value}-${__classPrivateFieldGet(this, _LastName_mother, "f")}` : this.value;
|
|
186
|
-
case types_1.Surname.ALL:
|
|
187
|
-
return this.hasMother ? `${this.value} ${__classPrivateFieldGet(this, _LastName_mother, "f")}` : this.value;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
initials(format) {
|
|
191
|
-
format = format || this.format;
|
|
192
|
-
const inits = [];
|
|
193
|
-
switch (format) {
|
|
194
|
-
case types_1.Surname.MOTHER:
|
|
195
|
-
if (this.hasMother)
|
|
196
|
-
inits.push(__classPrivateFieldGet(this, _LastName_mother, "f")[0]);
|
|
197
|
-
break;
|
|
198
|
-
case types_1.Surname.HYPHENATED:
|
|
199
|
-
case types_1.Surname.ALL:
|
|
200
|
-
inits.push(this.initial);
|
|
201
|
-
if (this.hasMother)
|
|
202
|
-
inits.push(__classPrivateFieldGet(this, _LastName_mother, "f")[0]);
|
|
203
|
-
break;
|
|
204
|
-
case types_1.Surname.FATHER:
|
|
205
|
-
default:
|
|
206
|
-
inits.push(this.initial);
|
|
207
|
-
}
|
|
208
|
-
return inits;
|
|
209
|
-
}
|
|
210
|
-
caps(range) {
|
|
211
|
-
range = range || this.capsRange;
|
|
212
|
-
this.value = (0, utils_1.capitalize)(this.value, range);
|
|
213
|
-
if (this.hasMother)
|
|
214
|
-
__classPrivateFieldSet(this, _LastName_mother, (0, utils_1.capitalize)(__classPrivateFieldGet(this, _LastName_mother, "f"), range), "f");
|
|
215
|
-
return this;
|
|
216
|
-
}
|
|
217
|
-
decaps(range) {
|
|
218
|
-
range = range || this.capsRange;
|
|
219
|
-
this.value = (0, utils_1.decapitalize)(this.value, range);
|
|
220
|
-
if (this.hasMother)
|
|
221
|
-
__classPrivateFieldSet(this, _LastName_mother, (0, utils_1.decapitalize)(__classPrivateFieldGet(this, _LastName_mother, "f"), range), "f");
|
|
222
|
-
return this;
|
|
223
|
-
}
|
|
224
|
-
copyWith(values) {
|
|
225
|
-
var _a, _b, _c;
|
|
226
|
-
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);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
exports.LastName = LastName;
|
|
230
|
-
_LastName_mother = new WeakMap();
|
package/dist/lib/namefully.js
DELETED
|
@@ -1,410 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
12
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
13
|
-
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");
|
|
14
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
15
|
-
};
|
|
16
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
17
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
18
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
19
|
-
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");
|
|
20
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
21
|
-
};
|
|
22
|
-
var _Namefully_instances, _Namefully_fullName, _Namefully_toParser, _Namefully_map;
|
|
23
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.Namefully = void 0;
|
|
25
|
-
const constants_1 = require("./constants");
|
|
26
|
-
const error_1 = require("./error");
|
|
27
|
-
const parser_1 = require("./parser");
|
|
28
|
-
const types_1 = require("./types");
|
|
29
|
-
const utils_1 = require("./utils");
|
|
30
|
-
class Namefully {
|
|
31
|
-
constructor(names, options) {
|
|
32
|
-
_Namefully_instances.add(this);
|
|
33
|
-
_Namefully_fullName.set(this, void 0);
|
|
34
|
-
__classPrivateFieldSet(this, _Namefully_fullName, __classPrivateFieldGet(this, _Namefully_instances, "m", _Namefully_toParser).call(this, names).parse(options), "f");
|
|
35
|
-
}
|
|
36
|
-
static tryParse(text) {
|
|
37
|
-
try {
|
|
38
|
-
return new this(parser_1.Parser.build(text));
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
static parse(text) {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
return parser_1.Parser.buildAsync(text).then((parser) => new Namefully(parser));
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
get config() {
|
|
50
|
-
return __classPrivateFieldGet(this, _Namefully_fullName, "f").config;
|
|
51
|
-
}
|
|
52
|
-
get length() {
|
|
53
|
-
return this.birth.length;
|
|
54
|
-
}
|
|
55
|
-
get prefix() {
|
|
56
|
-
var _a;
|
|
57
|
-
return (_a = __classPrivateFieldGet(this, _Namefully_fullName, "f").prefix) === null || _a === void 0 ? void 0 : _a.toString();
|
|
58
|
-
}
|
|
59
|
-
get first() {
|
|
60
|
-
return this.firstName();
|
|
61
|
-
}
|
|
62
|
-
get middle() {
|
|
63
|
-
return this.hasMiddle ? this.middleName()[0] : undefined;
|
|
64
|
-
}
|
|
65
|
-
get hasMiddle() {
|
|
66
|
-
return __classPrivateFieldGet(this, _Namefully_fullName, "f").has(types_1.Namon.MIDDLE_NAME);
|
|
67
|
-
}
|
|
68
|
-
get last() {
|
|
69
|
-
return this.lastName();
|
|
70
|
-
}
|
|
71
|
-
get suffix() {
|
|
72
|
-
var _a;
|
|
73
|
-
return (_a = __classPrivateFieldGet(this, _Namefully_fullName, "f").suffix) === null || _a === void 0 ? void 0 : _a.toString();
|
|
74
|
-
}
|
|
75
|
-
get birth() {
|
|
76
|
-
return this.birthName();
|
|
77
|
-
}
|
|
78
|
-
get short() {
|
|
79
|
-
return this.shorten();
|
|
80
|
-
}
|
|
81
|
-
get long() {
|
|
82
|
-
return this.birth;
|
|
83
|
-
}
|
|
84
|
-
get full() {
|
|
85
|
-
return this.fullName();
|
|
86
|
-
}
|
|
87
|
-
get public() {
|
|
88
|
-
return this.format('f $l');
|
|
89
|
-
}
|
|
90
|
-
toString() {
|
|
91
|
-
return this.full;
|
|
92
|
-
}
|
|
93
|
-
get(namon) {
|
|
94
|
-
if (namon.equal(types_1.Namon.PREFIX))
|
|
95
|
-
return __classPrivateFieldGet(this, _Namefully_fullName, "f").prefix;
|
|
96
|
-
if (namon.equal(types_1.Namon.FIRST_NAME))
|
|
97
|
-
return __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName;
|
|
98
|
-
if (namon.equal(types_1.Namon.MIDDLE_NAME))
|
|
99
|
-
return __classPrivateFieldGet(this, _Namefully_fullName, "f").middleName;
|
|
100
|
-
if (namon.equal(types_1.Namon.LAST_NAME))
|
|
101
|
-
return __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName;
|
|
102
|
-
if (namon.equal(types_1.Namon.SUFFIX))
|
|
103
|
-
return __classPrivateFieldGet(this, _Namefully_fullName, "f").suffix;
|
|
104
|
-
return undefined;
|
|
105
|
-
}
|
|
106
|
-
equal(other) {
|
|
107
|
-
return this.toString() === other.toString();
|
|
108
|
-
}
|
|
109
|
-
toJson() {
|
|
110
|
-
return {
|
|
111
|
-
prefix: this.prefix,
|
|
112
|
-
firstName: this.first,
|
|
113
|
-
middleName: this.middleName(),
|
|
114
|
-
lastName: this.last,
|
|
115
|
-
suffix: this.suffix,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
has(namon) {
|
|
119
|
-
return __classPrivateFieldGet(this, _Namefully_fullName, "f").has(namon);
|
|
120
|
-
}
|
|
121
|
-
fullName(orderedBy) {
|
|
122
|
-
const sep = this.config.ending ? ',' : '';
|
|
123
|
-
const names = [];
|
|
124
|
-
orderedBy = orderedBy || this.config.orderedBy;
|
|
125
|
-
if (this.prefix)
|
|
126
|
-
names.push(this.prefix);
|
|
127
|
-
if (orderedBy === types_1.NameOrder.FIRST_NAME) {
|
|
128
|
-
names.push(this.first, ...this.middleName(), this.last + sep);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
names.push(this.last, this.first, this.middleName().join(' ') + sep);
|
|
132
|
-
}
|
|
133
|
-
if (this.suffix)
|
|
134
|
-
names.push(this.suffix);
|
|
135
|
-
return names.join(' ').trim();
|
|
136
|
-
}
|
|
137
|
-
birthName(orderedBy) {
|
|
138
|
-
orderedBy = orderedBy || this.config.orderedBy;
|
|
139
|
-
return orderedBy === types_1.NameOrder.FIRST_NAME
|
|
140
|
-
? [this.first, ...this.middleName(), this.last].join(' ')
|
|
141
|
-
: [this.last, this.first, ...this.middleName()].join(' ');
|
|
142
|
-
}
|
|
143
|
-
firstName(withMore = true) {
|
|
144
|
-
return __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.toString(withMore);
|
|
145
|
-
}
|
|
146
|
-
middleName() {
|
|
147
|
-
return __classPrivateFieldGet(this, _Namefully_fullName, "f").middleName.map((n) => n.value);
|
|
148
|
-
}
|
|
149
|
-
lastName(format) {
|
|
150
|
-
return __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.toString(format);
|
|
151
|
-
}
|
|
152
|
-
initials(options) {
|
|
153
|
-
const initials = [];
|
|
154
|
-
const firstInits = __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.initials();
|
|
155
|
-
const midInits = __classPrivateFieldGet(this, _Namefully_fullName, "f").middleName.map((n) => n.initials()[0]);
|
|
156
|
-
const lastInits = __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.initials();
|
|
157
|
-
const mergedOptions = Object.assign({ orderedBy: this.config.orderedBy, only: types_1.NameType.BIRTH_NAME }, options);
|
|
158
|
-
const { orderedBy, only } = mergedOptions;
|
|
159
|
-
if (only !== types_1.NameType.BIRTH_NAME) {
|
|
160
|
-
if (only === types_1.NameType.FIRST_NAME) {
|
|
161
|
-
initials.push(...firstInits);
|
|
162
|
-
}
|
|
163
|
-
else if (only === types_1.NameType.MIDDLE_NAME) {
|
|
164
|
-
initials.push(...midInits);
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
initials.push(...lastInits);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
else if (orderedBy === types_1.NameOrder.FIRST_NAME) {
|
|
171
|
-
initials.push(...firstInits, ...midInits, ...lastInits);
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
initials.push(...lastInits, ...firstInits, ...midInits);
|
|
175
|
-
}
|
|
176
|
-
return initials;
|
|
177
|
-
}
|
|
178
|
-
shorten(orderedBy) {
|
|
179
|
-
orderedBy = orderedBy || this.config.orderedBy;
|
|
180
|
-
return orderedBy === types_1.NameOrder.FIRST_NAME
|
|
181
|
-
? [__classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.value, __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.toString()].join(' ')
|
|
182
|
-
: [__classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.toString(), __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.value].join(' ');
|
|
183
|
-
}
|
|
184
|
-
flatten(options) {
|
|
185
|
-
if (this.length <= options.limit)
|
|
186
|
-
return this.full;
|
|
187
|
-
const mergedOptions = Object.assign({ limit: 20, by: types_1.Flat.MIDDLE_NAME, withPeriod: true, recursive: false, withMore: false }, options);
|
|
188
|
-
const { by, limit, recursive, withMore, withPeriod, surname } = mergedOptions;
|
|
189
|
-
const sep = withPeriod ? '.' : '';
|
|
190
|
-
const fn = __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.toString();
|
|
191
|
-
const mn = this.middleName().join(' ');
|
|
192
|
-
const ln = __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.toString();
|
|
193
|
-
const hasMid = this.hasMiddle;
|
|
194
|
-
const f = __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.initials(withMore).join(sep + ' ') + sep;
|
|
195
|
-
const l = __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.initials(surname).join(sep + ' ') + sep;
|
|
196
|
-
const m = hasMid ? __classPrivateFieldGet(this, _Namefully_fullName, "f").middleName.map((n) => n.initials()[0]).join(sep + ' ') + sep : '';
|
|
197
|
-
let name = [];
|
|
198
|
-
if (this.config.orderedBy === types_1.NameOrder.FIRST_NAME) {
|
|
199
|
-
switch (by) {
|
|
200
|
-
case types_1.Flat.FIRST_NAME:
|
|
201
|
-
name = hasMid ? [f, mn, ln] : [f, ln];
|
|
202
|
-
break;
|
|
203
|
-
case types_1.Flat.LAST_NAME:
|
|
204
|
-
name = hasMid ? [fn, mn, l] : [fn, l];
|
|
205
|
-
break;
|
|
206
|
-
case types_1.Flat.MIDDLE_NAME:
|
|
207
|
-
name = hasMid ? [fn, m, ln] : [fn, ln];
|
|
208
|
-
break;
|
|
209
|
-
case types_1.Flat.FIRST_MID:
|
|
210
|
-
name = hasMid ? [f, m, ln] : [f, ln];
|
|
211
|
-
break;
|
|
212
|
-
case types_1.Flat.MID_LAST:
|
|
213
|
-
name = hasMid ? [fn, m, l] : [fn, l];
|
|
214
|
-
break;
|
|
215
|
-
case types_1.Flat.ALL:
|
|
216
|
-
name = hasMid ? [f, m, l] : [f, l];
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
switch (by) {
|
|
222
|
-
case types_1.Flat.FIRST_NAME:
|
|
223
|
-
name = hasMid ? [ln, f, mn] : [ln, f];
|
|
224
|
-
break;
|
|
225
|
-
case types_1.Flat.LAST_NAME:
|
|
226
|
-
name = hasMid ? [l, fn, mn] : [l, fn];
|
|
227
|
-
break;
|
|
228
|
-
case types_1.Flat.MIDDLE_NAME:
|
|
229
|
-
name = hasMid ? [ln, fn, m] : [ln, fn];
|
|
230
|
-
break;
|
|
231
|
-
case types_1.Flat.FIRST_MID:
|
|
232
|
-
name = hasMid ? [ln, f, m] : [ln, f];
|
|
233
|
-
break;
|
|
234
|
-
case types_1.Flat.MID_LAST:
|
|
235
|
-
name = hasMid ? [l, fn, m] : [l, fn];
|
|
236
|
-
break;
|
|
237
|
-
case types_1.Flat.ALL:
|
|
238
|
-
name = hasMid ? [l, f, m] : [l, f];
|
|
239
|
-
break;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
const flat = name.join(' ');
|
|
243
|
-
if (recursive && flat.length > limit) {
|
|
244
|
-
const next = by === types_1.Flat.FIRST_NAME
|
|
245
|
-
? types_1.Flat.MIDDLE_NAME
|
|
246
|
-
: by === types_1.Flat.MIDDLE_NAME
|
|
247
|
-
? types_1.Flat.LAST_NAME
|
|
248
|
-
: by === types_1.Flat.LAST_NAME
|
|
249
|
-
? types_1.Flat.FIRST_MID
|
|
250
|
-
: by === types_1.Flat.FIRST_MID
|
|
251
|
-
? types_1.Flat.MID_LAST
|
|
252
|
-
: by === types_1.Flat.MID_LAST
|
|
253
|
-
? types_1.Flat.ALL
|
|
254
|
-
: by === types_1.Flat.ALL
|
|
255
|
-
? types_1.Flat.ALL
|
|
256
|
-
: by;
|
|
257
|
-
if (next === by)
|
|
258
|
-
return flat;
|
|
259
|
-
return this.flatten(Object.assign(Object.assign({}, options), { by: next }));
|
|
260
|
-
}
|
|
261
|
-
return flat;
|
|
262
|
-
}
|
|
263
|
-
zip(by = types_1.Flat.MID_LAST, withPeriod = true) {
|
|
264
|
-
return this.flatten({ limit: 0, by, withPeriod });
|
|
265
|
-
}
|
|
266
|
-
format(pattern) {
|
|
267
|
-
var _a;
|
|
268
|
-
if (pattern === 'short')
|
|
269
|
-
return this.short;
|
|
270
|
-
if (pattern === 'long')
|
|
271
|
-
return this.long;
|
|
272
|
-
if (pattern === 'public')
|
|
273
|
-
return this.public;
|
|
274
|
-
if (pattern === 'official')
|
|
275
|
-
pattern = 'o';
|
|
276
|
-
let group = '';
|
|
277
|
-
const formatted = [];
|
|
278
|
-
for (const char of pattern.split('')) {
|
|
279
|
-
if (constants_1.ALLOWED_TOKENS.indexOf(char) === -1) {
|
|
280
|
-
throw new error_1.NotAllowedError({
|
|
281
|
-
source: this.full,
|
|
282
|
-
operation: 'format',
|
|
283
|
-
message: `unsupported character <${char}> from ${pattern}.`,
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
group += char;
|
|
287
|
-
if (char === '$')
|
|
288
|
-
continue;
|
|
289
|
-
formatted.push((_a = __classPrivateFieldGet(this, _Namefully_instances, "m", _Namefully_map).call(this, group)) !== null && _a !== void 0 ? _a : '');
|
|
290
|
-
group = '';
|
|
291
|
-
}
|
|
292
|
-
return formatted.join('').trim();
|
|
293
|
-
}
|
|
294
|
-
flip() {
|
|
295
|
-
this.config.updateOrder(this.config.orderedBy === types_1.NameOrder.FIRST_NAME ? types_1.NameOrder.LAST_NAME : types_1.NameOrder.FIRST_NAME);
|
|
296
|
-
}
|
|
297
|
-
split(separator = /[' -]/g) {
|
|
298
|
-
return this.birth.replace(separator, ' ').split(' ');
|
|
299
|
-
}
|
|
300
|
-
join(separator = '') {
|
|
301
|
-
return this.split().join(separator);
|
|
302
|
-
}
|
|
303
|
-
toUpperCase() {
|
|
304
|
-
return this.birth.toUpperCase();
|
|
305
|
-
}
|
|
306
|
-
toLowerCase() {
|
|
307
|
-
return this.birth.toLowerCase();
|
|
308
|
-
}
|
|
309
|
-
toCamelCase() {
|
|
310
|
-
return (0, utils_1.decapitalize)(this.toPascalCase());
|
|
311
|
-
}
|
|
312
|
-
toPascalCase() {
|
|
313
|
-
return this.split()
|
|
314
|
-
.map((n) => (0, utils_1.capitalize)(n))
|
|
315
|
-
.join('');
|
|
316
|
-
}
|
|
317
|
-
toSnakeCase() {
|
|
318
|
-
return this.split()
|
|
319
|
-
.map((n) => n.toLowerCase())
|
|
320
|
-
.join('_');
|
|
321
|
-
}
|
|
322
|
-
toHyphenCase() {
|
|
323
|
-
return this.split()
|
|
324
|
-
.map((n) => n.toLowerCase())
|
|
325
|
-
.join('-');
|
|
326
|
-
}
|
|
327
|
-
toDotCase() {
|
|
328
|
-
return this.split()
|
|
329
|
-
.map((n) => n.toLowerCase())
|
|
330
|
-
.join('.');
|
|
331
|
-
}
|
|
332
|
-
toToggleCase() {
|
|
333
|
-
return (0, utils_1.toggleCase)(this.birth);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
exports.Namefully = Namefully;
|
|
337
|
-
_Namefully_fullName = new WeakMap(), _Namefully_instances = new WeakSet(), _Namefully_toParser = function _Namefully_toParser(raw) {
|
|
338
|
-
if (raw instanceof parser_1.Parser)
|
|
339
|
-
return raw;
|
|
340
|
-
if (typeof raw === 'string')
|
|
341
|
-
return new parser_1.StringParser(raw);
|
|
342
|
-
if ((0, utils_1.isStringArray)(raw))
|
|
343
|
-
return new parser_1.ArrayStringParser(raw);
|
|
344
|
-
if ((0, utils_1.isNameArray)(raw))
|
|
345
|
-
return new parser_1.ArrayNameParser(raw);
|
|
346
|
-
if (typeof raw === 'object')
|
|
347
|
-
return new parser_1.NamaParser(raw);
|
|
348
|
-
throw new error_1.InputError({ source: raw, message: 'Cannot parse raw data. Review expected data types.' });
|
|
349
|
-
}, _Namefully_map = function _Namefully_map(char) {
|
|
350
|
-
var _a, _b;
|
|
351
|
-
switch (char) {
|
|
352
|
-
case '.':
|
|
353
|
-
case ',':
|
|
354
|
-
case ' ':
|
|
355
|
-
case '-':
|
|
356
|
-
case '_':
|
|
357
|
-
return char;
|
|
358
|
-
case 'b':
|
|
359
|
-
return this.birth;
|
|
360
|
-
case 'B':
|
|
361
|
-
return this.birth.toUpperCase();
|
|
362
|
-
case 'f':
|
|
363
|
-
return this.first;
|
|
364
|
-
case 'F':
|
|
365
|
-
return this.first.toUpperCase();
|
|
366
|
-
case 'l':
|
|
367
|
-
return this.last;
|
|
368
|
-
case 'L':
|
|
369
|
-
return this.last.toUpperCase();
|
|
370
|
-
case 'm':
|
|
371
|
-
case 'M':
|
|
372
|
-
return char === 'm' ? this.middleName().join(' ') : this.middleName().join(' ').toUpperCase();
|
|
373
|
-
case 'o':
|
|
374
|
-
case 'O':
|
|
375
|
-
const sep = this.config.ending ? ',' : '';
|
|
376
|
-
const names = [];
|
|
377
|
-
if (this.prefix)
|
|
378
|
-
names.push(this.prefix);
|
|
379
|
-
names.push(`${this.last},`.toUpperCase());
|
|
380
|
-
if (this.hasMiddle) {
|
|
381
|
-
names.push(this.first, this.middleName().join(' ') + sep);
|
|
382
|
-
}
|
|
383
|
-
else {
|
|
384
|
-
names.push(this.first + sep);
|
|
385
|
-
}
|
|
386
|
-
if (this.suffix)
|
|
387
|
-
names.push(this.suffix);
|
|
388
|
-
const nama = names.join(' ').trim();
|
|
389
|
-
return char === 'o' ? nama : nama.toUpperCase();
|
|
390
|
-
case 'p':
|
|
391
|
-
return this.prefix;
|
|
392
|
-
case 'P':
|
|
393
|
-
return (_a = this.prefix) === null || _a === void 0 ? void 0 : _a.toUpperCase();
|
|
394
|
-
case 's':
|
|
395
|
-
return this.suffix;
|
|
396
|
-
case 'S':
|
|
397
|
-
return (_b = this.suffix) === null || _b === void 0 ? void 0 : _b.toUpperCase();
|
|
398
|
-
case '$f':
|
|
399
|
-
case '$F':
|
|
400
|
-
return __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.initials()[0];
|
|
401
|
-
case '$l':
|
|
402
|
-
case '$L':
|
|
403
|
-
return __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.initials()[0];
|
|
404
|
-
case '$m':
|
|
405
|
-
case '$M':
|
|
406
|
-
return this.hasMiddle ? this.middle[0] : undefined;
|
|
407
|
-
default:
|
|
408
|
-
return undefined;
|
|
409
|
-
}
|
|
410
|
-
};
|