namefully 1.0.9 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/LICENSE +21 -674
  2. package/dist/example/index.js +2734 -0
  3. package/dist/lib/config.d.ts +121 -0
  4. package/dist/lib/config.js +189 -0
  5. package/dist/lib/config.js.map +1 -0
  6. package/dist/lib/constants.d.ts +4 -0
  7. package/dist/lib/constants.js +31 -0
  8. package/dist/lib/constants.js.map +1 -0
  9. package/dist/lib/error.d.ts +172 -0
  10. package/dist/lib/error.js +210 -0
  11. package/dist/lib/error.js.map +1 -0
  12. package/dist/lib/{usecases/index.d.ts → example/example.d.ts} +0 -0
  13. package/dist/lib/full-name.d.ts +71 -0
  14. package/dist/lib/full-name.js +147 -0
  15. package/dist/lib/full-name.js.map +1 -0
  16. package/dist/lib/index.d.ts +16 -6
  17. package/dist/lib/index.js +29 -8
  18. package/dist/lib/index.js.map +1 -1
  19. package/dist/lib/name.d.ts +177 -0
  20. package/dist/lib/name.js +322 -0
  21. package/dist/lib/name.js.map +1 -0
  22. package/dist/lib/namefully.d.ts +303 -208
  23. package/dist/lib/namefully.js +603 -442
  24. package/dist/lib/namefully.js.map +1 -1
  25. package/dist/lib/parser.d.ts +46 -0
  26. package/dist/lib/parser.js +173 -0
  27. package/dist/lib/parser.js.map +1 -0
  28. package/dist/lib/src/config.d.ts +121 -0
  29. package/dist/lib/src/constants.d.ts +4 -0
  30. package/dist/lib/src/error.d.ts +172 -0
  31. package/dist/lib/src/full-name.d.ts +71 -0
  32. package/dist/lib/src/index.d.ts +16 -6
  33. package/dist/lib/src/name.d.ts +177 -0
  34. package/dist/lib/src/namefully.d.ts +303 -208
  35. package/dist/lib/src/parser.d.ts +46 -0
  36. package/dist/lib/src/types.d.ts +127 -0
  37. package/dist/lib/src/utils.d.ts +63 -0
  38. package/dist/lib/src/validator.d.ts +66 -0
  39. package/dist/lib/types.d.ts +127 -0
  40. package/dist/lib/types.js +181 -0
  41. package/dist/lib/types.js.map +1 -0
  42. package/dist/lib/utils.d.ts +63 -0
  43. package/dist/lib/utils.js +138 -0
  44. package/dist/lib/utils.js.map +1 -0
  45. package/dist/lib/validator.d.ts +66 -0
  46. package/dist/lib/validator.js +332 -0
  47. package/dist/lib/validator.js.map +1 -0
  48. package/dist/umd/namefully.js +2191 -2111
  49. package/dist/umd/namefully.js.map +1 -1
  50. package/dist/umd/namefully.min.js +1 -1
  51. package/dist/umd/namefully.min.js.LICENSE.txt +8 -20
  52. package/dist/umd/namefully.min.js.map +1 -1
  53. package/package.json +50 -53
  54. package/readme.md +151 -175
  55. package/changelog.md +0 -114
  56. package/dist/lib/core/constants.d.ts +0 -26
  57. package/dist/lib/core/constants.js +0 -42
  58. package/dist/lib/core/constants.js.map +0 -1
  59. package/dist/lib/core/index.d.ts +0 -9
  60. package/dist/lib/core/index.js +0 -13
  61. package/dist/lib/core/index.js.map +0 -1
  62. package/dist/lib/core/parsers/array-name.parser.d.ts +0 -42
  63. package/dist/lib/core/parsers/array-name.parser.js +0 -84
  64. package/dist/lib/core/parsers/array-name.parser.js.map +0 -1
  65. package/dist/lib/core/parsers/array-string.parser.d.ts +0 -48
  66. package/dist/lib/core/parsers/array-string.parser.js +0 -96
  67. package/dist/lib/core/parsers/array-string.parser.js.map +0 -1
  68. package/dist/lib/core/parsers/index.d.ts +0 -11
  69. package/dist/lib/core/parsers/index.js +0 -11
  70. package/dist/lib/core/parsers/index.js.map +0 -1
  71. package/dist/lib/core/parsers/nama.parser.d.ts +0 -34
  72. package/dist/lib/core/parsers/nama.parser.js +0 -75
  73. package/dist/lib/core/parsers/nama.parser.js.map +0 -1
  74. package/dist/lib/core/parsers/parser.d.ts +0 -29
  75. package/dist/lib/core/parsers/parser.js +0 -3
  76. package/dist/lib/core/parsers/parser.js.map +0 -1
  77. package/dist/lib/core/parsers/string.parser.d.ts +0 -61
  78. package/dist/lib/core/parsers/string.parser.js +0 -63
  79. package/dist/lib/core/parsers/string.parser.js.map +0 -1
  80. package/dist/lib/core/utils/utils.d.ts +0 -14
  81. package/dist/lib/core/utils/utils.js +0 -67
  82. package/dist/lib/core/utils/utils.js.map +0 -1
  83. package/dist/lib/models/enums.d.ts +0 -91
  84. package/dist/lib/models/enums.js +0 -98
  85. package/dist/lib/models/enums.js.map +0 -1
  86. package/dist/lib/models/firstname.d.ts +0 -41
  87. package/dist/lib/models/firstname.js +0 -59
  88. package/dist/lib/models/firstname.js.map +0 -1
  89. package/dist/lib/models/index.d.ts +0 -12
  90. package/dist/lib/models/index.js +0 -15
  91. package/dist/lib/models/index.js.map +0 -1
  92. package/dist/lib/models/lastname.d.ts +0 -44
  93. package/dist/lib/models/lastname.js +0 -86
  94. package/dist/lib/models/lastname.js.map +0 -1
  95. package/dist/lib/models/misc.d.ts +0 -80
  96. package/dist/lib/models/misc.js +0 -3
  97. package/dist/lib/models/misc.js.map +0 -1
  98. package/dist/lib/models/name.d.ts +0 -48
  99. package/dist/lib/models/name.js +0 -72
  100. package/dist/lib/models/name.js.map +0 -1
  101. package/dist/lib/models/summary.d.ts +0 -23
  102. package/dist/lib/models/summary.js +0 -60
  103. package/dist/lib/models/summary.js.map +0 -1
  104. package/dist/lib/src/core/constants.d.ts +0 -26
  105. package/dist/lib/src/core/index.d.ts +0 -9
  106. package/dist/lib/src/core/parsers/array-name.parser.d.ts +0 -42
  107. package/dist/lib/src/core/parsers/array-string.parser.d.ts +0 -48
  108. package/dist/lib/src/core/parsers/index.d.ts +0 -11
  109. package/dist/lib/src/core/parsers/nama.parser.d.ts +0 -34
  110. package/dist/lib/src/core/parsers/parser.d.ts +0 -29
  111. package/dist/lib/src/core/parsers/string.parser.d.ts +0 -61
  112. package/dist/lib/src/core/utils/utils.d.ts +0 -14
  113. package/dist/lib/src/models/enums.d.ts +0 -91
  114. package/dist/lib/src/models/firstname.d.ts +0 -41
  115. package/dist/lib/src/models/index.d.ts +0 -12
  116. package/dist/lib/src/models/lastname.d.ts +0 -44
  117. package/dist/lib/src/models/misc.d.ts +0 -80
  118. package/dist/lib/src/models/name.d.ts +0 -48
  119. package/dist/lib/src/models/summary.d.ts +0 -23
  120. package/dist/lib/src/validators/array-name.validator.d.ts +0 -25
  121. package/dist/lib/src/validators/array-string.validator.d.ts +0 -43
  122. package/dist/lib/src/validators/common/validation-error.d.ts +0 -19
  123. package/dist/lib/src/validators/common/validation-rule.d.ts +0 -69
  124. package/dist/lib/src/validators/common/validation-type.d.ts +0 -24
  125. package/dist/lib/src/validators/firstname.validator.d.ts +0 -20
  126. package/dist/lib/src/validators/fullname.validator.d.ts +0 -21
  127. package/dist/lib/src/validators/index.d.ts +0 -21
  128. package/dist/lib/src/validators/lastname.validator.d.ts +0 -20
  129. package/dist/lib/src/validators/middlename.validator.d.ts +0 -20
  130. package/dist/lib/src/validators/nama.validator.d.ts +0 -21
  131. package/dist/lib/src/validators/namon.validator.d.ts +0 -20
  132. package/dist/lib/src/validators/prefix.validator.d.ts +0 -14
  133. package/dist/lib/src/validators/string-name.validator.d.ts +0 -20
  134. package/dist/lib/src/validators/suffix.validator.d.ts +0 -14
  135. package/dist/lib/src/validators/validator.d.ts +0 -13
  136. package/dist/lib/usecases/compress.usecase.d.ts +0 -8
  137. package/dist/lib/usecases/constants.d.ts +0 -7
  138. package/dist/lib/usecases/describe.usecase.d.ts +0 -12
  139. package/dist/lib/usecases/format.usecase.d.ts +0 -6
  140. package/dist/lib/usecases/namefully.usecase.d.ts +0 -14
  141. package/dist/lib/usecases/shorten.usecase.d.ts +0 -6
  142. package/dist/lib/validators/array-name.validator.d.ts +0 -25
  143. package/dist/lib/validators/array-name.validator.js +0 -82
  144. package/dist/lib/validators/array-name.validator.js.map +0 -1
  145. package/dist/lib/validators/array-string.validator.d.ts +0 -43
  146. package/dist/lib/validators/array-string.validator.js +0 -80
  147. package/dist/lib/validators/array-string.validator.js.map +0 -1
  148. package/dist/lib/validators/common/validation-error.d.ts +0 -19
  149. package/dist/lib/validators/common/validation-error.js +0 -26
  150. package/dist/lib/validators/common/validation-error.js.map +0 -1
  151. package/dist/lib/validators/common/validation-rule.d.ts +0 -69
  152. package/dist/lib/validators/common/validation-rule.js +0 -73
  153. package/dist/lib/validators/common/validation-rule.js.map +0 -1
  154. package/dist/lib/validators/common/validation-type.d.ts +0 -24
  155. package/dist/lib/validators/common/validation-type.js +0 -28
  156. package/dist/lib/validators/common/validation-type.js.map +0 -1
  157. package/dist/lib/validators/firstname.validator.d.ts +0 -20
  158. package/dist/lib/validators/firstname.validator.js +0 -29
  159. package/dist/lib/validators/firstname.validator.js.map +0 -1
  160. package/dist/lib/validators/fullname.validator.d.ts +0 -21
  161. package/dist/lib/validators/fullname.validator.js +0 -38
  162. package/dist/lib/validators/fullname.validator.js.map +0 -1
  163. package/dist/lib/validators/index.d.ts +0 -21
  164. package/dist/lib/validators/index.js +0 -35
  165. package/dist/lib/validators/index.js.map +0 -1
  166. package/dist/lib/validators/lastname.validator.d.ts +0 -20
  167. package/dist/lib/validators/lastname.validator.js +0 -29
  168. package/dist/lib/validators/lastname.validator.js.map +0 -1
  169. package/dist/lib/validators/middlename.validator.d.ts +0 -20
  170. package/dist/lib/validators/middlename.validator.js +0 -38
  171. package/dist/lib/validators/middlename.validator.js.map +0 -1
  172. package/dist/lib/validators/nama.validator.d.ts +0 -21
  173. package/dist/lib/validators/nama.validator.js +0 -43
  174. package/dist/lib/validators/nama.validator.js.map +0 -1
  175. package/dist/lib/validators/namon.validator.d.ts +0 -20
  176. package/dist/lib/validators/namon.validator.js +0 -29
  177. package/dist/lib/validators/namon.validator.js.map +0 -1
  178. package/dist/lib/validators/prefix.validator.d.ts +0 -14
  179. package/dist/lib/validators/prefix.validator.js +0 -31
  180. package/dist/lib/validators/prefix.validator.js.map +0 -1
  181. package/dist/lib/validators/string-name.validator.d.ts +0 -20
  182. package/dist/lib/validators/string-name.validator.js +0 -29
  183. package/dist/lib/validators/string-name.validator.js.map +0 -1
  184. package/dist/lib/validators/suffix.validator.d.ts +0 -14
  185. package/dist/lib/validators/suffix.validator.js +0 -31
  186. package/dist/lib/validators/suffix.validator.js.map +0 -1
  187. package/dist/lib/validators/validator.d.ts +0 -13
  188. package/dist/lib/validators/validator.js +0 -9
  189. package/dist/lib/validators/validator.js.map +0 -1
