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
@@ -0,0 +1,71 @@
1
+ import { Config } from './config';
2
+ import { FirstName, LastName, Name, JsonName } from './name';
3
+ import { Nullable, Namon } from './types';
4
+ /**
5
+ * The core component of this utility.
6
+ *
7
+ * This component is comprised of five entities that make it easy to handle a
8
+ * full name set: prefix, first name, middle name, last name, and suffix.
9
+ * This class is intended for internal processes. However, it is understandable
10
+ * that it might be needed at some point for additional purposes. For this reason,
11
+ * it's made available.
12
+ *
13
+ * It is recommended to avoid using this class unless it is highly necessary or
14
+ * a custom parser is used for uncommon use cases. This utility tries to cover
15
+ * as many use cases as possible.
16
+ *
17
+ * Additionally, an optional configuration can be used to indicate some specific
18
+ * behaviors related to that name handling.
19
+ */
20
+ export declare class FullName {
21
+ private _prefix;
22
+ private _firstName;
23
+ private _middleName;
24
+ private _lastName;
25
+ private _suffix;
26
+ private _config;
27
+ /**
28
+ * Creates a full name as it goes
29
+ * @param options optional configuration for additional features.
30
+ */
31
+ constructor(options?: Partial<Config>);
32
+ /**
33
+ * A snapshot of the configuration used to set up this full name.
34
+ */
35
+ get config(): Config;
36
+ /**
37
+ * The prefix part of the full name.
38
+ */
39
+ get prefix(): Nullable<Name>;
40
+ /**
41
+ * The first name part of the full name.
42
+ */
43
+ get firstName(): FirstName;
44
+ /**
45
+ * The last name part of the full name.
46
+ */
47
+ get lastName(): LastName;
48
+ /**
49
+ * The middle name part of the full name.
50
+ */
51
+ get middleName(): Name[];
52
+ /**
53
+ * The suffix part of the full name.
54
+ */
55
+ get suffix(): Nullable<Name>;
56
+ setPrefix(name: Nullable<string | Name>): FullName;
57
+ setFirstName(name: string | FirstName): FullName;
58
+ setLastName(name: string | LastName): FullName;
59
+ setMiddleName(names: string[] | Name[]): FullName;
60
+ setSuffix(name: Nullable<string | Name>): FullName;
61
+ /**
62
+ * Returns true if a namon has been set.
63
+ */
64
+ has(namon: Namon): boolean;
65
+ /**
66
+ * Parses a json name into a full name.
67
+ * @param json parsable name element
68
+ * @param config optional configuration for additional features.
69
+ */
70
+ static parse(json: JsonName, config?: Config): FullName;
71
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Welcome to namefully!
3
+ *
4
+ * `namefully` is a JavaScript utility for handing person names.
5
+ *
6
+ * Sources
7
+ * - repo: https://github.com/ralflorent/namefully
8
+ * - docs: https://namefully.netlify.app
9
+ * - npm: https://npmjs.com/package/namefully
10
+ *
11
+ * @license MIT
12
+ */
13
+ export * from './config';
14
+ export * from './error';
15
+ export * from './full-name';
16
+ export * from './name';
17
+ export * from './namefully';
18
+ export { Parser } from './parser';
19
+ export * from './types';
20
+ export { NameIndex } from './utils';
@@ -0,0 +1,177 @@
1
+ import { CapsRange, Namon, Surname } from './types';
2
+ /**
3
+ * Representation of a string type name with some extra capabilities.
4
+ */
5
+ export declare class Name {
6
+ readonly type: Namon;
7
+ private namon;
8
+ protected initial: string;
9
+ protected capsRange: CapsRange;
10
+ /**
11
+ * Creates augmented names by adding extra functionality to a string name.
12
+ * @param type must be indicated to categorize the name so it can be
13
+ * treated accordingly.
14
+ * @param capsRange determines how the name should be capitalized initially.
15
+ */
16
+ constructor(value: string, type: Namon, capsRange?: CapsRange);
17
+ set value(newValue: string);
18
+ /**
19
+ * The piece of string treated as a name.
20
+ */
21
+ get value(): string;
22
+ /**
23
+ * The length of the name.
24
+ */
25
+ get length(): number;
26
+ /**
27
+ * Whether the name is a prefix.
28
+ */
29
+ get isPrefix(): boolean;
30
+ /**
31
+ * Whether the name is a first name.
32
+ */
33
+ get isFirstName(): boolean;
34
+ /**
35
+ * Whether the name is a middle name.
36
+ */
37
+ get isMiddleName(): boolean;
38
+ /**
39
+ * Whether the name is a last name.
40
+ */
41
+ get isLastName(): boolean;
42
+ /**
43
+ * Whether the name is a suffix.
44
+ */
45
+ get isSuffix(): boolean;
46
+ /**
47
+ * Creates a prefix.
48
+ */
49
+ static prefix(value: string): Name;
50
+ /**
51
+ * Creates a first name.
52
+ */
53
+ static first(value: string): Name;
54
+ /**
55
+ * Creates a middle name.
56
+ */
57
+ static middle(value: string): Name;
58
+ /**
59
+ * Creates a last name.
60
+ */
61
+ static last(value: string): Name;
62
+ /**
63
+ * Creates a suffix.
64
+ */
65
+ static suffix(value: string): Name;
66
+ /**
67
+ * Gets the initials (first character) of this name.
68
+ */
69
+ initials(): string[];
70
+ /**
71
+ * String representation of this object.
72
+ */
73
+ toString(): string;
74
+ /**
75
+ * Returns true if the other is equal to this name.
76
+ */
77
+ equal(other: Name | unknown): boolean;
78
+ /**
79
+ * Capitalizes the name.
80
+ */
81
+ caps(range?: CapsRange): Name;
82
+ /**
83
+ * De-capitalizes the name.
84
+ */
85
+ decaps(range?: CapsRange): Name;
86
+ }
87
+ /**
88
+ * Representation of a first name with some extra functionality.
89
+ */
90
+ export declare class FirstName extends Name {
91
+ private _more;
92
+ /**
93
+ * Creates an extended version of `Name` and flags it as a first name `type`.
94
+ *
95
+ * Some may consider `more` additional name parts of a given name as their
96
+ * first names, but not as their middle names. Though, it may mean the same,
97
+ * `more` provides the freedom to do it as it pleases.
98
+ */
99
+ constructor(value: string, ...more: string[]);
100
+ /**
101
+ * Determines whether a first name has `more` name parts.
102
+ */
103
+ get hasMore(): boolean;
104
+ get length(): number;
105
+ /**
106
+ * Returns a combined version of the `value` and `more` if any.
107
+ */
108
+ get asNames(): Name[];
109
+ /**
110
+ * The additional name parts of the first name.
111
+ */
112
+ get more(): string[];
113
+ toString(withMore?: boolean): string;
114
+ initials(withMore?: boolean): string[];
115
+ caps(range?: CapsRange): FirstName;
116
+ decaps(range?: CapsRange): FirstName;
117
+ /**
118
+ * Makes a copy of the current name.
119
+ */
120
+ copyWith(values?: {
121
+ first?: string;
122
+ more?: string[];
123
+ }): FirstName;
124
+ }
125
+ /**
126
+ * Representation of a last name with some extra functionality.
127
+ */
128
+ export declare class LastName extends Name {
129
+ readonly format: Surname;
130
+ private _mother?;
131
+ /**
132
+ * Creates an extended version of `Name` and flags it as a last name `type`.
133
+ *
134
+ * Some people may keep their `mother`'s surname and want to keep a clear cut
135
+ * from their `father`'s surname. However, there are no clear rules about it.
136
+ */
137
+ constructor(father: string, mother?: string, format?: Surname);
138
+ /**
139
+ * The surname inherited from a father side.
140
+ */
141
+ get father(): string;
142
+ /**
143
+ * The surname inherited from a mother side.
144
+ */
145
+ get mother(): string | undefined;
146
+ /**
147
+ * Returns `true` if the mother's surname is defined.
148
+ */
149
+ get hasMother(): boolean;
150
+ get length(): number;
151
+ /**
152
+ * Returns a combined version of the `father` and `mother` if any.
153
+ */
154
+ get asNames(): Name[];
155
+ toString(format?: Surname): string;
156
+ initials(format?: Surname): string[];
157
+ caps(range?: CapsRange): LastName;
158
+ decaps(range?: CapsRange): LastName;
159
+ /**
160
+ * Makes a copy of the current name.
161
+ */
162
+ copyWith(values?: {
163
+ father?: string;
164
+ mother?: string;
165
+ format?: Surname;
166
+ }): LastName;
167
+ }
168
+ /**
169
+ * JSON signature for `FullName` data.
170
+ */
171
+ export interface JsonName {
172
+ prefix?: string;
173
+ firstName: string;
174
+ middleName?: string[];
175
+ lastName: string;
176
+ suffix?: string;
177
+ }
@@ -0,0 +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';
5
+ /**
6
+ * A helper for organizing person names in a particular order, way, or shape.
7
+ *
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.
17
+ *
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.
31
+ *
32
+ * @see https://departments.weber.edu/qsupport&training/Data_Standards/Name.htm
33
+ * for more info on name standards.
34
+ *
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.
39
+ *
40
+ * Once imported, all that is required to do is to create an instance of
41
+ * `Namefully` and the rest will follow.
42
+ *
43
+ * Some terminologies used across the library are:
44
+ * - namon: 1 piece of name (e.g., first name)
45
+ * - nama: 2+ pieces of name (e.g., first name + last name)
46
+ *
47
+ * Happy name handling 😊!
48
+ */
49
+ export declare class Namefully {
50
+ /**
51
+ * A copy of high-quality name data.
52
+ */
53
+ private _fullName;
54
+ /**
55
+ * A copy of the default configuration (combined with a custom one if any).
56
+ */
57
+ private _config;
58
+ /**
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.
66
+ */
67
+ constructor(names: string | string[] | Name[] | JsonName | Parser, options?: Partial<Config>);
68
+ /**
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`.
73
+ */
74
+ static tryParse(text: string): Namefully | undefined;
75
+ /**
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.
80
+ *
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.
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.
165
+ *
166
+ * The name order `orderedBy` forces to order by first or last name by
167
+ * overriding the preset configuration.
168
+ *
169
+ * `Namefully.format` may also be used to alter manually the order of appearance
170
+ * of full name.
171
+ *
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`.
182
+ *
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`.
189
+ *
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`.
200
+ *
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`.
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[];
220
+ /**
221
+ * Shortens a complex full name to a simple typical name, a combination of
222
+ * first and last name.
223
+ *
224
+ * @param orderedBy forces to order by first or last name by overriding the
225
+ * preset configuration.
226
+ *
227
+ * For a given name such as `Mr Keanu Charles Reeves`, shortening this name
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`.
237
+ */
238
+ shorten(orderedBy?: NameOrder): string;
239
+ /**
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`.
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
249
+ * name goes beyond the limit value.
250
+ *
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.'
259
+ *
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()`.
267
+ */
268
+ flatten(options: Partial<{
269
+ limit: number;
270
+ by: Flat;
271
+ withPeriod: boolean;
272
+ recursive: boolean;
273
+ withMore: boolean;
274
+ surname: Surname;
275
+ }>): string;
276
+ /**
277
+ * Zips or compacts a name using different forms of variants.
278
+ *
279
+ * @see `flatten()` for more details.
280
+ */
281
+ zip(by?: Flat, withPeriod?: boolean): string;
282
+ /**
283
+ * Formats the full name as desired.
284
+ * @param pattern character used to format it.
285
+ *
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
292
+ *
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.
320
+ * - format('l f') => 'Smith Joe'
321
+ * - format('L, f') => 'SMITH, Joe'
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.
328
+ */
329
+ format(pattern: string): string;
330
+ /**
331
+ * Flips definitely the name order from the preset/current config.
332
+ */
333
+ flip(): void;
334
+ /**
335
+ * Splits the name parts of a birth name.
336
+ * @param separator token for the split.
337
+ */
338
+ split(separator?: string | RegExp): string[];
339
+ /**
340
+ * Joins the name parts of a birth name.
341
+ * @param separator token for the junction.
342
+ */
343
+ join(separator?: string): string;
344
+ /**
345
+ * Transforms a birth name into UPPERCASE
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;
376
+ private build;
377
+ private toParser;
378
+ private map;
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
+ }