namefully 1.1.0 → 1.2.1

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 (136) hide show
  1. package/dist/lib/config.js +112 -0
  2. package/dist/lib/constants.js +30 -0
  3. package/dist/lib/error.js +92 -0
  4. package/dist/lib/full-name.js +115 -0
  5. package/dist/lib/index.js +27 -12
  6. package/dist/lib/name.js +230 -0
  7. package/dist/lib/namefully.js +368 -681
  8. package/dist/lib/parser.js +138 -0
  9. package/dist/lib/types.js +107 -0
  10. package/dist/lib/utils.js +92 -0
  11. package/dist/lib/validator.js +301 -0
  12. package/dist/types/config.d.ts +97 -0
  13. package/dist/types/constants.d.ts +4 -0
  14. package/dist/types/error.d.ts +158 -0
  15. package/dist/types/full-name.d.ts +54 -0
  16. package/dist/types/index.d.ts +21 -0
  17. package/dist/types/name.d.ts +126 -0
  18. package/dist/types/namefully.d.ts +313 -0
  19. package/dist/types/parser.d.ts +41 -0
  20. package/dist/types/types.d.ts +127 -0
  21. package/dist/types/utils.d.ts +53 -0
  22. package/dist/types/validator.d.ts +57 -0
  23. package/dist/umd/namefully.js +1503 -2900
  24. package/dist/umd/namefully.min.js +1 -3
  25. package/package.json +28 -38
  26. package/readme.md +138 -167
  27. package/changelog.md +0 -134
  28. package/dist/lib/core/constants.d.ts +0 -48
  29. package/dist/lib/core/constants.js +0 -101
  30. package/dist/lib/core/constants.js.map +0 -1
  31. package/dist/lib/core/core.d.ts +0 -17
  32. package/dist/lib/core/core.js +0 -24
  33. package/dist/lib/core/core.js.map +0 -1
  34. package/dist/lib/core/index.d.ts +0 -9
  35. package/dist/lib/core/index.js +0 -13
  36. package/dist/lib/core/index.js.map +0 -1
  37. package/dist/lib/core/parsers/array-name.parser.d.ts +0 -41
  38. package/dist/lib/core/parsers/array-name.parser.js +0 -86
  39. package/dist/lib/core/parsers/array-name.parser.js.map +0 -1
  40. package/dist/lib/core/parsers/array-string.parser.d.ts +0 -47
  41. package/dist/lib/core/parsers/array-string.parser.js +0 -95
  42. package/dist/lib/core/parsers/array-string.parser.js.map +0 -1
  43. package/dist/lib/core/parsers/index.d.ts +0 -11
  44. package/dist/lib/core/parsers/index.js +0 -11
  45. package/dist/lib/core/parsers/index.js.map +0 -1
  46. package/dist/lib/core/parsers/nama.parser.d.ts +0 -33
  47. package/dist/lib/core/parsers/nama.parser.js +0 -74
  48. package/dist/lib/core/parsers/nama.parser.js.map +0 -1
  49. package/dist/lib/core/parsers/parser.d.ts +0 -28
  50. package/dist/lib/core/parsers/parser.js +0 -3
  51. package/dist/lib/core/parsers/parser.js.map +0 -1
  52. package/dist/lib/core/parsers/string.parser.d.ts +0 -60
  53. package/dist/lib/core/parsers/string.parser.js +0 -62
  54. package/dist/lib/core/parsers/string.parser.js.map +0 -1
  55. package/dist/lib/core/utils.d.ts +0 -52
  56. package/dist/lib/core/utils.js +0 -178
  57. package/dist/lib/core/utils.js.map +0 -1
  58. package/dist/lib/index.d.ts +0 -10
  59. package/dist/lib/index.js.map +0 -1
  60. package/dist/lib/models/enums.d.ts +0 -106
  61. package/dist/lib/models/enums.js +0 -114
  62. package/dist/lib/models/enums.js.map +0 -1
  63. package/dist/lib/models/firstname.d.ts +0 -77
  64. package/dist/lib/models/firstname.js +0 -131
  65. package/dist/lib/models/firstname.js.map +0 -1
  66. package/dist/lib/models/fullname.d.ts +0 -73
  67. package/dist/lib/models/fullname.js +0 -99
  68. package/dist/lib/models/fullname.js.map +0 -1
  69. package/dist/lib/models/index.d.ts +0 -13
  70. package/dist/lib/models/index.js +0 -16
  71. package/dist/lib/models/index.js.map +0 -1
  72. package/dist/lib/models/lastname.d.ts +0 -80
  73. package/dist/lib/models/lastname.js +0 -157
  74. package/dist/lib/models/lastname.js.map +0 -1
  75. package/dist/lib/models/misc.d.ts +0 -108
  76. package/dist/lib/models/misc.js +0 -3
  77. package/dist/lib/models/misc.js.map +0 -1
  78. package/dist/lib/models/name.d.ts +0 -76
  79. package/dist/lib/models/name.js +0 -115
  80. package/dist/lib/models/name.js.map +0 -1
  81. package/dist/lib/models/summary.d.ts +0 -26
  82. package/dist/lib/models/summary.js +0 -61
  83. package/dist/lib/models/summary.js.map +0 -1
  84. package/dist/lib/namefully.d.ts +0 -302
  85. package/dist/lib/namefully.js.map +0 -1
  86. package/dist/lib/validators/array-name.validator.d.ts +0 -25
  87. package/dist/lib/validators/array-name.validator.js +0 -75
  88. package/dist/lib/validators/array-name.validator.js.map +0 -1
  89. package/dist/lib/validators/array-string.validator.d.ts +0 -43
  90. package/dist/lib/validators/array-string.validator.js +0 -76
  91. package/dist/lib/validators/array-string.validator.js.map +0 -1
  92. package/dist/lib/validators/common/validation-error.d.ts +0 -19
  93. package/dist/lib/validators/common/validation-error.js +0 -26
  94. package/dist/lib/validators/common/validation-error.js.map +0 -1
  95. package/dist/lib/validators/common/validation-rule.d.ts +0 -72
  96. package/dist/lib/validators/common/validation-rule.js +0 -76
  97. package/dist/lib/validators/common/validation-rule.js.map +0 -1
  98. package/dist/lib/validators/common/validation-type.d.ts +0 -24
  99. package/dist/lib/validators/common/validation-type.js +0 -28
  100. package/dist/lib/validators/common/validation-type.js.map +0 -1
  101. package/dist/lib/validators/firstname.validator.d.ts +0 -20
  102. package/dist/lib/validators/firstname.validator.js +0 -29
  103. package/dist/lib/validators/firstname.validator.js.map +0 -1
  104. package/dist/lib/validators/fullname.validator.d.ts +0 -21
  105. package/dist/lib/validators/fullname.validator.js +0 -38
  106. package/dist/lib/validators/fullname.validator.js.map +0 -1
  107. package/dist/lib/validators/index.d.ts +0 -21
  108. package/dist/lib/validators/index.js +0 -35
  109. package/dist/lib/validators/index.js.map +0 -1
  110. package/dist/lib/validators/lastname.validator.d.ts +0 -20
  111. package/dist/lib/validators/lastname.validator.js +0 -29
  112. package/dist/lib/validators/lastname.validator.js.map +0 -1
  113. package/dist/lib/validators/middlename.validator.d.ts +0 -20
  114. package/dist/lib/validators/middlename.validator.js +0 -38
  115. package/dist/lib/validators/middlename.validator.js.map +0 -1
  116. package/dist/lib/validators/nama.validator.d.ts +0 -21
  117. package/dist/lib/validators/nama.validator.js +0 -44
  118. package/dist/lib/validators/nama.validator.js.map +0 -1
  119. package/dist/lib/validators/namon.validator.d.ts +0 -20
  120. package/dist/lib/validators/namon.validator.js +0 -29
  121. package/dist/lib/validators/namon.validator.js.map +0 -1
  122. package/dist/lib/validators/prefix.validator.d.ts +0 -14
  123. package/dist/lib/validators/prefix.validator.js +0 -31
  124. package/dist/lib/validators/prefix.validator.js.map +0 -1
  125. package/dist/lib/validators/string-name.validator.d.ts +0 -20
  126. package/dist/lib/validators/string-name.validator.js +0 -29
  127. package/dist/lib/validators/string-name.validator.js.map +0 -1
  128. package/dist/lib/validators/suffix.validator.d.ts +0 -14
  129. package/dist/lib/validators/suffix.validator.js +0 -31
  130. package/dist/lib/validators/suffix.validator.js.map +0 -1
  131. package/dist/lib/validators/validator.d.ts +0 -13
  132. package/dist/lib/validators/validator.js +0 -9
  133. package/dist/lib/validators/validator.js.map +0 -1
  134. package/dist/umd/namefully.js.map +0 -1
  135. package/dist/umd/namefully.min.js.LICENSE.txt +0 -29
  136. package/dist/umd/namefully.min.js.map +0 -1
