namefully 1.2.1 → 1.3.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/builder.js +80 -0
- package/dist/lib/constants.js +1 -1
- package/dist/lib/index.js +3 -0
- package/dist/lib/namefully.js +32 -25
- package/dist/lib/parser.js +9 -3
- package/dist/lib/utils.js +12 -0
- package/dist/lib/validator.js +8 -24
- package/dist/types/builder.d.ts +73 -0
- package/dist/types/constants.d.ts +1 -1
- package/dist/types/index.d.ts +5 -1
- package/dist/types/namefully.d.ts +16 -6
- package/dist/types/parser.d.ts +4 -3
- package/dist/types/utils.d.ts +3 -1
- package/dist/umd/namefully.js +1006 -907
- package/dist/umd/namefully.min.js +1 -1
- package/package.json +20 -17
- package/readme.md +63 -35
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NameBuilder = void 0;
|
|
4
|
+
const namefully_1 = require("./namefully");
|
|
5
|
+
const validator_1 = require("./validator");
|
|
6
|
+
class Builder {
|
|
7
|
+
constructor(prebuild, postbuild, preclear, postclear) {
|
|
8
|
+
this.prebuild = prebuild;
|
|
9
|
+
this.postbuild = postbuild;
|
|
10
|
+
this.preclear = preclear;
|
|
11
|
+
this.postclear = postclear;
|
|
12
|
+
this.queue = [];
|
|
13
|
+
this.instance = null;
|
|
14
|
+
}
|
|
15
|
+
get size() {
|
|
16
|
+
return this.queue.length;
|
|
17
|
+
}
|
|
18
|
+
removeFirst() {
|
|
19
|
+
return this.queue.length > 0 ? this.queue.shift() : undefined;
|
|
20
|
+
}
|
|
21
|
+
removeLast() {
|
|
22
|
+
return this.queue.length > 0 ? this.queue.pop() : undefined;
|
|
23
|
+
}
|
|
24
|
+
addFirst(value) {
|
|
25
|
+
this.queue.unshift(value);
|
|
26
|
+
}
|
|
27
|
+
addLast(value) {
|
|
28
|
+
this.queue.push(value);
|
|
29
|
+
}
|
|
30
|
+
add(...values) {
|
|
31
|
+
this.queue.push(...values);
|
|
32
|
+
}
|
|
33
|
+
remove(value) {
|
|
34
|
+
const index = this.queue.indexOf(value);
|
|
35
|
+
if (index !== -1) {
|
|
36
|
+
this.queue.splice(index, 1);
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
removeWhere(callback) {
|
|
42
|
+
this.queue = this.queue.filter((item) => !callback(item));
|
|
43
|
+
}
|
|
44
|
+
retainWhere(callback) {
|
|
45
|
+
this.queue = this.queue.filter(callback);
|
|
46
|
+
}
|
|
47
|
+
clear() {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
if (this.instance !== null)
|
|
50
|
+
(_a = this.preclear) === null || _a === void 0 ? void 0 : _a.call(this, this.instance);
|
|
51
|
+
this.queue = [];
|
|
52
|
+
(_b = this.postclear) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
53
|
+
this.instance = null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
class NameBuilder extends Builder {
|
|
57
|
+
constructor(names, prebuild, postbuild, preclear, postclear) {
|
|
58
|
+
super(prebuild, postbuild, preclear, postclear);
|
|
59
|
+
this.add(...names);
|
|
60
|
+
}
|
|
61
|
+
static create(name) {
|
|
62
|
+
return new NameBuilder(name ? [name] : []);
|
|
63
|
+
}
|
|
64
|
+
static of(...initialNames) {
|
|
65
|
+
return new NameBuilder(initialNames);
|
|
66
|
+
}
|
|
67
|
+
static use({ names, prebuild, postbuild, preclear, postclear, }) {
|
|
68
|
+
return new NameBuilder(names !== null && names !== void 0 ? names : [], prebuild, postbuild, preclear, postclear);
|
|
69
|
+
}
|
|
70
|
+
build(config) {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
(_a = this.prebuild) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
73
|
+
const names = [...this.queue];
|
|
74
|
+
validator_1.ArrayNameValidator.create().validate(names);
|
|
75
|
+
this.instance = new namefully_1.Namefully(names, config);
|
|
76
|
+
(_b = this.postbuild) === null || _b === void 0 ? void 0 : _b.call(this, this.instance);
|
|
77
|
+
return this.instance;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.NameBuilder = NameBuilder;
|
package/dist/lib/constants.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ALLOWED_TOKENS = exports.MAX_NUMBER_OF_NAME_PARTS = exports.MIN_NUMBER_OF_NAME_PARTS = exports.VERSION = void 0;
|
|
4
|
-
exports.VERSION = '1.
|
|
4
|
+
exports.VERSION = '1.3.0';
|
|
5
5
|
exports.MIN_NUMBER_OF_NAME_PARTS = 2;
|
|
6
6
|
exports.MAX_NUMBER_OF_NAME_PARTS = 5;
|
|
7
7
|
exports.ALLOWED_TOKENS = [
|
package/dist/lib/index.js
CHANGED
|
@@ -15,6 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.NameIndex = exports.Parser = exports.version = void 0;
|
|
18
|
+
const namefully_1 = require("./namefully");
|
|
19
|
+
__exportStar(require("./builder"), exports);
|
|
18
20
|
__exportStar(require("./config"), exports);
|
|
19
21
|
var constants_1 = require("./constants");
|
|
20
22
|
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return constants_1.VERSION; } });
|
|
@@ -27,3 +29,4 @@ Object.defineProperty(exports, "Parser", { enumerable: true, get: function () {
|
|
|
27
29
|
__exportStar(require("./types"), exports);
|
|
28
30
|
var utils_1 = require("./utils");
|
|
29
31
|
Object.defineProperty(exports, "NameIndex", { enumerable: true, get: function () { return utils_1.NameIndex; } });
|
|
32
|
+
exports.default = namefully_1.default;
|
package/dist/lib/namefully.js
CHANGED
|
@@ -33,17 +33,17 @@ class Namefully {
|
|
|
33
33
|
_Namefully_fullName.set(this, void 0);
|
|
34
34
|
__classPrivateFieldSet(this, _Namefully_fullName, __classPrivateFieldGet(this, _Namefully_instances, "m", _Namefully_toParser).call(this, names).parse(options), "f");
|
|
35
35
|
}
|
|
36
|
-
static tryParse(text) {
|
|
36
|
+
static tryParse(text, index) {
|
|
37
37
|
try {
|
|
38
|
-
return new
|
|
38
|
+
return new Namefully(parser_1.Parser.build(text, index));
|
|
39
39
|
}
|
|
40
|
-
catch (
|
|
40
|
+
catch (_a) {
|
|
41
41
|
return undefined;
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
static parse(text) {
|
|
44
|
+
static parse(text, index) {
|
|
45
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
return parser_1.Parser.buildAsync(text).then((parser) => new Namefully(parser));
|
|
46
|
+
return parser_1.Parser.buildAsync(text, index).then((parser) => new Namefully(parser));
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
get config() {
|
|
@@ -87,6 +87,9 @@ class Namefully {
|
|
|
87
87
|
get public() {
|
|
88
88
|
return this.format('f $l');
|
|
89
89
|
}
|
|
90
|
+
get salutation() {
|
|
91
|
+
return this.format('p l');
|
|
92
|
+
}
|
|
90
93
|
toString() {
|
|
91
94
|
return this.full;
|
|
92
95
|
}
|
|
@@ -150,12 +153,13 @@ class Namefully {
|
|
|
150
153
|
return __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.toString(format);
|
|
151
154
|
}
|
|
152
155
|
initials(options) {
|
|
153
|
-
const initials = [];
|
|
154
156
|
const firstInits = __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.initials();
|
|
155
157
|
const midInits = __classPrivateFieldGet(this, _Namefully_fullName, "f").middleName.map((n) => n.initials()[0]);
|
|
156
158
|
const lastInits = __classPrivateFieldGet(this, _Namefully_fullName, "f").lastName.initials();
|
|
157
|
-
|
|
158
|
-
|
|
159
|
+
if (options === null || options === void 0 ? void 0 : options.asJson)
|
|
160
|
+
return { firstName: firstInits, middleName: midInits, lastName: lastInits };
|
|
161
|
+
const initials = [];
|
|
162
|
+
const { orderedBy = this.config.orderedBy, only = types_1.NameType.BIRTH_NAME } = options !== null && options !== void 0 ? options : {};
|
|
159
163
|
if (only !== types_1.NameType.BIRTH_NAME) {
|
|
160
164
|
if (only === types_1.NameType.FIRST_NAME) {
|
|
161
165
|
initials.push(...firstInits);
|
|
@@ -184,8 +188,7 @@ class Namefully {
|
|
|
184
188
|
flatten(options) {
|
|
185
189
|
if (this.length <= options.limit)
|
|
186
190
|
return this.full;
|
|
187
|
-
const
|
|
188
|
-
const { by, limit, recursive, withMore, withPeriod, surname } = mergedOptions;
|
|
191
|
+
const { by = types_1.Flat.MIDDLE_NAME, limit = 20, recursive = false, withMore = false, withPeriod = true, surname, } = options;
|
|
189
192
|
const sep = withPeriod ? '.' : '';
|
|
190
193
|
const fn = __classPrivateFieldGet(this, _Namefully_fullName, "f").firstName.toString();
|
|
191
194
|
const mn = this.middleName().join(' ');
|
|
@@ -372,21 +375,22 @@ _Namefully_fullName = new WeakMap(), _Namefully_instances = new WeakSet(), _Name
|
|
|
372
375
|
return char === 'm' ? this.middleName().join(' ') : this.middleName().join(' ').toUpperCase();
|
|
373
376
|
case 'o':
|
|
374
377
|
case 'O':
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
378
|
+
return ((character) => {
|
|
379
|
+
const sep = this.config.ending ? ',' : '', names = [];
|
|
380
|
+
if (this.prefix)
|
|
381
|
+
names.push(this.prefix);
|
|
382
|
+
names.push(`${this.last},`.toUpperCase());
|
|
383
|
+
if (this.hasMiddle) {
|
|
384
|
+
names.push(this.first, this.middleName().join(' ') + sep);
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
names.push(this.first + sep);
|
|
388
|
+
}
|
|
389
|
+
if (this.suffix)
|
|
390
|
+
names.push(this.suffix);
|
|
391
|
+
const nama = names.join(' ').trim();
|
|
392
|
+
return character === 'o' ? nama : nama.toUpperCase();
|
|
393
|
+
})(char);
|
|
390
394
|
case 'p':
|
|
391
395
|
return this.prefix;
|
|
392
396
|
case 'P':
|
|
@@ -408,3 +412,6 @@ _Namefully_fullName = new WeakMap(), _Namefully_instances = new WeakSet(), _Name
|
|
|
408
412
|
return undefined;
|
|
409
413
|
}
|
|
410
414
|
};
|
|
415
|
+
exports.default = (names, options) => {
|
|
416
|
+
return new Namefully(names, options);
|
|
417
|
+
};
|
package/dist/lib/parser.js
CHANGED
|
@@ -18,9 +18,15 @@ class Parser {
|
|
|
18
18
|
constructor(raw) {
|
|
19
19
|
this.raw = raw;
|
|
20
20
|
}
|
|
21
|
-
static build(text) {
|
|
21
|
+
static build(text, index) {
|
|
22
22
|
const parts = text.trim().split(types_1.Separator.SPACE.token);
|
|
23
23
|
const length = parts.length;
|
|
24
|
+
if (index instanceof utils_1.NameIndex) {
|
|
25
|
+
const names = Object.entries(index.toJson())
|
|
26
|
+
.filter(([, position]) => position > -1 && position < length)
|
|
27
|
+
.map(([key, position]) => new name_1.Name(parts[position], types_1.Namon.all.get(key)));
|
|
28
|
+
return new ArrayNameParser(names);
|
|
29
|
+
}
|
|
24
30
|
if (length < 2) {
|
|
25
31
|
throw new error_1.InputError({
|
|
26
32
|
source: text,
|
|
@@ -36,9 +42,9 @@ class Parser {
|
|
|
36
42
|
return new ArrayStringParser([first, middles.join(' '), last]);
|
|
37
43
|
}
|
|
38
44
|
}
|
|
39
|
-
static buildAsync(text) {
|
|
45
|
+
static buildAsync(text, index) {
|
|
40
46
|
try {
|
|
41
|
-
return Promise.resolve(Parser.build(text));
|
|
47
|
+
return Promise.resolve(Parser.build(text, index));
|
|
42
48
|
}
|
|
43
49
|
catch (error) {
|
|
44
50
|
return Promise.reject(error);
|
package/dist/lib/utils.js
CHANGED
|
@@ -51,6 +51,18 @@ class NameIndex {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
+
static only({ prefix = -1, firstName, middleName = -1, lastName, suffix = -1 }) {
|
|
55
|
+
return new this(prefix, firstName, middleName, lastName, suffix);
|
|
56
|
+
}
|
|
57
|
+
toJson() {
|
|
58
|
+
return {
|
|
59
|
+
prefix: this.prefix,
|
|
60
|
+
firstName: this.firstName,
|
|
61
|
+
middleName: this.middleName,
|
|
62
|
+
lastName: this.lastName,
|
|
63
|
+
suffix: this.suffix,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
54
66
|
}
|
|
55
67
|
exports.NameIndex = NameIndex;
|
|
56
68
|
function capitalize(str, range = types_1.CapsRange.INITIAL) {
|
package/dist/lib/validator.js
CHANGED
|
@@ -226,30 +226,14 @@ class ArrayStringValidator extends ArrayValidator {
|
|
|
226
226
|
}
|
|
227
227
|
validate(values) {
|
|
228
228
|
this.validateIndex(values);
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
Validators.lastName.validate(values[this.index.lastName]);
|
|
238
|
-
break;
|
|
239
|
-
case 4:
|
|
240
|
-
Validators.namon.validate(values[this.index.prefix]);
|
|
241
|
-
Validators.firstName.validate(values[this.index.firstName]);
|
|
242
|
-
Validators.middleName.validate(values[this.index.middleName]);
|
|
243
|
-
Validators.lastName.validate(values[this.index.lastName]);
|
|
244
|
-
break;
|
|
245
|
-
case 5:
|
|
246
|
-
Validators.namon.validate(values[this.index.prefix]);
|
|
247
|
-
Validators.firstName.validate(values[this.index.firstName]);
|
|
248
|
-
Validators.middleName.validate(values[this.index.middleName]);
|
|
249
|
-
Validators.lastName.validate(values[this.index.lastName]);
|
|
250
|
-
Validators.namon.validate(values[this.index.suffix]);
|
|
251
|
-
break;
|
|
252
|
-
}
|
|
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]);
|
|
253
237
|
}
|
|
254
238
|
validateIndex(values) {
|
|
255
239
|
super.validate(values);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Name } from './name';
|
|
2
|
+
import { Namefully } from './namefully';
|
|
3
|
+
import { Config } from './config';
|
|
4
|
+
type VoidCallback = () => void;
|
|
5
|
+
type Callback<Type, Return> = (value: Type) => Return;
|
|
6
|
+
/**
|
|
7
|
+
* A generic builder class that provides common functionality for building instances.
|
|
8
|
+
*/
|
|
9
|
+
declare abstract class Builder<T, I> {
|
|
10
|
+
protected readonly prebuild?: VoidCallback;
|
|
11
|
+
protected readonly postbuild?: Callback<I, void>;
|
|
12
|
+
protected readonly preclear?: Callback<I, void>;
|
|
13
|
+
protected readonly postclear?: VoidCallback;
|
|
14
|
+
protected queue: T[];
|
|
15
|
+
protected instance: I | null;
|
|
16
|
+
constructor(prebuild?: VoidCallback, postbuild?: Callback<I, void>, preclear?: Callback<I, void>, postclear?: VoidCallback);
|
|
17
|
+
/** Gets the current size of the builder. */
|
|
18
|
+
get size(): number;
|
|
19
|
+
/** Removes and returns the first element of the queue. */
|
|
20
|
+
removeFirst(): T | undefined;
|
|
21
|
+
/** Removes and returns the last element of the queue. */
|
|
22
|
+
removeLast(): T | undefined;
|
|
23
|
+
/** Adds a value at the beginning of the queue. */
|
|
24
|
+
addFirst(value: T): void;
|
|
25
|
+
/** Adds a value at the end of the queue. */
|
|
26
|
+
addLast(value: T): void;
|
|
27
|
+
/** Adds a value at the end of the queue. */
|
|
28
|
+
add(...values: T[]): void;
|
|
29
|
+
/** Removes a single instance of a value from the queue. */
|
|
30
|
+
remove(value: T): boolean;
|
|
31
|
+
/** Removes all elements matched by the test function from the queue. */
|
|
32
|
+
removeWhere(callback: Callback<T, boolean>): void;
|
|
33
|
+
/** Removes all elements not matched by the test function from the queue. */
|
|
34
|
+
retainWhere(callback: Callback<T, boolean>): void;
|
|
35
|
+
/** Removes all elements in the queue. */
|
|
36
|
+
clear(): void;
|
|
37
|
+
/** Builds the desired instance with optional parameters. */
|
|
38
|
+
abstract build(options?: Partial<Config>): I;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* An on-the-fly name builder.
|
|
42
|
+
*
|
|
43
|
+
* The builder uses a lazy-building method while capturing all necessary Names
|
|
44
|
+
* to finally construct a complete Namefully instance.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* const builder = NameBuilder.of([Name.first('Thomas'), Name.last('Edison')]);
|
|
48
|
+
* builder.add(Name.middle('Alva'));
|
|
49
|
+
* console.log(builder.build()); // 'Thomas Alva Edison'
|
|
50
|
+
*/
|
|
51
|
+
export declare class NameBuilder extends Builder<Name, Namefully> {
|
|
52
|
+
private constructor();
|
|
53
|
+
/** Creates a base builder from one Name to construct Namefully later. */
|
|
54
|
+
static create(name?: Name): NameBuilder;
|
|
55
|
+
/** Creates a base builder from many Names to construct Namefully later. */
|
|
56
|
+
static of(...initialNames: Name[]): NameBuilder;
|
|
57
|
+
/** Creates a base builder from many Names with lifecycle hooks. */
|
|
58
|
+
static use({ names, prebuild, postbuild, preclear, postclear, }: {
|
|
59
|
+
names?: Name[];
|
|
60
|
+
prebuild?: VoidCallback;
|
|
61
|
+
postbuild?: Callback<Namefully, void>;
|
|
62
|
+
preclear?: Callback<Namefully, void>;
|
|
63
|
+
postclear?: VoidCallback;
|
|
64
|
+
}): NameBuilder;
|
|
65
|
+
/**
|
|
66
|
+
* Builds an instance of Namefully from the previously collected names.
|
|
67
|
+
*
|
|
68
|
+
* Regardless of how the names are added, both first and last names must exist
|
|
69
|
+
* to complete a fine build. Otherwise, it throws a NameException.
|
|
70
|
+
*/
|
|
71
|
+
build(config?: Partial<Config>): Namefully;
|
|
72
|
+
}
|
|
73
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Welcome to namefully!
|
|
3
3
|
*
|
|
4
|
-
* `namefully` is a JavaScript utility for
|
|
4
|
+
* `namefully` is a JavaScript utility for handling personal names.
|
|
5
5
|
*
|
|
6
6
|
* Sources
|
|
7
7
|
* - repo: https://github.com/ralflorent/namefully
|
|
8
8
|
* - docs: https://namefully.netlify.app
|
|
9
9
|
* - npm: https://npmjs.com/package/namefully
|
|
10
|
+
* - jsr: https://jsr.io/@ralflorent/namefully
|
|
10
11
|
*
|
|
11
12
|
* @license MIT
|
|
12
13
|
*/
|
|
14
|
+
import namefully from './namefully';
|
|
15
|
+
export * from './builder';
|
|
13
16
|
export * from './config';
|
|
14
17
|
export { VERSION as version } from './constants';
|
|
15
18
|
export * from './error';
|
|
@@ -19,3 +22,4 @@ export * from './namefully';
|
|
|
19
22
|
export { Parser } from './parser';
|
|
20
23
|
export * from './types';
|
|
21
24
|
export { NameIndex } from './utils';
|
|
25
|
+
export default namefully;
|
|
@@ -2,6 +2,7 @@ import { Config } from './config';
|
|
|
2
2
|
import { Name, JsonName } from './name';
|
|
3
3
|
import { Parser } from './parser';
|
|
4
4
|
import { Flat, NameOrder, NameType, Namon, Nullable, Surname } from './types';
|
|
5
|
+
import { NameIndex } from './utils';
|
|
5
6
|
/**
|
|
6
7
|
* A helper for organizing person names in a particular order, way, or shape.
|
|
7
8
|
*
|
|
@@ -29,7 +30,7 @@ import { Flat, NameOrder, NameType, Namon, Nullable, Surname } from './types';
|
|
|
29
30
|
* this: `John Smith`, where `John` is the first name piece and `Smith`, the last
|
|
30
31
|
* name piece.
|
|
31
32
|
*
|
|
32
|
-
* @see https://
|
|
33
|
+
* @see https://www.fbiic.gov/public/2008/nov/Naming_practice_guide_UK_2006.pdf
|
|
33
34
|
* for more info on name standards.
|
|
34
35
|
*
|
|
35
36
|
* **IMPORTANT**: Keep in mind that the order of appearance (or name order) matters
|
|
@@ -48,8 +49,7 @@ import { Flat, NameOrder, NameType, Namon, Nullable, Surname } from './types';
|
|
|
48
49
|
*/
|
|
49
50
|
export declare class Namefully {
|
|
50
51
|
#private;
|
|
51
|
-
/**
|
|
52
|
-
* Creates a name with distinguishable parts from a raw string content.
|
|
52
|
+
/** Creates a name with distinguishable parts from a raw string content.
|
|
53
53
|
* @param names element to parse.
|
|
54
54
|
* @param options additional settings.
|
|
55
55
|
*
|
|
@@ -64,7 +64,7 @@ export declare class Namefully {
|
|
|
64
64
|
* It works like `parse` except that this function returns `null` where `parse`
|
|
65
65
|
* would throw a `NameError`.
|
|
66
66
|
*/
|
|
67
|
-
static tryParse(text: string): Namefully | undefined;
|
|
67
|
+
static tryParse(text: string, index?: NameIndex): Namefully | undefined;
|
|
68
68
|
/**
|
|
69
69
|
* Constructs a `Namefully` instance from a text.
|
|
70
70
|
*
|
|
@@ -80,7 +80,7 @@ export declare class Namefully {
|
|
|
80
80
|
* Keep in mind that prefix and suffix are not considered during the parsing
|
|
81
81
|
* process.
|
|
82
82
|
*/
|
|
83
|
-
static parse(text: string): Promise<Namefully>;
|
|
83
|
+
static parse(text: string, index?: NameIndex): Promise<Namefully>;
|
|
84
84
|
/** The current configuration. */
|
|
85
85
|
get config(): Config;
|
|
86
86
|
/** The number of characters of the `birthName`, including spaces. */
|
|
@@ -107,6 +107,8 @@ export declare class Namefully {
|
|
|
107
107
|
get full(): string;
|
|
108
108
|
/** The first name combined with the last name's initial. */
|
|
109
109
|
get public(): string;
|
|
110
|
+
/** The combination of prefix and last name. */
|
|
111
|
+
get salutation(): string;
|
|
110
112
|
/** Returns the full name as set. */
|
|
111
113
|
toString(): string;
|
|
112
114
|
/** Fetches the raw form of a name piece. */
|
|
@@ -171,7 +173,8 @@ export declare class Namefully {
|
|
|
171
173
|
initials(options?: {
|
|
172
174
|
orderedBy?: NameOrder;
|
|
173
175
|
only?: NameType;
|
|
174
|
-
|
|
176
|
+
asJson?: boolean;
|
|
177
|
+
}): string[] | Record<string, string[]>;
|
|
175
178
|
/**
|
|
176
179
|
* Shortens a complex full name to a simple typical name, a combination of
|
|
177
180
|
* first and last name.
|
|
@@ -311,3 +314,10 @@ export declare class Namefully {
|
|
|
311
314
|
/** Transforms a birth name into ToGgLeCaSe. */
|
|
312
315
|
toToggleCase(): string;
|
|
313
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* A default export for the `namefully` utility.
|
|
319
|
+
* @param names element to parse.
|
|
320
|
+
* @param options additional settings.
|
|
321
|
+
*/
|
|
322
|
+
declare const _default: (names: string | string[] | Name[] | JsonName | Parser, options?: Partial<Config>) => Namefully;
|
|
323
|
+
export default _default;
|
package/dist/types/parser.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { FullName } from './full-name';
|
|
2
2
|
import { Config } from './config';
|
|
3
|
+
import { NameIndex } from './utils';
|
|
3
4
|
import { Name, JsonName } from './name';
|
|
4
5
|
/**
|
|
5
6
|
* A parser signature that helps to organize the names accordingly.
|
|
6
7
|
*/
|
|
7
|
-
export declare abstract class Parser<T =
|
|
8
|
+
export declare abstract class Parser<T = unknown> {
|
|
8
9
|
raw: T;
|
|
9
10
|
/**
|
|
10
11
|
* Constructs a custom parser accordingly.
|
|
@@ -15,11 +16,11 @@ export declare abstract class Parser<T = any> {
|
|
|
15
16
|
* Builds a dynamic `Parser` on the fly and throws a `NameError` when unable
|
|
16
17
|
* to do so. The built parser only knows how to operate birth names.
|
|
17
18
|
*/
|
|
18
|
-
static build(text: string): Parser;
|
|
19
|
+
static build(text: string, index?: NameIndex): Parser;
|
|
19
20
|
/**
|
|
20
21
|
* Builds asynchronously a dynamic `Parser`.
|
|
21
22
|
*/
|
|
22
|
-
static buildAsync(text: string): Promise<Parser>;
|
|
23
|
+
static buildAsync(text: string, index?: NameIndex): Promise<Parser>;
|
|
23
24
|
/**
|
|
24
25
|
* Parses the raw data into a `FullName` while considering some options.
|
|
25
26
|
* @param options additional configuration to apply.
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare class NameIndex {
|
|
|
32
32
|
static get min(): number;
|
|
33
33
|
/** The maximum number of parts in a list of names. */
|
|
34
34
|
static get max(): number;
|
|
35
|
-
|
|
35
|
+
protected constructor(prefix: number, firstName: number, middleName: number, lastName: number, suffix: number);
|
|
36
36
|
/** The default or base indexing: firstName lastName. */
|
|
37
37
|
static base(): NameIndex;
|
|
38
38
|
/**
|
|
@@ -40,6 +40,8 @@ export declare class NameIndex {
|
|
|
40
40
|
* and their `order` of appearance.
|
|
41
41
|
*/
|
|
42
42
|
static when(order: NameOrder, count?: number): NameIndex;
|
|
43
|
+
static only({ prefix, firstName, middleName, lastName, suffix }: Record<string, number>): NameIndex;
|
|
44
|
+
toJson(): Record<string, number>;
|
|
43
45
|
}
|
|
44
46
|
/**
|
|
45
47
|
* Capitalizes a string via a `CapsRange` option.
|