namefully 1.1.0 → 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/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/example/example.d.ts +1 -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 +285 -208
- package/dist/lib/namefully.js +576 -576
- 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 +20 -0
- package/dist/lib/src/name.d.ts +177 -0
- package/dist/lib/src/namefully.d.ts +379 -0
- 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 +2118 -2700
- package/dist/umd/namefully.js.map +1 -1
- package/dist/umd/namefully.min.js +1 -1
- package/dist/umd/namefully.min.js.LICENSE.txt +1 -18
- package/dist/umd/namefully.min.js.map +1 -1
- package/package.json +50 -54
- package/readme.md +132 -162
- package/changelog.md +0 -134
- package/dist/lib/core/constants.d.ts +0 -48
- package/dist/lib/core/constants.js +0 -101
- package/dist/lib/core/constants.js.map +0 -1
- package/dist/lib/core/core.d.ts +0 -17
- package/dist/lib/core/core.js +0 -24
- package/dist/lib/core/core.js.map +0 -1
- package/dist/lib/core/index.d.ts +0 -9
- package/dist/lib/core/index.js +0 -13
- package/dist/lib/core/index.js.map +0 -1
- package/dist/lib/core/parsers/array-name.parser.d.ts +0 -41
- package/dist/lib/core/parsers/array-name.parser.js +0 -86
- package/dist/lib/core/parsers/array-name.parser.js.map +0 -1
- package/dist/lib/core/parsers/array-string.parser.d.ts +0 -47
- package/dist/lib/core/parsers/array-string.parser.js +0 -95
- package/dist/lib/core/parsers/array-string.parser.js.map +0 -1
- package/dist/lib/core/parsers/index.d.ts +0 -11
- package/dist/lib/core/parsers/index.js +0 -11
- package/dist/lib/core/parsers/index.js.map +0 -1
- package/dist/lib/core/parsers/nama.parser.d.ts +0 -33
- package/dist/lib/core/parsers/nama.parser.js +0 -74
- package/dist/lib/core/parsers/nama.parser.js.map +0 -1
- package/dist/lib/core/parsers/parser.d.ts +0 -28
- package/dist/lib/core/parsers/parser.js +0 -3
- package/dist/lib/core/parsers/parser.js.map +0 -1
- package/dist/lib/core/parsers/string.parser.d.ts +0 -60
- package/dist/lib/core/parsers/string.parser.js +0 -62
- package/dist/lib/core/parsers/string.parser.js.map +0 -1
- package/dist/lib/core/utils.d.ts +0 -52
- package/dist/lib/core/utils.js +0 -178
- package/dist/lib/core/utils.js.map +0 -1
- package/dist/lib/models/enums.d.ts +0 -106
- package/dist/lib/models/enums.js +0 -114
- package/dist/lib/models/enums.js.map +0 -1
- package/dist/lib/models/firstname.d.ts +0 -77
- package/dist/lib/models/firstname.js +0 -131
- package/dist/lib/models/firstname.js.map +0 -1
- package/dist/lib/models/fullname.d.ts +0 -73
- package/dist/lib/models/fullname.js +0 -99
- package/dist/lib/models/fullname.js.map +0 -1
- package/dist/lib/models/index.d.ts +0 -13
- package/dist/lib/models/index.js +0 -16
- package/dist/lib/models/index.js.map +0 -1
- package/dist/lib/models/lastname.d.ts +0 -80
- package/dist/lib/models/lastname.js +0 -157
- package/dist/lib/models/lastname.js.map +0 -1
- package/dist/lib/models/misc.d.ts +0 -108
- package/dist/lib/models/misc.js +0 -3
- package/dist/lib/models/misc.js.map +0 -1
- package/dist/lib/models/name.d.ts +0 -76
- package/dist/lib/models/name.js +0 -115
- package/dist/lib/models/name.js.map +0 -1
- package/dist/lib/models/summary.d.ts +0 -26
- package/dist/lib/models/summary.js +0 -61
- package/dist/lib/models/summary.js.map +0 -1
- package/dist/lib/validators/array-name.validator.d.ts +0 -25
- package/dist/lib/validators/array-name.validator.js +0 -75
- package/dist/lib/validators/array-name.validator.js.map +0 -1
- package/dist/lib/validators/array-string.validator.d.ts +0 -43
- package/dist/lib/validators/array-string.validator.js +0 -76
- package/dist/lib/validators/array-string.validator.js.map +0 -1
- package/dist/lib/validators/common/validation-error.d.ts +0 -19
- package/dist/lib/validators/common/validation-error.js +0 -26
- package/dist/lib/validators/common/validation-error.js.map +0 -1
- package/dist/lib/validators/common/validation-rule.d.ts +0 -72
- package/dist/lib/validators/common/validation-rule.js +0 -76
- package/dist/lib/validators/common/validation-rule.js.map +0 -1
- package/dist/lib/validators/common/validation-type.d.ts +0 -24
- package/dist/lib/validators/common/validation-type.js +0 -28
- package/dist/lib/validators/common/validation-type.js.map +0 -1
- package/dist/lib/validators/firstname.validator.d.ts +0 -20
- package/dist/lib/validators/firstname.validator.js +0 -29
- package/dist/lib/validators/firstname.validator.js.map +0 -1
- package/dist/lib/validators/fullname.validator.d.ts +0 -21
- package/dist/lib/validators/fullname.validator.js +0 -38
- package/dist/lib/validators/fullname.validator.js.map +0 -1
- package/dist/lib/validators/index.d.ts +0 -21
- package/dist/lib/validators/index.js +0 -35
- package/dist/lib/validators/index.js.map +0 -1
- package/dist/lib/validators/lastname.validator.d.ts +0 -20
- package/dist/lib/validators/lastname.validator.js +0 -29
- package/dist/lib/validators/lastname.validator.js.map +0 -1
- package/dist/lib/validators/middlename.validator.d.ts +0 -20
- package/dist/lib/validators/middlename.validator.js +0 -38
- package/dist/lib/validators/middlename.validator.js.map +0 -1
- package/dist/lib/validators/nama.validator.d.ts +0 -21
- package/dist/lib/validators/nama.validator.js +0 -44
- package/dist/lib/validators/nama.validator.js.map +0 -1
- package/dist/lib/validators/namon.validator.d.ts +0 -20
- package/dist/lib/validators/namon.validator.js +0 -29
- package/dist/lib/validators/namon.validator.js.map +0 -1
- package/dist/lib/validators/prefix.validator.d.ts +0 -14
- package/dist/lib/validators/prefix.validator.js +0 -31
- package/dist/lib/validators/prefix.validator.js.map +0 -1
- package/dist/lib/validators/string-name.validator.d.ts +0 -20
- package/dist/lib/validators/string-name.validator.js +0 -29
- package/dist/lib/validators/string-name.validator.js.map +0 -1
- package/dist/lib/validators/suffix.validator.d.ts +0 -14
- package/dist/lib/validators/suffix.validator.js +0 -31
- package/dist/lib/validators/suffix.validator.js.map +0 -1
- package/dist/lib/validators/validator.d.ts +0 -13
- package/dist/lib/validators/validator.js +0 -9
- package/dist/lib/validators/validator.js.map +0 -1
package/dist/lib/namefully.d.ts
CHANGED
|
@@ -1,302 +1,379 @@
|
|
|
1
|
-
import {
|
|
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';
|
|
2
5
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @class
|
|
6
|
+
* A helper for organizing person names in a particular order, way, or shape.
|
|
5
7
|
*
|
|
6
|
-
* `
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
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.
|
|
14
17
|
*
|
|
15
|
-
* `
|
|
16
|
-
* validated, a developer can only
|
|
17
|
-
* the name info.
|
|
18
|
-
* of `Namefully` must be created.
|
|
19
|
-
* to help
|
|
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.
|
|
23
|
+
*
|
|
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.
|
|
20
31
|
*
|
|
21
|
-
* Note that the name standards used for the current version of this library are
|
|
22
|
-
* as follows:
|
|
23
|
-
* [Prefix] Firstname [Middlename] Lastname [Suffix]
|
|
24
|
-
* The opening `[` and closing `]` brackets mean that these parts are optional.
|
|
25
|
-
* In other words, the most basic and typical case is a name that looks like this:
|
|
26
|
-
* `John Smith`, where `John` is the first name and `Smith`, the last name.
|
|
27
32
|
* @see https://departments.weber.edu/qsupport&training/Data_Standards/Name.htm
|
|
28
33
|
* for more info on name standards.
|
|
29
34
|
*
|
|
30
|
-
* **IMPORTANT**: Keep in mind that the order of appearance
|
|
31
|
-
* altered through configured parameters, which
|
|
32
|
-
* default, the order of appearance is as shown above and will be used as a
|
|
33
|
-
* 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.
|
|
34
39
|
*
|
|
35
40
|
* Once imported, all that is required to do is to create an instance of
|
|
36
41
|
* `Namefully` and the rest will follow.
|
|
37
42
|
*
|
|
38
43
|
* Some terminologies used across the library are:
|
|
39
|
-
* - namon: 1 piece of
|
|
40
|
-
* - nama: 2+ pieces of
|
|
44
|
+
* - namon: 1 piece of name (e.g., first name)
|
|
45
|
+
* - nama: 2+ pieces of name (e.g., first name + last name)
|
|
41
46
|
*
|
|
42
|
-
* Happy handling
|
|
47
|
+
* Happy name handling 😊!
|
|
43
48
|
*/
|
|
44
49
|
export declare class Namefully {
|
|
45
50
|
/**
|
|
46
|
-
*
|
|
47
|
-
* @see {Fullname} description for more details
|
|
51
|
+
* A copy of high-quality name data.
|
|
48
52
|
*/
|
|
49
|
-
private
|
|
53
|
+
private _fullName;
|
|
50
54
|
/**
|
|
51
|
-
*
|
|
52
|
-
* @see {Summary} class description for more details
|
|
55
|
+
* A copy of the default configuration (combined with a custom one if any).
|
|
53
56
|
*/
|
|
54
|
-
private
|
|
57
|
+
private _config;
|
|
55
58
|
/**
|
|
56
|
-
*
|
|
57
|
-
* @
|
|
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.
|
|
58
66
|
*/
|
|
59
|
-
|
|
67
|
+
constructor(names: string | string[] | Name[] | JsonName | Parser, options?: Partial<Config>);
|
|
60
68
|
/**
|
|
61
|
-
* Constructs
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
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`.
|
|
65
73
|
*/
|
|
66
|
-
|
|
74
|
+
static tryParse(text: string): Namefully | undefined;
|
|
67
75
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
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.
|
|
71
80
|
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
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.
|
|
97
|
+
*/
|
|
98
|
+
get length(): number;
|
|
99
|
+
/**
|
|
100
|
+
* The prefix part.
|
|
101
|
+
*/
|
|
102
|
+
get prefix(): Nullable<string>;
|
|
103
|
+
/**
|
|
104
|
+
* The firt name.
|
|
105
|
+
*/
|
|
106
|
+
get first(): string;
|
|
107
|
+
/**
|
|
108
|
+
* The first middle name if any.
|
|
109
|
+
*/
|
|
110
|
+
get middle(): Nullable<string>;
|
|
111
|
+
/**
|
|
112
|
+
* Returns true if any middle name has been set.
|
|
113
|
+
*/
|
|
114
|
+
get hasMiddle(): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* The last name.
|
|
117
|
+
*/
|
|
118
|
+
get last(): string;
|
|
119
|
+
/**
|
|
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.
|
|
74
137
|
*/
|
|
75
|
-
|
|
138
|
+
get full(): string;
|
|
76
139
|
/**
|
|
77
|
-
*
|
|
78
|
-
* @param {NameOrder} orderedBy force to order by first or last
|
|
79
|
-
* name by overriding the preset configuration
|
|
140
|
+
* The first name combined with the last name's initial.
|
|
80
141
|
*/
|
|
81
|
-
|
|
142
|
+
get public(): string;
|
|
82
143
|
/**
|
|
83
|
-
*
|
|
84
|
-
* @param {boolean} includeAll whether to include other pieces of the first
|
|
85
|
-
* name
|
|
144
|
+
* Returns the full name as set.
|
|
86
145
|
*/
|
|
87
|
-
|
|
146
|
+
toString(): string;
|
|
88
147
|
/**
|
|
89
|
-
*
|
|
90
|
-
* @param {LastnameFormat} [format] overrides the how-to format of a surname
|
|
91
|
-
* output, considering its subparts.
|
|
148
|
+
* Fetches the raw form of a name piece.
|
|
92
149
|
*/
|
|
93
|
-
|
|
150
|
+
get(namon: Namon): Nullable<Name | Name[]>;
|
|
94
151
|
/**
|
|
95
|
-
*
|
|
152
|
+
* Whether this name is equal to another one from a raw-string perspective.
|
|
96
153
|
*/
|
|
97
|
-
|
|
154
|
+
equal(other: Namefully): boolean;
|
|
98
155
|
/**
|
|
99
|
-
* Gets
|
|
156
|
+
* Gets a JSON representation of the full name.
|
|
100
157
|
*/
|
|
101
|
-
|
|
158
|
+
toJson(): JsonName;
|
|
102
159
|
/**
|
|
103
|
-
*
|
|
160
|
+
* Confirms that a name part has been set.
|
|
104
161
|
*/
|
|
105
|
-
|
|
162
|
+
has(namon: Namon): boolean;
|
|
106
163
|
/**
|
|
107
|
-
* Gets the
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
164
|
+
* Gets the full name ordered as configured.
|
|
165
|
+
*
|
|
166
|
+
* The name order `orderedBy` forces to order by first or last name by
|
|
167
|
+
* overriding the preset configuration.
|
|
111
168
|
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
169
|
+
* `Namefully.format` may also be used to alter manually the order of appearance
|
|
170
|
+
* of full name.
|
|
171
|
+
*
|
|
172
|
+
* For example:
|
|
173
|
+
* ```ts
|
|
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`.
|
|
118
182
|
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* `lastname firstname [middlename]`
|
|
122
|
-
* which means that if no middle name was set, setting `withMid` to true
|
|
123
|
-
* will output nothing and warn the end user about it.
|
|
183
|
+
* @param orderedBy forces to order by first or last name by overriding the
|
|
184
|
+
* preset configuration.
|
|
124
185
|
*/
|
|
125
|
-
|
|
186
|
+
birthName(orderedBy?: NameOrder): string;
|
|
126
187
|
/**
|
|
127
|
-
*
|
|
128
|
-
* dispersion and shape of the characters' distribution.
|
|
129
|
-
* @param what which variant to use when describe a name part
|
|
188
|
+
* Gets the first name part of the `FullName`.
|
|
130
189
|
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
*
|
|
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`.
|
|
137
200
|
*
|
|
138
|
-
* @
|
|
139
|
-
*
|
|
201
|
+
* @param format overrides the how-to formatting of a surname output,
|
|
202
|
+
* considering its sub-parts.
|
|
203
|
+
*/
|
|
204
|
+
lastName(format?: Surname): string;
|
|
205
|
+
/**
|
|
206
|
+
* Gets the initials of the `FullName`.
|
|
140
207
|
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
* top : A
|
|
145
|
-
* unique : 12
|
|
146
|
-
* distribution: { T: 1, H: 1, O: 2, M: 1, A: 2, S: 2, ' ': 2, L: 1, V: 1,
|
|
147
|
-
* E: 1, D: 1, I: 1, N: 1 }
|
|
208
|
+
* @param {options.orderedBy} forces to order by first or last name by
|
|
209
|
+
* overriding the preset configuration.
|
|
210
|
+
* @param
|
|
148
211
|
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* That is why the `count` for the example below result in `16` instead of
|
|
153
|
-
* `16`.
|
|
154
|
-
* Another thing to consider is that the summary is case *insensitive*. Note
|
|
155
|
-
* that the letter `a` has the top frequency, be it `3`.
|
|
212
|
+
* For example, given the names:
|
|
213
|
+
* - `John Smith` => `['J', 'S']`
|
|
214
|
+
* - `John Ben Smith` => `['J', 'B', 'S']`.
|
|
156
215
|
*/
|
|
157
|
-
|
|
216
|
+
initials(options?: {
|
|
217
|
+
orderedBy?: NameOrder;
|
|
218
|
+
only?: NameType;
|
|
219
|
+
}): string[];
|
|
158
220
|
/**
|
|
159
221
|
* Shortens a complex full name to a simple typical name, a combination of
|
|
160
|
-
* first
|
|
161
|
-
*
|
|
162
|
-
* name by overriding the
|
|
222
|
+
* first and last name.
|
|
223
|
+
*
|
|
224
|
+
* @param orderedBy forces to order by first or last name by overriding the
|
|
225
|
+
* preset configuration.
|
|
163
226
|
*
|
|
164
|
-
* @example
|
|
165
227
|
* For a given name such as `Mr Keanu Charles Reeves`, shortening this name
|
|
166
228
|
* is equivalent to making it `Keanu Reeves`.
|
|
167
229
|
*
|
|
168
230
|
* As a shortened name, the namon of the first name is favored over the other
|
|
169
231
|
* names forming part of the entire first names, if any. Meanwhile, for
|
|
170
|
-
* the last name, the configured `
|
|
232
|
+
* the last name, the configured `surname` is prioritized.
|
|
171
233
|
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
* `Firstname Mothername`.
|
|
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`.
|
|
176
237
|
*/
|
|
177
238
|
shorten(orderedBy?: NameOrder): string;
|
|
178
239
|
/**
|
|
179
|
-
*
|
|
180
|
-
* @param {number} [limit] a threshold to limit the number of characters
|
|
181
|
-
* @param {'firstname'|'lastname'|'middlename'|'firstmid'|'midlast'} [by]
|
|
182
|
-
* a variant to use when compressing the long name. The last two variants
|
|
183
|
-
* represent respectively the combination of `firstname + middlename` and
|
|
184
|
-
* `middlename + lastname`.
|
|
185
|
-
* @param {boolean} [warning] should warn when the set limit is violated
|
|
240
|
+
* Flattens a long name using the name types as variants.
|
|
186
241
|
*
|
|
187
|
-
* @
|
|
188
|
-
*
|
|
189
|
-
*
|
|
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`.
|
|
246
|
+
*
|
|
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
|
|
190
249
|
* name goes beyond the limit value.
|
|
191
250
|
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
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.'
|
|
198
259
|
*
|
|
199
|
-
*
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
* 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()`.
|
|
207
267
|
*/
|
|
208
|
-
|
|
268
|
+
flatten(options: Partial<{
|
|
269
|
+
limit: number;
|
|
270
|
+
by: Flat;
|
|
271
|
+
withPeriod: boolean;
|
|
272
|
+
recursive: boolean;
|
|
273
|
+
withMore: boolean;
|
|
274
|
+
surname: Surname;
|
|
275
|
+
}>): string;
|
|
209
276
|
/**
|
|
210
|
-
*
|
|
277
|
+
* Zips or compacts a name using different forms of variants.
|
|
211
278
|
*
|
|
212
|
-
*
|
|
213
|
-
* The validity of these usernames are not checked against any social media
|
|
214
|
-
* or web app online.
|
|
279
|
+
* @see `flatten()` for more details.
|
|
215
280
|
*/
|
|
216
|
-
|
|
281
|
+
zip(by?: Flat, withPeriod?: boolean): string;
|
|
217
282
|
/**
|
|
218
|
-
* Formats the name as desired
|
|
219
|
-
* @param
|
|
283
|
+
* Formats the full name as desired.
|
|
284
|
+
* @param pattern character used to format it.
|
|
220
285
|
*
|
|
221
|
-
* How to format it?
|
|
222
286
|
* string format
|
|
223
287
|
* -------------
|
|
224
|
-
* 'short': typical first + last name
|
|
225
|
-
* 'long': birth name (without prefix and suffix)
|
|
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
|
|
226
292
|
*
|
|
227
293
|
* char format
|
|
228
294
|
* -----------
|
|
229
|
-
* 'b': birth name
|
|
230
|
-
* 'B': capitalized birth name
|
|
231
|
-
* 'f': first name
|
|
232
|
-
* 'F': capitalized first name
|
|
233
|
-
* 'l': last name
|
|
234
|
-
* 'L': capitalized last name
|
|
235
|
-
* 'm': middle names
|
|
236
|
-
* 'M': capitalized middle names
|
|
237
|
-
* 'o': official document format
|
|
238
|
-
* 'O': official document format in capital letters
|
|
239
|
-
* 'p': prefix
|
|
240
|
-
* 'P': capitalized prefix
|
|
241
|
-
* 's': suffix
|
|
242
|
-
* 'S': capitalized suffix
|
|
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
|
|
243
309
|
*
|
|
244
310
|
* punctuations
|
|
245
311
|
* ------------
|
|
246
|
-
* '.': period
|
|
247
|
-
* ',': comma
|
|
248
|
-
* ' ': space
|
|
249
|
-
* '-': hyphen
|
|
250
|
-
* '_': underscore
|
|
312
|
+
* - '.': period
|
|
313
|
+
* - ',': comma
|
|
314
|
+
* - ' ': space
|
|
315
|
+
* - '-': hyphen
|
|
316
|
+
* - '_': underscore
|
|
317
|
+
* - '$': an escape character to select only the initial of the next char.
|
|
251
318
|
*
|
|
252
|
-
*
|
|
253
|
-
* Given the name `Joe Jim Smith`, call the `format` with the how string.
|
|
319
|
+
* Given the name `Joe Jim Smith`, use `format` with the `pattern` string.
|
|
254
320
|
* - format('l f') => 'Smith Joe'
|
|
255
321
|
* - format('L, f') => 'SMITH, Joe'
|
|
256
322
|
* - format('short') => 'Joe Smith'
|
|
257
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.
|
|
258
328
|
*/
|
|
259
|
-
format(
|
|
329
|
+
format(pattern: string): string;
|
|
260
330
|
/**
|
|
261
|
-
*
|
|
331
|
+
* Flips definitely the name order from the preset/current config.
|
|
262
332
|
*/
|
|
263
|
-
|
|
333
|
+
flip(): void;
|
|
264
334
|
/**
|
|
265
|
-
*
|
|
266
|
-
* @param
|
|
335
|
+
* Splits the name parts of a birth name.
|
|
336
|
+
* @param separator token for the split.
|
|
267
337
|
*/
|
|
268
|
-
|
|
269
|
-
nameType: NameType;
|
|
270
|
-
exceptions: string[];
|
|
271
|
-
}>): number[];
|
|
338
|
+
split(separator?: string | RegExp): string[];
|
|
272
339
|
/**
|
|
273
|
-
*
|
|
274
|
-
* @param
|
|
340
|
+
* Joins the name parts of a birth name.
|
|
341
|
+
* @param separator token for the junction.
|
|
275
342
|
*/
|
|
276
|
-
|
|
343
|
+
join(separator?: string): string;
|
|
277
344
|
/**
|
|
278
|
-
*
|
|
279
|
-
* @param {NameType} [what] which name part
|
|
345
|
+
* Transforms a birth name into UPPERCASE
|
|
280
346
|
*/
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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;
|
|
287
376
|
private build;
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
* Aliases for `Namefully`
|
|
291
|
-
*/
|
|
292
|
-
export interface Namefully {
|
|
293
|
-
full: typeof Namefully.prototype.getFullname;
|
|
294
|
-
birth: typeof Namefully.prototype.getBirthname;
|
|
295
|
-
fn: typeof Namefully.prototype.getFirstname;
|
|
296
|
-
ln: typeof Namefully.prototype.getLastname;
|
|
297
|
-
mn: typeof Namefully.prototype.getMiddlenames;
|
|
298
|
-
px: typeof Namefully.prototype.getPrefix;
|
|
299
|
-
sx: typeof Namefully.prototype.getSuffix;
|
|
300
|
-
inits: typeof Namefully.prototype.getInitials;
|
|
301
|
-
stats: typeof Namefully.prototype.describe;
|
|
377
|
+
private toParser;
|
|
378
|
+
private map;
|
|
302
379
|
}
|