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.
- package/LICENSE +21 -674
- 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/{usecases/index.d.ts → example/example.d.ts} +0 -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 +303 -208
- package/dist/lib/namefully.js +603 -442
- 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 +16 -6
- package/dist/lib/src/name.d.ts +177 -0
- package/dist/lib/src/namefully.d.ts +303 -208
- 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 +2191 -2111
- package/dist/umd/namefully.js.map +1 -1
- package/dist/umd/namefully.min.js +1 -1
- package/dist/umd/namefully.min.js.LICENSE.txt +8 -20
- package/dist/umd/namefully.min.js.map +1 -1
- package/package.json +50 -53
- package/readme.md +151 -175
- package/changelog.md +0 -114
- package/dist/lib/core/constants.d.ts +0 -26
- package/dist/lib/core/constants.js +0 -42
- package/dist/lib/core/constants.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 -42
- package/dist/lib/core/parsers/array-name.parser.js +0 -84
- package/dist/lib/core/parsers/array-name.parser.js.map +0 -1
- package/dist/lib/core/parsers/array-string.parser.d.ts +0 -48
- package/dist/lib/core/parsers/array-string.parser.js +0 -96
- 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 -34
- package/dist/lib/core/parsers/nama.parser.js +0 -75
- package/dist/lib/core/parsers/nama.parser.js.map +0 -1
- package/dist/lib/core/parsers/parser.d.ts +0 -29
- 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 -61
- package/dist/lib/core/parsers/string.parser.js +0 -63
- package/dist/lib/core/parsers/string.parser.js.map +0 -1
- package/dist/lib/core/utils/utils.d.ts +0 -14
- package/dist/lib/core/utils/utils.js +0 -67
- package/dist/lib/core/utils/utils.js.map +0 -1
- package/dist/lib/models/enums.d.ts +0 -91
- package/dist/lib/models/enums.js +0 -98
- package/dist/lib/models/enums.js.map +0 -1
- package/dist/lib/models/firstname.d.ts +0 -41
- package/dist/lib/models/firstname.js +0 -59
- package/dist/lib/models/firstname.js.map +0 -1
- package/dist/lib/models/index.d.ts +0 -12
- package/dist/lib/models/index.js +0 -15
- package/dist/lib/models/index.js.map +0 -1
- package/dist/lib/models/lastname.d.ts +0 -44
- package/dist/lib/models/lastname.js +0 -86
- package/dist/lib/models/lastname.js.map +0 -1
- package/dist/lib/models/misc.d.ts +0 -80
- 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 -48
- package/dist/lib/models/name.js +0 -72
- package/dist/lib/models/name.js.map +0 -1
- package/dist/lib/models/summary.d.ts +0 -23
- package/dist/lib/models/summary.js +0 -60
- package/dist/lib/models/summary.js.map +0 -1
- package/dist/lib/src/core/constants.d.ts +0 -26
- package/dist/lib/src/core/index.d.ts +0 -9
- package/dist/lib/src/core/parsers/array-name.parser.d.ts +0 -42
- package/dist/lib/src/core/parsers/array-string.parser.d.ts +0 -48
- package/dist/lib/src/core/parsers/index.d.ts +0 -11
- package/dist/lib/src/core/parsers/nama.parser.d.ts +0 -34
- package/dist/lib/src/core/parsers/parser.d.ts +0 -29
- package/dist/lib/src/core/parsers/string.parser.d.ts +0 -61
- package/dist/lib/src/core/utils/utils.d.ts +0 -14
- package/dist/lib/src/models/enums.d.ts +0 -91
- package/dist/lib/src/models/firstname.d.ts +0 -41
- package/dist/lib/src/models/index.d.ts +0 -12
- package/dist/lib/src/models/lastname.d.ts +0 -44
- package/dist/lib/src/models/misc.d.ts +0 -80
- package/dist/lib/src/models/name.d.ts +0 -48
- package/dist/lib/src/models/summary.d.ts +0 -23
- package/dist/lib/src/validators/array-name.validator.d.ts +0 -25
- package/dist/lib/src/validators/array-string.validator.d.ts +0 -43
- package/dist/lib/src/validators/common/validation-error.d.ts +0 -19
- package/dist/lib/src/validators/common/validation-rule.d.ts +0 -69
- package/dist/lib/src/validators/common/validation-type.d.ts +0 -24
- package/dist/lib/src/validators/firstname.validator.d.ts +0 -20
- package/dist/lib/src/validators/fullname.validator.d.ts +0 -21
- package/dist/lib/src/validators/index.d.ts +0 -21
- package/dist/lib/src/validators/lastname.validator.d.ts +0 -20
- package/dist/lib/src/validators/middlename.validator.d.ts +0 -20
- package/dist/lib/src/validators/nama.validator.d.ts +0 -21
- package/dist/lib/src/validators/namon.validator.d.ts +0 -20
- package/dist/lib/src/validators/prefix.validator.d.ts +0 -14
- package/dist/lib/src/validators/string-name.validator.d.ts +0 -20
- package/dist/lib/src/validators/suffix.validator.d.ts +0 -14
- package/dist/lib/src/validators/validator.d.ts +0 -13
- package/dist/lib/usecases/compress.usecase.d.ts +0 -8
- package/dist/lib/usecases/constants.d.ts +0 -7
- package/dist/lib/usecases/describe.usecase.d.ts +0 -12
- package/dist/lib/usecases/format.usecase.d.ts +0 -6
- package/dist/lib/usecases/namefully.usecase.d.ts +0 -14
- package/dist/lib/usecases/shorten.usecase.d.ts +0 -6
- package/dist/lib/validators/array-name.validator.d.ts +0 -25
- package/dist/lib/validators/array-name.validator.js +0 -82
- 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 -80
- 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 -69
- package/dist/lib/validators/common/validation-rule.js +0 -73
- 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 -43
- 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,55 +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
|
-
"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
|
-
[![
|
|
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
|
|
|
8
8
|
## Description
|
|
9
9
|
|
|
10
|
-
|
|
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
|
|
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
|
|
19
|
-
Probably yes. If not, it will come at some point. Be patient.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
|
42
|
-
2. Handle various
|
|
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('
|
|
69
|
-
console.log(name.
|
|
70
|
-
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.
|
|
71
80
|
```
|
|
72
81
|
|
|
73
|
-
> NOTE:
|
|
74
|
-
>
|
|
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
|
-
##
|
|
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
|
-
`
|
|
100
|
+
`NameOrder` - default: `NameOrder.FIRST_NAME`
|
|
83
101
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
|
91
|
-
console.log(
|
|
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
|
|
95
|
-
console.log(
|
|
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
|
|
99
|
-
> the results will prioritize the order of appearance set in the first
|
|
100
|
-
>
|
|
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:
|
|
105
|
-
console.log(name.
|
|
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.
|
|
127
|
+
console.log(name.fullName(NameOrder.FIRST_NAME)); // John Joe Smith
|
|
109
128
|
```
|
|
110
129
|
|
|
111
130
|
### separator
|
|
112
131
|
|
|
113
|
-
`
|
|
132
|
+
`Separator` - default: `Separator.SPACE`
|
|
114
133
|
|
|
115
|
-
|
|
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('
|
|
120
|
-
console.log(name.full
|
|
138
|
+
const name = new Namefully('John,Smith', { separator: Separator.COMMA });
|
|
139
|
+
console.log(name.full); // John Smith
|
|
121
140
|
```
|
|
122
141
|
|
|
123
|
-
###
|
|
142
|
+
### title
|
|
124
143
|
|
|
125
|
-
`
|
|
144
|
+
`Title` - default: `Title.UK`
|
|
126
145
|
|
|
127
|
-
|
|
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
|
|
150
|
+
English, no periods are used in these abbreviations.
|
|
132
151
|
|
|
133
152
|
```ts
|
|
134
153
|
const name = new Namefully({
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}, {
|
|
139
|
-
console.log(name.full
|
|
140
|
-
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.
|
|
141
160
|
```
|
|
142
161
|
|
|
143
162
|
### ending
|
|
144
163
|
|
|
145
|
-
`
|
|
164
|
+
`boolean` - default: `false`
|
|
146
165
|
|
|
147
|
-
|
|
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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
console.log(name.
|
|
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
|
-
###
|
|
178
|
+
### surname
|
|
160
179
|
|
|
161
|
-
`
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
|
194
|
+
`boolean` - default: `true`
|
|
178
195
|
|
|
179
|
-
|
|
196
|
+
Skips all the validators (i.e., validation rules, regular expressions).
|
|
180
197
|
|
|
181
198
|
```ts
|
|
182
|
-
const name = new Namefully(
|
|
183
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
227
|
+
import { Config, FullName, Namefully, Parser } from 'namefully'
|
|
200
228
|
|
|
201
229
|
// Suppose you want to cover this '#' separator
|
|
202
|
-
class
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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(
|
|
214
|
-
console.log(name.full
|
|
237
|
+
const name = new Namefully(SimpleParser('Juan#Garcia'));
|
|
238
|
+
console.log(name.full); // Juan Garcia
|
|
215
239
|
```
|
|
216
240
|
|
|
217
|
-
|
|
241
|
+
## Concepts and examples
|
|
218
242
|
|
|
219
|
-
|
|
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
|
-
|
|
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
|
|
249
|
+
`John Smith`, where `John` is the _firstName_ and `Smith`, the _lastName_.
|
|
241
250
|
|
|
242
|
-
> NOTE:
|
|
243
|
-
> altered through configured parameters. By default,
|
|
244
|
-
> 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.
|
|
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
|
-
|
|
263
|
+
`Mr John Joe Smith PhD`
|
|
254
264
|
|
|
255
265
|
So, this utility understands the name parts as follows:
|
|
256
266
|
|
|
257
|
-
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
-
|
|
264
|
-
-
|
|
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:
|
|
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*|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 [
|
|
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
|
-
[
|
|
325
|
-
[
|
|
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]:
|
|
305
|
+
[license-url]: https://opensource.org/licenses/MIT
|