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
package/package.json CHANGED
@@ -1,56 +1,52 @@
1
1
  {
2
- "name": "namefully",
3
- "version": "1.1.0",
4
- "description": "Person name handler",
5
- "main": "dist/lib/index.js",
6
- "types": "dist/lib/index.d.ts",
7
- "files": [
8
- "dist/**/*"
9
- ],
10
- "browser": "dist/umd/namefully.min.js",
11
- "scripts": {
12
- "build": "webpack --config webpack.dev.js --progress",
13
- "build:umd": "webpack --config webpack.prod.js --progress",
14
- "lint": "tslint -p tsconfig.json",
15
- "test": "jest --collectCoverage=true",
16
- "usecases": "npm run build && node ./usecases/index.js",
17
- "uc": "npm run usecases",
18
- "prepublish": "tsc & npm run build:umd"
19
- },
20
- "repository": {
21
- "type": "git",
22
- "url": "git+https://github.com/ralflorent/namefully.git"
23
- },
24
- "keywords": [
25
- "fullname",
26
- "firstname",
27
- "lastname",
28
- "middlename",
29
- "prefix",
30
- "suffix"
31
- ],
32
- "author": {
33
- "name": "Ralph Florent",
34
- "email": "ralflornt@gmail.com",
35
- "url": "https://ralflorent.com"
36
- },
37
- "license": "MIT",
38
- "bugs": {
39
- "url": "https://github.com/ralflorent/namefully/issues"
40
- },
41
- "homepage": "https://namefully.netlify.app",
42
- "devDependencies": {
43
- "@types/jest": "^25.1.3",
44
- "@types/node": "^13.9.0",
45
- "clean-webpack-plugin": "^3.0.0",
46
- "jest": "^25.1.0",
47
- "terser-webpack-plugin": "^2.3.5",
48
- "ts-jest": "^25.2.1",
49
- "ts-loader": "^6.2.1",
50
- "tsconfig-paths-webpack-plugin": "^3.2.0",
51
- "tslint": "^6.0.0",
52
- "typescript": "^3.8.3",
53
- "webpack": "^4.42.0",
54
- "webpack-cli": "^3.3.11"
55
- }
2
+ "name": "namefully",
3
+ "version": "1.2.0",
4
+ "description": "A JavaScript utility for handling person names in a particular order, way, or shape.",
5
+ "main": "dist/lib/index.js",
6
+ "types": "dist/lib/index.d.ts",
7
+ "files": [
8
+ "dist/**/*"
9
+ ],
10
+ "browser": "dist/umd/namefully.min.js",
11
+ "scripts": {
12
+ "example": "webpack --config webpack.dev.js --progress && node ./dist/example/index.js",
13
+ "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
14
+ "build": "tsc",
15
+ "build:umd": "webpack --config webpack.prod.js --progress",
16
+ "lint": "tslint -p tsconfig.json",
17
+ "test": "jest --collectCoverage=true",
18
+ "prepare": "npm run build && npm run build:umd"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/ralflorent/namefully.git"
23
+ },
24
+ "keywords": [
25
+ "name",
26
+ "format"
27
+ ],
28
+ "author": {
29
+ "name": "Ralph Florent",
30
+ "email": "ralflornt@gmail.com"
31
+ },
32
+ "license": "MIT",
33
+ "bugs": {
34
+ "url": "https://github.com/ralflorent/namefully/issues"
35
+ },
36
+ "homepage": "https://namefully.netlify.com",
37
+ "devDependencies": {
38
+ "@types/jest": "^25.1.3",
39
+ "@types/node": "^13.9.0",
40
+ "clean-webpack-plugin": "^3.0.0",
41
+ "jest": "^25.1.0",
42
+ "prettier": "2.6.0",
43
+ "terser-webpack-plugin": "^2.3.5",
44
+ "ts-jest": "^25.2.1",
45
+ "ts-loader": "^6.2.1",
46
+ "tsconfig-paths-webpack-plugin": "^3.2.0",
47
+ "tslint": "^6.0.0",
48
+ "typescript": "^3.8.3",
49
+ "webpack": "^4.42.0",
50
+ "webpack-cli": "^3.3.11"
51
+ }
56
52
  }
package/readme.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # namefully
2
2
 
3
3
  [![npm version][version-img]][version-url]
4
- [![CircleCI][circleci-img]][circleci-url]
4
+ [![CI build][ci-img]][ci-url]
5
5
  [![Coverage Status][codecov-img]][codecov-url]
6
6
  [![MIT License][license-img]][license-url]
7
7
 
