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.
Files changed (156) hide show
  1. package/dist/example/index.js +2734 -0
  2. package/dist/lib/config.d.ts +121 -0
  3. package/dist/lib/config.js +189 -0
  4. package/dist/lib/config.js.map +1 -0
  5. package/dist/lib/constants.d.ts +4 -0
  6. package/dist/lib/constants.js +31 -0
  7. package/dist/lib/constants.js.map +1 -0
  8. package/dist/lib/error.d.ts +172 -0
  9. package/dist/lib/error.js +210 -0
  10. package/dist/lib/error.js.map +1 -0
  11. package/dist/lib/example/example.d.ts +1 -0
  12. package/dist/lib/full-name.d.ts +71 -0
  13. package/dist/lib/full-name.js +147 -0
  14. package/dist/lib/full-name.js.map +1 -0
  15. package/dist/lib/index.d.ts +16 -6
  16. package/dist/lib/index.js +29 -8
  17. package/dist/lib/index.js.map +1 -1
  18. package/dist/lib/name.d.ts +177 -0
  19. package/dist/lib/name.js +322 -0
  20. package/dist/lib/name.js.map +1 -0
  21. package/dist/lib/namefully.d.ts +285 -208
  22. package/dist/lib/namefully.js +576 -576
  23. package/dist/lib/namefully.js.map +1 -1
  24. package/dist/lib/parser.d.ts +46 -0
  25. package/dist/lib/parser.js +173 -0
  26. package/dist/lib/parser.js.map +1 -0
  27. package/dist/lib/src/config.d.ts +121 -0
  28. package/dist/lib/src/constants.d.ts +4 -0
  29. package/dist/lib/src/error.d.ts +172 -0
  30. package/dist/lib/src/full-name.d.ts +71 -0
  31. package/dist/lib/src/index.d.ts +20 -0
  32. package/dist/lib/src/name.d.ts +177 -0
  33. package/dist/lib/src/namefully.d.ts +379 -0
  34. package/dist/lib/src/parser.d.ts +46 -0
  35. package/dist/lib/src/types.d.ts +127 -0
  36. package/dist/lib/src/utils.d.ts +63 -0
  37. package/dist/lib/src/validator.d.ts +66 -0
  38. package/dist/lib/types.d.ts +127 -0
  39. package/dist/lib/types.js +181 -0
  40. package/dist/lib/types.js.map +1 -0
  41. package/dist/lib/utils.d.ts +63 -0
  42. package/dist/lib/utils.js +138 -0
  43. package/dist/lib/utils.js.map +1 -0
  44. package/dist/lib/validator.d.ts +66 -0
  45. package/dist/lib/validator.js +332 -0
  46. package/dist/lib/validator.js.map +1 -0
  47. package/dist/umd/namefully.js +2118 -2700
  48. package/dist/umd/namefully.js.map +1 -1
  49. package/dist/umd/namefully.min.js +1 -1
  50. package/dist/umd/namefully.min.js.LICENSE.txt +1 -18
  51. package/dist/umd/namefully.min.js.map +1 -1
  52. package/package.json +50 -54
  53. package/readme.md +132 -162
  54. package/changelog.md +0 -134
  55. package/dist/lib/core/constants.d.ts +0 -48
  56. package/dist/lib/core/constants.js +0 -101
  57. package/dist/lib/core/constants.js.map +0 -1
  58. package/dist/lib/core/core.d.ts +0 -17
  59. package/dist/lib/core/core.js +0 -24
  60. package/dist/lib/core/core.js.map +0 -1
  61. package/dist/lib/core/index.d.ts +0 -9
  62. package/dist/lib/core/index.js +0 -13
  63. package/dist/lib/core/index.js.map +0 -1
  64. package/dist/lib/core/parsers/array-name.parser.d.ts +0 -41
  65. package/dist/lib/core/parsers/array-name.parser.js +0 -86
  66. package/dist/lib/core/parsers/array-name.parser.js.map +0 -1
  67. package/dist/lib/core/parsers/array-string.parser.d.ts +0 -47
  68. package/dist/lib/core/parsers/array-string.parser.js +0 -95
  69. package/dist/lib/core/parsers/array-string.parser.js.map +0 -1
  70. package/dist/lib/core/parsers/index.d.ts +0 -11
  71. package/dist/lib/core/parsers/index.js +0 -11
  72. package/dist/lib/core/parsers/index.js.map +0 -1
  73. package/dist/lib/core/parsers/nama.parser.d.ts +0 -33
  74. package/dist/lib/core/parsers/nama.parser.js +0 -74
  75. package/dist/lib/core/parsers/nama.parser.js.map +0 -1
  76. package/dist/lib/core/parsers/parser.d.ts +0 -28
  77. package/dist/lib/core/parsers/parser.js +0 -3
  78. package/dist/lib/core/parsers/parser.js.map +0 -1
  79. package/dist/lib/core/parsers/string.parser.d.ts +0 -60
  80. package/dist/lib/core/parsers/string.parser.js +0 -62
  81. package/dist/lib/core/parsers/string.parser.js.map +0 -1
  82. package/dist/lib/core/utils.d.ts +0 -52
  83. package/dist/lib/core/utils.js +0 -178
  84. package/dist/lib/core/utils.js.map +0 -1
  85. package/dist/lib/models/enums.d.ts +0 -106
  86. package/dist/lib/models/enums.js +0 -114
  87. package/dist/lib/models/enums.js.map +0 -1
  88. package/dist/lib/models/firstname.d.ts +0 -77
  89. package/dist/lib/models/firstname.js +0 -131
  90. package/dist/lib/models/firstname.js.map +0 -1
  91. package/dist/lib/models/fullname.d.ts +0 -73
  92. package/dist/lib/models/fullname.js +0 -99
  93. package/dist/lib/models/fullname.js.map +0 -1
  94. package/dist/lib/models/index.d.ts +0 -13
  95. package/dist/lib/models/index.js +0 -16
  96. package/dist/lib/models/index.js.map +0 -1
  97. package/dist/lib/models/lastname.d.ts +0 -80
  98. package/dist/lib/models/lastname.js +0 -157
  99. package/dist/lib/models/lastname.js.map +0 -1
  100. package/dist/lib/models/misc.d.ts +0 -108
  101. package/dist/lib/models/misc.js +0 -3
  102. package/dist/lib/models/misc.js.map +0 -1
  103. package/dist/lib/models/name.d.ts +0 -76
  104. package/dist/lib/models/name.js +0 -115
  105. package/dist/lib/models/name.js.map +0 -1
  106. package/dist/lib/models/summary.d.ts +0 -26
  107. package/dist/lib/models/summary.js +0 -61
  108. package/dist/lib/models/summary.js.map +0 -1
  109. package/dist/lib/validators/array-name.validator.d.ts +0 -25
  110. package/dist/lib/validators/array-name.validator.js +0 -75
  111. package/dist/lib/validators/array-name.validator.js.map +0 -1
  112. package/dist/lib/validators/array-string.validator.d.ts +0 -43
  113. package/dist/lib/validators/array-string.validator.js +0 -76
  114. package/dist/lib/validators/array-string.validator.js.map +0 -1
  115. package/dist/lib/validators/common/validation-error.d.ts +0 -19
  116. package/dist/lib/validators/common/validation-error.js +0 -26
  117. package/dist/lib/validators/common/validation-error.js.map +0 -1
  118. package/dist/lib/validators/common/validation-rule.d.ts +0 -72
  119. package/dist/lib/validators/common/validation-rule.js +0 -76
  120. package/dist/lib/validators/common/validation-rule.js.map +0 -1
  121. package/dist/lib/validators/common/validation-type.d.ts +0 -24
  122. package/dist/lib/validators/common/validation-type.js +0 -28
  123. package/dist/lib/validators/common/validation-type.js.map +0 -1
  124. package/dist/lib/validators/firstname.validator.d.ts +0 -20
  125. package/dist/lib/validators/firstname.validator.js +0 -29
  126. package/dist/lib/validators/firstname.validator.js.map +0 -1
  127. package/dist/lib/validators/fullname.validator.d.ts +0 -21
  128. package/dist/lib/validators/fullname.validator.js +0 -38
  129. package/dist/lib/validators/fullname.validator.js.map +0 -1
  130. package/dist/lib/validators/index.d.ts +0 -21
  131. package/dist/lib/validators/index.js +0 -35
  132. package/dist/lib/validators/index.js.map +0 -1
  133. package/dist/lib/validators/lastname.validator.d.ts +0 -20
  134. package/dist/lib/validators/lastname.validator.js +0 -29
  135. package/dist/lib/validators/lastname.validator.js.map +0 -1
  136. package/dist/lib/validators/middlename.validator.d.ts +0 -20
  137. package/dist/lib/validators/middlename.validator.js +0 -38
  138. package/dist/lib/validators/middlename.validator.js.map +0 -1
  139. package/dist/lib/validators/nama.validator.d.ts +0 -21
  140. package/dist/lib/validators/nama.validator.js +0 -44
  141. package/dist/lib/validators/nama.validator.js.map +0 -1
  142. package/dist/lib/validators/namon.validator.d.ts +0 -20
  143. package/dist/lib/validators/namon.validator.js +0 -29
  144. package/dist/lib/validators/namon.validator.js.map +0 -1
  145. package/dist/lib/validators/prefix.validator.d.ts +0 -14
  146. package/dist/lib/validators/prefix.validator.js +0 -31
  147. package/dist/lib/validators/prefix.validator.js.map +0 -1
  148. package/dist/lib/validators/string-name.validator.d.ts +0 -20
  149. package/dist/lib/validators/string-name.validator.js +0 -29
  150. package/dist/lib/validators/string-name.validator.js.map +0 -1
  151. package/dist/lib/validators/suffix.validator.d.ts +0 -14
  152. package/dist/lib/validators/suffix.validator.js +0 -31
  153. package/dist/lib/validators/suffix.validator.js.map +0 -1
  154. package/dist/lib/validators/validator.d.ts +0 -13
  155. package/dist/lib/validators/validator.js +0 -9
  156. package/dist/lib/validators/validator.js.map +0 -1
