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.
Files changed (189) hide show
  1. package/LICENSE +21 -674
  2. package/dist/example/index.js +2734 -0
  3. package/dist/lib/config.d.ts +121 -0
  4. package/dist/lib/config.js +189 -0
  5. package/dist/lib/config.js.map +1 -0
  6. package/dist/lib/constants.d.ts +4 -0
  7. package/dist/lib/constants.js +31 -0
  8. package/dist/lib/constants.js.map +1 -0
  9. package/dist/lib/error.d.ts +172 -0
  10. package/dist/lib/error.js +210 -0
  11. package/dist/lib/error.js.map +1 -0
  12. package/dist/lib/{usecases/index.d.ts → example/example.d.ts} +0 -0
  13. package/dist/lib/full-name.d.ts +71 -0
  14. package/dist/lib/full-name.js +147 -0
  15. package/dist/lib/full-name.js.map +1 -0
  16. package/dist/lib/index.d.ts +16 -6
  17. package/dist/lib/index.js +29 -8
  18. package/dist/lib/index.js.map +1 -1
  19. package/dist/lib/name.d.ts +177 -0
  20. package/dist/lib/name.js +322 -0
  21. package/dist/lib/name.js.map +1 -0
  22. package/dist/lib/namefully.d.ts +303 -208
  23. package/dist/lib/namefully.js +603 -442
  24. package/dist/lib/namefully.js.map +1 -1
  25. package/dist/lib/parser.d.ts +46 -0
  26. package/dist/lib/parser.js +173 -0
  27. package/dist/lib/parser.js.map +1 -0
  28. package/dist/lib/src/config.d.ts +121 -0
  29. package/dist/lib/src/constants.d.ts +4 -0
  30. package/dist/lib/src/error.d.ts +172 -0
  31. package/dist/lib/src/full-name.d.ts +71 -0
  32. package/dist/lib/src/index.d.ts +16 -6
  33. package/dist/lib/src/name.d.ts +177 -0
  34. package/dist/lib/src/namefully.d.ts +303 -208
  35. package/dist/lib/src/parser.d.ts +46 -0
  36. package/dist/lib/src/types.d.ts +127 -0
  37. package/dist/lib/src/utils.d.ts +63 -0
  38. package/dist/lib/src/validator.d.ts +66 -0
  39. package/dist/lib/types.d.ts +127 -0
  40. package/dist/lib/types.js +181 -0
  41. package/dist/lib/types.js.map +1 -0
  42. package/dist/lib/utils.d.ts +63 -0
  43. package/dist/lib/utils.js +138 -0
  44. package/dist/lib/utils.js.map +1 -0
  45. package/dist/lib/validator.d.ts +66 -0
  46. package/dist/lib/validator.js +332 -0
  47. package/dist/lib/validator.js.map +1 -0
  48. package/dist/umd/namefully.js +2191 -2111
  49. package/dist/umd/namefully.js.map +1 -1
  50. package/dist/umd/namefully.min.js +1 -1
  51. package/dist/umd/namefully.min.js.LICENSE.txt +8 -20
  52. package/dist/umd/namefully.min.js.map +1 -1
  53. package/package.json +50 -53
  54. package/readme.md +151 -175
  55. package/changelog.md +0 -114
  56. package/dist/lib/core/constants.d.ts +0 -26
  57. package/dist/lib/core/constants.js +0 -42
  58. package/dist/lib/core/constants.js.map +0 -1
  59. package/dist/lib/core/index.d.ts +0 -9
  60. package/dist/lib/core/index.js +0 -13
  61. package/dist/lib/core/index.js.map +0 -1
  62. package/dist/lib/core/parsers/array-name.parser.d.ts +0 -42
  63. package/dist/lib/core/parsers/array-name.parser.js +0 -84
  64. package/dist/lib/core/parsers/array-name.parser.js.map +0 -1
  65. package/dist/lib/core/parsers/array-string.parser.d.ts +0 -48
  66. package/dist/lib/core/parsers/array-string.parser.js +0 -96
  67. package/dist/lib/core/parsers/array-string.parser.js.map +0 -1
  68. package/dist/lib/core/parsers/index.d.ts +0 -11
  69. package/dist/lib/core/parsers/index.js +0 -11
  70. package/dist/lib/core/parsers/index.js.map +0 -1
  71. package/dist/lib/core/parsers/nama.parser.d.ts +0 -34
  72. package/dist/lib/core/parsers/nama.parser.js +0 -75
  73. package/dist/lib/core/parsers/nama.parser.js.map +0 -1
  74. package/dist/lib/core/parsers/parser.d.ts +0 -29
  75. package/dist/lib/core/parsers/parser.js +0 -3
  76. package/dist/lib/core/parsers/parser.js.map +0 -1
  77. package/dist/lib/core/parsers/string.parser.d.ts +0 -61
  78. package/dist/lib/core/parsers/string.parser.js +0 -63
  79. package/dist/lib/core/parsers/string.parser.js.map +0 -1
  80. package/dist/lib/core/utils/utils.d.ts +0 -14
  81. package/dist/lib/core/utils/utils.js +0 -67
  82. package/dist/lib/core/utils/utils.js.map +0 -1
  83. package/dist/lib/models/enums.d.ts +0 -91
  84. package/dist/lib/models/enums.js +0 -98
  85. package/dist/lib/models/enums.js.map +0 -1
  86. package/dist/lib/models/firstname.d.ts +0 -41
  87. package/dist/lib/models/firstname.js +0 -59
  88. package/dist/lib/models/firstname.js.map +0 -1
  89. package/dist/lib/models/index.d.ts +0 -12
  90. package/dist/lib/models/index.js +0 -15
  91. package/dist/lib/models/index.js.map +0 -1
  92. package/dist/lib/models/lastname.d.ts +0 -44
  93. package/dist/lib/models/lastname.js +0 -86
  94. package/dist/lib/models/lastname.js.map +0 -1
  95. package/dist/lib/models/misc.d.ts +0 -80
  96. package/dist/lib/models/misc.js +0 -3
  97. package/dist/lib/models/misc.js.map +0 -1
  98. package/dist/lib/models/name.d.ts +0 -48
  99. package/dist/lib/models/name.js +0 -72
  100. package/dist/lib/models/name.js.map +0 -1
  101. package/dist/lib/models/summary.d.ts +0 -23
  102. package/dist/lib/models/summary.js +0 -60
  103. package/dist/lib/models/summary.js.map +0 -1
  104. package/dist/lib/src/core/constants.d.ts +0 -26
  105. package/dist/lib/src/core/index.d.ts +0 -9
  106. package/dist/lib/src/core/parsers/array-name.parser.d.ts +0 -42
  107. package/dist/lib/src/core/parsers/array-string.parser.d.ts +0 -48
  108. package/dist/lib/src/core/parsers/index.d.ts +0 -11
  109. package/dist/lib/src/core/parsers/nama.parser.d.ts +0 -34
  110. package/dist/lib/src/core/parsers/parser.d.ts +0 -29
  111. package/dist/lib/src/core/parsers/string.parser.d.ts +0 -61
  112. package/dist/lib/src/core/utils/utils.d.ts +0 -14
  113. package/dist/lib/src/models/enums.d.ts +0 -91
  114. package/dist/lib/src/models/firstname.d.ts +0 -41
  115. package/dist/lib/src/models/index.d.ts +0 -12
  116. package/dist/lib/src/models/lastname.d.ts +0 -44
  117. package/dist/lib/src/models/misc.d.ts +0 -80
  118. package/dist/lib/src/models/name.d.ts +0 -48
  119. package/dist/lib/src/models/summary.d.ts +0 -23
  120. package/dist/lib/src/validators/array-name.validator.d.ts +0 -25
  121. package/dist/lib/src/validators/array-string.validator.d.ts +0 -43
  122. package/dist/lib/src/validators/common/validation-error.d.ts +0 -19
  123. package/dist/lib/src/validators/common/validation-rule.d.ts +0 -69
  124. package/dist/lib/src/validators/common/validation-type.d.ts +0 -24
  125. package/dist/lib/src/validators/firstname.validator.d.ts +0 -20
  126. package/dist/lib/src/validators/fullname.validator.d.ts +0 -21
  127. package/dist/lib/src/validators/index.d.ts +0 -21
  128. package/dist/lib/src/validators/lastname.validator.d.ts +0 -20
  129. package/dist/lib/src/validators/middlename.validator.d.ts +0 -20
  130. package/dist/lib/src/validators/nama.validator.d.ts +0 -21
  131. package/dist/lib/src/validators/namon.validator.d.ts +0 -20
  132. package/dist/lib/src/validators/prefix.validator.d.ts +0 -14
  133. package/dist/lib/src/validators/string-name.validator.d.ts +0 -20
  134. package/dist/lib/src/validators/suffix.validator.d.ts +0 -14
  135. package/dist/lib/src/validators/validator.d.ts +0 -13
  136. package/dist/lib/usecases/compress.usecase.d.ts +0 -8
  137. package/dist/lib/usecases/constants.d.ts +0 -7
  138. package/dist/lib/usecases/describe.usecase.d.ts +0 -12
  139. package/dist/lib/usecases/format.usecase.d.ts +0 -6
  140. package/dist/lib/usecases/namefully.usecase.d.ts +0 -14
  141. package/dist/lib/usecases/shorten.usecase.d.ts +0 -6
  142. package/dist/lib/validators/array-name.validator.d.ts +0 -25
  143. package/dist/lib/validators/array-name.validator.js +0 -82
  144. package/dist/lib/validators/array-name.validator.js.map +0 -1
  145. package/dist/lib/validators/array-string.validator.d.ts +0 -43
  146. package/dist/lib/validators/array-string.validator.js +0 -80
  147. package/dist/lib/validators/array-string.validator.js.map +0 -1
  148. package/dist/lib/validators/common/validation-error.d.ts +0 -19
  149. package/dist/lib/validators/common/validation-error.js +0 -26
  150. package/dist/lib/validators/common/validation-error.js.map +0 -1
  151. package/dist/lib/validators/common/validation-rule.d.ts +0 -69
  152. package/dist/lib/validators/common/validation-rule.js +0 -73
  153. package/dist/lib/validators/common/validation-rule.js.map +0 -1
  154. package/dist/lib/validators/common/validation-type.d.ts +0 -24
  155. package/dist/lib/validators/common/validation-type.js +0 -28
  156. package/dist/lib/validators/common/validation-type.js.map +0 -1
  157. package/dist/lib/validators/firstname.validator.d.ts +0 -20
  158. package/dist/lib/validators/firstname.validator.js +0 -29
  159. package/dist/lib/validators/firstname.validator.js.map +0 -1
  160. package/dist/lib/validators/fullname.validator.d.ts +0 -21
  161. package/dist/lib/validators/fullname.validator.js +0 -38
  162. package/dist/lib/validators/fullname.validator.js.map +0 -1
  163. package/dist/lib/validators/index.d.ts +0 -21
  164. package/dist/lib/validators/index.js +0 -35
  165. package/dist/lib/validators/index.js.map +0 -1
  166. package/dist/lib/validators/lastname.validator.d.ts +0 -20
  167. package/dist/lib/validators/lastname.validator.js +0 -29
  168. package/dist/lib/validators/lastname.validator.js.map +0 -1
  169. package/dist/lib/validators/middlename.validator.d.ts +0 -20
  170. package/dist/lib/validators/middlename.validator.js +0 -38
  171. package/dist/lib/validators/middlename.validator.js.map +0 -1
  172. package/dist/lib/validators/nama.validator.d.ts +0 -21
  173. package/dist/lib/validators/nama.validator.js +0 -43
  174. package/dist/lib/validators/nama.validator.js.map +0 -1
  175. package/dist/lib/validators/namon.validator.d.ts +0 -20
  176. package/dist/lib/validators/namon.validator.js +0 -29
  177. package/dist/lib/validators/namon.validator.js.map +0 -1
  178. package/dist/lib/validators/prefix.validator.d.ts +0 -14
  179. package/dist/lib/validators/prefix.validator.js +0 -31
  180. package/dist/lib/validators/prefix.validator.js.map +0 -1
  181. package/dist/lib/validators/string-name.validator.d.ts +0 -20
  182. package/dist/lib/validators/string-name.validator.js +0 -29
  183. package/dist/lib/validators/string-name.validator.js.map +0 -1
  184. package/dist/lib/validators/suffix.validator.d.ts +0 -14
  185. package/dist/lib/validators/suffix.validator.js +0 -31
  186. package/dist/lib/validators/suffix.validator.js.map +0 -1
  187. package/dist/lib/validators/validator.d.ts +0 -13
  188. package/dist/lib/validators/validator.js +0 -9
  189. 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
