namefully 1.3.0 → 1.3.1
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/lib/config.js +10 -4
- package/dist/lib/constants.js +3 -26
- package/dist/lib/error.js +5 -10
- package/dist/lib/full-name.js +39 -14
- package/dist/lib/name.js +28 -29
- package/dist/lib/namefully.js +76 -62
- package/dist/lib/parser.js +25 -41
- package/dist/lib/types.js +19 -1
- package/dist/lib/utils.js +19 -31
- package/dist/lib/validator.js +34 -48
- package/dist/types/builder.d.ts +4 -2
- package/dist/types/config.d.ts +2 -5
- package/dist/types/constants.d.ts +2 -2
- package/dist/types/error.d.ts +11 -16
- package/dist/types/full-name.d.ts +16 -13
- package/dist/types/name.d.ts +25 -26
- package/dist/types/namefully.d.ts +115 -91
- package/dist/types/parser.d.ts +7 -10
- package/dist/types/types.d.ts +19 -48
- package/dist/types/utils.d.ts +4 -6
- package/dist/types/validator.d.ts +1 -1
- package/dist/umd/namefully.js +258 -266
- package/dist/umd/namefully.min.js +1 -1
- package/package.json +2 -2
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { Config } from './config';
|
|
2
|
-
import { FirstName, LastName, Name, JsonName } from './name';
|
|
3
2
|
import { Nullable, Namon } from './types';
|
|
3
|
+
import { FirstName, LastName, Name, JsonName } from './name';
|
|
4
4
|
/**
|
|
5
5
|
* The core component of this utility.
|
|
6
6
|
*
|
|
7
|
-
* This component is
|
|
7
|
+
* This component is composed of five entities that make it easy to handle a
|
|
8
8
|
* full name set: prefix, first name, middle name, last name, and suffix.
|
|
9
|
-
*
|
|
9
|
+
* It is indeed intended for internal processes. However, it is understandable
|
|
10
10
|
* that it might be needed at some point for additional purposes. For this reason,
|
|
11
11
|
* it's made available.
|
|
12
12
|
*
|
|
13
13
|
* It is recommended to avoid using this class unless it is highly necessary or
|
|
14
|
-
* a custom parser is used for uncommon use cases
|
|
15
|
-
* as many use cases as possible.
|
|
14
|
+
* a custom parser is used for uncommon use cases although this utility tries to
|
|
15
|
+
* cover as many use cases as possible.
|
|
16
16
|
*
|
|
17
17
|
* Additionally, an optional configuration can be used to indicate some specific
|
|
18
18
|
* behaviors related to that name handling.
|
|
@@ -21,7 +21,7 @@ export declare class FullName {
|
|
|
21
21
|
#private;
|
|
22
22
|
/**
|
|
23
23
|
* Creates a full name as it goes
|
|
24
|
-
* @param options
|
|
24
|
+
* @param options settings for additional features.
|
|
25
25
|
*/
|
|
26
26
|
constructor(options?: Partial<Config>);
|
|
27
27
|
/** A snapshot of the configuration used to set up this full name. */
|
|
@@ -37,9 +37,9 @@ export declare class FullName {
|
|
|
37
37
|
/** The suffix part of the full name. */
|
|
38
38
|
get suffix(): Nullable<Name>;
|
|
39
39
|
/**
|
|
40
|
-
* Parses a
|
|
41
|
-
* @param json parsable name element
|
|
42
|
-
* @param config
|
|
40
|
+
* Parses a JSON name into a full name.
|
|
41
|
+
* @param {JsonName} json parsable name element
|
|
42
|
+
* @param {Config} config for additional features.
|
|
43
43
|
*/
|
|
44
44
|
static parse(json: JsonName, config?: Config): FullName;
|
|
45
45
|
setPrefix(name: Nullable<string | Name>): FullName;
|
|
@@ -47,8 +47,11 @@ export declare class FullName {
|
|
|
47
47
|
setLastName(name: string | LastName): FullName;
|
|
48
48
|
setMiddleName(names: string[] | Name[]): FullName;
|
|
49
49
|
setSuffix(name: Nullable<string | Name>): FullName;
|
|
50
|
-
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
/** Returns true if a namon has been set. */
|
|
51
|
+
has(key: Namon | string): boolean;
|
|
52
|
+
toString(): string;
|
|
53
|
+
/** Returns an `Iterable` of existing `Name`s. */
|
|
54
|
+
toIterable(flat?: boolean): Iterable<Name>;
|
|
55
|
+
/** Returns the default iterator for this name set (enabling for-of statements). */
|
|
56
|
+
[Symbol.iterator](): Iterator<Name>;
|
|
54
57
|
}
|
package/dist/types/name.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { CapsRange, Namon, Surname } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Representation of a string type name with some extra capabilities.
|
|
4
|
-
*/
|
|
2
|
+
/** Representation of a string type name with some extra capabilities. */
|
|
5
3
|
export declare class Name {
|
|
6
4
|
#private;
|
|
7
5
|
readonly type: Namon;
|
|
@@ -9,9 +7,9 @@ export declare class Name {
|
|
|
9
7
|
protected capsRange: CapsRange;
|
|
10
8
|
/**
|
|
11
9
|
* Creates augmented names by adding extra functionality to a string name.
|
|
12
|
-
* @param type must be indicated to categorize the name so it can be
|
|
10
|
+
* @param {Namon} type must be indicated to categorize the name so it can be
|
|
13
11
|
* treated accordingly.
|
|
14
|
-
* @param capsRange determines how the name should be capitalized initially.
|
|
12
|
+
* @param {CapsRange} capsRange determines how the name should be capitalized initially.
|
|
15
13
|
*/
|
|
16
14
|
constructor(value: string, type: Namon, capsRange?: CapsRange);
|
|
17
15
|
set value(newValue: string);
|
|
@@ -51,16 +49,14 @@ export declare class Name {
|
|
|
51
49
|
decaps(range?: CapsRange): Name;
|
|
52
50
|
protected validate(name?: string): void;
|
|
53
51
|
}
|
|
54
|
-
/**
|
|
55
|
-
* Representation of a first name with some extra functionality.
|
|
56
|
-
*/
|
|
52
|
+
/** Representation of a first name with some extra functionality. */
|
|
57
53
|
export declare class FirstName extends Name {
|
|
58
54
|
#private;
|
|
59
55
|
/**
|
|
60
56
|
* Creates an extended version of `Name` and flags it as a first name `type`.
|
|
61
57
|
*
|
|
62
58
|
* Some may consider `more` additional name parts of a given name as their
|
|
63
|
-
* first names, but not as their middle names. Though
|
|
59
|
+
* first names, but not as their middle names. Though it may mean the same,
|
|
64
60
|
* `more` provides the freedom to do it as it pleases.
|
|
65
61
|
*/
|
|
66
62
|
constructor(value: string, ...more: string[]);
|
|
@@ -81,30 +77,28 @@ export declare class FirstName extends Name {
|
|
|
81
77
|
more?: string[];
|
|
82
78
|
}): FirstName;
|
|
83
79
|
}
|
|
84
|
-
/**
|
|
85
|
-
* Representation of a last name with some extra functionality.
|
|
86
|
-
*/
|
|
80
|
+
/** Representation of a last name with some extra functionality. */
|
|
87
81
|
export declare class LastName extends Name {
|
|
88
82
|
#private;
|
|
89
|
-
readonly format: Surname;
|
|
83
|
+
readonly format: Surname | 'father' | 'mother' | 'hyphenated' | 'all';
|
|
90
84
|
/**
|
|
91
85
|
* Creates an extended version of `Name` and flags it as a last name `type`.
|
|
92
86
|
*
|
|
93
|
-
* Some people may keep their
|
|
94
|
-
* from their
|
|
87
|
+
* Some people may keep their @param mother's surname and want to keep a clear cut
|
|
88
|
+
* from their @param father's surname. However, there are no clear rules about it.
|
|
95
89
|
*/
|
|
96
|
-
constructor(father: string, mother?: string, format?: Surname);
|
|
97
|
-
/** The surname inherited from
|
|
90
|
+
constructor(father: string, mother?: string, format?: Surname | 'father' | 'mother' | 'hyphenated' | 'all');
|
|
91
|
+
/** The surname inherited from the father side. */
|
|
98
92
|
get father(): string;
|
|
99
|
-
/** The surname inherited from
|
|
93
|
+
/** The surname inherited from the mother side. */
|
|
100
94
|
get mother(): string | undefined;
|
|
101
95
|
/** Returns `true` if the mother's surname is defined. */
|
|
102
96
|
get hasMother(): boolean;
|
|
103
97
|
get length(): number;
|
|
104
98
|
/** Returns a combined version of the `father` and `mother` if any. */
|
|
105
99
|
get asNames(): Name[];
|
|
106
|
-
toString(format?: Surname): string;
|
|
107
|
-
initials(format?: Surname): string[];
|
|
100
|
+
toString(format?: Surname | 'father' | 'mother' | 'hyphenated' | 'all'): string;
|
|
101
|
+
initials(format?: Surname | 'father' | 'mother' | 'hyphenated' | 'all'): string[];
|
|
108
102
|
caps(range?: CapsRange): LastName;
|
|
109
103
|
decaps(range?: CapsRange): LastName;
|
|
110
104
|
/** Makes a copy of the current name. */
|
|
@@ -114,13 +108,18 @@ export declare class LastName extends Name {
|
|
|
114
108
|
format?: Surname;
|
|
115
109
|
}): LastName;
|
|
116
110
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
*/
|
|
111
|
+
export declare function isNameArray(value?: unknown): value is Name[];
|
|
112
|
+
/** JSON signature for `FullName` data. */
|
|
120
113
|
export interface JsonName {
|
|
121
114
|
prefix?: string;
|
|
122
|
-
firstName: string
|
|
123
|
-
|
|
124
|
-
|
|
115
|
+
firstName: string | {
|
|
116
|
+
value: string;
|
|
117
|
+
more?: string[];
|
|
118
|
+
};
|
|
119
|
+
middleName?: string | string[];
|
|
120
|
+
lastName: string | {
|
|
121
|
+
father: string;
|
|
122
|
+
mother?: string;
|
|
123
|
+
};
|
|
125
124
|
suffix?: string;
|
|
126
125
|
}
|
|
@@ -1,74 +1,76 @@
|
|
|
1
1
|
import { Config } from './config';
|
|
2
2
|
import { Name, JsonName } from './name';
|
|
3
|
-
import { Parser } from './parser';
|
|
4
|
-
import { Flat, NameOrder, NameType, Namon, Nullable, Surname } from './types';
|
|
5
3
|
import { NameIndex } from './utils';
|
|
4
|
+
import { Flat, NameOrder, NameType, Namon, Nullable, Surname, Separator, Title } from './types';
|
|
5
|
+
import { Parser } from './parser';
|
|
6
6
|
/**
|
|
7
|
-
* A
|
|
7
|
+
* A utility for organizing human names in a particular order, way, or shape.
|
|
8
8
|
*
|
|
9
|
-
* Though `namefully` is easy to use, it does not magically guess
|
|
10
|
-
* the name is what (prefix, suffix, first, last, or middle names).
|
|
11
|
-
* actually on how the name parts are indicated (i.e., their roles)
|
|
12
|
-
* it can perform internally certain operations and saves us some extra
|
|
13
|
-
* calculations/processing.
|
|
14
|
-
* distinct raw data shapes. This is intended to give some flexibility to
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
9
|
+
* Though `namefully` is designed to be easy to use, it does not magically guess
|
|
10
|
+
* which part of the name is what (prefix, suffix, first, last, or middle names).
|
|
11
|
+
* It relies actually on how the name parts are indicated (i.e., their roles)
|
|
12
|
+
* so that it can perform internally certain operations and saves us some extra
|
|
13
|
+
* calculations/processing. Additionally, `Namefully` objects may be created using
|
|
14
|
+
* distinct raw data shapes. This is intended to give some flexibility to you
|
|
15
|
+
* so that you are not bound to a particular data format (e.g., string).
|
|
16
|
+
* Follow the API reference to know how to harness its usability as this utility
|
|
17
|
+
* aims to save time in formatting names.
|
|
18
18
|
*
|
|
19
|
-
* `namefully` also works like a trapdoor. Once
|
|
20
|
-
* validated,
|
|
21
|
-
*
|
|
22
|
-
* instance of `Namefully` must be created. In
|
|
23
|
-
* Remember, this utility's primary objective is to help manipulate
|
|
19
|
+
* `namefully` also works like a trapdoor. Once some name data is provided and
|
|
20
|
+
* validated, you may only *access* it but not update any part of it. This
|
|
21
|
+
* means that *no editing* is possible. If the name is mistaken, a new
|
|
22
|
+
* instance of `Namefully` must be created. In simple terms, it's immutable.
|
|
23
|
+
* Remember, this utility's primary objective is to help manipulate human names,
|
|
24
|
+
* not the opposite.
|
|
24
25
|
*
|
|
25
|
-
* Note that the name standards used for the current version of this
|
|
26
|
-
*
|
|
26
|
+
* Note that the name standards used for the current version of this utility are
|
|
27
|
+
* as follows:
|
|
27
28
|
* `[prefix] firstName [middleName] lastName [suffix]`
|
|
28
|
-
*
|
|
29
|
+
* where the opening `[` and closing `]` brackets mean that these parts are optional.
|
|
29
30
|
* In other words, the most basic and typical case is a name that looks like
|
|
30
31
|
* this: `John Smith`, where `John` is the first name piece and `Smith`, the last
|
|
31
32
|
* name piece.
|
|
32
33
|
*
|
|
33
|
-
* @see https://www.fbiic.gov/public/2008/nov/Naming_practice_guide_UK_2006.pdf
|
|
34
|
-
*
|
|
34
|
+
* @see {@link https://www.fbiic.gov/public/2008/nov/Naming_practice_guide_UK_2006.pdf} for
|
|
35
|
+
* more info on name standards.
|
|
35
36
|
*
|
|
36
37
|
* **IMPORTANT**: Keep in mind that the order of appearance (or name order) matters
|
|
37
|
-
* and may be altered through
|
|
38
|
+
* and may be altered through configurable parameters, which will be seen later.
|
|
38
39
|
* By default, the order of appearance is as shown above and will be used as a
|
|
39
40
|
* basis for future examples and use cases.
|
|
40
41
|
*
|
|
41
|
-
* Once imported, all that is required to do is to create
|
|
42
|
-
*
|
|
42
|
+
* Once imported, all that is required to do is to create instances of `Namefully`
|
|
43
|
+
* as you see fit and the rest will follow.
|
|
43
44
|
*
|
|
44
45
|
* Some terminologies used across the library are:
|
|
45
|
-
* - namon: 1 piece of name (e.g.,
|
|
46
|
-
* - nama: 2+ pieces of name (e.g., first name + last name)
|
|
46
|
+
* - namon: 1 piece of name (e.g., prefix)
|
|
47
|
+
* - nama: a combination of 2+ pieces of name (e.g., first name + last name)
|
|
47
48
|
*
|
|
48
49
|
* Happy name handling 😊!
|
|
49
50
|
*/
|
|
50
51
|
export declare class Namefully {
|
|
51
52
|
#private;
|
|
52
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Creates a name with distinguishable parts.
|
|
53
55
|
* @param names element to parse.
|
|
54
56
|
* @param options additional settings.
|
|
55
57
|
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
58
|
+
* Optional parameters may be provided with specifics on how to treat a full
|
|
59
|
+
* name during its existence. All name parts must have at least one (1) character
|
|
60
|
+
* to proceed. That is the only requirement/validation of namefully.
|
|
59
61
|
*/
|
|
60
|
-
constructor(names: string | string[] | Name[] | JsonName | Parser, options?:
|
|
62
|
+
constructor(names: string | string[] | Name[] | JsonName | Parser, options?: NameOptions);
|
|
61
63
|
/**
|
|
62
64
|
* Constructs a `Namefully` instance from a text.
|
|
63
65
|
*
|
|
64
|
-
* It works like `parse` except that this function returns `
|
|
65
|
-
* would throw a `NameError`.
|
|
66
|
+
* It works like `parse` except that this function returns `undefined` when
|
|
67
|
+
* `parse` would throw a `NameError`.
|
|
66
68
|
*/
|
|
67
69
|
static tryParse(text: string, index?: NameIndex): Namefully | undefined;
|
|
68
70
|
/**
|
|
69
71
|
* Constructs a `Namefully` instance from a text.
|
|
70
72
|
*
|
|
71
|
-
*
|
|
73
|
+
* @throws a `NameError` if the @param text cannot be parsed. Use `tryParse`
|
|
72
74
|
* instead if a `null` return is preferred over a throwable error.
|
|
73
75
|
*
|
|
74
76
|
* This operation is computed asynchronously, which gives more flexibility at
|
|
@@ -81,27 +83,27 @@ export declare class Namefully {
|
|
|
81
83
|
* process.
|
|
82
84
|
*/
|
|
83
85
|
static parse(text: string, index?: NameIndex): Promise<Namefully>;
|
|
84
|
-
/** The
|
|
86
|
+
/** The configuration dictating this name's behavior. */
|
|
85
87
|
get config(): Config;
|
|
86
88
|
/** The number of characters of the `birthName`, including spaces. */
|
|
87
89
|
get length(): number;
|
|
88
|
-
/** The prefix part. */
|
|
89
|
-
get prefix():
|
|
90
|
-
/** The firt name part. */
|
|
90
|
+
/** The prefix part of the name set. */
|
|
91
|
+
get prefix(): string | undefined;
|
|
92
|
+
/** The firt name part of the name set. */
|
|
91
93
|
get first(): string;
|
|
92
|
-
/** The first middle name part if any. */
|
|
93
|
-
get middle():
|
|
94
|
+
/** The first middle name part of the name set if any. */
|
|
95
|
+
get middle(): string | undefined;
|
|
94
96
|
/** Returns true if any middle name has been set. */
|
|
95
97
|
get hasMiddle(): boolean;
|
|
96
|
-
/** The last name part. */
|
|
98
|
+
/** The last name part of the name set. */
|
|
97
99
|
get last(): string;
|
|
98
|
-
/** The suffix part. */
|
|
99
|
-
get suffix():
|
|
100
|
-
/** The birth name part. */
|
|
100
|
+
/** The suffix part of the name set. */
|
|
101
|
+
get suffix(): string | undefined;
|
|
102
|
+
/** The birth name part of the name set. */
|
|
101
103
|
get birth(): string;
|
|
102
|
-
/** The shortest version of a
|
|
104
|
+
/** The shortest version of a human name (first + last name). */
|
|
103
105
|
get short(): string;
|
|
104
|
-
/** The longest version of a
|
|
106
|
+
/** The longest version of a human name (a.k.a birth name). */
|
|
105
107
|
get long(): string;
|
|
106
108
|
/** The entire name set. */
|
|
107
109
|
get full(): string;
|
|
@@ -109,93 +111,114 @@ export declare class Namefully {
|
|
|
109
111
|
get public(): string;
|
|
110
112
|
/** The combination of prefix and last name. */
|
|
111
113
|
get salutation(): string;
|
|
112
|
-
/**
|
|
114
|
+
/**
|
|
115
|
+
* Returns an iterable of the name components in their natural form.
|
|
116
|
+
*
|
|
117
|
+
* Regardless of the order of appearance, this method will always return the
|
|
118
|
+
* existing `Name`s according to the name standards upon which this library
|
|
119
|
+
* is based.
|
|
120
|
+
*
|
|
121
|
+
* This is useful for iterating over the name parts in a consistent manner and
|
|
122
|
+
* this automatically enables operations such as mapping, filtering, etc.
|
|
123
|
+
*/
|
|
124
|
+
get parts(): Iterable<Name>;
|
|
125
|
+
/** The number of name components. */
|
|
126
|
+
get size(): number;
|
|
127
|
+
/**
|
|
128
|
+
* Makes the name set iterable (i.e., for-of statements).
|
|
129
|
+
*
|
|
130
|
+
* This is similar to `parts` with the exception that all name components are
|
|
131
|
+
* returned as `Name` classes (instead of their natural form - e.g., `FirstName`)
|
|
132
|
+
* to maintain certain homogeneity and consistency across each name piece.
|
|
133
|
+
*/
|
|
134
|
+
[Symbol.iterator](): Iterator<Name>;
|
|
135
|
+
/** Gets a string representation of the full name. */
|
|
113
136
|
toString(): string;
|
|
114
137
|
/** Fetches the raw form of a name piece. */
|
|
115
|
-
get(
|
|
138
|
+
get(key: Namon | string): Nullable<Name | Name[]>;
|
|
116
139
|
/** Whether this name is equal to another one from a raw-string perspective. */
|
|
117
140
|
equal(other: Namefully): boolean;
|
|
141
|
+
/** Whether this name is equal to another one from a component perspective. */
|
|
142
|
+
deepEqual(other: Namefully): boolean;
|
|
118
143
|
/** Gets a JSON representation of the full name. */
|
|
119
144
|
toJson(): JsonName;
|
|
120
|
-
|
|
121
|
-
|
|
145
|
+
json: () => JsonName;
|
|
146
|
+
/** Confirms whether a name component exists. */
|
|
147
|
+
has(namon: Namon | string): boolean;
|
|
122
148
|
/**
|
|
123
149
|
* Gets the full name ordered as configured.
|
|
124
150
|
*
|
|
125
|
-
*
|
|
126
|
-
* overriding the preset configuration.
|
|
127
|
-
*
|
|
128
|
-
* `Namefully.format` may also be used to alter manually the order of appearance
|
|
129
|
-
* of full name.
|
|
151
|
+
* @param {NameOrder} orderedBy forces to arrange a name set by first or last
|
|
152
|
+
* name, overriding the preset configuration.
|
|
130
153
|
*
|
|
131
|
-
*
|
|
154
|
+
* `Namefully.format()` may also be used to alter manually the order of appearance
|
|
155
|
+
* of a full name. For example:
|
|
132
156
|
* ```ts
|
|
133
157
|
* const name = new Namefully('Jon Stark Snow');
|
|
134
158
|
* console.log(name.fullName(NameOrder.LAST_NAME)); // "Snow Jon Stark"
|
|
135
159
|
* console.log(name.format('l f m')); // "Snow Jon Stark"
|
|
136
160
|
* ```
|
|
137
161
|
*/
|
|
138
|
-
fullName(orderedBy?:
|
|
162
|
+
fullName(orderedBy?: NameOptions['orderedBy']): string;
|
|
139
163
|
/**
|
|
140
164
|
* Gets the birth name ordered as configured, no `prefix` or `suffix`.
|
|
141
165
|
*
|
|
142
166
|
* @param orderedBy forces to order by first or last name by overriding the
|
|
143
167
|
* preset configuration.
|
|
144
168
|
*/
|
|
145
|
-
birthName(orderedBy?:
|
|
169
|
+
birthName(orderedBy?: NameOptions['orderedBy']): string;
|
|
146
170
|
/**
|
|
147
171
|
* Gets the first name part of the `FullName`.
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* name.
|
|
172
|
+
* @param {boolean} withMore determines whether to include other pieces of the
|
|
173
|
+
* first name.
|
|
151
174
|
*/
|
|
152
175
|
firstName(withMore?: boolean): string;
|
|
153
176
|
/** Gets the middle name part of the `FullName`. */
|
|
154
177
|
middleName(): string[];
|
|
155
178
|
/**
|
|
156
179
|
* Gets the last name part of the `FullName`.
|
|
157
|
-
*
|
|
158
|
-
* @param format overrides the how-to formatting of a surname output,
|
|
180
|
+
* @param {Surname} format overrides the how-to formatting of a surname output,
|
|
159
181
|
* considering its sub-parts.
|
|
160
182
|
*/
|
|
161
|
-
lastName(format?:
|
|
183
|
+
lastName(format?: NameOptions['surname']): string;
|
|
162
184
|
/**
|
|
163
185
|
* Gets the initials of the `FullName`.
|
|
164
186
|
*
|
|
165
|
-
* @param {
|
|
187
|
+
* @param {object} options when getting the initials.
|
|
188
|
+
* @param {NameOrder} options.orderedBy forces to order by first or last name by
|
|
166
189
|
* overriding the preset configuration.
|
|
167
|
-
* @param
|
|
190
|
+
* @param {NameType} options.only selects initials of only certain name parts.
|
|
191
|
+
* @param {boolean} options.asJson whether to return initials as an array or JSON.
|
|
168
192
|
*
|
|
169
193
|
* For example, given the names:
|
|
170
194
|
* - `John Smith` => `['J', 'S']`
|
|
171
195
|
* - `John Ben Smith` => `['J', 'B', 'S']`.
|
|
172
196
|
*/
|
|
173
197
|
initials(options?: {
|
|
174
|
-
orderedBy?:
|
|
175
|
-
only?: NameType;
|
|
198
|
+
orderedBy?: NameOptions['orderedBy'];
|
|
199
|
+
only?: NameType | 'firstName' | 'lastName' | 'middleName' | 'birthName';
|
|
176
200
|
asJson?: boolean;
|
|
177
201
|
}): string[] | Record<string, string[]>;
|
|
178
202
|
/**
|
|
179
203
|
* Shortens a complex full name to a simple typical name, a combination of
|
|
180
204
|
* first and last name.
|
|
181
205
|
*
|
|
182
|
-
* @param orderedBy forces to order by first or last name
|
|
183
|
-
* preset configuration.
|
|
206
|
+
* @param {NameOrder} orderedBy forces to order by first or last name, overriding
|
|
207
|
+
* the preset configuration.
|
|
184
208
|
*
|
|
185
209
|
* For a given name such as `Mr Keanu Charles Reeves`, shortening this name
|
|
186
210
|
* is equivalent to making it `Keanu Reeves`.
|
|
187
211
|
*
|
|
188
212
|
* As a shortened name, the namon of the first name is favored over the other
|
|
189
|
-
* names forming part of the entire first names, if any. Meanwhile, for
|
|
190
|
-
*
|
|
213
|
+
* names forming part of the entire first names, if any. Meanwhile, for the
|
|
214
|
+
* last name, the configured `surname` is prioritized.
|
|
191
215
|
*
|
|
192
216
|
* For a given `FirstName FatherName MotherName`, shortening this name when
|
|
193
|
-
* the surname is set as `mother` is equivalent to making it:
|
|
194
|
-
* `FirstName MotherName`.
|
|
217
|
+
* the surname is set as `mother` is equivalent to making it: `FirstName MotherName`.
|
|
195
218
|
*/
|
|
196
|
-
shorten(orderedBy?:
|
|
219
|
+
shorten(orderedBy?: NameOptions['orderedBy']): string;
|
|
197
220
|
/**
|
|
198
|
-
* Flattens
|
|
221
|
+
* Flattens long names using the name types as variants.
|
|
199
222
|
*
|
|
200
223
|
* While @param limit sets a threshold as a limited number of characters
|
|
201
224
|
* supported to flatten a `FullName`, @param by indicates which variant
|
|
@@ -229,17 +252,16 @@ export declare class Namefully {
|
|
|
229
252
|
withPeriod: boolean;
|
|
230
253
|
recursive: boolean;
|
|
231
254
|
withMore: boolean;
|
|
232
|
-
surname:
|
|
255
|
+
surname: NameOptions['surname'];
|
|
233
256
|
}>): string;
|
|
234
257
|
/**
|
|
235
258
|
* Zips or compacts a name using different forms of variants.
|
|
236
|
-
*
|
|
237
259
|
* @see `flatten()` for more details.
|
|
238
260
|
*/
|
|
239
261
|
zip(by?: Flat, withPeriod?: boolean): string;
|
|
240
262
|
/**
|
|
241
263
|
* Formats the full name as desired.
|
|
242
|
-
* @param pattern character used to format it.
|
|
264
|
+
* @param {string} pattern character used to format it.
|
|
243
265
|
*
|
|
244
266
|
* string format
|
|
245
267
|
* -------------
|
|
@@ -264,14 +286,6 @@ export declare class Namefully {
|
|
|
264
286
|
* - 'P': capitalized prefix
|
|
265
287
|
* - 's': suffix
|
|
266
288
|
* - 'S': capitalized suffix
|
|
267
|
-
*
|
|
268
|
-
* punctuations
|
|
269
|
-
* ------------
|
|
270
|
-
* - '.': period
|
|
271
|
-
* - ',': comma
|
|
272
|
-
* - ' ': space
|
|
273
|
-
* - '-': hyphen
|
|
274
|
-
* - '_': underscore
|
|
275
289
|
* - '$': an escape character to select only the initial of the next char.
|
|
276
290
|
*
|
|
277
291
|
* Given the name `Joe Jim Smith`, use `format` with the `pattern` string.
|
|
@@ -285,7 +299,7 @@ export declare class Namefully {
|
|
|
285
299
|
* first, middle, and last names.
|
|
286
300
|
*/
|
|
287
301
|
format(pattern: string): string;
|
|
288
|
-
/** Flips
|
|
302
|
+
/** Flips or swaps the name order from the preset/current config. */
|
|
289
303
|
flip(): void;
|
|
290
304
|
/**
|
|
291
305
|
* Splits the name parts of a birth name.
|
|
@@ -294,7 +308,7 @@ export declare class Namefully {
|
|
|
294
308
|
split(separator?: string | RegExp): string[];
|
|
295
309
|
/**
|
|
296
310
|
* Joins the name parts of a birth name.
|
|
297
|
-
* @param separator token for the junction.
|
|
311
|
+
* @param {string} separator token for the junction.
|
|
298
312
|
*/
|
|
299
313
|
join(separator?: string): string;
|
|
300
314
|
/** Transforms a birth name into UPPERCASE. */
|
|
@@ -319,5 +333,15 @@ export declare class Namefully {
|
|
|
319
333
|
* @param names element to parse.
|
|
320
334
|
* @param options additional settings.
|
|
321
335
|
*/
|
|
322
|
-
declare const _default: (names: string | string[] | Name[] | JsonName | Parser, options?:
|
|
336
|
+
declare const _default: (names: string | string[] | Name[] | JsonName | Parser, options?: NameOptions) => Namefully;
|
|
323
337
|
export default _default;
|
|
338
|
+
/** Optional namefully parameters (@see {@linkcode Config} for more details). */
|
|
339
|
+
export type NameOptions = Partial<{
|
|
340
|
+
name: string;
|
|
341
|
+
orderedBy: NameOrder | 'firstName' | 'lastName';
|
|
342
|
+
separator: Separator;
|
|
343
|
+
title: Title | 'UK' | 'US';
|
|
344
|
+
ending: boolean;
|
|
345
|
+
bypass: boolean;
|
|
346
|
+
surname: Surname | 'father' | 'mother' | 'hyphenated' | 'all';
|
|
347
|
+
}>;
|
package/dist/types/parser.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FullName } from './full-name';
|
|
2
1
|
import { Config } from './config';
|
|
3
2
|
import { NameIndex } from './utils';
|
|
3
|
+
import { FullName } from './full-name';
|
|
4
4
|
import { Name, JsonName } from './name';
|
|
5
5
|
/**
|
|
6
6
|
* A parser signature that helps to organize the names accordingly.
|
|
@@ -12,20 +12,18 @@ export declare abstract class Parser<T = unknown> {
|
|
|
12
12
|
* @param raw data to be parsed
|
|
13
13
|
*/
|
|
14
14
|
constructor(raw: T);
|
|
15
|
+
/**
|
|
16
|
+
* Parses raw data into a `FullName` while applying some options.
|
|
17
|
+
* @param options for additional configuration to apply.
|
|
18
|
+
*/
|
|
19
|
+
abstract parse(options?: Partial<Config>): FullName;
|
|
15
20
|
/**
|
|
16
21
|
* Builds a dynamic `Parser` on the fly and throws a `NameError` when unable
|
|
17
22
|
* to do so. The built parser only knows how to operate birth names.
|
|
18
23
|
*/
|
|
19
24
|
static build(text: string, index?: NameIndex): Parser;
|
|
20
|
-
/**
|
|
21
|
-
* Builds asynchronously a dynamic `Parser`.
|
|
22
|
-
*/
|
|
25
|
+
/** Builds asynchronously a dynamic `Parser`. */
|
|
23
26
|
static buildAsync(text: string, index?: NameIndex): Promise<Parser>;
|
|
24
|
-
/**
|
|
25
|
-
* Parses the raw data into a `FullName` while considering some options.
|
|
26
|
-
* @param options additional configuration to apply.
|
|
27
|
-
*/
|
|
28
|
-
abstract parse(options?: Partial<Config>): FullName;
|
|
29
27
|
}
|
|
30
28
|
export declare class StringParser extends Parser<string> {
|
|
31
29
|
parse(options: Partial<Config>): FullName;
|
|
@@ -34,7 +32,6 @@ export declare class ArrayStringParser extends Parser<string[]> {
|
|
|
34
32
|
parse(options: Partial<Config>): FullName;
|
|
35
33
|
}
|
|
36
34
|
export declare class NamaParser extends Parser<JsonName> {
|
|
37
|
-
#private;
|
|
38
35
|
parse(options: Partial<Config>): FullName;
|
|
39
36
|
}
|
|
40
37
|
export declare class ArrayNameParser extends Parser<Name[]> {
|