@@ -1,302 +1,379 @@
1
- import { Fullname, Name, Nama, Summary, Config, NameOrder, NameType, LastnameFormat } from './models';
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
- * Person name handler
4
- * @class
6
+ * A helper for organizing person names in a particular order, way, or shape.
5
7
  *
6
- * `Namefully` does not magically guess which part of the name is what. It relies
7
- * actually on how the developer indicates the roles of the name parts so that
8
- * it, internally, can perform certain operations and saves the developer some
9
- * calculations/processings. Nevertheless, Namefully can be constructed using
10
- * distinct raw data shape. This is intended to give some flexibility to the
11
- * developer so that he or she is not bound to a particular data format. Please,
12
- * do follow closely the APIs to know how to properly use it in order to avoid
13
- * some errors (mainly validation's).
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
- * `Namefully` also works like a trap door. Once a raw data is provided and
16
- * validated, a developer can only ACCESS in a vast amount of, yet effective ways
17
- * the name info. NO EDITING is possible. If the name is mistaken, a new instance
18
- * of `Namefully` must be created. Remember, this utility's primary objective is
19
- * to help to **handle** a person name.
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 matters and can be
31
- * altered through configured parameters, which we will be seeing later on. By
32
- * default, the order of appearance is as shown above and will be used as a basis
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 a name (e.g., firstname)
40
- * - nama: 2+ pieces of a name (e.g., firstname + lastname)
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
- * Holds a json-like high quality of data
47
- * @see {Fullname} description for more details
51
+ * A copy of high-quality name data.
48
52
  */
49
- private fullname;
53
+ private _fullName;
50
54
  /**
51
- * Holds statistical info on the name
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 summary;
57
+ private _config;
55
58
  /**
56
- * Holds a json-like copy of the preset configuration
57
- * @see {Config} description for more details
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
- private config;
67
+ constructor(names: string | string[] | Name[] | JsonName | Parser, options?: Partial<Config>);
60
68
  /**
61
- * Constructs an instance of the utility and helps to benefit from many helpers
62
- * @param {string | string[] | Name[] | Nama | Fullname} raw element to parse or
63
- * construct the pieces of the name
64
- * @param {Config} options to configure how to run the utility
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
- constructor(raw: string | string[] | Name[] | Nama | Fullname, options?: Partial<Config>);
74
+ static tryParse(text: string): Namefully | undefined;
67
75
  /**
68
- * Gets the full name ordered as configured
69
- * @param {NameOrder} orderedBy force to order by first or last
70
- * name by overriding the preset configuration
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
- * @see {format} to alter manually the order of appearance of the full name.
73
- * For example, ::format('l f m') outputs `lastname firstname middlename`.
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
- getFullname(orderedBy?: NameOrder): string;
138
+ get full(): string;
76
139
  /**
77
- * Gets the birth name ordered as configured, no prefix or suffix
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
- getBirthname(orderedBy?: NameOrder): string;
142
+ get public(): string;
82
143
  /**
83
- * Gets the first name part of the full name
84
- * @param {boolean} includeAll whether to include other pieces of the first
85
- * name
144
+ * Returns the full name as set.
86
145
  */
87
- getFirstname(includeAll?: boolean): string;
146
+ toString(): string;
88
147
  /**
89
- * Gets the last name part of the full name
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
- getLastname(format?: LastnameFormat): string;
150
+ get(namon: Namon): Nullable<Name | Name[]>;
94
151
  /**
95
- * Gets the middle names part of the full name
152
+ * Whether this name is equal to another one from a raw-string perspective.
96
153
  */
97
- getMiddlenames(): string[];
154
+ equal(other: Namefully): boolean;
98
155
  /**
99
- * Gets the prefix part of the full name
156
+ * Gets a JSON representation of the full name.
100
157
  */
101
- getPrefix(): string;
158
+ toJson(): JsonName;
102
159
  /**
103
- * Gets the suffix part of the full name
160
+ * Confirms that a name part has been set.
104
161
  */
105
- getSuffix(): string;
162
+ has(namon: Namon): boolean;
106
163
  /**
107
- * Gets the initials of the full name
108
- * @param {NameOrder} orderedBy force to order by first or last name by
109
- * overriding the preset configuration
110
- * @param {boolean} [withMid] whether to include middle names's
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
- * @example
113
- * Given the names:
114
- * - `John Smith` => ['J', 'S']
115
- * - `John Ben Smith` => ['J', 'S']
116
- * when `withMid` is set to true:
117
- * - `John Ben Smith` => ['J', 'B', 'S']
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
- * **NOTE**:
120
- * Ordered by last name obeys the following format:
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
- getInitials(orderedBy?: NameOrder, withMid?: boolean): string[];
186
+ birthName(orderedBy?: NameOrder): string;
126
187
  /**
127
- * Gives some descriptive statistics that summarize the central tendency,
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
- * Treated as a categorical dataset, the summary contains the following info:
132
- * `count` : the number of *unrestricted* characters of the name;
133
- * `frequency` : the highest frequency within the characters;
134
- * `top` : the character with the highest frequency;
135
- * `unique` : the count of unique characters of the name;
136
- * `distribution` : the characters' distribution.
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
- * @example
139
- * Given the name "Thomas Alva Edison", the summary will output as follows:
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
- * Descriptive statistics for "Thomas Alva Edison"
142
- * count : 16
143
- * frequency: 3
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
- * **NOTE:**
150
- * During the setup, a set of restricted characters can be defined to be removed
151
- * from the stats. By default, the only restricted character is the `space`.
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
- describe(what?: NameType): Summary;
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 name and last name.
161
- * @param {NameOrder} orderedBy force to order by first or last
162
- * name by overriding the preset configuration
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 `lastnameFormat` is prioritized.
232
+ * the last name, the configured `surname` is prioritized.
171
233
  *
172
- * @example
173
- * For a given `Firstname Fathername Mothername`, shortening this name when
174
- * the lastnameFormat is set as `mother` is equivalent to making it:
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
- * Compresses a name by using different forms of variants
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
- * @example
188
- * The compressing operation is only executed iff there is valid entry and it
189
- * surpasses the limit set. In the examples below, let us assume that the
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
- * Compressing a long name refers to reducing the name to the following forms:
193
- * 1. by firstname: 'John Moe Beau Lennon' => 'J. Moe Beau Lennon'
194
- * 2. by middlename: 'John Moe Beau Lennon' => 'John M. B. Lennon'
195
- * 3. by lastname: 'John Moe Beau Lennon' => 'John Moe Beau L.'
196
- * 4. by firstmid: 'John Moe Beau Lennon' => 'J. M. B. Lennon'
197
- * 5. by midlast: 'John Moe Beau Lennon' => 'John M. B. L.'
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
- * By default, it compresses by 'firstmid' variant: 'J. M. B. Lennon'.
200
- */
201
- compress(limit?: number, by?: 'fn' | 'ln' | 'mn' | 'fm' | 'ml' | 'firstname' | 'lastname' | 'middlename' | 'firstmid' | 'midlast', warning?: boolean): string;
202
- /**
203
- * Zips or compresses a name by using different forms of variants
204
- * @param by a variant to use when compressing the long name. The last two
205
- * variants represent respectively the combination of `firstname + middlename`
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
- zip(by?: 'fn' | 'ln' | 'mn' | 'fm' | 'ml' | 'firstname' | 'lastname' | 'middlename' | 'firstmid' | 'midlast'): string;
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
- * Suggests possible (randomly) usernames closest to the name
277
+ * Zips or compacts a name using different forms of variants.
211
278
  *
212
- * **NOTE**
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
- username(): string[];
281
+ zip(by?: Flat, withPeriod?: boolean): string;
217
282
  /**
218
- * Formats the name as desired
219
- * @param {string} how to format the full name
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 (official)
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
- * @example
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(how?: string): string;
329
+ format(pattern: string): string;
260
330
  /**
261
- * Returns the count of characters of the birth name, excluding punctuations
331
+ * Flips definitely the name order from the preset/current config.
262
332
  */
263
- size(): number;
333
+ flip(): void;
264
334
  /**
265
- * Returns an ascii representation of each characters of a name as specified
266
- * @param options use specifics to shape conversion
335
+ * Splits the name parts of a birth name.
336
+ * @param separator token for the split.
267
337
  */
268
- ascii(options?: Partial<{
269
- nameType: NameType;
270
- exceptions: string[];
271
- }>): number[];
338
+ split(separator?: string | RegExp): string[];
272
339
  /**
273
- * Transforms a birth name to a specific case
274
- * @param case which case to convert a birth name to
340
+ * Joins the name parts of a birth name.
341
+ * @param separator token for the junction.
275
342
  */
276
- to(_case: 'upper' | 'lower' | 'camel' | 'pascal' | 'snake' | 'hyphen' | 'dot' | 'toggle'): string;
343
+ join(separator?: string): string;
277
344
  /**
278
- * Returns a password-like representation of a name
279
- * @param {NameType} [what] which name part
345
+ * Transforms a birth name into UPPERCASE
280
346
  */
281
- passwd(what?: NameType): string;
282
- private hasMiddlename;
283
- private configure;
284
- private initialize;
285
- private parseNameOrder;
286
- private map;
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
  }