- * `Namefully` person name handler
6
+ * A helper for organizing person names in a particular order, way, or shape.
3
7
  *
4
- * Created on March 03, 2020
5
- * @author Ralph Florent <ralflornt@gmail.com>
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
- * @license GPL-3.0
8
- * @see {@link https://github.com/ralflorent/namefully|namefully} for more info.
9
- */
10
- import { Parser } from './core/index';
11
- import { Name, Nama, Separator, Summary, NameOrder, AbbrTitle, LastnameFormat } from './models/index';
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
- * `Namefully` also works like a trap door. Once a raw data is provided and
26
- * validated, a developer can only ACCESS in a vast amount of, yet effective ways
27
- * the name info. NO EDITING is possible. If the name is mistaken, a new instance
28
- * of `Namefully` must be created. Remember, this utility's primary objective is
29
- * to help to **handle** a person name.
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 matters and can be
41
- * altered through configured parameters, which we will be seeing later on. By
42
- * default, the order of appearance is as shown above and will be used as a basis
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 a name (e.g., firstname)
50
- * - nama: 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)
51
46
  *
52
- * Happy naming!
47
+ * Happy name handling 😊!
53
48
  */
54
49
  export declare class Namefully {
55
50
  /**
56
- * Holds a json-like high quality of data
57
- * @see {Fullname} description for more details
51
+ * A copy of high-quality name data.
58
52
  */
59
- private fullname;
53
+ private _fullName;
60
54
  /**
61
- * Holds statistical info on the name
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 summary;
57
+ private _config;
65
58
  /**
66
- * Holds a json-like copy of the preset configuration
67
- * @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.
68
66
  */
69
- private config;
67
+ constructor(names: string | string[] | Name[] | JsonName | Parser, options?: Partial<Config>);
70
68
  /**
71
- * Constructs an instance of the utility and helps to benefit from many helpers
72
- * @param {string | string[] | Array<Name> | Nama} raw element to parse or
73
- * construct the pieces of the name
74
- * @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`.
75
73
  */
76
- constructor(raw: string | Array<string> | Array<Name> | Nama, options?: Partial<{
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
- * Gets the full name ordered as configured
87
- * @param {'firstname'|'lastname'} orderedBy force to order by first or last
88
- * name by overriding the preset configuration
89
- * @returns {string} the suffix
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
- * @see {format} to alter manually the order of appearance of the full name.
92
- * 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.
93
97
  */
94
- getFullname(orderedBy?: NameOrder): string;
98
+ get length(): number;
95
99
  /**
96
- * Gets the first name part of the full name
97
- * @returns {string} the first name
100
+ * The prefix part.
98
101
  */
99
- getFirstname(): string;
102
+ get prefix(): Nullable<string>;
100
103
  /**
101
- * Gets the last name part of the full name
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
- getLastname(format?: LastnameFormat): string;
106
+ get first(): string;
107
107
  /**
108
- * Gets the middle names part of the full name
109
- * @returns {Array<string>} the middle names
108
+ * The first middle name if any.
110
109
  */
111
- getMiddlenames(): string[];
110
+ get middle(): Nullable<string>;
112
111
  /**
113
- * Gets the prefix part of the full name
114
- * @returns {string} the prefix
112
+ * Returns true if any middle name has been set.
115
113
  */
116
- getPrefix(): string;
114
+ get hasMiddle(): boolean;
117
115
  /**
118
- * Gets the suffix part of the full name
119
- * @returns {string} the suffix
116
+ * The last name.
120
117
  */
121
- getSuffix(): string;
118
+ get last(): string;
122
119
  /**
123
- * Gets the initials of the full name
124
- * @param {'firstname'|'lastname'} orderedBy force to order by first or last
125
- * name by overriding the preset configuration
126
- * @param {boolean} [withMid] whether to include middle names's
127
- * @returns {Array<string>} the initials
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
- * @example
130
- * Given the names:
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
- * **NOTE**:
137
- * Ordered by last name obeys the following format:
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
- * Treated as a categorical dataset, the summary contains the following info:
150
- * `count` : the number of *unrestricted* characters of the name;
151
- * `frequency` : the highest frequency within the characters;
152
- * `top` : the character with the highest frequency;
153
- * `unique` : the count of unique characters of the name.
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
- * @example
156
- * Given the name "Thomas Alva Edison", the summary will output as follows:
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
- * Descriptive statistics for "Thomas Alva Edison"
159
- * count : 16
160
- * frequency: 3
161
- * top : A
162
- * unique : 12
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
- * **NOTE:**
165
- * During the setup, a set of restricted characters can be defined to be removed
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
- describe(what?: 'fullname' | 'firstname' | 'lastname' | 'middlename'): Summary;
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 name and last name.
176
- * @param {'firstname'|'lastname'} orderedBy force to order by first or last
177
- * name by overriding the preset configuration
178
- * @returns {string} a typical name
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?: 'firstname' | 'lastname'): string;
238
+ shorten(orderedBy?: NameOrder): string;
185
239
  /**
186
- * Compresses a name by using different forms of variants
187
- * @param {number} [limit] a threshold to limit the number of characters
188
- * @param {'firstname'|'lastname'|'middlename'|'firstmid'|'midlast'} [by]
189
- * a variant to use when compressing the long name. The last two variants
190
- * represent respectively the combination of `firstname + middlename` and
191
- * `middlename + lastname`.
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
- * @example
195
- * The compressing operation is only executed iff there is valid entry and it
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
- * Compressing a long name refers to reducing the name to the following forms:
200
- * 1. by firstname: 'John Moe Beau Lennon' => 'J. Moe Beau Lennon'
201
- * 2. by middlename: 'John Moe Beau Lennon' => 'John M. B. Lennon'
202
- * 3. by lastname: 'John Moe Beau Lennon' => 'John Moe Beau L.'
203
- * 4. by firstmid: 'John Moe Beau Lennon' => 'J. M. B. Lennon'
204
- * 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.'
205
259
  *
206
- * By default, it compresses by 'firstmid' variant: 'J. M. B. Lennon'.
207
- */
208
- compress(limit?: number, by?: 'firstname' | 'lastname' | 'middlename' | 'firstmid' | 'midlast', warning?: boolean): string;
209
- /**
210
- * Zips or compresses a name by using different forms of variants
211
- * @param by a variant to use when compressing the long name. The last two
212
- * variants represent respectively the combination of `firstname + middlename`
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
- 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;
216
276
  /**
217
- * Suggests possible (randomly) usernames closest to the name
218
- * @returns {Array<string>} a set of usernames
277
+ * Zips or compacts a name using different forms of variants.
219
278
  *
220
- * **NOTE**
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
- username(): string[];
281
+ zip(by?: Flat, withPeriod?: boolean): string;
225
282
  /**
226
- * Formats the name as desired
227
- * @param {string} how to format the full name
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
- * How to format it?
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
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
- * @example
240
- * Given the name `Joe Jim Smith`, call the `format` with the how string.
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('fml') => 'JoeJimSmith'
244
- * - format('FML') => 'JOEJIMSMITH'
245
- * - format('L, f m') => 'SMITH, Joe Jim'
246
- * - format('O') => 'SMITH, Joe Jim'
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(how?: string): string;
329
+ format(pattern: string): string;
249
330
  /**
250
- * Configures how the setup will be working
251
- * @param {Config} options for a customized setup
331
+ * Flips definitely the name order from the preset/current config.
252
332
  */
253
- private configure;
333
+ flip(): void;
254
334
  /**
255
- * Defines the full name by having the pieces (namon) of the names ready
256
- * @param parser customized or user-defined parser to get the full name
335
+ * Splits the name parts of a birth name.
336
+ * @param separator token for the split.
257
337
  */
258
- private initialize;
338
+ split(separator?: string | RegExp): string[];
259
339
  /**
260
- * Maps a character to a specific piece of the name
261
- * @param c character to be mapped
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
- private map;
343
+ join(separator?: string): string;
265
344
  /**
266
- * Builds a high qualitty of data using parsers and validators
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
+ }