package/package.json CHANGED
@@ -1,55 +1,52 @@
1
1
  {
2
- "name": "namefully",
3
- "version": "1.0.9",
4
- "description": "Person name handler",
5
- "main": "dist/lib/index.js",
6
- "types": "dist/lib/index.d.ts",
7
- "files": [
8
- "dist/**/*"
9
- ],
10
- "scripts": {
11
- "build": "webpack --config webpack.dev.js --progress",
12
- "build:umd": "webpack --config webpack.prod.js --progress",
13
- "lint": "tslint -p tsconfig.json",
14
- "test": "jest --collectCoverage=true",
15
- "usecases": "npm run build && node ./usecases/index.js",
16
- "uc": "npm run usecases",
17
- "prepublish": "tsc & npm run build:umd"
18
- },
19
- "repository": {
20
- "type": "git",
21
- "url": "git+https://github.com/ralflorent/namefully.git"
22
- },
23
- "keywords": [
24
- "fullname",
25
- "firstname",
26
- "lastname",
27
- "middlename",
28
- "prefix",
29
- "suffix"
30
- ],
31
- "author": {
32
- "name": "Ralph Florent",
33
- "email": "ralflornt@gmail.com",
34
- "url": "https://ralflorent.com"
35
- },
36
- "license": "GPL-3.0",
37
- "bugs": {
38
- "url": "https://github.com/ralflorent/namefully/issues"
39
- },
40
- "homepage": "https://github.com/ralflorent/namefully#readme",
41
- "devDependencies": {
42
- "@types/jest": "^25.1.3",
43
- "@types/node": "^13.9.0",
44
- "clean-webpack-plugin": "^3.0.0",
45
- "jest": "^25.1.0",
46
- "terser-webpack-plugin": "^2.3.5",
47
- "ts-jest": "^25.2.1",
48
- "ts-loader": "^6.2.1",
49
- "tsconfig-paths-webpack-plugin": "^3.2.0",
50
- "tslint": "^6.0.0",
51
- "typescript": "^3.8.3",
52
- "webpack": "^4.42.0",
53
- "webpack-cli": "^3.3.11"
54
- }
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
+ }
55
52
  }
