namefully 2.0.0 → 2.0.2
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/cjs/config.js +14 -5
- package/dist/cjs/constants.js +3 -3
- package/dist/cjs/error.js +4 -7
- package/dist/cjs/fullname.js +10 -11
- package/dist/cjs/name.js +18 -22
- package/dist/cjs/namefully.js +32 -40
- package/dist/cjs/parser.js +13 -15
- package/dist/cjs/utils.js +18 -25
- package/dist/cjs/validator.js +24 -39
- package/dist/esm/builder.d.ts +4 -2
- package/dist/esm/config.d.ts +6 -1
- package/dist/esm/config.js +14 -5
- package/dist/esm/constants.d.ts +2 -2
- package/dist/esm/constants.js +2 -2
- package/dist/esm/error.d.ts +10 -14
- package/dist/esm/error.js +4 -7
- package/dist/esm/fullname.d.ts +10 -12
- package/dist/esm/fullname.js +10 -11
- package/dist/esm/name.d.ts +12 -20
- package/dist/esm/name.js +18 -22
- package/dist/esm/namefully.d.ts +64 -65
- package/dist/esm/namefully.js +33 -41
- package/dist/esm/parser.d.ts +3 -6
- package/dist/esm/parser.js +13 -15
- package/dist/esm/types.d.ts +16 -48
- package/dist/esm/utils.d.ts +4 -5
- package/dist/esm/utils.js +18 -25
- package/dist/esm/validator.d.ts +1 -1
- package/dist/esm/validator.js +29 -44
- package/dist/namefully.js +124 -155
- package/dist/namefully.min.js +1 -1
- package/package.json +7 -7
- package/readme.md +16 -17
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Make a type nullable.
|
|
3
|
-
*/
|
|
1
|
+
/** Make a type nullable. */
|
|
4
2
|
export type Nullable<T> = T | null | undefined;
|
|
5
3
|
/**
|
|
6
4
|
* The abbreviation type to indicate whether or not to add period to a prefix
|
|
@@ -23,25 +21,19 @@ export declare enum Surname {
|
|
|
23
21
|
HYPHENATED = "hyphenated",
|
|
24
22
|
ALL = "all"
|
|
25
23
|
}
|
|
26
|
-
/**
|
|
27
|
-
* The order of appearance of a `FullName`.
|
|
28
|
-
*/
|
|
24
|
+
/** The order of appearance of a `FullName`. */
|
|
29
25
|
export declare enum NameOrder {
|
|
30
26
|
FIRST_NAME = "firstName",
|
|
31
27
|
LAST_NAME = "lastName"
|
|
32
28
|
}
|
|
33
|
-
/**
|
|
34
|
-
* The types of name handled in this according the name standards.
|
|
35
|
-
*/
|
|
29
|
+
/** The types of name handled in this according the name standards. */
|
|
36
30
|
export declare enum NameType {
|
|
37
31
|
FIRST_NAME = "firstName",
|
|
38
32
|
MIDDLE_NAME = "middleName",
|
|
39
33
|
LAST_NAME = "lastName",
|
|
40
34
|
BIRTH_NAME = "birthName"
|
|
41
35
|
}
|
|
42
|
-
/**
|
|
43
|
-
* The possible variants to indicate how to flatten a `FullName`.
|
|
44
|
-
*/
|
|
36
|
+
/** The possible variants to indicate how to flatten a `FullName`. */
|
|
45
37
|
export declare enum Flat {
|
|
46
38
|
FIRST_NAME = "firstName",
|
|
47
39
|
MIDDLE_NAME = "middleName",
|
|
@@ -50,17 +42,13 @@ export declare enum Flat {
|
|
|
50
42
|
MID_LAST = "midLast",
|
|
51
43
|
ALL = "all"
|
|
52
44
|
}
|
|
53
|
-
/**
|
|
54
|
-
* The range to use when capitalizing a string content.
|
|
55
|
-
*/
|
|
45
|
+
/** The range to use when capitalizing a string content. */
|
|
56
46
|
export declare enum CapsRange {
|
|
57
47
|
NONE = 0,
|
|
58
48
|
INITIAL = 1,
|
|
59
49
|
ALL = 2
|
|
60
50
|
}
|
|
61
|
-
/**
|
|
62
|
-
* The types of name handled in this utility according the name standards.
|
|
63
|
-
*/
|
|
51
|
+
/** The types of name handled in this utility according the name standards. */
|
|
64
52
|
export declare class Namon {
|
|
65
53
|
readonly index: number;
|
|
66
54
|
readonly key: string;
|
|
@@ -69,35 +57,21 @@ export declare class Namon {
|
|
|
69
57
|
static readonly MIDDLE_NAME: Namon;
|
|
70
58
|
static readonly LAST_NAME: Namon;
|
|
71
59
|
static readonly SUFFIX: Namon;
|
|
72
|
-
/**
|
|
73
|
-
* The list of supported name types.
|
|
74
|
-
*/
|
|
60
|
+
/** The list of supported name types. */
|
|
75
61
|
static readonly values: Namon[];
|
|
76
|
-
/**
|
|
77
|
-
* All the predefined name types.
|
|
78
|
-
*/
|
|
62
|
+
/** All the predefined name types. */
|
|
79
63
|
static readonly all: Map<string, Namon>;
|
|
80
64
|
private constructor();
|
|
81
|
-
/**
|
|
82
|
-
* Whether this string key is part of the predefined keys.
|
|
83
|
-
*/
|
|
65
|
+
/** Whether this string key is part of the predefined keys. */
|
|
84
66
|
static has(key: string): boolean;
|
|
85
|
-
/**
|
|
86
|
-
* Makes a string key a namon type.
|
|
87
|
-
*/
|
|
67
|
+
/** Makes a string key a namon type. */
|
|
88
68
|
static cast(key: string): Nullable<Namon>;
|
|
89
|
-
/**
|
|
90
|
-
* String representation of this object.
|
|
91
|
-
*/
|
|
69
|
+
/** String representation of this object. */
|
|
92
70
|
toString(): string;
|
|
93
|
-
/**
|
|
94
|
-
* Whether this and the other value are equal.
|
|
95
|
-
*/
|
|
71
|
+
/** Whether this and the other value are equal. */
|
|
96
72
|
equal(other: Namon | unknown): boolean;
|
|
97
73
|
}
|
|
98
|
-
/**
|
|
99
|
-
* The token used to indicate how to split string values.
|
|
100
|
-
*/
|
|
74
|
+
/** The token used to indicate how to split string values. */
|
|
101
75
|
export declare class Separator {
|
|
102
76
|
readonly name: string;
|
|
103
77
|
readonly token: string;
|
|
@@ -111,17 +85,11 @@ export declare class Separator {
|
|
|
111
85
|
static readonly SINGLE_QUOTE: Separator;
|
|
112
86
|
static readonly SPACE: Separator;
|
|
113
87
|
static readonly UNDERSCORE: Separator;
|
|
114
|
-
/**
|
|
115
|
-
* All the available separators.
|
|
116
|
-
*/
|
|
88
|
+
/** All the available separators. */
|
|
117
89
|
static readonly all: Map<string, Separator>;
|
|
118
|
-
/**
|
|
119
|
-
* All the available tokens.
|
|
120
|
-
*/
|
|
90
|
+
/** All the available tokens. */
|
|
121
91
|
static readonly tokens: string[];
|
|
122
92
|
private constructor();
|
|
123
|
-
/**
|
|
124
|
-
* String representation of this object.
|
|
125
|
-
*/
|
|
93
|
+
/** String representation of this object. */
|
|
126
94
|
toString(): string;
|
|
127
95
|
}
|
package/dist/esm/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NameOrder, CapsRange } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
* A
|
|
3
|
+
* A set of values to handle specific positions for list of names.
|
|
4
4
|
*
|
|
5
5
|
* As for list of names, this helps to follow a specific order based on the
|
|
6
6
|
* count of elements. It is expected that the list has to be between two and
|
|
@@ -42,13 +42,12 @@ export declare class NameIndex {
|
|
|
42
42
|
static when(order: NameOrder, count?: number): NameIndex;
|
|
43
43
|
static only({ prefix, firstName, middleName, lastName, suffix }: Record<string, number>): NameIndex;
|
|
44
44
|
toJson(): Record<string, number>;
|
|
45
|
+
json: () => Record<string, number>;
|
|
45
46
|
}
|
|
46
|
-
/**
|
|
47
|
-
* Capitalizes a string via a `CapsRange` option.
|
|
48
|
-
*/
|
|
47
|
+
/** Capitalizes a string via a `CapsRange` option. */
|
|
49
48
|
export declare function capitalize(str: string, range?: CapsRange): string;
|
|
50
49
|
/** Decapitalizes a string via a `CapsRange` option. */
|
|
51
50
|
export declare function decapitalize(str: string, range?: CapsRange): string;
|
|
52
51
|
/** Toggles a string representation. */
|
|
53
52
|
export declare function toggleCase(str: string): string;
|
|
54
|
-
export declare function isStringArray(value?: unknown):
|
|
53
|
+
export declare function isStringArray(value?: unknown): value is string[];
|
package/dist/esm/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MIN_NUMBER_OF_NAME_PARTS, MAX_NUMBER_OF_NAME_PARTS } from './constants.js';
|
|
2
1
|
import { NameOrder, CapsRange } from './types.js';
|
|
2
|
+
import { MIN_NUMBER_OF_NAME_PARTS, MAX_NUMBER_OF_NAME_PARTS } from './constants.js';
|
|
3
3
|
export class NameIndex {
|
|
4
4
|
prefix;
|
|
5
5
|
firstName;
|
|
@@ -20,19 +20,19 @@ export class NameIndex {
|
|
|
20
20
|
this.suffix = suffix;
|
|
21
21
|
}
|
|
22
22
|
static base() {
|
|
23
|
-
return new
|
|
23
|
+
return new NameIndex(-1, 0, -1, 1, -1);
|
|
24
24
|
}
|
|
25
25
|
static when(order, count = 2) {
|
|
26
26
|
if (order === NameOrder.FIRST_NAME) {
|
|
27
27
|
switch (count) {
|
|
28
28
|
case 2:
|
|
29
|
-
return new
|
|
29
|
+
return new NameIndex(-1, 0, -1, 1, -1);
|
|
30
30
|
case 3:
|
|
31
|
-
return new
|
|
31
|
+
return new NameIndex(-1, 0, 1, 2, -1);
|
|
32
32
|
case 4:
|
|
33
|
-
return new
|
|
33
|
+
return new NameIndex(0, 1, 2, 3, -1);
|
|
34
34
|
case 5:
|
|
35
|
-
return new
|
|
35
|
+
return new NameIndex(0, 1, 2, 3, 4);
|
|
36
36
|
default:
|
|
37
37
|
return NameIndex.base();
|
|
38
38
|
}
|
|
@@ -40,20 +40,20 @@ export class NameIndex {
|
|
|
40
40
|
else {
|
|
41
41
|
switch (count) {
|
|
42
42
|
case 2:
|
|
43
|
-
return new
|
|
43
|
+
return new NameIndex(-1, 1, -1, 0, -1);
|
|
44
44
|
case 3:
|
|
45
|
-
return new
|
|
45
|
+
return new NameIndex(-1, 1, 2, 0, -1);
|
|
46
46
|
case 4:
|
|
47
|
-
return new
|
|
47
|
+
return new NameIndex(0, 2, 3, 1, -1);
|
|
48
48
|
case 5:
|
|
49
|
-
return new
|
|
49
|
+
return new NameIndex(0, 2, 3, 1, 4);
|
|
50
50
|
default:
|
|
51
51
|
return NameIndex.base();
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
static only({ prefix = -1, firstName, middleName = -1, lastName, suffix = -1 }) {
|
|
56
|
-
return new
|
|
56
|
+
return new NameIndex(prefix, firstName, middleName, lastName, suffix);
|
|
57
57
|
}
|
|
58
58
|
toJson() {
|
|
59
59
|
return {
|
|
@@ -64,32 +64,25 @@ export class NameIndex {
|
|
|
64
64
|
suffix: this.suffix,
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
+
json = this.toJson;
|
|
67
68
|
}
|
|
68
69
|
export function capitalize(str, range = CapsRange.INITIAL) {
|
|
69
70
|
if (!str || range === CapsRange.NONE)
|
|
70
71
|
return str;
|
|
71
|
-
const initial = str[0].toUpperCase();
|
|
72
|
-
const rest = str.slice(1).toLowerCase();
|
|
72
|
+
const [initial, rest] = [str[0].toUpperCase(), str.slice(1).toLowerCase()];
|
|
73
73
|
return range === CapsRange.INITIAL ? initial.concat(rest) : str.toUpperCase();
|
|
74
74
|
}
|
|
75
75
|
export function decapitalize(str, range = CapsRange.INITIAL) {
|
|
76
76
|
if (!str || range === CapsRange.NONE)
|
|
77
77
|
return str;
|
|
78
|
-
const initial = str[0].toLowerCase();
|
|
79
|
-
const rest = str.slice(1);
|
|
78
|
+
const [initial, rest] = [str[0].toLowerCase(), str.slice(1)];
|
|
80
79
|
return range === CapsRange.INITIAL ? initial.concat(rest) : str.toLowerCase();
|
|
81
80
|
}
|
|
82
81
|
export function toggleCase(str) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
chars.push(c.toUpperCase());
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return chars.join('');
|
|
82
|
+
return str
|
|
83
|
+
.split('')
|
|
84
|
+
.map((c) => (c === c.toUpperCase() ? c.toLowerCase() : c.toUpperCase()))
|
|
85
|
+
.join('');
|
|
93
86
|
}
|
|
94
87
|
export function isStringArray(value) {
|
|
95
88
|
return Array.isArray(value) && value.length > 0 && value.every((e) => typeof e === 'string');
|
package/dist/esm/validator.d.ts
CHANGED
package/dist/esm/validator.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { MIN_NUMBER_OF_NAME_PARTS, MAX_NUMBER_OF_NAME_PARTS } from './constants.js';
|
|
2
|
-
import { InputError, ValidationError } from './error.js';
|
|
3
|
-
import { FirstName, LastName, Name, isNameArray } from './name.js';
|
|
4
1
|
import { Namon } from './types.js';
|
|
5
2
|
import { NameIndex } from './utils.js';
|
|
3
|
+
import { FirstName, LastName, Name, isNameArray } from './name.js';
|
|
4
|
+
import { InputError, ValidationError } from './error.js';
|
|
5
|
+
import { MIN_NUMBER_OF_NAME_PARTS as MIN, MAX_NUMBER_OF_NAME_PARTS as MAX } from './constants.js';
|
|
6
6
|
class ValidationRule {
|
|
7
7
|
static base = /[a-zA-Z\u00C0-\u00D6\u00D8-\u00f6\u00f8-\u00ff\u0400-\u04FFΆ-ωΑ-ώ]/;
|
|
8
8
|
static namon = new RegExp(`^${ValidationRule.base.source}+(([' -]${ValidationRule.base.source})?${ValidationRule.base.source}*)*$`);
|
|
@@ -15,10 +15,10 @@ const toNameSource = (values) => {
|
|
|
15
15
|
};
|
|
16
16
|
class ArrayValidator {
|
|
17
17
|
validate(values) {
|
|
18
|
-
if (values.length === 0 || values.length <
|
|
18
|
+
if (values.length === 0 || values.length < MIN || values.length > MAX) {
|
|
19
19
|
throw new InputError({
|
|
20
20
|
source: values.map((n) => n.toString()),
|
|
21
|
-
message: `expecting a list of ${
|
|
21
|
+
message: `expecting a list of ${MIN}-${MAX} elements`,
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -26,7 +26,7 @@ class ArrayValidator {
|
|
|
26
26
|
class NamonValidator {
|
|
27
27
|
static #validator;
|
|
28
28
|
static create() {
|
|
29
|
-
return this.#validator || (this.#validator = new
|
|
29
|
+
return this.#validator || (this.#validator = new NamonValidator());
|
|
30
30
|
}
|
|
31
31
|
validate(value, type) {
|
|
32
32
|
if (value instanceof Name) {
|
|
@@ -37,22 +37,19 @@ class NamonValidator {
|
|
|
37
37
|
throw new ValidationError({
|
|
38
38
|
source: value,
|
|
39
39
|
nameType: 'namon',
|
|
40
|
-
message: 'invalid content',
|
|
40
|
+
message: 'invalid name content failing namon regex',
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
else {
|
|
45
|
-
throw new InputError({
|
|
46
|
-
source: typeof value,
|
|
47
|
-
message: 'expecting types of string | Name',
|
|
48
|
-
});
|
|
45
|
+
throw new InputError({ source: typeof value, message: 'expecting types of string or Name' });
|
|
49
46
|
}
|
|
50
47
|
}
|
|
51
48
|
}
|
|
52
49
|
class FirstNameValidator {
|
|
53
50
|
static #validator;
|
|
54
51
|
static create() {
|
|
55
|
-
return this.#validator || (this.#validator = new
|
|
52
|
+
return this.#validator || (this.#validator = new FirstNameValidator());
|
|
56
53
|
}
|
|
57
54
|
validate(value) {
|
|
58
55
|
if (value instanceof FirstName) {
|
|
@@ -63,22 +60,19 @@ class FirstNameValidator {
|
|
|
63
60
|
throw new ValidationError({
|
|
64
61
|
source: value,
|
|
65
62
|
nameType: 'firstName',
|
|
66
|
-
message: 'invalid content',
|
|
63
|
+
message: 'invalid name content failing firstName regex',
|
|
67
64
|
});
|
|
68
65
|
}
|
|
69
66
|
}
|
|
70
67
|
else {
|
|
71
|
-
throw new InputError({
|
|
72
|
-
source: typeof value,
|
|
73
|
-
message: 'expecting types string | FirstName',
|
|
74
|
-
});
|
|
68
|
+
throw new InputError({ source: typeof value, message: 'expecting types string or FirstName' });
|
|
75
69
|
}
|
|
76
70
|
}
|
|
77
71
|
}
|
|
78
72
|
class MiddleNameValidator {
|
|
79
73
|
static #validator;
|
|
80
74
|
static create() {
|
|
81
|
-
return this.#validator || (this.#validator = new
|
|
75
|
+
return this.#validator || (this.#validator = new MiddleNameValidator());
|
|
82
76
|
}
|
|
83
77
|
validate(value) {
|
|
84
78
|
if (typeof value === 'string') {
|
|
@@ -86,7 +80,7 @@ class MiddleNameValidator {
|
|
|
86
80
|
throw new ValidationError({
|
|
87
81
|
source: value,
|
|
88
82
|
nameType: 'middleName',
|
|
89
|
-
message: 'invalid content',
|
|
83
|
+
message: 'invalid name content failing middleName regex',
|
|
90
84
|
});
|
|
91
85
|
}
|
|
92
86
|
}
|
|
@@ -107,7 +101,7 @@ class MiddleNameValidator {
|
|
|
107
101
|
else {
|
|
108
102
|
throw new InputError({
|
|
109
103
|
source: typeof value,
|
|
110
|
-
message: 'expecting types of string
|
|
104
|
+
message: 'expecting types of string, string[] or Name[]',
|
|
111
105
|
});
|
|
112
106
|
}
|
|
113
107
|
}
|
|
@@ -115,7 +109,7 @@ class MiddleNameValidator {
|
|
|
115
109
|
class LastNameValidator {
|
|
116
110
|
static #validator;
|
|
117
111
|
static create() {
|
|
118
|
-
return this.#validator || (this.#validator = new
|
|
112
|
+
return this.#validator || (this.#validator = new LastNameValidator());
|
|
119
113
|
}
|
|
120
114
|
validate(value) {
|
|
121
115
|
if (value instanceof LastName) {
|
|
@@ -126,36 +120,33 @@ class LastNameValidator {
|
|
|
126
120
|
throw new ValidationError({
|
|
127
121
|
source: value,
|
|
128
122
|
nameType: 'lastName',
|
|
129
|
-
message: 'invalid content',
|
|
123
|
+
message: 'invalid name content failing lastName regex',
|
|
130
124
|
});
|
|
131
125
|
}
|
|
132
126
|
}
|
|
133
127
|
else {
|
|
134
|
-
throw new InputError({
|
|
135
|
-
source: typeof value,
|
|
136
|
-
message: 'expecting types string | LastName',
|
|
137
|
-
});
|
|
128
|
+
throw new InputError({ source: typeof value, message: 'expecting types string or LastName' });
|
|
138
129
|
}
|
|
139
130
|
}
|
|
140
131
|
}
|
|
141
132
|
class NameValidator {
|
|
142
133
|
static #validator;
|
|
143
134
|
static create() {
|
|
144
|
-
return this.#validator || (this.#validator = new
|
|
135
|
+
return this.#validator || (this.#validator = new NameValidator());
|
|
145
136
|
}
|
|
146
137
|
validate(name, type) {
|
|
147
138
|
if (type && name.type !== type) {
|
|
148
139
|
throw new ValidationError({
|
|
149
140
|
source: name.toString(),
|
|
150
141
|
nameType: name.type.toString(),
|
|
151
|
-
message: 'wrong type',
|
|
142
|
+
message: 'wrong name type; only Namon types are supported',
|
|
152
143
|
});
|
|
153
144
|
}
|
|
154
145
|
if (!ValidationRule.namon.test(name.value)) {
|
|
155
146
|
throw new ValidationError({
|
|
156
147
|
source: name.toString(),
|
|
157
148
|
nameType: name.type.toString(),
|
|
158
|
-
message: 'invalid content',
|
|
149
|
+
message: 'invalid name content failing namon regex',
|
|
159
150
|
});
|
|
160
151
|
}
|
|
161
152
|
}
|
|
@@ -163,7 +154,7 @@ class NameValidator {
|
|
|
163
154
|
export class NamaValidator {
|
|
164
155
|
static #validator;
|
|
165
156
|
static create() {
|
|
166
|
-
return this.#validator || (this.#validator = new
|
|
157
|
+
return this.#validator || (this.#validator = new NamaValidator());
|
|
167
158
|
}
|
|
168
159
|
validate(value) {
|
|
169
160
|
this.validateKeys(value);
|
|
@@ -178,23 +169,17 @@ export class NamaValidator {
|
|
|
178
169
|
if (!nama.size) {
|
|
179
170
|
throw new InputError({ source: undefined, message: 'Map<k,v> must not be empty' });
|
|
180
171
|
}
|
|
181
|
-
else if (nama.size <
|
|
172
|
+
else if (nama.size < MIN || nama.size > MAX) {
|
|
182
173
|
throw new InputError({
|
|
183
174
|
source: [...nama.values()],
|
|
184
|
-
message: `expecting ${
|
|
175
|
+
message: `expecting ${MIN}-${MAX} fields`,
|
|
185
176
|
});
|
|
186
177
|
}
|
|
187
178
|
if (!nama.has(Namon.FIRST_NAME)) {
|
|
188
|
-
throw new InputError({
|
|
189
|
-
source: [...nama.values()],
|
|
190
|
-
message: '"firstName" is a required key',
|
|
191
|
-
});
|
|
179
|
+
throw new InputError({ source: [...nama.values()], message: '"firstName" is a required key' });
|
|
192
180
|
}
|
|
193
181
|
if (!nama.has(Namon.LAST_NAME)) {
|
|
194
|
-
throw new InputError({
|
|
195
|
-
source: [...nama.values()],
|
|
196
|
-
message: '"lastName" is a required key',
|
|
197
|
-
});
|
|
182
|
+
throw new InputError({ source: [...nama.values()], message: '"lastName" is a required key' });
|
|
198
183
|
}
|
|
199
184
|
}
|
|
200
185
|
}
|
|
@@ -222,13 +207,13 @@ export class ArrayStringValidator extends ArrayValidator {
|
|
|
222
207
|
export class ArrayNameValidator {
|
|
223
208
|
static #validator;
|
|
224
209
|
static create() {
|
|
225
|
-
return this.#validator || (this.#validator = new
|
|
210
|
+
return this.#validator || (this.#validator = new ArrayNameValidator());
|
|
226
211
|
}
|
|
227
212
|
validate(value) {
|
|
228
|
-
if (value.length <
|
|
213
|
+
if (value.length < MIN) {
|
|
229
214
|
throw new InputError({
|
|
230
215
|
source: toNameSource(value),
|
|
231
|
-
message: `expecting at least ${
|
|
216
|
+
message: `expecting at least ${MIN} elements`,
|
|
232
217
|
});
|
|
233
218
|
}
|
|
234
219
|
if (!this.#hasBasicNames(value)) {
|
|
@@ -245,7 +230,7 @@ export class ArrayNameValidator {
|
|
|
245
230
|
accumulator[name.type.key] = name.toString();
|
|
246
231
|
}
|
|
247
232
|
}
|
|
248
|
-
return Object.keys(accumulator).length ===
|
|
233
|
+
return Object.keys(accumulator).length === MIN;
|
|
249
234
|
}
|
|
250
235
|
}
|
|
251
236
|
export class Validators {
|