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.
- package/dist/example/index.js +2734 -0
- package/dist/lib/config.d.ts +121 -0
- package/dist/lib/config.js +189 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/constants.d.ts +4 -0
- package/dist/lib/constants.js +31 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/error.d.ts +172 -0
- package/dist/lib/error.js +210 -0
- package/dist/lib/error.js.map +1 -0
- package/dist/lib/example/example.d.ts +1 -0
- package/dist/lib/full-name.d.ts +71 -0
- package/dist/lib/full-name.js +147 -0
- package/dist/lib/full-name.js.map +1 -0
- package/dist/lib/index.d.ts +16 -6
- package/dist/lib/index.js +29 -8
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/name.d.ts +177 -0
- package/dist/lib/name.js +322 -0
- package/dist/lib/name.js.map +1 -0
- package/dist/lib/namefully.d.ts +285 -208
- package/dist/lib/namefully.js +576 -576
- package/dist/lib/namefully.js.map +1 -1
- package/dist/lib/parser.d.ts +46 -0
- package/dist/lib/parser.js +173 -0
- package/dist/lib/parser.js.map +1 -0
- package/dist/lib/src/config.d.ts +121 -0
- package/dist/lib/src/constants.d.ts +4 -0
- package/dist/lib/src/error.d.ts +172 -0
- package/dist/lib/src/full-name.d.ts +71 -0
- package/dist/lib/src/index.d.ts +20 -0
- package/dist/lib/src/name.d.ts +177 -0
- package/dist/lib/src/namefully.d.ts +379 -0
- package/dist/lib/src/parser.d.ts +46 -0
- package/dist/lib/src/types.d.ts +127 -0
- package/dist/lib/src/utils.d.ts +63 -0
- package/dist/lib/src/validator.d.ts +66 -0
- package/dist/lib/types.d.ts +127 -0
- package/dist/lib/types.js +181 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utils.d.ts +63 -0
- package/dist/lib/utils.js +138 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/lib/validator.d.ts +66 -0
- package/dist/lib/validator.js +332 -0
- package/dist/lib/validator.js.map +1 -0
- package/dist/umd/namefully.js +2118 -2700
- package/dist/umd/namefully.js.map +1 -1
- package/dist/umd/namefully.min.js +1 -1
- package/dist/umd/namefully.min.js.LICENSE.txt +1 -18
- package/dist/umd/namefully.min.js.map +1 -1
- package/package.json +50 -54
- package/readme.md +132 -162
- package/changelog.md +0 -134
- package/dist/lib/core/constants.d.ts +0 -48
- package/dist/lib/core/constants.js +0 -101
- package/dist/lib/core/constants.js.map +0 -1
- package/dist/lib/core/core.d.ts +0 -17
- package/dist/lib/core/core.js +0 -24
- package/dist/lib/core/core.js.map +0 -1
- package/dist/lib/core/index.d.ts +0 -9
- package/dist/lib/core/index.js +0 -13
- package/dist/lib/core/index.js.map +0 -1
- package/dist/lib/core/parsers/array-name.parser.d.ts +0 -41
- package/dist/lib/core/parsers/array-name.parser.js +0 -86
- package/dist/lib/core/parsers/array-name.parser.js.map +0 -1
- package/dist/lib/core/parsers/array-string.parser.d.ts +0 -47
- package/dist/lib/core/parsers/array-string.parser.js +0 -95
- package/dist/lib/core/parsers/array-string.parser.js.map +0 -1
- package/dist/lib/core/parsers/index.d.ts +0 -11
- package/dist/lib/core/parsers/index.js +0 -11
- package/dist/lib/core/parsers/index.js.map +0 -1
- package/dist/lib/core/parsers/nama.parser.d.ts +0 -33
- package/dist/lib/core/parsers/nama.parser.js +0 -74
- package/dist/lib/core/parsers/nama.parser.js.map +0 -1
- package/dist/lib/core/parsers/parser.d.ts +0 -28
- package/dist/lib/core/parsers/parser.js +0 -3
- package/dist/lib/core/parsers/parser.js.map +0 -1
- package/dist/lib/core/parsers/string.parser.d.ts +0 -60
- package/dist/lib/core/parsers/string.parser.js +0 -62
- package/dist/lib/core/parsers/string.parser.js.map +0 -1
- package/dist/lib/core/utils.d.ts +0 -52
- package/dist/lib/core/utils.js +0 -178
- package/dist/lib/core/utils.js.map +0 -1
- package/dist/lib/models/enums.d.ts +0 -106
- package/dist/lib/models/enums.js +0 -114
- package/dist/lib/models/enums.js.map +0 -1
- package/dist/lib/models/firstname.d.ts +0 -77
- package/dist/lib/models/firstname.js +0 -131
- package/dist/lib/models/firstname.js.map +0 -1
- package/dist/lib/models/fullname.d.ts +0 -73
- package/dist/lib/models/fullname.js +0 -99
- package/dist/lib/models/fullname.js.map +0 -1
- package/dist/lib/models/index.d.ts +0 -13
- package/dist/lib/models/index.js +0 -16
- package/dist/lib/models/index.js.map +0 -1
- package/dist/lib/models/lastname.d.ts +0 -80
- package/dist/lib/models/lastname.js +0 -157
- package/dist/lib/models/lastname.js.map +0 -1
- package/dist/lib/models/misc.d.ts +0 -108
- package/dist/lib/models/misc.js +0 -3
- package/dist/lib/models/misc.js.map +0 -1
- package/dist/lib/models/name.d.ts +0 -76
- package/dist/lib/models/name.js +0 -115
- package/dist/lib/models/name.js.map +0 -1
- package/dist/lib/models/summary.d.ts +0 -26
- package/dist/lib/models/summary.js +0 -61
- package/dist/lib/models/summary.js.map +0 -1
- package/dist/lib/validators/array-name.validator.d.ts +0 -25
- package/dist/lib/validators/array-name.validator.js +0 -75
- package/dist/lib/validators/array-name.validator.js.map +0 -1
- package/dist/lib/validators/array-string.validator.d.ts +0 -43
- package/dist/lib/validators/array-string.validator.js +0 -76
- package/dist/lib/validators/array-string.validator.js.map +0 -1
- package/dist/lib/validators/common/validation-error.d.ts +0 -19
- package/dist/lib/validators/common/validation-error.js +0 -26
- package/dist/lib/validators/common/validation-error.js.map +0 -1
- package/dist/lib/validators/common/validation-rule.d.ts +0 -72
- package/dist/lib/validators/common/validation-rule.js +0 -76
- package/dist/lib/validators/common/validation-rule.js.map +0 -1
- package/dist/lib/validators/common/validation-type.d.ts +0 -24
- package/dist/lib/validators/common/validation-type.js +0 -28
- package/dist/lib/validators/common/validation-type.js.map +0 -1
- package/dist/lib/validators/firstname.validator.d.ts +0 -20
- package/dist/lib/validators/firstname.validator.js +0 -29
- package/dist/lib/validators/firstname.validator.js.map +0 -1
- package/dist/lib/validators/fullname.validator.d.ts +0 -21
- package/dist/lib/validators/fullname.validator.js +0 -38
- package/dist/lib/validators/fullname.validator.js.map +0 -1
- package/dist/lib/validators/index.d.ts +0 -21
- package/dist/lib/validators/index.js +0 -35
- package/dist/lib/validators/index.js.map +0 -1
- package/dist/lib/validators/lastname.validator.d.ts +0 -20
- package/dist/lib/validators/lastname.validator.js +0 -29
- package/dist/lib/validators/lastname.validator.js.map +0 -1
- package/dist/lib/validators/middlename.validator.d.ts +0 -20
- package/dist/lib/validators/middlename.validator.js +0 -38
- package/dist/lib/validators/middlename.validator.js.map +0 -1
- package/dist/lib/validators/nama.validator.d.ts +0 -21
- package/dist/lib/validators/nama.validator.js +0 -44
- package/dist/lib/validators/nama.validator.js.map +0 -1
- package/dist/lib/validators/namon.validator.d.ts +0 -20
- package/dist/lib/validators/namon.validator.js +0 -29
- package/dist/lib/validators/namon.validator.js.map +0 -1
- package/dist/lib/validators/prefix.validator.d.ts +0 -14
- package/dist/lib/validators/prefix.validator.js +0 -31
- package/dist/lib/validators/prefix.validator.js.map +0 -1
- package/dist/lib/validators/string-name.validator.d.ts +0 -20
- package/dist/lib/validators/string-name.validator.js +0 -29
- package/dist/lib/validators/string-name.validator.js.map +0 -1
- package/dist/lib/validators/suffix.validator.d.ts +0 -14
- package/dist/lib/validators/suffix.validator.js +0 -31
- package/dist/lib/validators/suffix.validator.js.map +0 -1
- package/dist/lib/validators/validator.d.ts +0 -13
- package/dist/lib/validators/validator.js +0 -9
- package/dist/lib/validators/validator.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,56 +1,52 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
[![
|
|
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
|
-
[
|
|
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.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
|
37
|
-
2. Handle various
|
|
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('
|
|
65
|
-
console.log(name.
|
|
66
|
-
console.log(name.
|
|
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:
|
|
70
|
-
>
|
|
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
|
-
|
|
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
|
-
`
|
|
100
|
+
`NameOrder` - default: `NameOrder.FIRST_NAME`
|
|
79
101
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
|
87
|
-
console.log(
|
|
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
|
|
91
|
-
console.log(
|
|
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
|
|
95
|
-
> the results will prioritize the order of appearance set in the first
|
|
96
|
-
> the other operations. Keep in mind that in some cases, it can be
|
|
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:
|
|
102
|
-
console.log(name.
|
|
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.
|
|
127
|
+
console.log(name.fullName(NameOrder.FIRST_NAME)); // John Joe Smith
|
|
106
128
|
```
|
|
107
129
|
|
|
108
130
|
### separator
|
|
109
131
|
|
|
110
|
-
`
|
|
132
|
+
`Separator` - default: `Separator.SPACE`
|
|
111
133
|
|
|
112
|
-
|
|
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('
|
|
117
|
-
console.log(name.full
|
|
138
|
+
const name = new Namefully('John,Smith', { separator: Separator.COMMA });
|
|
139
|
+
console.log(name.full); // John Smith
|
|
118
140
|
```
|
|
119
141
|
|
|
120
|
-
###
|
|
142
|
+
### title
|
|
121
143
|
|
|
122
|
-
`
|
|
144
|
+
`Title` - default: `Title.UK`
|
|
123
145
|
|
|
124
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}, {
|
|
136
|
-
console.log(name.full
|
|
137
|
-
console.log(name.
|
|
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
|
|
164
|
+
`boolean` - default: `false`
|
|
143
165
|
|
|
144
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
suffix: 'PhD'
|
|
170
|
+
firstName: 'John',
|
|
171
|
+
lastName: 'Smith',
|
|
172
|
+
suffix: 'Ph.D'
|
|
152
173
|
}, { ending: true })
|
|
153
|
-
console.log(name.full
|
|
174
|
+
console.log(name.full) // John Smith, Ph.D
|
|
175
|
+
console.log(name.suffix) // Ph.D
|
|
154
176
|
```
|
|
155
177
|
|
|
156
|
-
###
|
|
178
|
+
### surname
|
|
157
179
|
|
|
158
|
-
`
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
|
194
|
+
`boolean` - default: `true`
|
|
175
195
|
|
|
176
|
-
|
|
196
|
+
Skips all the validators (i.e., validation rules, regular expressions).
|
|
177
197
|
|
|
178
198
|
```ts
|
|
179
|
-
const name = new Namefully(
|
|
180
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
227
|
+
import { Config, FullName, Namefully, Parser } from 'namefully'
|
|
197
228
|
|
|
198
229
|
// Suppose you want to cover this '#' separator
|
|
199
|
-
class
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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(
|
|
211
|
-
console.log(name.full
|
|
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
|
-
|
|
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
|
|
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
|
|
240
|
-
> can be altered through configured parameters. By default,
|
|
241
|
-
> is as shown above and will be used as a basis for
|
|
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
|
-
|
|
263
|
+
`Mr John Joe Smith PhD`
|
|
251
264
|
|
|
252
265
|
So, this utility understands the name parts as follows:
|
|
253
266
|
|
|
254
|
-
-
|
|
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
|
-
-
|
|
274
|
+
- short version: `John Smith`
|
|
275
|
+
- flattened: `John J. S.`
|
|
263
276
|
- initials: `J J S`
|
|
264
|
-
-
|
|
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:
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
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
|
-
[
|
|
331
|
-
[
|
|
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
|