namefully 1.0.9 → 1.2.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/LICENSE +21 -674
- package/dist/example/index.js +2734 -0
- package/dist/lib/config.d.ts +121 -0
- package/dist/lib/config.js +189 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/constants.d.ts +4 -0
- package/dist/lib/constants.js +31 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/error.d.ts +172 -0
- package/dist/lib/error.js +210 -0
- package/dist/lib/error.js.map +1 -0
- package/dist/lib/{usecases/index.d.ts → example/example.d.ts} +0 -0
- package/dist/lib/full-name.d.ts +71 -0
- package/dist/lib/full-name.js +147 -0
- package/dist/lib/full-name.js.map +1 -0
- package/dist/lib/index.d.ts +16 -6
- package/dist/lib/index.js +29 -8
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/name.d.ts +177 -0
- package/dist/lib/name.js +322 -0
- package/dist/lib/name.js.map +1 -0
- package/dist/lib/namefully.d.ts +303 -208
- package/dist/lib/namefully.js +603 -442
- package/dist/lib/namefully.js.map +1 -1
- package/dist/lib/parser.d.ts +46 -0
- package/dist/lib/parser.js +173 -0
- package/dist/lib/parser.js.map +1 -0
- package/dist/lib/src/config.d.ts +121 -0
- package/dist/lib/src/constants.d.ts +4 -0
- package/dist/lib/src/error.d.ts +172 -0
- package/dist/lib/src/full-name.d.ts +71 -0
- package/dist/lib/src/index.d.ts +16 -6
- package/dist/lib/src/name.d.ts +177 -0
- package/dist/lib/src/namefully.d.ts +303 -208
- package/dist/lib/src/parser.d.ts +46 -0
- package/dist/lib/src/types.d.ts +127 -0
- package/dist/lib/src/utils.d.ts +63 -0
- package/dist/lib/src/validator.d.ts +66 -0
- package/dist/lib/types.d.ts +127 -0
- package/dist/lib/types.js +181 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utils.d.ts +63 -0
- package/dist/lib/utils.js +138 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/lib/validator.d.ts +66 -0
- package/dist/lib/validator.js +332 -0
- package/dist/lib/validator.js.map +1 -0
- package/dist/umd/namefully.js +2191 -2111
- package/dist/umd/namefully.js.map +1 -1
- package/dist/umd/namefully.min.js +1 -1
- package/dist/umd/namefully.min.js.LICENSE.txt +8 -20
- package/dist/umd/namefully.min.js.map +1 -1
- package/package.json +50 -53
- package/readme.md +151 -175
- package/changelog.md +0 -114
- package/dist/lib/core/constants.d.ts +0 -26
- package/dist/lib/core/constants.js +0 -42
- package/dist/lib/core/constants.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 -42
- package/dist/lib/core/parsers/array-name.parser.js +0 -84
- package/dist/lib/core/parsers/array-name.parser.js.map +0 -1
- package/dist/lib/core/parsers/array-string.parser.d.ts +0 -48
- package/dist/lib/core/parsers/array-string.parser.js +0 -96
- 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 -34
- package/dist/lib/core/parsers/nama.parser.js +0 -75
- package/dist/lib/core/parsers/nama.parser.js.map +0 -1
- package/dist/lib/core/parsers/parser.d.ts +0 -29
- 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 -61
- package/dist/lib/core/parsers/string.parser.js +0 -63
- package/dist/lib/core/parsers/string.parser.js.map +0 -1
- package/dist/lib/core/utils/utils.d.ts +0 -14
- package/dist/lib/core/utils/utils.js +0 -67
- package/dist/lib/core/utils/utils.js.map +0 -1
- package/dist/lib/models/enums.d.ts +0 -91
- package/dist/lib/models/enums.js +0 -98
- package/dist/lib/models/enums.js.map +0 -1
- package/dist/lib/models/firstname.d.ts +0 -41
- package/dist/lib/models/firstname.js +0 -59
- package/dist/lib/models/firstname.js.map +0 -1
- package/dist/lib/models/index.d.ts +0 -12
- package/dist/lib/models/index.js +0 -15
- package/dist/lib/models/index.js.map +0 -1
- package/dist/lib/models/lastname.d.ts +0 -44
- package/dist/lib/models/lastname.js +0 -86
- package/dist/lib/models/lastname.js.map +0 -1
- package/dist/lib/models/misc.d.ts +0 -80
- 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 -48
- package/dist/lib/models/name.js +0 -72
- package/dist/lib/models/name.js.map +0 -1
- package/dist/lib/models/summary.d.ts +0 -23
- package/dist/lib/models/summary.js +0 -60
- package/dist/lib/models/summary.js.map +0 -1
- package/dist/lib/src/core/constants.d.ts +0 -26
- package/dist/lib/src/core/index.d.ts +0 -9
- package/dist/lib/src/core/parsers/array-name.parser.d.ts +0 -42
- package/dist/lib/src/core/parsers/array-string.parser.d.ts +0 -48
- package/dist/lib/src/core/parsers/index.d.ts +0 -11
- package/dist/lib/src/core/parsers/nama.parser.d.ts +0 -34
- package/dist/lib/src/core/parsers/parser.d.ts +0 -29
- package/dist/lib/src/core/parsers/string.parser.d.ts +0 -61
- package/dist/lib/src/core/utils/utils.d.ts +0 -14
- package/dist/lib/src/models/enums.d.ts +0 -91
- package/dist/lib/src/models/firstname.d.ts +0 -41
- package/dist/lib/src/models/index.d.ts +0 -12
- package/dist/lib/src/models/lastname.d.ts +0 -44
- package/dist/lib/src/models/misc.d.ts +0 -80
- package/dist/lib/src/models/name.d.ts +0 -48
- package/dist/lib/src/models/summary.d.ts +0 -23
- package/dist/lib/src/validators/array-name.validator.d.ts +0 -25
- package/dist/lib/src/validators/array-string.validator.d.ts +0 -43
- package/dist/lib/src/validators/common/validation-error.d.ts +0 -19
- package/dist/lib/src/validators/common/validation-rule.d.ts +0 -69
- package/dist/lib/src/validators/common/validation-type.d.ts +0 -24
- package/dist/lib/src/validators/firstname.validator.d.ts +0 -20
- package/dist/lib/src/validators/fullname.validator.d.ts +0 -21
- package/dist/lib/src/validators/index.d.ts +0 -21
- package/dist/lib/src/validators/lastname.validator.d.ts +0 -20
- package/dist/lib/src/validators/middlename.validator.d.ts +0 -20
- package/dist/lib/src/validators/nama.validator.d.ts +0 -21
- package/dist/lib/src/validators/namon.validator.d.ts +0 -20
- package/dist/lib/src/validators/prefix.validator.d.ts +0 -14
- package/dist/lib/src/validators/string-name.validator.d.ts +0 -20
- package/dist/lib/src/validators/suffix.validator.d.ts +0 -14
- package/dist/lib/src/validators/validator.d.ts +0 -13
- package/dist/lib/usecases/compress.usecase.d.ts +0 -8
- package/dist/lib/usecases/constants.d.ts +0 -7
- package/dist/lib/usecases/describe.usecase.d.ts +0 -12
- package/dist/lib/usecases/format.usecase.d.ts +0 -6
- package/dist/lib/usecases/namefully.usecase.d.ts +0 -14
- package/dist/lib/usecases/shorten.usecase.d.ts +0 -6
- package/dist/lib/validators/array-name.validator.d.ts +0 -25
- package/dist/lib/validators/array-name.validator.js +0 -82
- 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 -80
- 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 -69
- package/dist/lib/validators/common/validation-rule.js +0 -73
- 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 -43
- 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
|
@@ -1,284 +1,379 @@
|
|
|
1
|
+
import { Config } from './config';
|
|
2
|
+
import { Name, JsonName } from './name';
|
|
3
|
+
import { Parser } from './parser';
|
|
4
|
+
import { Flat, NameOrder, NameType, Namon, Nullable, Surname } from './types';
|
|
1
5
|
/**
|
|
2
|
-
*
|
|
6
|
+
* A helper for organizing person names in a particular order, way, or shape.
|
|
3
7
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
8
|
+
* Though `namefully` is easy to use, it does not magically guess which part of
|
|
9
|
+
* the name is what (prefix, suffix, first, last, or middle names). It relies
|
|
10
|
+
* actually on how the name parts are indicated (i.e., their roles) so that
|
|
11
|
+
* it can perform internally certain operations and saves us some extra
|
|
12
|
+
* calculations/processing. In addition, `Namefully` can be created using
|
|
13
|
+
* distinct raw data shapes. This is intended to give some flexibility to the
|
|
14
|
+
* developer so that he or she is not bound to a particular data format.
|
|
15
|
+
* By following closely the API reference to know how to harness its usability,
|
|
16
|
+
* this utility aims to save time in formatting names.
|
|
6
17
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Person name handler
|
|
14
|
-
* @class
|
|
15
|
-
* @classdesc
|
|
16
|
-
* `Namefully` does not magically guess which part of the name is what. It relies
|
|
17
|
-
* actually on how the developer indicates the roles of the name parts so that
|
|
18
|
-
* it, internally, can perform certain operations and saves the developer some
|
|
19
|
-
* calculations/processings. Nevertheless, Namefully can be constructed using
|
|
20
|
-
* distinct raw data shape. This is intended to give some flexibility to the
|
|
21
|
-
* developer so that he or she is not bound to a particular data format. Please,
|
|
22
|
-
* do follow closely the APIs to know how to properly use it in order to avoid
|
|
23
|
-
* some errors (mainly validation's).
|
|
18
|
+
* `namefully` also works like a trapdoor. Once a raw data is provided and
|
|
19
|
+
* validated, a developer can only *access* in a vast amount of, yet effective
|
|
20
|
+
* ways the name info. *No editing* is possible. If the name is mistaken, a new
|
|
21
|
+
* instance of `Namefully` must be created. In other words, it's immutable.
|
|
22
|
+
* Remember, this utility's primary objective is to help manipulate a person name.
|
|
24
23
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
24
|
+
* Note that the name standards used for the current version of this library
|
|
25
|
+
* are as follows:
|
|
26
|
+
* `[prefix] firstName [middleName] lastName [suffix]`
|
|
27
|
+
* The opening `[` and closing `]` symbols mean that these parts are optional.
|
|
28
|
+
* In other words, the most basic and typical case is a name that looks like
|
|
29
|
+
* this: `John Smith`, where `John` is the first name piece and `Smith`, the last
|
|
30
|
+
* name piece.
|
|
30
31
|
*
|
|
31
|
-
* Note that the name standards used for the current version of this library are
|
|
32
|
-
* as follows:
|
|
33
|
-
* [Prefix] Firstname [Middlename] Lastname [Suffix]
|
|
34
|
-
* The opening `[` and closing `]` brackets mean that these parts are optional.
|
|
35
|
-
* In other words, the most basic and typical case is a name that looks like this:
|
|
36
|
-
* `John Smith`, where `John` is the first name and `Smith`, the last name.
|
|
37
32
|
* @see https://departments.weber.edu/qsupport&training/Data_Standards/Name.htm
|
|
38
33
|
* for more info on name standards.
|
|
39
34
|
*
|
|
40
|
-
* **IMPORTANT**: Keep in mind that the order of appearance
|
|
41
|
-
* altered through configured parameters, which
|
|
42
|
-
* default, the order of appearance is as shown above and will be used as a
|
|
43
|
-
* for future examples and use cases.
|
|
35
|
+
* **IMPORTANT**: Keep in mind that the order of appearance (or name order) matters
|
|
36
|
+
* and may be altered through configured parameters, which will be seen later.
|
|
37
|
+
* By default, the order of appearance is as shown above and will be used as a
|
|
38
|
+
* basis for future examples and use cases.
|
|
44
39
|
*
|
|
45
40
|
* Once imported, all that is required to do is to create an instance of
|
|
46
41
|
* `Namefully` and the rest will follow.
|
|
47
42
|
*
|
|
48
43
|
* Some terminologies used across the library are:
|
|
49
|
-
* - namon: piece of
|
|
50
|
-
* - nama: pieces of
|
|
44
|
+
* - namon: 1 piece of name (e.g., first name)
|
|
45
|
+
* - nama: 2+ pieces of name (e.g., first name + last name)
|
|
51
46
|
*
|
|
52
|
-
* Happy
|
|
47
|
+
* Happy name handling 😊!
|
|
53
48
|
*/
|
|
54
49
|
export declare class Namefully {
|
|
55
50
|
/**
|
|
56
|
-
*
|
|
57
|
-
* @see {Fullname} description for more details
|
|
51
|
+
* A copy of high-quality name data.
|
|
58
52
|
*/
|
|
59
|
-
private
|
|
53
|
+
private _fullName;
|
|
60
54
|
/**
|
|
61
|
-
*
|
|
62
|
-
* @see {Summary} class description for more details
|
|
55
|
+
* A copy of the default configuration (combined with a custom one if any).
|
|
63
56
|
*/
|
|
64
|
-
private
|
|
57
|
+
private _config;
|
|
65
58
|
/**
|
|
66
|
-
*
|
|
67
|
-
* @
|
|
59
|
+
* Creates a name with distinguishable parts from a raw string content.
|
|
60
|
+
* @param names element to parse.
|
|
61
|
+
* @param options additional settings.
|
|
62
|
+
*
|
|
63
|
+
* An optional configuration may be provided with specifics on how to treat
|
|
64
|
+
* a full name during its course. By default, all name parts are validated
|
|
65
|
+
* against some basic validation rules to avoid common runtime exceptions.
|
|
68
66
|
*/
|
|
69
|
-
|
|
67
|
+
constructor(names: string | string[] | Name[] | JsonName | Parser, options?: Partial<Config>);
|
|
70
68
|
/**
|
|
71
|
-
* Constructs
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
69
|
+
* Constructs a `Namefully` instance from a text.
|
|
70
|
+
*
|
|
71
|
+
* It works like `parse` except that this function returns `null` where `parse`
|
|
72
|
+
* would throw a `NameError`.
|
|
75
73
|
*/
|
|
76
|
-
|
|
77
|
-
orderedBy: NameOrder;
|
|
78
|
-
separator: Separator;
|
|
79
|
-
titling: AbbrTitle;
|
|
80
|
-
ending: Separator;
|
|
81
|
-
bypass: boolean;
|
|
82
|
-
parser: Parser<any>;
|
|
83
|
-
lastnameFormat: LastnameFormat;
|
|
84
|
-
}>);
|
|
74
|
+
static tryParse(text: string): Namefully | undefined;
|
|
85
75
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
76
|
+
* Constructs a `Namefully` instance from a text.
|
|
77
|
+
*
|
|
78
|
+
* It throws a `NameError` if the text cannot be parsed. Use `tryParse`
|
|
79
|
+
* instead if a `null` return is preferred over a throwable error.
|
|
90
80
|
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
81
|
+
* This operation is computed asynchronously, which gives more flexibility at
|
|
82
|
+
* the time of catching the error (and stack trace if any). The acceptable
|
|
83
|
+
* text format is a string composed of two or more name pieces. For instance,
|
|
84
|
+
* `John Lennon`, or `John Winston Ono Lennon` are parsable names and follow
|
|
85
|
+
* the basic name standard rules (i.e., first-middle-last).
|
|
86
|
+
*
|
|
87
|
+
* Keep in mind that prefix and suffix are not considered during the parsing
|
|
88
|
+
* process.
|
|
89
|
+
*/
|
|
90
|
+
static parse(text: string): Promise<Namefully>;
|
|
91
|
+
/**
|
|
92
|
+
* The current configuration.
|
|
93
|
+
*/
|
|
94
|
+
get config(): Config;
|
|
95
|
+
/**
|
|
96
|
+
* The number of characters of the `birthName`, including spaces.
|
|
93
97
|
*/
|
|
94
|
-
|
|
98
|
+
get length(): number;
|
|
95
99
|
/**
|
|
96
|
-
*
|
|
97
|
-
* @returns {string} the first name
|
|
100
|
+
* The prefix part.
|
|
98
101
|
*/
|
|
99
|
-
|
|
102
|
+
get prefix(): Nullable<string>;
|
|
100
103
|
/**
|
|
101
|
-
*
|
|
102
|
-
* @param {LastnameFormat} [format] overrides the how-to format of a surname
|
|
103
|
-
* output, considering its subparts.
|
|
104
|
-
* @returns {string} the last name
|
|
104
|
+
* The firt name.
|
|
105
105
|
*/
|
|
106
|
-
|
|
106
|
+
get first(): string;
|
|
107
107
|
/**
|
|
108
|
-
*
|
|
109
|
-
* @returns {Array<string>} the middle names
|
|
108
|
+
* The first middle name if any.
|
|
110
109
|
*/
|
|
111
|
-
|
|
110
|
+
get middle(): Nullable<string>;
|
|
112
111
|
/**
|
|
113
|
-
*
|
|
114
|
-
* @returns {string} the prefix
|
|
112
|
+
* Returns true if any middle name has been set.
|
|
115
113
|
*/
|
|
116
|
-
|
|
114
|
+
get hasMiddle(): boolean;
|
|
117
115
|
/**
|
|
118
|
-
*
|
|
119
|
-
* @returns {string} the suffix
|
|
116
|
+
* The last name.
|
|
120
117
|
*/
|
|
121
|
-
|
|
118
|
+
get last(): string;
|
|
122
119
|
/**
|
|
123
|
-
*
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
*
|
|
120
|
+
* The suffix part.
|
|
121
|
+
*/
|
|
122
|
+
get suffix(): Nullable<string>;
|
|
123
|
+
/**
|
|
124
|
+
* The birth name.
|
|
125
|
+
*/
|
|
126
|
+
get birth(): string;
|
|
127
|
+
/**
|
|
128
|
+
* The shortest version of a person name.
|
|
129
|
+
*/
|
|
130
|
+
get short(): string;
|
|
131
|
+
/**
|
|
132
|
+
* The longest version of a person name.
|
|
133
|
+
*/
|
|
134
|
+
get long(): string;
|
|
135
|
+
/**
|
|
136
|
+
* The entire name set.
|
|
137
|
+
*/
|
|
138
|
+
get full(): string;
|
|
139
|
+
/**
|
|
140
|
+
* The first name combined with the last name's initial.
|
|
141
|
+
*/
|
|
142
|
+
get public(): string;
|
|
143
|
+
/**
|
|
144
|
+
* Returns the full name as set.
|
|
145
|
+
*/
|
|
146
|
+
toString(): string;
|
|
147
|
+
/**
|
|
148
|
+
* Fetches the raw form of a name piece.
|
|
149
|
+
*/
|
|
150
|
+
get(namon: Namon): Nullable<Name | Name[]>;
|
|
151
|
+
/**
|
|
152
|
+
* Whether this name is equal to another one from a raw-string perspective.
|
|
153
|
+
*/
|
|
154
|
+
equal(other: Namefully): boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Gets a JSON representation of the full name.
|
|
157
|
+
*/
|
|
158
|
+
toJson(): JsonName;
|
|
159
|
+
/**
|
|
160
|
+
* Confirms that a name part has been set.
|
|
161
|
+
*/
|
|
162
|
+
has(namon: Namon): boolean;
|
|
163
|
+
/**
|
|
164
|
+
* Gets the full name ordered as configured.
|
|
128
165
|
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* - `John Smith` => ['J', 'S']
|
|
132
|
-
* - `John Ben Smith` => ['J', 'S']
|
|
133
|
-
* when `withMid` is set to true:
|
|
134
|
-
* - `John Ben Smith` => ['J', 'B', 'S']
|
|
166
|
+
* The name order `orderedBy` forces to order by first or last name by
|
|
167
|
+
* overriding the preset configuration.
|
|
135
168
|
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* `lastname firstname [middlename]`
|
|
139
|
-
* which means that if no middle name was set, setting `withMid` to true
|
|
140
|
-
* will output nothing and warn the end user about it.
|
|
141
|
-
*/
|
|
142
|
-
getInitials(orderedBy?: NameOrder, withMid?: boolean): string[];
|
|
143
|
-
/**
|
|
144
|
-
* Gives some descriptive statistics that summarize the central tendency,
|
|
145
|
-
* dispersion and shape of the characters' distribution.
|
|
146
|
-
* @param what which variant to use when describe a name part
|
|
147
|
-
* @returns {string} the stats behind the full name.
|
|
169
|
+
* `Namefully.format` may also be used to alter manually the order of appearance
|
|
170
|
+
* of full name.
|
|
148
171
|
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
172
|
+
* For example:
|
|
173
|
+
* ```typescript
|
|
174
|
+
* const name = new Namefully('Jon Stark Snow');
|
|
175
|
+
* console.log(name.fullName(NameOrder.LAST_NAME)); // "Snow Jon Stark"
|
|
176
|
+
* console.log(name.format('l f m')); // "Snow Jon Stark"
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
fullName(orderedBy?: NameOrder): string;
|
|
180
|
+
/**
|
|
181
|
+
* Gets the birth name ordered as configured, no `prefix` or `suffix`.
|
|
154
182
|
*
|
|
155
|
-
* @
|
|
156
|
-
*
|
|
183
|
+
* @param orderedBy forces to order by first or last name by overriding the
|
|
184
|
+
* preset configuration.
|
|
185
|
+
*/
|
|
186
|
+
birthName(orderedBy?: NameOrder): string;
|
|
187
|
+
/**
|
|
188
|
+
* Gets the first name part of the `FullName`.
|
|
157
189
|
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
190
|
+
* @param withMore determines whether to include other pieces of the first
|
|
191
|
+
* name.
|
|
192
|
+
*/
|
|
193
|
+
firstName(withMore?: boolean): string;
|
|
194
|
+
/**
|
|
195
|
+
* Gets the middle name part of the `FullName`.
|
|
196
|
+
*/
|
|
197
|
+
middleName(): string[];
|
|
198
|
+
/**
|
|
199
|
+
* Gets the last name part of the `FullName`.
|
|
163
200
|
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
* from the stats. By default, the only restricted character is the `space`.
|
|
167
|
-
* That is why the `count` for the example below result in `16` instead of
|
|
168
|
-
* `16`.
|
|
169
|
-
* Another thing to consider is that the summary is case *insensitive*. Note
|
|
170
|
-
* that the letter `a` has the top frequency, be it `3`.
|
|
201
|
+
* @param format overrides the how-to formatting of a surname output,
|
|
202
|
+
* considering its sub-parts.
|
|
171
203
|
*/
|
|
172
|
-
|
|
204
|
+
lastName(format?: Surname): string;
|
|
205
|
+
/**
|
|
206
|
+
* Gets the initials of the `FullName`.
|
|
207
|
+
*
|
|
208
|
+
* @param {options.orderedBy} forces to order by first or last name by
|
|
209
|
+
* overriding the preset configuration.
|
|
210
|
+
* @param
|
|
211
|
+
*
|
|
212
|
+
* For example, given the names:
|
|
213
|
+
* - `John Smith` => `['J', 'S']`
|
|
214
|
+
* - `John Ben Smith` => `['J', 'B', 'S']`.
|
|
215
|
+
*/
|
|
216
|
+
initials(options?: {
|
|
217
|
+
orderedBy?: NameOrder;
|
|
218
|
+
only?: NameType;
|
|
219
|
+
}): string[];
|
|
173
220
|
/**
|
|
174
221
|
* Shortens a complex full name to a simple typical name, a combination of
|
|
175
|
-
* first
|
|
176
|
-
*
|
|
177
|
-
* name by overriding the
|
|
178
|
-
*
|
|
222
|
+
* first and last name.
|
|
223
|
+
*
|
|
224
|
+
* @param orderedBy forces to order by first or last name by overriding the
|
|
225
|
+
* preset configuration.
|
|
179
226
|
*
|
|
180
|
-
* @example
|
|
181
227
|
* For a given name such as `Mr Keanu Charles Reeves`, shortening this name
|
|
182
228
|
* is equivalent to making it `Keanu Reeves`.
|
|
229
|
+
*
|
|
230
|
+
* As a shortened name, the namon of the first name is favored over the other
|
|
231
|
+
* names forming part of the entire first names, if any. Meanwhile, for
|
|
232
|
+
* the last name, the configured `surname` is prioritized.
|
|
233
|
+
*
|
|
234
|
+
* For a given `FirstName FatherName MotherName`, shortening this name when
|
|
235
|
+
* the surname is set as `mother` is equivalent to making it:
|
|
236
|
+
* `FirstName MotherName`.
|
|
183
237
|
*/
|
|
184
|
-
shorten(orderedBy?:
|
|
238
|
+
shorten(orderedBy?: NameOrder): string;
|
|
185
239
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
* @param
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
* `
|
|
192
|
-
* @param {boolean} [warning] should warn when the set limit is violated
|
|
240
|
+
* Flattens a long name using the name types as variants.
|
|
241
|
+
*
|
|
242
|
+
* While @param limit sets a threshold as a limited number of characters
|
|
243
|
+
* supported to flatten a `FullName`, @param by indicates which variant
|
|
244
|
+
* to use when doing so. By default, a full name gets flattened by
|
|
245
|
+
* `Flat.MIDDLE_NAME`.
|
|
193
246
|
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* surpasses the limit set. In the examples below, let us assume that the
|
|
247
|
+
* The flattening operation is only executed iff there is a valid entry and
|
|
248
|
+
* it surpasses the limit set. In the examples below, let us assume that the
|
|
197
249
|
* name goes beyond the limit value.
|
|
198
250
|
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
251
|
+
* Flattening a long name refers to reducing the name to the following forms.
|
|
252
|
+
* For example, `John Winston Ono Lennon` flattened by:
|
|
253
|
+
* * Flat.FIRST_NAME: => 'J. Winston Ono Lennon'
|
|
254
|
+
* * Flat.MIDDLE_NAME: => 'John W. O. Lennon'
|
|
255
|
+
* * Flat.LAST_NAME: => 'John Winston Ono L.'
|
|
256
|
+
* * Flat.FIRST_MID: => 'J. W. O. Lennon'
|
|
257
|
+
* * Flat.MID_LAST: => 'John W. O. L.'
|
|
258
|
+
* * Flat.ALL: => 'J. W. O. L.'
|
|
205
259
|
*
|
|
206
|
-
*
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
* and `middlename + lastname`.
|
|
260
|
+
* With the help of the @param recursive flag, the above operation can happen
|
|
261
|
+
* recursively in the same order if the name is still too long. For example,
|
|
262
|
+
* flattening `John Winston Ono Lennon` using the following params:
|
|
263
|
+
* `flatten({ limit: 18, by: Flat.FIRST_NAME, recursive: true })`
|
|
264
|
+
* will result in `John W. O. Lennon` and not `J. Winston Ono Lennon`.
|
|
265
|
+
*
|
|
266
|
+
* A shorter version of this method is `zip()`.
|
|
214
267
|
*/
|
|
215
|
-
|
|
268
|
+
flatten(options: Partial<{
|
|
269
|
+
limit: number;
|
|
270
|
+
by: Flat;
|
|
271
|
+
withPeriod: boolean;
|
|
272
|
+
recursive: boolean;
|
|
273
|
+
withMore: boolean;
|
|
274
|
+
surname: Surname;
|
|
275
|
+
}>): string;
|
|
216
276
|
/**
|
|
217
|
-
*
|
|
218
|
-
* @returns {Array<string>} a set of usernames
|
|
277
|
+
* Zips or compacts a name using different forms of variants.
|
|
219
278
|
*
|
|
220
|
-
*
|
|
221
|
-
* The validity of these usernames are not checked against any social media
|
|
222
|
-
* or web app online.
|
|
279
|
+
* @see `flatten()` for more details.
|
|
223
280
|
*/
|
|
224
|
-
|
|
281
|
+
zip(by?: Flat, withPeriod?: boolean): string;
|
|
225
282
|
/**
|
|
226
|
-
* Formats the name as desired
|
|
227
|
-
* @param
|
|
228
|
-
* @returns {string} the formatted name as specified
|
|
283
|
+
* Formats the full name as desired.
|
|
284
|
+
* @param pattern character used to format it.
|
|
229
285
|
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
* '
|
|
233
|
-
* '
|
|
234
|
-
* '
|
|
235
|
-
* '
|
|
236
|
-
* 'M': Capitalized middle names
|
|
237
|
-
* 'O': official document format
|
|
286
|
+
* string format
|
|
287
|
+
* -------------
|
|
288
|
+
* - 'short': typical first + last name
|
|
289
|
+
* - 'long': birth name (without prefix and suffix)
|
|
290
|
+
* - 'public': first name combined with the last name's initial.
|
|
291
|
+
* - 'official': official document format
|
|
238
292
|
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
293
|
+
* char format
|
|
294
|
+
* -----------
|
|
295
|
+
* - 'b': birth name
|
|
296
|
+
* - 'B': capitalized birth name
|
|
297
|
+
* - 'f': first name
|
|
298
|
+
* - 'F': capitalized first name
|
|
299
|
+
* - 'l': last name
|
|
300
|
+
* - 'L': capitalized last name
|
|
301
|
+
* - 'm': middle names
|
|
302
|
+
* - 'M': capitalized middle names
|
|
303
|
+
* - 'o': official document format
|
|
304
|
+
* - 'O': official document format in capital letters
|
|
305
|
+
* - 'p': prefix
|
|
306
|
+
* - 'P': capitalized prefix
|
|
307
|
+
* - 's': suffix
|
|
308
|
+
* - 'S': capitalized suffix
|
|
309
|
+
*
|
|
310
|
+
* punctuations
|
|
311
|
+
* ------------
|
|
312
|
+
* - '.': period
|
|
313
|
+
* - ',': comma
|
|
314
|
+
* - ' ': space
|
|
315
|
+
* - '-': hyphen
|
|
316
|
+
* - '_': underscore
|
|
317
|
+
* - '$': an escape character to select only the initial of the next char.
|
|
318
|
+
*
|
|
319
|
+
* Given the name `Joe Jim Smith`, use `format` with the `pattern` string.
|
|
241
320
|
* - format('l f') => 'Smith Joe'
|
|
242
321
|
* - format('L, f') => 'SMITH, Joe'
|
|
243
|
-
* - format('
|
|
244
|
-
* - format(
|
|
245
|
-
* - format('
|
|
246
|
-
*
|
|
322
|
+
* - format('short') => 'Joe Smith'
|
|
323
|
+
* - format() => 'SMITH, Joe Jim'
|
|
324
|
+
* - format(r'f $l.') => 'Joe S.'.
|
|
325
|
+
*
|
|
326
|
+
* Do note that the escape character is only valid for the birth name parts:
|
|
327
|
+
* first, middle, and last names.
|
|
247
328
|
*/
|
|
248
|
-
format(
|
|
329
|
+
format(pattern: string): string;
|
|
249
330
|
/**
|
|
250
|
-
*
|
|
251
|
-
* @param {Config} options for a customized setup
|
|
331
|
+
* Flips definitely the name order from the preset/current config.
|
|
252
332
|
*/
|
|
253
|
-
|
|
333
|
+
flip(): void;
|
|
254
334
|
/**
|
|
255
|
-
*
|
|
256
|
-
* @param
|
|
335
|
+
* Splits the name parts of a birth name.
|
|
336
|
+
* @param separator token for the split.
|
|
257
337
|
*/
|
|
258
|
-
|
|
338
|
+
split(separator?: string | RegExp): string[];
|
|
259
339
|
/**
|
|
260
|
-
*
|
|
261
|
-
* @param
|
|
262
|
-
* @return {string} piece of name
|
|
340
|
+
* Joins the name parts of a birth name.
|
|
341
|
+
* @param separator token for the junction.
|
|
263
342
|
*/
|
|
264
|
-
|
|
343
|
+
join(separator?: string): string;
|
|
265
344
|
/**
|
|
266
|
-
*
|
|
267
|
-
* @param {string | string[] | Array<Name> | Nama} raw data to parse or
|
|
268
|
-
* construct the pieces of the name
|
|
345
|
+
* Transforms a birth name into UPPERCASE
|
|
269
346
|
*/
|
|
347
|
+
toUpperCase(): string;
|
|
348
|
+
/**
|
|
349
|
+
* Transforms a birth name into lowercase
|
|
350
|
+
*/
|
|
351
|
+
toLowerCase(): string;
|
|
352
|
+
/**
|
|
353
|
+
* Transforms a birth name into camelCase
|
|
354
|
+
*/
|
|
355
|
+
toCamelCase(): string;
|
|
356
|
+
/**
|
|
357
|
+
* Transforms a birth name into PascalCase
|
|
358
|
+
*/
|
|
359
|
+
toPascalCase(): string;
|
|
360
|
+
/**
|
|
361
|
+
* Transforms a birth name into snake_case
|
|
362
|
+
*/
|
|
363
|
+
toSnakeCase(): string;
|
|
364
|
+
/**
|
|
365
|
+
* Transforms a birth name into hyphen-case
|
|
366
|
+
*/
|
|
367
|
+
toHyphenCase(): string;
|
|
368
|
+
/**
|
|
369
|
+
* Transforms a birth name into dot.case
|
|
370
|
+
*/
|
|
371
|
+
toDotCase(): string;
|
|
372
|
+
/**
|
|
373
|
+
* Transforms a birth name into ToGgLeCaSe
|
|
374
|
+
*/
|
|
375
|
+
toToggleCase(): string;
|
|
270
376
|
private build;
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
* Aliases for `Namefully`
|
|
274
|
-
*/
|
|
275
|
-
export interface Namefully {
|
|
276
|
-
full: typeof Namefully.prototype.getFullname;
|
|
277
|
-
fn: typeof Namefully.prototype.getFirstname;
|
|
278
|
-
ln: typeof Namefully.prototype.getLastname;
|
|
279
|
-
mn: typeof Namefully.prototype.getMiddlenames;
|
|
280
|
-
px: typeof Namefully.prototype.getPrefix;
|
|
281
|
-
sx: typeof Namefully.prototype.getSuffix;
|
|
282
|
-
inits: typeof Namefully.prototype.getInitials;
|
|
283
|
-
stats: typeof Namefully.prototype.describe;
|
|
377
|
+
private toParser;
|
|
378
|
+
private map;
|
|
284
379
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { FullName } from './full-name';
|
|
2
|
+
import { Config } from './config';
|
|
3
|
+
import { Name, JsonName } from './name';
|
|
4
|
+
/**
|
|
5
|
+
* A parser signature that helps to organize the names accordingly.
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class Parser<T = any> {
|
|
8
|
+
raw: T;
|
|
9
|
+
/**
|
|
10
|
+
* Constructs a custom parser accordingly.
|
|
11
|
+
* @param raw data to be parsed
|
|
12
|
+
*/
|
|
13
|
+
constructor(raw: T);
|
|
14
|
+
/**
|
|
15
|
+
* Parses the raw data into a `FullName` while considering some options.
|
|
16
|
+
* @param options additional configuration to apply.
|
|
17
|
+
*/
|
|
18
|
+
abstract parse(options?: Partial<Config>): FullName;
|
|
19
|
+
/**
|
|
20
|
+
* Builds a dynamic `Parser` on the fly and throws a `NameError` when unable
|
|
21
|
+
* to do so. The built parser only knows how to operate birth names.
|
|
22
|
+
*/
|
|
23
|
+
static build(text: string): Parser;
|
|
24
|
+
/**
|
|
25
|
+
* Builds asynchronously a dynamic `Parser`.
|
|
26
|
+
*/
|
|
27
|
+
static buildAsync(text: string): Promise<Parser>;
|
|
28
|
+
}
|
|
29
|
+
export declare class StringParser extends Parser<string> {
|
|
30
|
+
constructor(raw: string);
|
|
31
|
+
parse(options: Partial<Config>): FullName;
|
|
32
|
+
}
|
|
33
|
+
export declare class ArrayStringParser extends Parser<string[]> {
|
|
34
|
+
constructor(raw: string[]);
|
|
35
|
+
parse(options: Partial<Config>): FullName;
|
|
36
|
+
private split;
|
|
37
|
+
}
|
|
38
|
+
export declare class NamaParser extends Parser<JsonName> {
|
|
39
|
+
constructor(raw: JsonName);
|
|
40
|
+
parse(options: Partial<Config>): FullName;
|
|
41
|
+
private asNama;
|
|
42
|
+
}
|
|
43
|
+
export declare class ArrayNameParser extends Parser<Name[]> {
|
|
44
|
+
constructor(raw: Name[]);
|
|
45
|
+
parse(options: Partial<Config>): FullName;
|
|
46
|
+
}
|