namefully 1.3.0 → 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/{lib → cjs}/builder.js +15 -13
- 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 -15
- 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 +17 -17
- package/dist/cjs/validator.js +266 -0
- package/dist/{types → esm}/builder.d.ts +8 -8
- 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 +8 -8
- package/dist/esm/namefully.js +387 -0
- package/dist/esm/package.json +1 -0
- package/dist/{types → esm}/parser.d.ts +4 -4
- package/dist/esm/parser.js +127 -0
- package/dist/esm/types.js +106 -0
- package/dist/{types → esm}/utils.d.ts +1 -2
- 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 +44 -27
- package/readme.md +1 -1
- 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 -417
- package/dist/lib/parser.js +0 -144
- package/dist/lib/validator.js +0 -285
- package/dist/types/index.d.ts +0 -25
- package/dist/umd/namefully.js +0 -1931
- package/dist/umd/namefully.min.js +0 -1
- /package/dist/{types → esm}/types.d.ts +0 -0
package/dist/lib/validator.js
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
|
-
};
|
|
13
|
-
var _a, _NamonValidator_validator, _b, _FirstNameValidator_validator, _c, _MiddleNameValidator_validator, _d, _LastNameValidator_validator, _e, _NameValidator_validator, _f, _NamaValidator_validator, _ArrayNameValidator_instances, _g, _ArrayNameValidator_validator, _ArrayNameValidator_hasBasicNames;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.Validators = exports.ArrayNameValidator = exports.ArrayStringValidator = exports.NamaValidator = void 0;
|
|
16
|
-
const constants_1 = require("./constants");
|
|
17
|
-
const error_1 = require("./error");
|
|
18
|
-
const name_1 = require("./name");
|
|
19
|
-
const types_1 = require("./types");
|
|
20
|
-
const utils_1 = require("./utils");
|
|
21
|
-
class ValidationRule {
|
|
22
|
-
}
|
|
23
|
-
ValidationRule.base = /[a-zA-Z\u00C0-\u00D6\u00D8-\u00f6\u00f8-\u00ff\u0400-\u04FFΆ-ωΑ-ώ]/;
|
|
24
|
-
ValidationRule.namon = new RegExp(`^${ValidationRule.base.source}+(([' -]${ValidationRule.base.source})?${ValidationRule.base.source}*)*$`);
|
|
25
|
-
ValidationRule.firstName = ValidationRule.namon;
|
|
26
|
-
ValidationRule.middleName = new RegExp(`^${ValidationRule.base.source}+(([' -]${ValidationRule.base.source})?${ValidationRule.base.source}*)*$`);
|
|
27
|
-
ValidationRule.lastName = ValidationRule.namon;
|
|
28
|
-
class ArrayValidator {
|
|
29
|
-
validate(values) {
|
|
30
|
-
if (values.length === 0 || values.length < constants_1.MIN_NUMBER_OF_NAME_PARTS || values.length > constants_1.MAX_NUMBER_OF_NAME_PARTS) {
|
|
31
|
-
throw new error_1.InputError({
|
|
32
|
-
source: values.map((n) => n.toString()),
|
|
33
|
-
message: `expecting a list of ${constants_1.MIN_NUMBER_OF_NAME_PARTS}-${constants_1.MIN_NUMBER_OF_NAME_PARTS} elements`,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
class NamonValidator {
|
|
39
|
-
static create() {
|
|
40
|
-
return __classPrivateFieldGet(this, _a, "f", _NamonValidator_validator) || (__classPrivateFieldSet(this, _a, new this(), "f", _NamonValidator_validator));
|
|
41
|
-
}
|
|
42
|
-
validate(value, type) {
|
|
43
|
-
if (value instanceof name_1.Name) {
|
|
44
|
-
NameValidator.create().validate(value, type);
|
|
45
|
-
}
|
|
46
|
-
else if (typeof value === 'string') {
|
|
47
|
-
if (!ValidationRule.namon.test(value)) {
|
|
48
|
-
throw new error_1.ValidationError({
|
|
49
|
-
source: value,
|
|
50
|
-
nameType: 'namon',
|
|
51
|
-
message: 'invalid content',
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
throw new error_1.InputError({
|
|
57
|
-
source: typeof value,
|
|
58
|
-
message: 'expecting types of string | Name',
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
_a = NamonValidator;
|
|
64
|
-
_NamonValidator_validator = { value: void 0 };
|
|
65
|
-
class FirstNameValidator {
|
|
66
|
-
static create() {
|
|
67
|
-
return __classPrivateFieldGet(this, _b, "f", _FirstNameValidator_validator) || (__classPrivateFieldSet(this, _b, new this(), "f", _FirstNameValidator_validator));
|
|
68
|
-
}
|
|
69
|
-
validate(value) {
|
|
70
|
-
if (value instanceof name_1.FirstName) {
|
|
71
|
-
value.asNames.forEach((name) => this.validate(name.value));
|
|
72
|
-
}
|
|
73
|
-
else if (typeof value === 'string') {
|
|
74
|
-
if (!ValidationRule.firstName.test(value)) {
|
|
75
|
-
throw new error_1.ValidationError({
|
|
76
|
-
source: value,
|
|
77
|
-
nameType: 'firstName',
|
|
78
|
-
message: 'invalid content',
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
throw new error_1.InputError({
|
|
84
|
-
source: typeof value,
|
|
85
|
-
message: 'expecting types string | FirstName',
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
_b = FirstNameValidator;
|
|
91
|
-
_FirstNameValidator_validator = { value: void 0 };
|
|
92
|
-
class MiddleNameValidator {
|
|
93
|
-
static create() {
|
|
94
|
-
return __classPrivateFieldGet(this, _c, "f", _MiddleNameValidator_validator) || (__classPrivateFieldSet(this, _c, new this(), "f", _MiddleNameValidator_validator));
|
|
95
|
-
}
|
|
96
|
-
validate(value) {
|
|
97
|
-
if (typeof value === 'string') {
|
|
98
|
-
if (!ValidationRule.middleName.test(value)) {
|
|
99
|
-
throw new error_1.ValidationError({
|
|
100
|
-
source: value,
|
|
101
|
-
nameType: 'middleName',
|
|
102
|
-
message: 'invalid content',
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
else if (Array.isArray(value)) {
|
|
107
|
-
try {
|
|
108
|
-
const validator = NamonValidator.create();
|
|
109
|
-
for (const name of value)
|
|
110
|
-
validator.validate(name, types_1.Namon.MIDDLE_NAME);
|
|
111
|
-
}
|
|
112
|
-
catch (error) {
|
|
113
|
-
throw new error_1.ValidationError({
|
|
114
|
-
source: value,
|
|
115
|
-
nameType: 'middleName',
|
|
116
|
-
message: error === null || error === void 0 ? void 0 : error.message,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
throw new error_1.InputError({
|
|
122
|
-
source: typeof value,
|
|
123
|
-
message: 'expecting types of string | string[] | Name[]',
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
_c = MiddleNameValidator;
|
|
129
|
-
_MiddleNameValidator_validator = { value: void 0 };
|
|
130
|
-
class LastNameValidator {
|
|
131
|
-
static create() {
|
|
132
|
-
return __classPrivateFieldGet(this, _d, "f", _LastNameValidator_validator) || (__classPrivateFieldSet(this, _d, new this(), "f", _LastNameValidator_validator));
|
|
133
|
-
}
|
|
134
|
-
validate(value) {
|
|
135
|
-
if (value instanceof name_1.LastName) {
|
|
136
|
-
value.asNames.forEach((name) => this.validate(name.value));
|
|
137
|
-
}
|
|
138
|
-
else if (typeof value === 'string') {
|
|
139
|
-
if (!ValidationRule.lastName.test(value)) {
|
|
140
|
-
throw new error_1.ValidationError({
|
|
141
|
-
source: value,
|
|
142
|
-
nameType: 'lastName',
|
|
143
|
-
message: 'invalid content',
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
throw new error_1.InputError({
|
|
149
|
-
source: typeof value,
|
|
150
|
-
message: 'expecting types string | LastName',
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
_d = LastNameValidator;
|
|
156
|
-
_LastNameValidator_validator = { value: void 0 };
|
|
157
|
-
class NameValidator {
|
|
158
|
-
static create() {
|
|
159
|
-
return __classPrivateFieldGet(this, _e, "f", _NameValidator_validator) || (__classPrivateFieldSet(this, _e, new this(), "f", _NameValidator_validator));
|
|
160
|
-
}
|
|
161
|
-
validate(name, type) {
|
|
162
|
-
if (type && name.type !== type) {
|
|
163
|
-
throw new error_1.ValidationError({
|
|
164
|
-
source: [name],
|
|
165
|
-
nameType: name.type.toString(),
|
|
166
|
-
message: 'wrong type',
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
if (!ValidationRule.namon.test(name.value)) {
|
|
170
|
-
throw new error_1.ValidationError({
|
|
171
|
-
source: [name],
|
|
172
|
-
nameType: name.type.toString(),
|
|
173
|
-
message: 'invalid content',
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
_e = NameValidator;
|
|
179
|
-
_NameValidator_validator = { value: void 0 };
|
|
180
|
-
class NamaValidator {
|
|
181
|
-
static create() {
|
|
182
|
-
return __classPrivateFieldGet(this, _f, "f", _NamaValidator_validator) || (__classPrivateFieldSet(this, _f, new this(), "f", _NamaValidator_validator));
|
|
183
|
-
}
|
|
184
|
-
validate(value) {
|
|
185
|
-
this.validateKeys(value);
|
|
186
|
-
Validators.firstName.validate(value.get(types_1.Namon.FIRST_NAME));
|
|
187
|
-
Validators.lastName.validate(value.get(types_1.Namon.LAST_NAME));
|
|
188
|
-
if (value.has(types_1.Namon.PREFIX)) {
|
|
189
|
-
Validators.namon.validate(value.get(types_1.Namon.PREFIX));
|
|
190
|
-
}
|
|
191
|
-
if (value.has(types_1.Namon.SUFFIX)) {
|
|
192
|
-
Validators.namon.validate(value.get(types_1.Namon.SUFFIX));
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
validateKeys(nama) {
|
|
196
|
-
if (!nama.size) {
|
|
197
|
-
throw new error_1.InputError({ source: undefined, message: 'Map<k,v> must not be empty' });
|
|
198
|
-
}
|
|
199
|
-
else if (nama.size < constants_1.MIN_NUMBER_OF_NAME_PARTS || nama.size > constants_1.MAX_NUMBER_OF_NAME_PARTS) {
|
|
200
|
-
throw new error_1.InputError({
|
|
201
|
-
source: [...nama.values()],
|
|
202
|
-
message: `expecting ${constants_1.MIN_NUMBER_OF_NAME_PARTS}-${constants_1.MIN_NUMBER_OF_NAME_PARTS} fields`,
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
if (!nama.has(types_1.Namon.FIRST_NAME)) {
|
|
206
|
-
throw new error_1.InputError({
|
|
207
|
-
source: [...nama.values()],
|
|
208
|
-
message: '"firstName" is a required key',
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
if (!nama.has(types_1.Namon.LAST_NAME)) {
|
|
212
|
-
throw new error_1.InputError({
|
|
213
|
-
source: [...nama.values()],
|
|
214
|
-
message: '"lastName" is a required key',
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
exports.NamaValidator = NamaValidator;
|
|
220
|
-
_f = NamaValidator;
|
|
221
|
-
_NamaValidator_validator = { value: void 0 };
|
|
222
|
-
class ArrayStringValidator extends ArrayValidator {
|
|
223
|
-
constructor(index = utils_1.NameIndex.base()) {
|
|
224
|
-
super();
|
|
225
|
-
this.index = index;
|
|
226
|
-
}
|
|
227
|
-
validate(values) {
|
|
228
|
-
this.validateIndex(values);
|
|
229
|
-
Validators.firstName.validate(values[this.index.firstName]);
|
|
230
|
-
Validators.lastName.validate(values[this.index.lastName]);
|
|
231
|
-
if (values.length >= 3)
|
|
232
|
-
Validators.middleName.validate(values[this.index.middleName]);
|
|
233
|
-
if (values.length >= 4)
|
|
234
|
-
Validators.namon.validate(values[this.index.prefix]);
|
|
235
|
-
if (values.length === 5)
|
|
236
|
-
Validators.namon.validate(values[this.index.suffix]);
|
|
237
|
-
}
|
|
238
|
-
validateIndex(values) {
|
|
239
|
-
super.validate(values);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
exports.ArrayStringValidator = ArrayStringValidator;
|
|
243
|
-
class ArrayNameValidator {
|
|
244
|
-
constructor() {
|
|
245
|
-
_ArrayNameValidator_instances.add(this);
|
|
246
|
-
}
|
|
247
|
-
static create() {
|
|
248
|
-
return __classPrivateFieldGet(this, _g, "f", _ArrayNameValidator_validator) || (__classPrivateFieldSet(this, _g, new this(), "f", _ArrayNameValidator_validator));
|
|
249
|
-
}
|
|
250
|
-
validate(value) {
|
|
251
|
-
if (value.length < constants_1.MIN_NUMBER_OF_NAME_PARTS) {
|
|
252
|
-
throw new error_1.InputError({
|
|
253
|
-
source: value,
|
|
254
|
-
message: `expecting at least ${constants_1.MIN_NUMBER_OF_NAME_PARTS} elements`,
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
if (!__classPrivateFieldGet(this, _ArrayNameValidator_instances, "m", _ArrayNameValidator_hasBasicNames).call(this, value)) {
|
|
258
|
-
throw new error_1.InputError({
|
|
259
|
-
source: value,
|
|
260
|
-
message: 'both first and last names are required',
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
exports.ArrayNameValidator = ArrayNameValidator;
|
|
266
|
-
_g = ArrayNameValidator, _ArrayNameValidator_instances = new WeakSet(), _ArrayNameValidator_hasBasicNames = function _ArrayNameValidator_hasBasicNames(names) {
|
|
267
|
-
const accumulator = {};
|
|
268
|
-
for (const name of names) {
|
|
269
|
-
if (name.isFirstName || name.isLastName) {
|
|
270
|
-
accumulator[name.type.key] = name.toString();
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
return Object.keys(accumulator).length === constants_1.MIN_NUMBER_OF_NAME_PARTS;
|
|
274
|
-
};
|
|
275
|
-
_ArrayNameValidator_validator = { value: void 0 };
|
|
276
|
-
class Validators {
|
|
277
|
-
}
|
|
278
|
-
exports.Validators = Validators;
|
|
279
|
-
Validators.namon = NamonValidator.create();
|
|
280
|
-
Validators.nama = NamaValidator.create();
|
|
281
|
-
Validators.prefix = NamonValidator.create();
|
|
282
|
-
Validators.firstName = FirstNameValidator.create();
|
|
283
|
-
Validators.middleName = MiddleNameValidator.create();
|
|
284
|
-
Validators.lastName = LastNameValidator.create();
|
|
285
|
-
Validators.suffix = NamonValidator.create();
|
package/dist/types/index.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Welcome to namefully!
|
|
3
|
-
*
|
|
4
|
-
* `namefully` is a JavaScript utility for handling personal names.
|
|
5
|
-
*
|
|
6
|
-
* Sources
|
|
7
|
-
* - repo: https://github.com/ralflorent/namefully
|
|
8
|
-
* - docs: https://namefully.netlify.app
|
|
9
|
-
* - npm: https://npmjs.com/package/namefully
|
|
10
|
-
* - jsr: https://jsr.io/@ralflorent/namefully
|
|
11
|
-
*
|
|
12
|
-
* @license MIT
|
|
13
|
-
*/
|
|
14
|
-
import namefully from './namefully';
|
|
15
|
-
export * from './builder';
|
|
16
|
-
export * from './config';
|
|
17
|
-
export { VERSION as version } from './constants';
|
|
18
|
-
export * from './error';
|
|
19
|
-
export * from './full-name';
|
|
20
|
-
export * from './name';
|
|
21
|
-
export * from './namefully';
|
|
22
|
-
export { Parser } from './parser';
|
|
23
|
-
export * from './types';
|
|
24
|
-
export { NameIndex } from './utils';
|
|
25
|
-
export default namefully;
|