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
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { NameOrder, Separator, Title, Surname } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* The Configuration to use across the other components.
|
|
4
|
+
*
|
|
5
|
+
* The multiton pattern is used to handle configurations across the `namefully`
|
|
6
|
+
* setup. This adds consistency when building other components such as `FirstName`,
|
|
7
|
+
* `LastName`, or `Name` of distinct types that may be of particular shapes.
|
|
8
|
+
*
|
|
9
|
+
* For example, a person's `FullName` may appear by:
|
|
10
|
+
* - NameOrder.FIRST_NAME: `Jon Snow` or
|
|
11
|
+
* - NameOrder.LAST_NAME: `Snow Jon`.
|
|
12
|
+
*
|
|
13
|
+
* `Config` makes it easy to set up a specific configuration for `Namefully`
|
|
14
|
+
* and reuse it through other instances or components along the way. If a new
|
|
15
|
+
* `Config` is needed, a named configuration may be created. It is actually
|
|
16
|
+
* advised to use named `Config.create(name)` instead as it may help mitigate issues
|
|
17
|
+
* and avoid confusion and ambiguity in the future. Plus, a named configuration
|
|
18
|
+
* explains its purpose.
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* const defaultConfig = Config.create();
|
|
22
|
+
* const mergedConfig = Config.merge({ name: 'other', title: Title.US });
|
|
23
|
+
* const copyConfig = mergedConfig.copyWith({ ending: true });
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* Additionally, a configuration may be merged with or copied from an existing
|
|
27
|
+
* configuration, prioritizing the new one's values, as shown in the example
|
|
28
|
+
* above.
|
|
29
|
+
*/
|
|
30
|
+
export declare class Config {
|
|
31
|
+
private _name;
|
|
32
|
+
private _orderedBy;
|
|
33
|
+
private _separator;
|
|
34
|
+
private _title;
|
|
35
|
+
private _ending;
|
|
36
|
+
private _bypass;
|
|
37
|
+
private _surname;
|
|
38
|
+
/**
|
|
39
|
+
* Cache for multiple instances.
|
|
40
|
+
*/
|
|
41
|
+
private static cache;
|
|
42
|
+
/**
|
|
43
|
+
* The order of appearance of a full name.
|
|
44
|
+
*/
|
|
45
|
+
get orderedBy(): NameOrder;
|
|
46
|
+
/**
|
|
47
|
+
* The token used to indicate how to split string values.
|
|
48
|
+
*/
|
|
49
|
+
get separator(): Separator;
|
|
50
|
+
/**
|
|
51
|
+
* The abbreviation type to indicate whether or not to add period to a prefix
|
|
52
|
+
* using the American or British way.
|
|
53
|
+
*/
|
|
54
|
+
get title(): Title;
|
|
55
|
+
/**
|
|
56
|
+
* The option indicating if an ending suffix is used in a formal way.
|
|
57
|
+
*/
|
|
58
|
+
get ending(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* A bypass of the validation rules with this option. This option is ideal
|
|
61
|
+
* to avoid checking their validity.
|
|
62
|
+
*/
|
|
63
|
+
get bypass(): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* An option indicating how to format a surname.
|
|
66
|
+
*
|
|
67
|
+
* The supported formats are:
|
|
68
|
+
* - `FATHER` name only
|
|
69
|
+
* - `MOTHER` name only
|
|
70
|
+
* - `HYPHENATED`, joining both father and mother names with a hyphen
|
|
71
|
+
* - `ALL`, joining both father and mother names with a space.
|
|
72
|
+
*
|
|
73
|
+
* Note that this option can be set when creating a `LastName`. As this can
|
|
74
|
+
* become ambiguous at the time of handling it, the value set in this is
|
|
75
|
+
* prioritized and viewed as the source of truth for future considerations.
|
|
76
|
+
*/
|
|
77
|
+
get surname(): Surname;
|
|
78
|
+
/**
|
|
79
|
+
* The name of the cached configuration.
|
|
80
|
+
*/
|
|
81
|
+
get name(): string;
|
|
82
|
+
private constructor();
|
|
83
|
+
/**
|
|
84
|
+
* Returns a named configuration with default values.
|
|
85
|
+
* @param name describing its purpose.
|
|
86
|
+
*/
|
|
87
|
+
static create(name?: string): Config;
|
|
88
|
+
/**
|
|
89
|
+
* Returns a combined version of the existing values of the default configuration
|
|
90
|
+
* and the provided optional values of another configuration.
|
|
91
|
+
* @param other partial config to be combined with.
|
|
92
|
+
*/
|
|
93
|
+
static merge(other?: Partial<Config>): Config;
|
|
94
|
+
/**
|
|
95
|
+
* Returns a copy of this configuration merged with the provided values.
|
|
96
|
+
*
|
|
97
|
+
* The word `_copy` is added to the existing config's name to create the new
|
|
98
|
+
* config's name if the name already exists for previous configurations. This
|
|
99
|
+
* is useful to maintain the uniqueness of each configuration. For example,
|
|
100
|
+
* if the new copy is made from the default configuration, this new copy will
|
|
101
|
+
* be named `default_copy`.
|
|
102
|
+
*/
|
|
103
|
+
copyWith(options?: Partial<Config>): Config;
|
|
104
|
+
/**
|
|
105
|
+
* Makes an exact copy of the current configuration.
|
|
106
|
+
*/
|
|
107
|
+
clone(): Config;
|
|
108
|
+
/**
|
|
109
|
+
* Resets the configuration by setting it back to its default values.
|
|
110
|
+
*/
|
|
111
|
+
reset(): void;
|
|
112
|
+
/**
|
|
113
|
+
* Alters the name order between the first and last name, and rearrange the
|
|
114
|
+
* order of appearance of a name set.
|
|
115
|
+
*/
|
|
116
|
+
updateOrder(order: NameOrder): void;
|
|
117
|
+
/**
|
|
118
|
+
* Generates a unique new name.
|
|
119
|
+
*/
|
|
120
|
+
private genNewName;
|
|
121
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Config = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
const defaultName = 'default';
|
|
6
|
+
const copyAlias = '_copy';
|
|
7
|
+
/**
|
|
8
|
+
* The Configuration to use across the other components.
|
|
9
|
+
*
|
|
10
|
+
* The multiton pattern is used to handle configurations across the `namefully`
|
|
11
|
+
* setup. This adds consistency when building other components such as `FirstName`,
|
|
12
|
+
* `LastName`, or `Name` of distinct types that may be of particular shapes.
|
|
13
|
+
*
|
|
14
|
+
* For example, a person's `FullName` may appear by:
|
|
15
|
+
* - NameOrder.FIRST_NAME: `Jon Snow` or
|
|
16
|
+
* - NameOrder.LAST_NAME: `Snow Jon`.
|
|
17
|
+
*
|
|
18
|
+
* `Config` makes it easy to set up a specific configuration for `Namefully`
|
|
19
|
+
* and reuse it through other instances or components along the way. If a new
|
|
20
|
+
* `Config` is needed, a named configuration may be created. It is actually
|
|
21
|
+
* advised to use named `Config.create(name)` instead as it may help mitigate issues
|
|
22
|
+
* and avoid confusion and ambiguity in the future. Plus, a named configuration
|
|
23
|
+
* explains its purpose.
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* const defaultConfig = Config.create();
|
|
27
|
+
* const mergedConfig = Config.merge({ name: 'other', title: Title.US });
|
|
28
|
+
* const copyConfig = mergedConfig.copyWith({ ending: true });
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* Additionally, a configuration may be merged with or copied from an existing
|
|
32
|
+
* configuration, prioritizing the new one's values, as shown in the example
|
|
33
|
+
* above.
|
|
34
|
+
*/
|
|
35
|
+
class Config {
|
|
36
|
+
constructor(name, orderedBy = types_1.NameOrder.FIRST_NAME, separator = types_1.Separator.SPACE, title = types_1.Title.UK, ending = false, bypass = true, surname = types_1.Surname.FATHER) {
|
|
37
|
+
this._name = name;
|
|
38
|
+
this._orderedBy = orderedBy;
|
|
39
|
+
this._separator = separator;
|
|
40
|
+
this._title = title;
|
|
41
|
+
this._ending = ending;
|
|
42
|
+
this._bypass = bypass;
|
|
43
|
+
this._surname = surname;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The order of appearance of a full name.
|
|
47
|
+
*/
|
|
48
|
+
get orderedBy() {
|
|
49
|
+
return this._orderedBy;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The token used to indicate how to split string values.
|
|
53
|
+
*/
|
|
54
|
+
get separator() {
|
|
55
|
+
return this._separator;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The abbreviation type to indicate whether or not to add period to a prefix
|
|
59
|
+
* using the American or British way.
|
|
60
|
+
*/
|
|
61
|
+
get title() {
|
|
62
|
+
return this._title;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The option indicating if an ending suffix is used in a formal way.
|
|
66
|
+
*/
|
|
67
|
+
get ending() {
|
|
68
|
+
return this._ending;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A bypass of the validation rules with this option. This option is ideal
|
|
72
|
+
* to avoid checking their validity.
|
|
73
|
+
*/
|
|
74
|
+
get bypass() {
|
|
75
|
+
return this._bypass;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* An option indicating how to format a surname.
|
|
79
|
+
*
|
|
80
|
+
* The supported formats are:
|
|
81
|
+
* - `FATHER` name only
|
|
82
|
+
* - `MOTHER` name only
|
|
83
|
+
* - `HYPHENATED`, joining both father and mother names with a hyphen
|
|
84
|
+
* - `ALL`, joining both father and mother names with a space.
|
|
85
|
+
*
|
|
86
|
+
* Note that this option can be set when creating a `LastName`. As this can
|
|
87
|
+
* become ambiguous at the time of handling it, the value set in this is
|
|
88
|
+
* prioritized and viewed as the source of truth for future considerations.
|
|
89
|
+
*/
|
|
90
|
+
get surname() {
|
|
91
|
+
return this._surname;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The name of the cached configuration.
|
|
95
|
+
*/
|
|
96
|
+
get name() {
|
|
97
|
+
return this._name;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Returns a named configuration with default values.
|
|
101
|
+
* @param name describing its purpose.
|
|
102
|
+
*/
|
|
103
|
+
static create(name = defaultName) {
|
|
104
|
+
if (!Config.cache.has(name)) {
|
|
105
|
+
Config.cache.set(name, new this(name));
|
|
106
|
+
}
|
|
107
|
+
return Config.cache.get(name);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Returns a combined version of the existing values of the default configuration
|
|
111
|
+
* and the provided optional values of another configuration.
|
|
112
|
+
* @param other partial config to be combined with.
|
|
113
|
+
*/
|
|
114
|
+
static merge(other) {
|
|
115
|
+
var _a, _b, _c, _d, _e, _f;
|
|
116
|
+
if (!other) {
|
|
117
|
+
return Config.create();
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
const config = Config.create(other.name);
|
|
121
|
+
config._orderedBy = (_a = other.orderedBy) !== null && _a !== void 0 ? _a : config.orderedBy;
|
|
122
|
+
config._separator = (_b = other.separator) !== null && _b !== void 0 ? _b : config.separator;
|
|
123
|
+
config._title = (_c = other.title) !== null && _c !== void 0 ? _c : config.title;
|
|
124
|
+
config._ending = (_d = other.ending) !== null && _d !== void 0 ? _d : config.ending;
|
|
125
|
+
config._bypass = (_e = other.bypass) !== null && _e !== void 0 ? _e : config.bypass;
|
|
126
|
+
config._surname = (_f = other.surname) !== null && _f !== void 0 ? _f : config.surname;
|
|
127
|
+
return config;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Returns a copy of this configuration merged with the provided values.
|
|
132
|
+
*
|
|
133
|
+
* The word `_copy` is added to the existing config's name to create the new
|
|
134
|
+
* config's name if the name already exists for previous configurations. This
|
|
135
|
+
* is useful to maintain the uniqueness of each configuration. For example,
|
|
136
|
+
* if the new copy is made from the default configuration, this new copy will
|
|
137
|
+
* be named `default_copy`.
|
|
138
|
+
*/
|
|
139
|
+
copyWith(options = {}) {
|
|
140
|
+
const { name, orderedBy, separator, title, ending, bypass, surname } = options;
|
|
141
|
+
const config = Config.create(this.genNewName(name !== null && name !== void 0 ? name : this.name + copyAlias));
|
|
142
|
+
config._orderedBy = orderedBy !== null && orderedBy !== void 0 ? orderedBy : this.orderedBy;
|
|
143
|
+
config._separator = separator !== null && separator !== void 0 ? separator : this.separator;
|
|
144
|
+
config._title = title !== null && title !== void 0 ? title : this.title;
|
|
145
|
+
config._ending = ending !== null && ending !== void 0 ? ending : this.ending;
|
|
146
|
+
config._bypass = bypass !== null && bypass !== void 0 ? bypass : this.bypass;
|
|
147
|
+
config._surname = surname !== null && surname !== void 0 ? surname : this.surname;
|
|
148
|
+
return config;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Makes an exact copy of the current configuration.
|
|
152
|
+
*/
|
|
153
|
+
clone() {
|
|
154
|
+
return this.copyWith();
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Resets the configuration by setting it back to its default values.
|
|
158
|
+
*/
|
|
159
|
+
reset() {
|
|
160
|
+
this._orderedBy = types_1.NameOrder.FIRST_NAME;
|
|
161
|
+
this._separator = types_1.Separator.SPACE;
|
|
162
|
+
this._title = types_1.Title.UK;
|
|
163
|
+
this._ending = false;
|
|
164
|
+
this._bypass = true;
|
|
165
|
+
this._surname = types_1.Surname.FATHER;
|
|
166
|
+
Config.cache.set(this.name, this);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Alters the name order between the first and last name, and rearrange the
|
|
170
|
+
* order of appearance of a name set.
|
|
171
|
+
*/
|
|
172
|
+
updateOrder(order) {
|
|
173
|
+
if (order && order !== this._orderedBy) {
|
|
174
|
+
Config.cache.get(this.name)._orderedBy = order;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Generates a unique new name.
|
|
179
|
+
*/
|
|
180
|
+
genNewName(name) {
|
|
181
|
+
return name === this.name || Config.cache.has(name) ? this.genNewName(name + copyAlias) : name;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.Config = Config;
|
|
185
|
+
/**
|
|
186
|
+
* Cache for multiple instances.
|
|
187
|
+
*/
|
|
188
|
+
Config.cache = new Map();
|
|
189
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";;;AAAA,mCAA8D;AAE9D,MAAM,WAAW,GAAG,SAAS,CAAA;AAC7B,MAAM,SAAS,GAAG,OAAO,CAAA;AAEzB;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAa,MAAM;IA2Ef,YACI,IAAY,EACZ,SAAS,GAAG,iBAAS,CAAC,UAAU,EAChC,SAAS,GAAG,iBAAS,CAAC,KAAK,EAC3B,KAAK,GAAG,aAAK,CAAC,EAAE,EAChB,MAAM,GAAG,KAAK,EACd,MAAM,GAAG,IAAI,EACb,OAAO,GAAG,eAAO,CAAC,MAAM;QAExB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;QACjB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAA;QAC3B,IAAI,CAAC,UAAU,GAAG,SAAS,CAAA;QAC3B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACn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,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ALLOWED_TOKENS = exports.MAX_NUMBER_OF_NAME_PARTS = exports.MIN_NUMBER_OF_NAME_PARTS = exports.version = void 0;
|
|
4
|
+
exports.version = '1.2.0';
|
|
5
|
+
exports.MIN_NUMBER_OF_NAME_PARTS = 2;
|
|
6
|
+
exports.MAX_NUMBER_OF_NAME_PARTS = 5;
|
|
7
|
+
exports.ALLOWED_TOKENS = [
|
|
8
|
+
'.',
|
|
9
|
+
',',
|
|
10
|
+
' ',
|
|
11
|
+
'-',
|
|
12
|
+
'_',
|
|
13
|
+
'b',
|
|
14
|
+
'B',
|
|
15
|
+
'f',
|
|
16
|
+
'F',
|
|
17
|
+
'l',
|
|
18
|
+
'L',
|
|
19
|
+
'm',
|
|
20
|
+
'M',
|
|
21
|
+
'n',
|
|
22
|
+
'N',
|
|
23
|
+
'o',
|
|
24
|
+
'O',
|
|
25
|
+
'p',
|
|
26
|
+
'P',
|
|
27
|
+
's',
|
|
28
|
+
'S',
|
|
29
|
+
'$',
|
|
30
|
+
];
|
|
31
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,OAAO,CAAA;AACjB,QAAA,wBAAwB,GAAG,CAAC,CAAA;AAC5B,QAAA,wBAAwB,GAAG,CAAC,CAAA;AAC5B,QAAA,cAAc,GAAG;IAC1B,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;CACN,CAAA"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { Name } from './name';
|
|
2
|
+
import { Nullable } from './types';
|
|
3
|
+
declare type NameSource = Nullable<string | string[] | Name[]>;
|
|
4
|
+
interface ErrorMessage {
|
|
5
|
+
source: NameSource;
|
|
6
|
+
message?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The error types supported by `Namefully`.
|
|
10
|
+
*/
|
|
11
|
+
export declare enum NameErrorType {
|
|
12
|
+
/**
|
|
13
|
+
* Thrown when a name entry/argument is incorrect.
|
|
14
|
+
*
|
|
15
|
+
* For example, a name should have a minimum of 2 characters, so an empty
|
|
16
|
+
* string or a string of one character would cause this kind of error.
|
|
17
|
+
*/
|
|
18
|
+
INPUT = 0,
|
|
19
|
+
/**
|
|
20
|
+
* Thrown when the name components do not match the validation rules if the
|
|
21
|
+
* `Config.bypass` is not flagged up. This bypass option skips the validation
|
|
22
|
+
* rules.
|
|
23
|
+
*
|
|
24
|
+
* See also: `ValidationError`
|
|
25
|
+
*/
|
|
26
|
+
VALIDATION = 1,
|
|
27
|
+
/**
|
|
28
|
+
* Thrown by not allowed operations such as in NameBuilder or name formatting.
|
|
29
|
+
*
|
|
30
|
+
* See also: `NotAllowedError`, `Namefully.format`.
|
|
31
|
+
*/
|
|
32
|
+
NOT_ALLOWED = 2,
|
|
33
|
+
/**
|
|
34
|
+
* Thrown by any other unknown sources or unexpected situation.
|
|
35
|
+
*/
|
|
36
|
+
UNKNOWN = 3
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Base class for all name-related errors.
|
|
40
|
+
*
|
|
41
|
+
* A custom error is intended to convey information to the user about a failure,
|
|
42
|
+
* so that it can be addressed programmatically.
|
|
43
|
+
*
|
|
44
|
+
* A name handling failure is not considered a native error that should cause a
|
|
45
|
+
* program failure. Au contraire, it is expected that a programmer using this utility
|
|
46
|
+
* would consider validating a name using its own business rules. That is not
|
|
47
|
+
* this utility's job to guess those rules. So, the predefined `ValidationRules`
|
|
48
|
+
* obey some common validation techniques when it comes to sanitizing a person
|
|
49
|
+
* name. For this reason, the [Config.bypass] is set to `true` by default,
|
|
50
|
+
* indicating that those predefined rules should be skipped for the sake of the
|
|
51
|
+
* program.
|
|
52
|
+
*
|
|
53
|
+
* A programmer may leverage `Parser` to indicate business-tailored rules if he
|
|
54
|
+
* or she wants this utility to perform those safety checks behind the scenes.
|
|
55
|
+
*
|
|
56
|
+
* A name error intends to provide useful information about what causes the error
|
|
57
|
+
* and let the user take initiative on what happens next to the given name:
|
|
58
|
+
* reconstructing it or skipping it.
|
|
59
|
+
*/
|
|
60
|
+
export declare class NameError extends Error {
|
|
61
|
+
readonly source: NameSource;
|
|
62
|
+
readonly type: NameErrorType;
|
|
63
|
+
/**
|
|
64
|
+
* Creates an error with a message describing the issue for a name source.
|
|
65
|
+
* @param source name input that caused the error
|
|
66
|
+
* @param message a message describing the failure.
|
|
67
|
+
* @param type of `NameErrorType`
|
|
68
|
+
*/
|
|
69
|
+
constructor(source: NameSource, message?: string, type?: NameErrorType);
|
|
70
|
+
/**
|
|
71
|
+
* The actual source input which caused the error.
|
|
72
|
+
*/
|
|
73
|
+
get sourceAsString(): string;
|
|
74
|
+
/**
|
|
75
|
+
* Whether a message describing the failure exists.
|
|
76
|
+
*/
|
|
77
|
+
get hasMessage(): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Returns a string representation of the error.
|
|
80
|
+
*/
|
|
81
|
+
toString(): string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* An error thrown when a name source input is incorrect.
|
|
85
|
+
*
|
|
86
|
+
* A `Name` is a name for this utility under certain criteria (i.e., 2+ chars),
|
|
87
|
+
* hence, a wrong input will cause this kind of error. Another common reason
|
|
88
|
+
* may be a wrong key in a Json name parsing mechanism.
|
|
89
|
+
*
|
|
90
|
+
* Keep in mind that this error is different from a `ValidationError`.
|
|
91
|
+
*/
|
|
92
|
+
export declare class InputError extends NameError {
|
|
93
|
+
/**
|
|
94
|
+
* Creates a new `InputError` with an optional error `message`.
|
|
95
|
+
*
|
|
96
|
+
* The name source is by nature a string content, maybe wrapped up in a different
|
|
97
|
+
* type. This string value may be extracted to form the following output:
|
|
98
|
+
* "InputError (stringName)",
|
|
99
|
+
* "InputError (stringName): message".
|
|
100
|
+
*/
|
|
101
|
+
constructor(error: ErrorMessage);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* An error thrown to indicate that a name fails the validation rules.
|
|
105
|
+
*/
|
|
106
|
+
export declare class ValidationError extends NameError {
|
|
107
|
+
/**
|
|
108
|
+
* Name of the invalid `nameType` if available.
|
|
109
|
+
*/
|
|
110
|
+
readonly nameType: string;
|
|
111
|
+
/**
|
|
112
|
+
* Creates error containing the invalid `nameType` and a `message` that
|
|
113
|
+
* briefly describes the problem if provided.
|
|
114
|
+
*
|
|
115
|
+
* For example, a validation error can be interpreted as:
|
|
116
|
+
* "ValidationError (nameType='stringName')",
|
|
117
|
+
* "ValidationError (nameType='stringName'): message"
|
|
118
|
+
*/
|
|
119
|
+
constructor(error: ErrorMessage & {
|
|
120
|
+
nameType: string;
|
|
121
|
+
});
|
|
122
|
+
toString(): string;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Thrown by not allowed operations such as in name formatting.
|
|
126
|
+
*
|
|
127
|
+
* For example, this will occur when trying to format a name accordingly using
|
|
128
|
+
* a non-supported key.
|
|
129
|
+
*/
|
|
130
|
+
export declare class NotAllowedError extends NameError {
|
|
131
|
+
/**
|
|
132
|
+
* The revoked operation name.
|
|
133
|
+
*/
|
|
134
|
+
readonly operation: string;
|
|
135
|
+
/**
|
|
136
|
+
* Creates a new `NotAllowedError` with an optional error `message` and the
|
|
137
|
+
* `operation` name.
|
|
138
|
+
*
|
|
139
|
+
* For example, an error of this kind can be interpreted as:
|
|
140
|
+
* "NotAllowedError (stringName)",
|
|
141
|
+
* "NotAllowedError (stringName) - operationName",
|
|
142
|
+
* "NotAllowedError (stringName) - operationName: message"
|
|
143
|
+
*/
|
|
144
|
+
constructor(error: ErrorMessage & {
|
|
145
|
+
operation: string;
|
|
146
|
+
});
|
|
147
|
+
toString(): string;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* A fallback error thrown by any unknown sources or unexpected failure that are
|
|
151
|
+
* not of `NameError`.
|
|
152
|
+
*
|
|
153
|
+
* In this particular case, an `origin` remains useful as it provides details
|
|
154
|
+
* on the sources and the true nature of the unexpected error.
|
|
155
|
+
* At this point, deciding whether to exit the program or not depends on the
|
|
156
|
+
* programmer.
|
|
157
|
+
*/
|
|
158
|
+
export declare class UnknownError extends NameError {
|
|
159
|
+
/**
|
|
160
|
+
* The possible unknown error, with trace revealing its source and reason.
|
|
161
|
+
*/
|
|
162
|
+
readonly origin?: Error;
|
|
163
|
+
/**
|
|
164
|
+
* Creates a new `UnknownError` with an optional error `message`.
|
|
165
|
+
* Optionally, the original error revealing the true nature of the failure.
|
|
166
|
+
*/
|
|
167
|
+
constructor(error: ErrorMessage & {
|
|
168
|
+
error?: Error;
|
|
169
|
+
});
|
|
170
|
+
toString(): string;
|
|
171
|
+
}
|
|
172
|
+
export {};
|