package/readme.md CHANGED
@@ -1,42 +1,49 @@
1
1
  # namefully
2
2
 
3
3
  [![npm version][version-img]][version-url]
4
- [![CircleCI][circleci-img]][circleci-url]
4
+ [![JSR Version][jsr-version]][jsr-url]
5
+ [![CI build][ci-img]][ci-url]
5
6
  [![Coverage Status][codecov-img]][codecov-url]
6
7
  [![MIT License][license-img]][license-url]
7
8
 
8
- ## Description
9
-
10
- A JavaScript utility for handling person names.
9
+ Human name handling made easy.
11
10
  [Try it live](https://stackblitz.com/edit/namefully).
12
11
 
13
12
  ## Documentation
14
13
 
15
14
  Check out the official documentation at
16
- [https://namefully.netlify.app](https://namefully.netlify.app/).
15
+ [namefully.netlify.app](https://namefully.netlify.app).
17
16
 
18
17
  ## Motivation
19
18
 
20
19
  Have you ever had to format a user's name in a particular order, way, or shape?
21
20
  Probably yes. If not, it will come at some point. Be patient.
22
21
 
22
+ You may want to use this library if:
23
+
24
+ - you've been repeatedly dealing with users' given names and surnames;
25
+ - you need to occasionally format a name in a particular order, way, or shape;
26
+ - you keep copy-pasting your name-related business logic for every project;
27
+ - you're curious about trying new, cool stuff.
28
+
23
29
  ## Key features
24
30
 
25
- 1. Offer supports for Latin alphabet, including other European ones
26
- (e.g., German, Greek, Cyrillic, Icelandic characters)
27
- 2. Accept different data shapes as input
28
- 3. Use of optional parameters to access advanced features
29
- 4. Format a name as desired
30
- 5. Offer support for prefixes and suffixes
31
- 6. Access to names' initials
32
- 7. Allow hyphenated names, including with apostrophes
31
+ 1. Accept different data shapes as input
32
+ 2. Use optional parameters to access advanced features
33
+ 3. Format a name as desired
34
+ 4. Offer support for prefixes and suffixes
35
+ 5. Access to names' initials
36
+ 6. Support hyphenated names (and other special characters)
37
+ 7. Offer predefined validation rules for many writing systems, including the
38
+ Latin and European ones (e.g., German, Greek, Cyrillic, Icelandic characters)
33
39
 
34
40
  ## Advanced features
35
41
 
36
- 1. Alter the order of appearance of a name: by given name or surname
37
- 2. Handle various subparts of a surname and given name
42
+ 1. Alter the name order anytime
43
+ 2. Handle various parts of a surname and a given name
38
44
  3. Use tokens (separators) to reshape prefixes and suffixes
39
45
  4. Accept customized parsers (do it yourself)
46
+ 5. Parse non-standard name cases
40
47
 
41
48
  ## Installation
42
49
 
@@ -58,70 +65,84 @@ This package is also available in [Angular](https://angular.io/) and
58
65
 
59
66
  ## Usage
60
67
 
68
+ See `example/example.ts`.
69
+
61
70
  ```ts
62
71
  import { Namefully } from 'namefully'
63
72
 
64
- const name = new Namefully('John Joe Smith')
65
- console.log(name.format('L, f m')) // => SMITH, John Joe
66
- console.log(name.zip()) // => John J. Smith
73
+ const name = new Namefully('Thomas Alva Edison');
74
+ console.log(name.short); // Thomas Edison
75
+ console.log(name.public); // Thomas E
76
+ console.log(name.initials()); // ['T', 'A', 'E']
77
+ console.log(name.format('L, f m')); // EDISON, Thomas Alva
78
+ console.log(name.zip()); // Thomas A. E.
67
79
  ```
68
80
 
69
- > NOTE: This package comes with its own declaration file for
70
- > [TypeScript](https://www.typescriptlang.org/) support.
81
+ > NOTE: if you intend to use this utility for non-standard name cases such as
82
+ > many middle names or last names, some extra work is required. For example,
83
+ > using `Namefully.parse()` lets you parse names containing many middle names
84
+ > with the risk of throwing a `NameError` when the parsing is not possible.
85
+
86
+ ## `Config` and default values
71
87
 
72
- ## Options and default values
88
+ `Config` is a single configuration to use across the other components.
89
+
90
+ The multiton pattern is used to keep one configuration across the `Namefully`
91
+ setup. This is useful for avoiding confusion when building other components such
92
+ as `FirstName`, `LastName`, or `Name` of distinct types (or `Namon`) that may
93
+ be of particular shapes.
73
94
 
74
95
  Below are enlisted the options supported by `namefully`.
75
96
 
76
97
  ### orderedBy
77
98
 
78
- `string: 'firstname' | 'lastname'`, default: `firstname`
99
+ `NameOrder` - default: `NameOrder.FIRST_NAME`
79
100
 
80
- Indicate in what order the names appear when set as a raw string values or
81
- string array values. That is, the first element/piece of the name is either the
82
- given name (e.g., `Jon Snow`) or the surname (e.g.,`Snow Jon`).
101
+ Indicates in what order the names appear when set as raw string values or string
102
+ array values. That is, the first element/piece of the name is either the given
103
+ name (e.g., `Jon Snow`) or the surname (e.g.,`Snow Jon`).
83
104
 
84
105
  ```ts
85
106
  // 'Smith' is the surname in this raw string case
86
- const name = new Namefully('Smith John Joe', { orderedBy: 'lastname' })
87
- console.log(name.ln()) // => Smith
107
+ const name1 = new Namefully('Smith John Joe', { orderedBy: NameOrder.LAST_NAME });
108
+ console.log(name1.last); // Smith
88
109
 
89
110
  // 'Edison' is the surname in this string array case
90
- const name = new Namefully(['Edison', 'Thomas'], { orderedBy: 'lastname' })
91
- console.log(name.fn()) // => Thomas
111
+ const name2 = new Namefully(['Edison', 'Thomas'], { orderedBy: NameOrder.LAST_NAME });
112
+ console.log(name2.first); // Thomas
92
113
  ```
93
114
 
94
- > NOTE: This option also affects all the other results of the API. In other words,
95
- > the results will prioritize the order of appearance set in the first place for
96
- > the other operations. Keep in mind that in some cases, it can be altered on the
97
- > go. See the example below.
115
+ > NOTE: This option also affects all the other results of the API. In other
116
+ > words, the results will prioritize the order of appearance set in the first
117
+ > place for the other operations. Keep in mind that in some cases, it can be
118
+ > altered on the go. See the example below.
98
119
 
99
120
  ```ts
100
121
  // 'Smith' is the surname in this raw string case
101
- const name = new Namefully('Smith John Joe', { orderedBy: 'lastname' })
102
- console.log(name.full()) // => Smith John Joe
122
+ const name = new Namefully('Smith John Joe', { orderedBy: NameOrder.LAST_NAME });
123
+ console.log(name.fullName()); // Smith John Joe
103
124
 
104
125
  // Now alter the order by choosing the given name first
105
- console.log(name.full('firstname')) // => John Joe Smith
126
+ console.log(name.fullName(NameOrder.FIRST_NAME)); // John Joe Smith
106
127
  ```
107
128
 
108
129
  ### separator
109
130
 
110
- `enum: Separator`, default: `Separator.SPACE`
131
+ `Separator` - default: `Separator.SPACE`
111
132
 
112
- Only valid for raw string values, this option indicates how to split the parts of
113
- a raw string name under the hood.
133
+ _Only valid for raw string values_, this option indicates how to split the parts
134
+ of a raw string name under the hood.
114
135
 
115
136
  ```ts
116
- const name = new Namefully('Adam,Sandler', { separator: Separator.COMMA })
117
- console.log(name.full()) // => Adam Sandler
137
+ const name = new Namefully('John,Smith', { separator: Separator.COMMA });
138
+ console.log(name.full); // John Smith
118
139
  ```
119
140
 
120
- ### titling
141
+ ### title
121
142
 
122
- `string: 'uk' | 'us'`, default: `uk`
143
+ `Title` - default: `Title.UK`
123
144
 
124
- Abide by the ways the international community defines an abbreviated title.
145
+ Abides by the ways the international community defines an abbreviated title.
125
146
  American and Canadian English follow slightly different rules for abbreviated
126
147
  titles than British and Australian English. In North American English, titles
127
148
  before a name require a period: `Mr., Mrs., Ms., Dr.`. In British and Australian
@@ -129,116 +150,107 @@ English, no periods are used in these abbreviations.
129
150
 
130
151
  ```ts
131
152
  const name = new Namefully({
132
- prefix: 'Mr',
133
- firstname: 'John',
134
- lastname: 'Smith'
135
- }, { titling: 'us' })
136
- console.log(name.full()) // => Mr. John Smith
137
- console.log(name.px()) // => Mr.
153
+ prefix: 'Mr',
154
+ firstName: 'John',
155
+ lastName: 'Smith',
156
+ }, { title: Title.US });
157
+ console.log(name.full); // Mr. John Smith
158
+ console.log(name.prefix); // Mr.
138
159
  ```
139
160
 
140
161
  ### ending
141
162
 
142
- `boolean`, default: `false`
163
+ `boolean` - default: `false`
143
164
 
144
- Set an ending character after the full name (a comma before the suffix actually).
165
+ Sets an ending character after the full name (a comma before the suffix actually).
145
166
 
146
167
  ```ts
147
168
  const name = new Namefully({
148
- prefix: 'Mr',
149
- firstname: 'John',
150
- lastname: 'Smith',
151
- suffix: 'PhD'
169
+ firstName: 'John',
170
+ lastName: 'Smith',
171
+ suffix: 'Ph.D'
152
172
  }, { ending: true })
153
- console.log(name.full()) // => Mr John Smith, PhD
173
+ console.log(name.full) // John Smith, Ph.D
174
+ console.log(name.suffix) // Ph.D
154
175
  ```
155
176
 
156
- ### lastnameFormat
177
+ ### surname
157
178
 
158
- `string: 'father' | 'mother' | 'hyphenated' | 'all'`, default: `father`
179
+ `Surname` - default: `Surname.FATHER`
159
180
 
160
- Defines the distinct formats to output a compound surname (e.g., Hispanic
161
- surnames).
181
+ Defines the distinct formats to output a compound surname (e.g., Hispanic surnames).
162
182
 
163
183
  ```ts
164
- import { Namefully, Firstname, Lastname } from 'namefully'
165
-
166
- const fn = new Firstname('Jaden')
167
- const ln = new Lastname('Smith', 'Pinkett')
168
- const name = new Namefully([fn, ln], { lastnameFormat: 'hyphenated' })
169
- console.log(name.full()) // => Jaden Smith-Pinkett
184
+ const name = new Namefully(
185
+ [new FirstName('John'), new LastName('Doe', 'Smith')],
186
+ { surname: Surname.HYPHENATED },
187
+ );
188
+ console.log(name.full); // John Doe-Smith
170
189
  ```
171
190
 
172
191
  ### bypass
173
192
 
174
- `boolean`, default: `false`
193
+ `boolean` - default: `true`
175
194
 
176
- Skip all the validators (i.e., validation rules, regular expressions).
195
+ Skips all the validators (i.e., validation rules, regular expressions).
177
196
 
178
197
  ```ts
179
- const name = new Namefully('2Pac Shakur', { bypass: true }) // normally would fail the regex
180
- console.log(name.fn()) // => 2Pac
198
+ const name = new Namefully(
199
+ {
200
+ firstName: 'John',
201
+ lastName: 'Smith',
202
+ suffix: 'M.Sc.', // will fail the validation rule and throw an exception.
203
+ },
204
+ { bypass: false, ending: true },
205
+ );
181
206
  ```
182
207
 
183
- > NOTE: This option can help to trick the utility and allow us to use it for
184
- > unsupported languages or inner contents like prefixes or suffixes. For example,
185
- > the Hindi characters will not pass the validation rules. Or, the Spanish
186
- > equivalent for `Mr` => `Sr` will raise an exception as it is not part of the
187
- > predefined prefixes.
208
+ To sum it all up, the default values are:
188
209
 
189
- ### parser
210
+ ```ts
211
+ {
212
+ orderedBy: NameOrder.FIRST_NAME,
213
+ separator: Separator.SPACE,
214
+ title: Title.UK,
215
+ ending: false,
216
+ bypass: true,
217
+ surname: Surname.FATHER
218
+ }
219
+ ```
190
220
 
191
- `object`, default: `null`
221
+ ## Do It Yourself
192
222
 
193
223
  Customize your own parser to indicate the full name yourself.
194
224
 
195
225
  ```ts
196
- import { Namefully, Firstname, Lastname, Parser } from 'namefully'
226
+ import { Config, FullName, Namefully, Parser } from 'namefully'
197
227
 
198
228
  // Suppose you want to cover this '#' separator
199
- class MyParser implements Parser<string> {
200
- constructor(public raw: string) {}
201
- parse() {
202
- const [fn, ln] = this.raw.split('#');
203
- return {
204
- firstname: new Firstname(fn),
205
- lastname: new Lastname(ln),
206
- }
229
+ class SimpleParser extends Parser<string> {
230
+ parse(options: Partial<Config>): FullName {
231
+ const [firstName, lastName] = this.raw.split('#')
232
+ return FullName.parse({ firstName, lastName }, Config.merge(options))
207
233
  }
208
234
  }
209
235
 
210
- const name = new Namefully(null, { parser: new MyParser('Juan#Garcia') })
211
- console.log(name.full()) // => Juan Garcia
212
- ```
213
-
214
- To sum up, the default values are:
215
-
216
- ```json
217
- {
218
- "orderedBy": "firstname",
219
- "separator": " ",
220
- "titling": "uk",
221
- "ending": false,
222
- "lastnameFormat": "father",
223
- "bypass": false,
224
- "parser": null
225
- }
236
+ const name = new Namefully(new SimpleParser('Juan#Garcia'));
237
+ console.log(name.full); // Juan Garcia
226
238
  ```
227
239
 
228
240
  ## Concepts and examples
229
241
 
230
- The name standards used for the current version of this library are as
231
- follows:
242
+ The name standards used for the current version of this library are as follows:
232
243
 
233
- ```[Prefix] Firstname [Middlename] Lastname [Suffix]```
244
+ `[prefix] firstName [middleName] lastName [suffix]`
234
245
 
235
246
  The opening `[` and closing `]` brackets mean that these parts are optional. In
236
247
  other words, the most basic/typical case is a name that looks like this:
237
- `John Smith`, where `John` is the *Firstname* and `Smith`, the *Lastname*.
248
+ `John Smith`, where `John` is the _firstName_ and `Smith`, the _lastName_.
238
249
 
239
- > NOTE: Do notice that the order of appearance matters and (as shown [here](#orderedBy))
240
- > can be altered through configured parameters. By default, the order of appearance
241
- > is as shown above and will be used as a basis for future examples and use cases.
250
+ > NOTE: Do notice that the order of appearance matters and (as shown in
251
+ > [orderedBy](#orderedby)) can be altered through configured parameters. By default,
252
+ > the order of appearance is as shown above and will be used as a basis for
253
+ > future examples and use cases.
242
254
 
243
255
  Once imported, all that is required to do is to create an instance of
244
256
  `Namefully` and the rest will follow.
@@ -247,74 +259,30 @@ Once imported, all that is required to do is to create an instance of
247
259
 
248
260
  Let us take a common example:
249
261
 
250
- ```Mr John Joe Smith PhD```
262
+ `Mr John Joe Smith PhD`
251
263
 
252
264
  So, this utility understands the name parts as follows:
253
265
 
254
- - typical name: `John Smith`
266
+ - prefix: `Mr`
255
267
  - first name: `John`
256
268
  - middle name: `Joe`
257
269
  - last name: `Smith`
258
- - prefix: `Mr`
259
270
  - suffix: `PhD`
260
271
  - full name: `Mr John Joe Smith PhD`
261
272
  - birth name: `John Joe Smith`
262
- - zipped: `John J. Smith`
273
+ - short version: `John Smith`
274
+ - flattened: `John J. S.`
263
275
  - initials: `J J S`
264
- - usernames: `jsmith, johnsmith`, etc.
276
+ - public: `John S`
265
277
 
266
278
  ### Limitations
267
279
 
268
280
  `namefully` does not have support for certain use cases:
269
281
 
270
- - mononame: `Plato`. It can be tricked though by setting the mononame as both
271
- first and last name;
272
- - multiple surnames: `De La Cruz`, `Da Vinci`. You can also trick it using your
273
- own parsing method or setting separately each name part via the `Nama|Name` type
274
- or the string array input;
275
- - multiple prefixes: `Prof. Dr. Einstein`. An alternative would be to use the `bypass` option.
276
-
277
- See the [use cases](usecases) for further details.
278
-
279
- ## API
280
-
281
- | Name | Arguments | Default | Returns | Description |
282
- |---|---|---|---|---|
283
- |*getPrefix*|none|none|`string`|Gets the prefix part of the full name, if any|
284
- |*getFirstname*|`includeAll`|`true`|`string`|Gets the first name part of the full name|
285
- |*getMiddlenames*|none|none|`string[]`|Gets the middle name part of the full name, if any|
286
- |*getLastname*|`format`|`null`|`string`|Gets the last name part of the full name|
287
- |*getSuffix*|none|none|`string`|Gets the suffix part of the full name, if any|
288
- |*getFullname*|`orderedBy`|`null`|`string`|Gets the full name|
289
- |*getBirthname*|`orderedBy`|`null`|`string`|Gets the birth name, no prefix or suffix|
290
- |*getInitials*|`orderedBy`, `withMid`|`null`, `false`|`string`|Gets the initials of the first and last names|
291
- |*describe*|`nameType`|`null`|`Summary`|Gives some descriptive statistics of the characters' distribution.|
292
- |*shorten*|`orderedBy`|`null`|`string`|Returns a typical name (e.g. first and last name)|
293
- |*compress*|`limit`, `by`|`20`, `middlename`|`string`|Compresses a name using different forms of variants|
294
- |*username*|none|none|`string[]`|Suggests possible (randomly) usernames closest to the name|
295
- |*format*|`how`|`null`|`string`|Formats the name as desired|
296
- |*zip*|`nameType`|`null`|`string`|Shortens a full name|
297
- |*size*|none|none|`number`|Returns the count of characters of the birth name, excluding punctuations|
298
- |*ascii*|`options`|`{}`|`number[]`|Returns an ascii representation of each characters|
299
- |*to*|`case`|none|`string`|Transforms a birth name to a specific title case|
300
- |*passwd*|`nameType`|`null`|`string`|Returns a password-like representation of a name|
301
-
302
- ## Aliases
303
-
304
- If you find the names of the methods somewhat too long, we provide aliases to make
305
- your life easier as a coder.
306
-
307
- |Method|Aliases|
308
- |---|---|
309
- |*getPrefix*|*px*|
310
- |*getSuffix*|*sx*|
311
- |*getFirstname*|*fn*|
312
- |*getLastname*|*ln*|
313
- |*getMiddlenames*|*mn*|
314
- |*getFullname*|*full*|
315
- |*getBirthname*|*birth*|
316
- |*getInitials*|*inits*|
317
- |*describe*|*stats*|
282
+ - mononame: `Plato`. A workaround is to set the mononame as both first and last name;
283
+ - multiple prefixes: `Prof. Dr. Einstein`.
284
+
285
+ See the [test cases](test) for further details.
318
286
 
319
287
  ## Author
320
288
 
@@ -322,14 +290,17 @@ Developed by [Ralph Florent](https://github.com/ralflorent).
322
290
 
323
291
  ## License
324
292
 
325
- The underlying content of this utility is licensed under [MIT](LICENSE).
293
+ The underlying content of this utility is licensed under [MIT License](LICENSE).
326
294
 
327
295
  <!-- References -->
296
+
328
297
  [version-img]: https://img.shields.io/npm/v/namefully
329
298
  [version-url]: https://www.npmjs.com/package/namefully
330
- [circleci-img]: https://circleci.com/gh/ralflorent/namefully.svg?style=shield
331
- [circleci-url]: https://circleci.com/gh/ralflorent/namefully
332
- [codecov-img]: https://codecov.io/gh/ralflorent/namefully/branch/master/graph/badge.svg
299
+ [jsr-version]: https://jsr.io/badges/@ralflorent/namefully
300
+ [jsr-url]: https://jsr.io/@ralflorent/namefully
301
+ [ci-img]: https://github.com/ralflorent/namefully/workflows/build/badge.svg
302
+ [ci-url]: https://github.com/ralflorent/namefully/actions/workflows/ci.yml
303
+ [codecov-img]: https://codecov.io/gh/ralflorent/namefully/branch/main/graph/badge.svg
333
304
  [codecov-url]: https://codecov.io/gh/ralflorent/namefully
334
305
  [license-img]: https://img.shields.io/npm/l/namefully
335
306
  [license-url]: https://opensource.org/licenses/MIT
package/changelog.md DELETED
@@ -1,134 +0,0 @@
1
- # Changelog
2
-
3
- This file contains the documentation on the notable changes and bug fixes, and
4
- is formatted following this [standard](https://keepachangelog.com/en/1.0.0/).
5
- This project also adheres to [Semantic Versioning](https://semver.org/).
6
-
7
- ## [1.1.0] - 2020-07-05
8
-
9
- **Added**:
10
-
11
- - Add a full name builder to construct `Namefully`
12
- - Augment a `namon` functionality
13
- - capitalize
14
- - decapitalize
15
- - normalize
16
- - reset
17
- - Add ASCII representations
18
- - Add password-like representations
19
- - Add support for title cases
20
- - Add support for birth names (full name without prefix or suffix)
21
- - Add test coverage for all the API methods
22
- - Update use cases for new features
23
- - Use string formats (`short`, `long`, `official`) when formatting a name
24
-
25
- **Fixed**:
26
-
27
- - Support space in regex
28
- - Use simplified regex
29
- - Support for more than one name parts in a first name
30
- - Revert changes in `compress(...)`: always include a token in the compressed part.
31
- - Switch to MIT License
32
-
33
- ## [1.0.9] - 2020-05-18
34
-
35
- **Added**:
36
-
37
- - Add support for Cyrillic and Greek alphabet
38
-
39
- **Fixed**:
40
-
41
- - Fix validation rules (regex) for specific fields
42
-
43
- ## [1.0.8] - 2020-04-18
44
-
45
- **Added**:
46
-
47
- - Add short API equivalent for `compress` => `zip`
48
- - Add `lastnameFormat` option to config and surname subparts handling
49
- - Refactor return values for `describe` (object instead of string)
50
- - Add support for titling when compressing or zipping
51
-
52
- **Fixed**:
53
-
54
- - Fix missing bypass for fullname validator
55
- - Fix logic for name parts handling in `Firstname` class
56
-
57
- ## [1.0.7] - 2020-03-28
58
-
59
- **Added**:
60
-
61
- - Add `titling` option to config
62
- - Add support for prefixes and suffixes when formatting names
63
- - including a clear cut for (de)-capitalized official names
64
-
65
- **Fixed**:
66
-
67
- - Fix wrong ending reference for suffixes
68
-
69
- ## [1.0.6] - 2020-03-20
70
-
71
- **Added**:
72
-
73
- - Add support for Latin (European and Spanish) names
74
- - Add a bypass to skip validation rules (regex)
75
-
76
- ## [1.0.5] - 2020-03-17
77
-
78
- **Added**:
79
-
80
- - Add optional parameters for the `getFullname` and `getInitials` API;
81
- - Users can forcefully alter order of appearance the full name and initials;
82
- - Add optional parameters for the `describe` API;
83
- - Users can either decide to describe the full name or some specific name parts;
84
- - Introduce new option in `Namefully` creation;
85
- - `ending` accepts a separator for to mark an ending suffix;
86
- - Add some jsdoc comments to document the API;
87
- - Add some aliases to the API.
88
-
89
- **Fixed**:
90
-
91
- - Fix validation error for string array input using wrong/insufficient entries;
92
- - Fix options in `Namefully` creation;
93
- - `orderedBy` accepts now two name parts only (first or last name);
94
- - `separator` works as the splitting name factor;
95
- - Fix the order of appearance for the full name and `compress` API.
96
-
97
- ## [1.0.3] - 2020-03-11
98
-
99
- **Fixed**:
100
-
101
- - Fix typescript compilation for ES2015, UMD
102
- - Fix `namefully` version
103
-
104
- ## [1.0.2] - 2020-03-11
105
-
106
- **Added**:
107
-
108
- - Add use cases
109
- - Add test coverage
110
- - Add setup CI/CD
111
- - Add support for UMD
112
- - Make validation error message more explicit
113
-
114
- ## [1.0.1] - 2020-03-07
115
-
116
- **Fixed**:
117
-
118
- - Fix typo in readme
119
- - Fix build system for npm
120
-
121
- ## [1.0.0] - 2020-03-07
122
-
123
- Initial version
124
-
125
- [1.1.0]: https://github.com/ralflorent/namefully/compare/v1.0.9...v1.1.0
126
- [1.0.9]: https://github.com/ralflorent/namefully/compare/v1.0.8...v1.0.9
127
- [1.0.8]: https://github.com/ralflorent/namefully/compare/v1.0.7...v1.0.8
128
- [1.0.7]: https://github.com/ralflorent/namefully/compare/v1.0.6...v1.0.7
129
- [1.0.6]: https://github.com/ralflorent/namefully/compare/v1.0.5...v1.0.6
130
- [1.0.5]: https://github.com/ralflorent/namefully/compare/v1.0.3...v1.0.5
131
- [1.0.3]: https://github.com/ralflorent/namefully/compare/v1.0.2...v1.0.3
132
- [1.0.2]: https://github.com/ralflorent/namefully/compare/v1.0.1...v1.0.2
133
- [1.0.1]: https://github.com/ralflorent/namefully/compare/v1.0.0...v1.0.1
134
- [1.0.0]: https://github.com/ralflorent/namefully/releases/tag/v1.0.0
@@ -1,48 +0,0 @@
1
- /**
2
- * Constants
3
- *
4
- * Created on March 07, 2020
5
- * @author Ralph Florent <ralflornt@gmail.com>
6
- */
7
- import { Separator, Config, NameIndex } from '../models/index';
8
- import { CharSet } from './core';
9
- /**
10
- * The current version of `Namefully`.
11
- * @constant
12
- */
13
- export declare const version = "1.1.0";
14
- /**
15
- * CONFIG
16
- * @constant
17
- * @type {Config}
18
- * @default
19
- */
20
- export declare const CONFIG: Config;
21
- /**
22
- * NAME_INDEX
23
- * @constant
24
- * @type {NameIndex}
25
- * @default
26
- */
27
- export declare const NAME_INDEX: NameIndex;
28
- export declare const FIRST_LAST_NAME_INDEX = 2;
29
- export declare const LAST_FIRST_NAME_INDEX = 2;
30
- export declare const FIRST_MIDDLE_LAST_NAME_INDEX = 3;
31
- export declare const LAST_FIRST_MIDDLE_NAME_INDEX = 3;
32
- export declare const PREFIX_FIRST_MIDDLE_LAST_NAME_INDEX = 4;
33
- export declare const PREFIX_LAST_FIRST_MIDDLE_NAME_INDEX = 4;
34
- export declare const PREFIX_FIRST_MIDDLE_LAST_SUFFIX_NAME_INDEX = 5;
35
- export declare const PREFIX_LAST_FIRST_MIDDLE_SUFFIX_NAME_INDEX = 5;
36
- export declare const MIN_NUMBER_NAME_PART = 2;
37
- export declare const MAX_NUMBER_NAME_PART = 5;
38
- /**
39
- * RESTRICTED_CHARS
40
- * @constant
41
- * @default
42
- */
43
- export declare const RESTRICTED_CHARS: readonly [Separator.SPACE, Separator.SINGLE_QUOTE, Separator.HYPHEN, Separator.PERIOD, Separator.COMMA];
44
- /**
45
- * PASSWORD_MAPPER
46
- * @constant
47
- */
48
- export declare const PASSWORD_MAPPER: Map<string, CharSet<string>>;