package/readme.md CHANGED
@@ -1,46 +1,50 @@
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
- [![GPL-3.0 License][license-img]][license-url]
6
+ [![MIT License][license-img]][license-url]
7
7
 
8
8
  ## Description
9
9
 
10
- Person name handler. [Try it live](https://stackblitz.com/edit/namefully).
10
+ A JavaScript utility for handling person names.
11
+ [Try it live](https://stackblitz.com/edit/namefully).
11
12
 
12
13
  ## Documentation
13
14
 
14
- Check out the official documentation at [https://namefully.netlify.app/](https://namefully.netlify.app/).
15
+ Check out the official documentation at
16
+ [namefully.netlify.com](https://namefully.netlify.com).
15
17
 
16
18
  ## Motivation
17
19
 
18
- Have you ever had to format a user's name in a particular order (or shape)?
19
- Probably yes. If not, it will come at some point. Be patient. Anyway, that is
20
- simple and easy to implement. Then, a new requirement for a different project
21
- comes up and demands that you reuse and/or readjust that old implementation for some
22
- reason. And trust me, more requirements will keep coming, and you'll have to do
23
- it over and over. When you face this sort of situation on many occasions, it
24
- surely becomes annoying and forces you to proceed by copy-paste. Well, as you
25
- probably guess, that has been my situation for a while.
20
+ Have you ever had to format a user's name in a particular order, way, or shape?
21
+ Probably yes. If not, it will come at some point. Be patient.
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.
26
29
 
27
30
  ## Key features
28
31
 
29
- 1. Offer supports for Latin alphabet, including other European ones
30
- (e.g., German, Greek, Cyrillic, Icelandic characters)
31
- 2. Accept different data shape as input
32
- 3. Allow a developer to configure optional parameters
33
- 4. Accept customized parsers (do it yourself)
34
- 5. Format a name as desired
35
- 6. Offer support for prefixes and suffixes
36
- 7. Suggest possible usernames associated with the name
37
- 8. 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)
38
40
 
39
41
  ## Advanced features
40
42
 
41
- 1. Alter the order of appearance of a name: by given name or surname
42
- 2. Handle various subparts of a surname
43
+ 1. Alter the name order anytime
44
+ 2. Handle various parts of a surname and a given name
43
45
  3. Use tokens (separators) to reshape prefixes and suffixes
46
+ 4. Accept customized parsers (do it yourself)
47
+ 5. Parse non-standard name cases
44
48
 
45
49
  ## Installation
46
50
 
@@ -62,186 +66,192 @@ This package is also available in [Angular](https://angular.io/) and
62
66
 
63
67
  ## Usage
64
68
 
69
+ See `example/example.ts`.
70
+
65
71
  ```ts
66
72
  import { Namefully } from 'namefully'
67
73
 
68
- const name = new Namefully('John Joe Smith')
69
- console.log(name.format('L, f m')) // => SMITH, John Joe
70
- 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.
71
80
  ```
72
81
 
73
- > NOTE: The package comes with its own declaration file for
74
- > [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.
75
86
 
76
- ## Options and default values
87
+ ## `Config` and default values
88
+
89
+ `Config` is a single configuration to use across the other components.
90
+
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.
77
95
 
78
96
  Below are enlisted the options supported by `namefully`.
79
97
 
80
98
  ### orderedBy
81
99
 
82
- `string: 'firstname' | 'lastname'`, default: `firstname`
100
+ `NameOrder` - default: `NameOrder.FIRST_NAME`
83
101
 
84
- Indicate in what order the names appear when set as a raw string values or
85
- string array values. That is, the first element/piece of the name is either the
86
- 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`).
87
105
 
88
106
  ```ts
89
107
  // 'Smith' is the surname in this raw string case
90
- const name = new Namefully('Smith John Joe', { orderedBy: 'lastname' })
91
- console.log(name.ln()) // => Smith
108
+ const name1 = new Namefully('Smith John Joe', { orderedBy: NameOrder.LAST_NAME });
109
+ console.log(name1.last); // Smith
92
110
 
93
111
  // 'Edison' is the surname in this string array case
94
- const name = new Namefully(['Edison', 'Thomas'], { orderedBy: 'lastname' })
95
- console.log(name.fn()) // => Thomas
112
+ const name2 = new Namefully(['Edison', 'Thomas'], { orderedBy: NameOrder.LAST_NAME });
113
+ console.log(name2.first); // Thomas
96
114
  ```
97
115
 
98
- > NOTE: This option also affects all the other results of the API. In other words,
99
- > the results will prioritize the order of appearance set in the first place for
100
- > future operations. Keep in mind that in some cases it can be altered. 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.
101
120
 
102
121
  ```ts
103
122
  // 'Smith' is the surname in this raw string case
104
- const name = new Namefully('Smith John Joe', { orderedBy: 'lastname' })
105
- 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
106
125
 
107
126
  // Now alter the order by choosing the given name first
108
- console.log(name.full('firstname')) // => John Joe Smith
127
+ console.log(name.fullName(NameOrder.FIRST_NAME)); // John Joe Smith
109
128
  ```
110
129
 
111
130
  ### separator
112
131
 
113
- `string: ':' | ',' | '-', | ',' | ' ' | '_'`, default: `(space)`
132
+ `Separator` - default: `Separator.SPACE`
114
133
 
115
- Only valid for raw string values, this option indicates how to split the parts of
116
- 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.
117
136
 
118
137
  ```ts
119
- const name = new Namefully('Adam,Sandler', { separator: ',' })
120
- console.log(name.full()) // => Adam Sandler
138
+ const name = new Namefully('John,Smith', { separator: Separator.COMMA });
139
+ console.log(name.full); // John Smith
121
140
  ```
122
141
 
123
- ### titling
142
+ ### title
124
143
 
125
- `string: 'uk' | 'us'`, default: `uk`
144
+ `Title` - default: `Title.UK`
126
145
 
127
- Define the ways the international community defines an abbreviated title.
146
+ Abides by the ways the international community defines an abbreviated title.
128
147
  American and Canadian English follow slightly different rules for abbreviated
129
148
  titles than British and Australian English. In North American English, titles
130
149
  before a name require a period: `Mr., Mrs., Ms., Dr.`. In British and Australian
131
- English, no full stops are used in these abbreviations.
150
+ English, no periods are used in these abbreviations.
132
151
 
133
152
  ```ts
134
153
  const name = new Namefully({
135
- prefix: 'Mr',
136
- firstname: 'John',
137
- lastname: 'Smith'
138
- }, { titling: 'us' })
139
- console.log(name.full()) // => Mr. John Smith
140
- console.log(name.zip('fn')) // => Mr. J. Smith
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.
141
160
  ```
142
161
 
143
162
  ### ending
144
163
 
145
- `string: ':' | ',' | '-', | ',' | ' ' | '_'`, default: `(space)`
164
+ `boolean` - default: `false`
146
165
 
147
- Set an ending character after the full name (before the suffix actually).
166
+ Sets an ending character after the full name (a comma before the suffix actually).
148
167
 
149
168
  ```ts
150
169
  const name = new Namefully({
151
- prefix: 'Mr',
152
- firstname: 'John',
153
- lastname: 'Smith',
154
- suffix: 'PhD'
155
- }, { ending: ',' })
156
- console.log(name.full()) // => Mr. John Smith, PhD
170
+ firstName: 'John',
171
+ lastName: 'Smith',
172
+ suffix: 'Ph.D'
173
+ }, { ending: true })
174
+ console.log(name.full) // John Smith, Ph.D
175
+ console.log(name.suffix) // Ph.D
157
176
  ```
158
177
 
159
- ### lastnameFormat
178
+ ### surname
160
179
 
161
- `string: 'father' | 'mother' | 'hyphenated' | 'all'`, default: `father`
180
+ `Surname` - default: `Surname.FATHER`
162
181
 
163
- Defines the distinct formats to output a compound surname (e.g., Hispanic
164
- surnames).
182
+ Defines the distinct formats to output a compound surname (e.g., Hispanic surnames).
165
183
 
166
184
  ```ts
167
- import { Namefully, Firstname, Lastname } from 'namefully'
168
-
169
- const fn = new Firstname('Jaden')
170
- const ln = new Lastname('Smith', 'Pinkett')
171
- const name = new Namefully([fn, ln], { lastnameFormat: 'hyphenated' })
172
- 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
173
190
  ```
174
191
 
175
192
  ### bypass
176
193
 
177
- `boolean`, default: `false`
194
+ `boolean` - default: `true`
178
195
 
179
- Skip all the validators (or validation rules using regular expressions).
196
+ Skips all the validators (i.e., validation rules, regular expressions).
180
197
 
181
198
  ```ts
182
- const name = new Namefully('2Pac Shakur', { bypass: true }) // normally would fail the regex
183
- console.log(name.full()) // => 2Pac Shakur
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
+ );
184
207
  ```
185
208
 
186
- > NOTE: This option can help to trick the utility and allow us to use it for
187
- > unsupported languages or inner contents like prefixes or suffixes. For example,
188
- > the Hindi characters will not pass the validation rules. Or, the Spanish
189
- > equivalent for `Mr` => `Sr` will cause a failure of the utility. Do note though
190
- > you risk facing some validation errors for certain API.
209
+ To sum it all up, the default values are:
191
210
 
192
- ### 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
+ ```
193
221
 
194
- `object`, default: `null`
222
+ ## Do It Yourself
195
223
 
196
224
  Customize your own parser to indicate the full name yourself.
197
225
 
198
226
  ```ts
199
- import { Namefully, Firstname, Lastname, Parser } from 'namefully'
227
+ import { Config, FullName, Namefully, Parser } from 'namefully'
200
228
 
201
229
  // Suppose you want to cover this '#' separator
202
- class MyParser implements Parser<string> {
203
- constructor(public raw: string) {}
204
- parse() {
205
- const names = this.raw.split('#');
206
- return {
207
- firstname: new Firstname(names[0]),
208
- lastname: new Lastname(names[1]),
209
- }
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))
210
234
  }
211
235
  }
212
236
 
213
- const name = new Namefully(null, { parser: new MyParser('Juan#Garcia') })
214
- console.log(name.full()) // => Juan Garcia
237
+ const name = new Namefully(SimpleParser('Juan#Garcia'));
238
+ console.log(name.full); // Juan Garcia
215
239
  ```
216
240
 
217
- To sum up, the default values are:
241
+ ## Concepts and examples
218
242
 
219
- ```json
220
- {
221
- "orderedBy": "firstname",
222
- "separator": " ",
223
- "titling": "uk",
224
- "ending": " ",
225
- "lastnameFormat": "father",
226
- "bypass": false,
227
- "parser": null
228
- }
229
- ```
243
+ The name standards used for the current version of this library are as follows:
230
244
 
231
- ## Concepts and Examples
232
-
233
- The name standards used for the current version of this library are as
234
- follows:
235
-
236
- ```[Prefix] Firstname [Middlename] Lastname [Suffix]```
245
+ `[prefix] firstName [middleName] lastName [suffix]`
237
246
 
238
247
  The opening `[` and closing `]` brackets mean that these parts are optional. In
239
248
  other words, the most basic/typical case is a name that looks like this:
240
- `John Smith`, where `John` is the *Firstname* and `Smith`, the *Lastname*.
249
+ `John Smith`, where `John` is the _firstName_ and `Smith`, the _lastName_.
241
250
 
242
- > NOTE: Keep in mind that the order of appearance matters and (as shown [here](#orderedBy)) can be
243
- > altered through configured parameters. By default, the order of appearance is
244
- > 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.
245
255
 
246
256
  Once imported, all that is required to do is to create an instance of
247
257
  `Namefully` and the rest will follow.
@@ -250,65 +260,30 @@ Once imported, all that is required to do is to create an instance of
250
260
 
251
261
  Let us take a common example:
252
262
 
253
- ```Mr John Joe Smith PhD```
263
+ `Mr John Joe Smith PhD`
254
264
 
255
265
  So, this utility understands the name parts as follows:
256
266
 
257
- - a typical name: `John Smith`
258
- - with middle name: `John Joe Smith`
259
- - with prefix: `Mr John Smith`
260
- - with suffix: `John Smith, PhD`
261
- - with both prefix and suffix: `Mr John Smith, PhD`
262
- - full name: `Mr. John Joe Smith, PhD`
263
- - zipped: `John J Smith`
264
- - possible usernames: `jsmith, johnsmith, j.smith`, etc.
267
+ - prefix: `Mr`
268
+ - first name: `John`
269
+ - middle name: `Joe`
270
+ - last name: `Smith`
271
+ - suffix: `PhD`
272
+ - full name: `Mr John Joe Smith PhD`
273
+ - birth name: `John Joe Smith`
274
+ - short version: `John Smith`
275
+ - flattened: `John J. S.`
276
+ - initials: `J J S`
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`. You can still trick it 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 by using your
273
- own parsing method or by 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*|none|none|`string`|Gets the first name part of the full name|
285
- |*getMiddlenames*|none|none|`string[]`|Gets the middle name part of the full name|
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
- |*getInitials*|`orderedBy`, `withMid`|`null`, `false`|`string`|Gets the initials of the first and last name|
290
- |*describe*|`what`|`fullname`|`object`|Gives some descriptive statistics of the characters' distribution.|
291
- |*shorten*|`orderedBy`|`null`|`string`|Returns a typical name (e.g. first and last name)|
292
- |*compress*|`limit`, `by`|`20`, `middlename`|`string`|Compresses a name by using different forms of variants|
293
- |*username*|none|none|`string[]`|Suggests possible (randomly) usernames closest to the name|
294
- |*format*|`how`|`null`|`string`|Formats the name as desired|
295
- |*zip*|`by`|`null`|`string`|Shortens a full name|
296
-
297
- ## Aliases
298
-
299
- If you find the names of the method somewhat too long, we provide aliases to make
300
- your life easier as a coder.
301
-
302
- |Method|Aliases|
303
- |---|---|
304
- |*getPrefix*|*px*|
305
- |*getSuffix*|*sx*|
306
- |*getFirstname*|*fn*|
307
- |*getLastname*|*ln*|
308
- |*getMiddlenames*|*mn*|
309
- |*getFullname*|*full*|
310
- |*getInitials*|*inits*|
311
- |*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.
312
287
 
313
288
  ## Author
314
289
 
@@ -316,14 +291,15 @@ Developed by [Ralph Florent](https://github.com/ralflorent).
316
291
 
317
292
  ## License
318
293
 
319
- The underlying content of this utility is licensed under [GPL-3.0](LICENSE).
294
+ The underlying content of this utility is licensed under [MIT](LICENSE).
320
295
 
321
296
  <!-- References -->
297
+
322
298
  [version-img]: https://img.shields.io/npm/v/namefully
323
299
  [version-url]: https://www.npmjs.com/package/namefully
324
- [circleci-img]: https://circleci.com/gh/ralflorent/namefully.svg?style=shield
325
- [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
326
302
  [codecov-img]: https://codecov.io/gh/ralflorent/namefully/branch/master/graph/badge.svg
327
303
  [codecov-url]: https://codecov.io/gh/ralflorent/namefully
328
304
  [license-img]: https://img.shields.io/npm/l/namefully
329
- [license-url]: http://www.gnu.org/licenses/gpl-3.0.en.html
305
+ [license-url]: https://opensource.org/licenses/MIT