@@ -13,30 +13,38 @@ A JavaScript utility for handling person names.
13
13
  ## Documentation
14
14
 
15
15
  Check out the official documentation at
16
- [https://namefully.netlify.app](https://namefully.netlify.app/).
16
+ [namefully.netlify.com](https://namefully.netlify.com).
17
17
 
18
18
  ## Motivation
19
19
 
20
20
  Have you ever had to format a user's name in a particular order, way, or shape?
21
21
  Probably yes. If not, it will come at some point. Be patient.
22
22
 
23
+ You may want to use this library if:
24
+
25
+ - you've been repeatedly dealing with users' given names and surnames;
26
+ - you need to occasionally format a name in a particular order, way, or shape;
27
+ - you keep copy-pasting your name-related business logic for every project;
28
+ - you're curious about trying new, cool stuff.
29
+
23
30
  ## Key features
24
31
 
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
32
+ 1. Accept different data shapes as input
33
+ 2. Use optional parameters to access advanced features
34
+ 3. Format a name as desired
35
+ 4. Offer support for prefixes and suffixes
36
+ 5. Access to names' initials
37
+ 6. Support hyphenated names (and other special characters)
38
+ 7. Offer predefined validation rules for many writing systems, including the
39
+ Latin and European ones (e.g., German, Greek, Cyrillic, Icelandic characters)
33
40
 
34
41
  ## Advanced features
35
42
 
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
43
+ 1. Alter the name order anytime
44
+ 2. Handle various parts of a surname and a given name
38
45
  3. Use tokens (separators) to reshape prefixes and suffixes
39
46
  4. Accept customized parsers (do it yourself)
47
+ 5. Parse non-standard name cases
40
48
 
41
49
  ## Installation
42
50
 
@@ -58,70 +66,84 @@ This package is also available in [Angular](https://angular.io/) and
58
66
 
59
67
  ## Usage
60
68
 
69
+ See `example/example.ts`.
70
+
61
71
  ```ts
62
72
  import { Namefully } from 'namefully'
63
73
 
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
74
+ const name = new Namefully('Thomas Alva Edison');
75
+ console.log(name.short); // Thomas Edison
76
+ console.log(name.public); // Thomas E
77
+ console.log(name.initials()); // ['T', 'A', 'E']
78
+ console.log(name.format('L, f m')); // EDISON, Thomas Alva
79
+ console.log(name.zip()); // Thomas A. E.
67
80
  ```
68
81
 
69
- > NOTE: This package comes with its own declaration file for
70
- > [TypeScript](https://www.typescriptlang.org/) support.
82
+ > NOTE: if you intend to use this utility for non-standard name cases such as
83
+ > many middle names or last names, some extra work is required. For example,
84
+ > using `Namefully.parse()` lets you parse names containing many middle names
85
+ > with the risk of throwing a `NameError` when the parsing is not possible.
86
+
87
+ ## `Config` and default values
88
+
89
+ `Config` is a single configuration to use across the other components.
71
90
 
72
- ## Options and default values
91
+ The multiton pattern is used to keep one configuration across the `Namefully`
92
+ setup. This is useful for avoiding confusion when building other components such
93
+ as `FirstName`, `LastName`, or `Name` of distinct types (or `Namon`) that may
94
+ be of particular shapes.
73
95
 
74
96
  Below are enlisted the options supported by `namefully`.
75
97
 
76
98
  ### orderedBy
77
99
 
78
- `string: 'firstname' | 'lastname'`, default: `firstname`
100
+ `NameOrder` - default: `NameOrder.FIRST_NAME`
79
101
 
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`).
102
+ Indicates in what order the names appear when set as raw string values or string
103
+ array values. That is, the first element/piece of the name is either the given
104
+ name (e.g., `Jon Snow`) or the surname (e.g.,`Snow Jon`).
83
105
 
84
106
  ```ts
85
107
  // '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
108
+ const name1 = new Namefully('Smith John Joe', { orderedBy: NameOrder.LAST_NAME });
109
+ console.log(name1.last); // Smith
88
110
 
89
111
  // 'Edison' is the surname in this string array case
90
- const name = new Namefully(['Edison', 'Thomas'], { orderedBy: 'lastname' })
91
- console.log(name.fn()) // => Thomas
112
+ const name2 = new Namefully(['Edison', 'Thomas'], { orderedBy: NameOrder.LAST_NAME });
113
+ console.log(name2.first); // Thomas
92
114
  ```
93
115
 
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.
116
+ > NOTE: This option also affects all the other results of the API. In other
117
+ > words, the results will prioritize the order of appearance set in the first
118
+ > place for the other operations. Keep in mind that in some cases, it can be
119
+ > altered on the go. See the example below.
98
120
 
99
121
  ```ts
100
122
  // '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
123
+ const name = new Namefully('Smith John Joe', { orderedBy: NameOrder.LAST_NAME });
124
+ console.log(name.fullName()); // Smith John Joe
103
125
 
104
126
  // Now alter the order by choosing the given name first
105
- console.log(name.full('firstname')) // => John Joe Smith
127
+ console.log(name.fullName(NameOrder.FIRST_NAME)); // John Joe Smith
106
128
  ```
107
129
 
108
130
  ### separator
109
131
 
110
- `enum: Separator`, default: `Separator.SPACE`
132
+ `Separator` - default: `Separator.SPACE`
111
133
 
112
- Only valid for raw string values, this option indicates how to split the parts of
113
- a raw string name under the hood.
134
+ _Only valid for raw string values_, this option indicates how to split the parts
135
+ of a raw string name under the hood.
114
136
 
115
137
  ```ts
116
- const name = new Namefully('Adam,Sandler', { separator: Separator.COMMA })
117
- console.log(name.full()) // => Adam Sandler
138
+ const name = new Namefully('John,Smith', { separator: Separator.COMMA });
139
+ console.log(name.full); // John Smith
118
140
  ```
119
141
 
120
- ### titling
142
+ ### title
121
143
 
122
- `string: 'uk' | 'us'`, default: `uk`
144
+ `Title` - default: `Title.UK`
123
145
 
124
- Abide by the ways the international community defines an abbreviated title.
146
+ Abides by the ways the international community defines an abbreviated title.
125
147
  American and Canadian English follow slightly different rules for abbreviated
126
148
  titles than British and Australian English. In North American English, titles
127
149
  before a name require a period: `Mr., Mrs., Ms., Dr.`. In British and Australian
@@ -129,116 +151,107 @@ English, no periods are used in these abbreviations.
129
151
 
130
152
  ```ts
131
153
  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.
154
+ prefix: 'Mr',
155
+ firstName: 'John',
156
+ lastName: 'Smith',
157
+ }, { title: Title.US });
158
+ console.log(name.full); // Mr. John Smith
159
+ console.log(name.prefix); // Mr.
138
160
  ```
139
161
 
140
162
  ### ending
141
163
 
142
- `boolean`, default: `false`
164
+ `boolean` - default: `false`
143
165
 
144
- Set an ending character after the full name (a comma before the suffix actually).
166
+ Sets an ending character after the full name (a comma before the suffix actually).
145
167
 
146
168
  ```ts
147
169
  const name = new Namefully({
148
- prefix: 'Mr',
149
- firstname: 'John',
150
- lastname: 'Smith',
151
- suffix: 'PhD'
170
+ firstName: 'John',
171
+ lastName: 'Smith',
172
+ suffix: 'Ph.D'
152
173
  }, { ending: true })
153
- console.log(name.full()) // => Mr John Smith, PhD
174
+ console.log(name.full) // John Smith, Ph.D
175
+ console.log(name.suffix) // Ph.D
154
176
  ```
155
177
 
156
- ### lastnameFormat
178
+ ### surname
157
179
 
158
- `string: 'father' | 'mother' | 'hyphenated' | 'all'`, default: `father`
180
+ `Surname` - default: `Surname.FATHER`
159
181
 
160
- Defines the distinct formats to output a compound surname (e.g., Hispanic
161
- surnames).
182
+ Defines the distinct formats to output a compound surname (e.g., Hispanic surnames).
162
183
 
163
184
  ```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
185
+ const name = new Namefully(
186
+ [FirstName('John'), LastName('Doe', 'Smith')],
187
+ { surname: Surname.HYPHENATED },
188
+ );
189
+ console.log(name.full); // John Doe-Smith
170
190
  ```
171
191
 
172
192
  ### bypass
173
193
 
174
- `boolean`, default: `false`
194
+ `boolean` - default: `true`
175
195
 
176
- Skip all the validators (i.e., validation rules, regular expressions).
196
+ Skips all the validators (i.e., validation rules, regular expressions).
177
197
 
178
198
  ```ts
179
- const name = new Namefully('2Pac Shakur', { bypass: true }) // normally would fail the regex
180
- console.log(name.fn()) // => 2Pac
199
+ const name = new Namefully(
200
+ {
201
+ firstName: 'John',
202
+ lastName: 'Smith',
203
+ suffix: 'M.Sc.', // will fail the validation rule and throw an exception.
204
+ },
205
+ { bypass: false, ending: true },
206
+ );
181
207
  ```
182
208
 
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.
209
+ To sum it all up, the default values are:
188
210
 
189
- ### parser
211
+ ```ts
212
+ {
213
+ orderedBy: NameOrder.FIRST_NAME,
214
+ separator: Separator.SPACE,
215
+ title: Title.UK
216
+ ending: false,
217
+ bypass: true,
218
+ surname: Surname.FATHER
219
+ }
220
+ ```
190
221
 
191
- `object`, default: `null`
222
+ ## Do It Yourself
192
223
 
193
224
  Customize your own parser to indicate the full name yourself.
194
225
 
195
226
  ```ts
196
- import { Namefully, Firstname, Lastname, Parser } from 'namefully'
227
+ import { Config, FullName, Namefully, Parser } from 'namefully'
197
228
 
198
229
  // 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
- }
230
+ class SimpleParser extends Parser<string> {
231
+ parse(options: Partial<Config>): FullName {
232
+ const [firstName, lastName] = this.raw.split('#')
233
+ return FullName.parse({ firstName, lastName }, Config.merge(options))
207
234
  }
208
235
  }
209
236
 
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
- }
237
+ const name = new Namefully(SimpleParser('Juan#Garcia'));
238
+ console.log(name.full); // Juan Garcia
226
239
  ```
227
240
 
228
241
  ## Concepts and examples
229
242
 
230
- The name standards used for the current version of this library are as
231
- follows:
243
+ The name standards used for the current version of this library are as follows:
232
244
 
233
- ```[Prefix] Firstname [Middlename] Lastname [Suffix]```
245
+ `[prefix] firstName [middleName] lastName [suffix]`
234
246
 
235
247
  The opening `[` and closing `]` brackets mean that these parts are optional. In
236
248
  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*.
249
+ `John Smith`, where `John` is the _firstName_ and `Smith`, the _lastName_.
238
250
 
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.
251
+ > NOTE: Do notice that the order of appearance matters and (as shown in
252
+ > [orderedBy](#orderedby)) can be altered through configured parameters. By default,
253
+ > the order of appearance is as shown above and will be used as a basis for
254
+ > future examples and use cases.
242
255
 
243
256
  Once imported, all that is required to do is to create an instance of
244
257
  `Namefully` and the rest will follow.
@@ -247,74 +260,30 @@ Once imported, all that is required to do is to create an instance of
247
260
 
248
261
  Let us take a common example:
249
262
 
250
- ```Mr John Joe Smith PhD```
263
+ `Mr John Joe Smith PhD`
251
264
 
252
265
  So, this utility understands the name parts as follows:
253
266
 
254
- - typical name: `John Smith`
267
+ - prefix: `Mr`
255
268
  - first name: `John`
256
269
  - middle name: `Joe`
257
270
  - last name: `Smith`
258
- - prefix: `Mr`
259
271
  - suffix: `PhD`
260
272
  - full name: `Mr John Joe Smith PhD`
261
273
  - birth name: `John Joe Smith`
262
- - zipped: `John J. Smith`
274
+ - short version: `John Smith`
275
+ - flattened: `John J. S.`
263
276
  - initials: `J J S`
264
- - usernames: `jsmith, johnsmith`, etc.
277
+ - public: `John S`
265
278
 
266
279
  ### Limitations
267
280
 
268
281
  `namefully` does not have support for certain use cases:
269
282
 
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*|
283
+ - mononame: `Plato`. A workaround is to set the mononame as both first and last name;
284
+ - multiple prefixes: `Prof. Dr. Einstein`.
285
+
286
+ See the [test cases](test) for further details.
318
287
 
319
288
  ## Author
320
289
 
@@ -325,10 +294,11 @@ Developed by [Ralph Florent](https://github.com/ralflorent).
325
294
  The underlying content of this utility is licensed under [MIT](LICENSE).
326
295
 
327
296
  <!-- References -->
297
+
328
298
  [version-img]: https://img.shields.io/npm/v/namefully
329
299
  [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
300
+ [ci-img]: https://github.com/ralflorent/namefully/workflows/build/badge.svg
301
+ [ci-url]: https://github.com/ralflorent/namefully/actions/workflows/config.yml
332
302
  [codecov-img]: https://codecov.io/gh/ralflorent/namefully/branch/master/graph/badge.svg
333
303
  [codecov-url]: https://codecov.io/gh/ralflorent/namefully
334
304
  [license-img]: https://img.shields.io/npm/l/namefully