@fgv/ts-utils 5.0.0-21 → 5.0.0-23

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.
Files changed (80) hide show
  1. package/dist/ts-utils.d.ts +307 -33
  2. package/lib/index.d.ts +2 -1
  3. package/lib/index.js +3 -1
  4. package/lib/packlets/base/index.d.ts +0 -2
  5. package/lib/packlets/base/index.js +1 -25
  6. package/lib/packlets/base/result.d.ts +49 -0
  7. package/lib/packlets/base/result.js +36 -0
  8. package/lib/packlets/collections/collector.d.ts +9 -0
  9. package/lib/packlets/collections/collector.js +6 -0
  10. package/lib/packlets/collections/validatingCollector.d.ts +5 -1
  11. package/lib/packlets/hash/hashingNormalizer.js +4 -3
  12. package/lib/packlets/logging/index.d.ts +3 -0
  13. package/{src/packlets/hash/index.ts → lib/packlets/logging/index.js} +19 -3
  14. package/lib/packlets/logging/logReporter.d.ts +69 -0
  15. package/lib/packlets/logging/logReporter.js +72 -0
  16. package/lib/packlets/logging/logger.d.ts +183 -0
  17. package/lib/packlets/logging/logger.js +237 -0
  18. package/lib/test/unit/consoleLogger.test.d.ts +2 -0
  19. package/lib/test/unit/hashingNormalizerCollisions.test.d.ts +2 -0
  20. package/package.json +1 -1
  21. package/lib/packlets/base/logger.d.ts +0 -52
  22. package/lib/packlets/base/logger.js +0 -128
  23. package/src/index.ts +0 -63
  24. package/src/packlets/base/brand.ts +0 -28
  25. package/src/packlets/base/index.ts +0 -31
  26. package/src/packlets/base/logger.ts +0 -156
  27. package/src/packlets/base/mapResults.ts +0 -302
  28. package/src/packlets/base/messageAggregator.ts +0 -120
  29. package/src/packlets/base/normalize.ts +0 -144
  30. package/src/packlets/base/result.ts +0 -961
  31. package/src/packlets/base/utils.ts +0 -236
  32. package/src/packlets/collections/collectible.ts +0 -238
  33. package/src/packlets/collections/collector.ts +0 -273
  34. package/src/packlets/collections/collectorValidator.ts +0 -178
  35. package/src/packlets/collections/common.ts +0 -27
  36. package/src/packlets/collections/convertingCollector.ts +0 -223
  37. package/src/packlets/collections/convertingCollectorValidator.ts +0 -164
  38. package/src/packlets/collections/index.ts +0 -39
  39. package/src/packlets/collections/keyValueConverters.ts +0 -142
  40. package/src/packlets/collections/readonlyResultMap.ts +0 -99
  41. package/src/packlets/collections/resultMap.ts +0 -322
  42. package/src/packlets/collections/resultMapValidator.ts +0 -188
  43. package/src/packlets/collections/utils.ts +0 -33
  44. package/src/packlets/collections/validatingCollector.ts +0 -123
  45. package/src/packlets/collections/validatingConvertingCollector.ts +0 -113
  46. package/src/packlets/collections/validatingResultMap.ts +0 -94
  47. package/src/packlets/conversion/baseConverter.ts +0 -330
  48. package/src/packlets/conversion/converter.ts +0 -260
  49. package/src/packlets/conversion/converters.ts +0 -1039
  50. package/src/packlets/conversion/defaultingConverter.ts +0 -188
  51. package/src/packlets/conversion/index.ts +0 -30
  52. package/src/packlets/conversion/objectConverter.ts +0 -259
  53. package/src/packlets/conversion/stringConverter.ts +0 -165
  54. package/src/packlets/file-tree/directoryItem.ts +0 -84
  55. package/src/packlets/file-tree/fileItem.ts +0 -119
  56. package/src/packlets/file-tree/fileTree.ts +0 -152
  57. package/src/packlets/file-tree/fileTreeAccessors.ts +0 -176
  58. package/src/packlets/file-tree/fsTree.ts +0 -118
  59. package/src/packlets/file-tree/in-memory/inMemoryTree.ts +0 -171
  60. package/src/packlets/file-tree/in-memory/index.ts +0 -23
  61. package/src/packlets/file-tree/in-memory/treeBuilder.ts +0 -203
  62. package/src/packlets/file-tree/index.ts +0 -31
  63. package/src/packlets/hash/crcNormalizer.ts +0 -81
  64. package/src/packlets/hash/hashingNormalizer.ts +0 -102
  65. package/src/packlets/validation/array.ts +0 -84
  66. package/src/packlets/validation/boolean.ts +0 -63
  67. package/src/packlets/validation/classes.ts +0 -38
  68. package/src/packlets/validation/common.ts +0 -28
  69. package/src/packlets/validation/field.ts +0 -99
  70. package/src/packlets/validation/genericValidator.ts +0 -204
  71. package/src/packlets/validation/index.ts +0 -31
  72. package/src/packlets/validation/number.ts +0 -66
  73. package/src/packlets/validation/object.ts +0 -208
  74. package/src/packlets/validation/oneOf.ts +0 -78
  75. package/src/packlets/validation/string.ts +0 -66
  76. package/src/packlets/validation/traits.ts +0 -113
  77. package/src/packlets/validation/typeGuard.ts +0 -83
  78. package/src/packlets/validation/validator.ts +0 -157
  79. package/src/packlets/validation/validatorBase.ts +0 -66
  80. package/src/packlets/validation/validators.ts +0 -254
@@ -1,63 +0,0 @@
1
- /*
2
- * Copyright (c) 2021 Erik Fortune
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in all
12
- * copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
- import { Failure, fail } from '../base';
24
- import { GenericValidator, GenericValidatorConstructorParams } from './genericValidator';
25
-
26
- /**
27
- * Parameters used to construct a {@link Validation.Classes.BooleanValidator | BooleanValidator}.
28
- * @public
29
- */
30
- export type BooleanValidatorConstructorParams<TC = unknown> = GenericValidatorConstructorParams<boolean, TC>;
31
-
32
- /**
33
- * An in-place {@link Validation.Validator | Validator} for `boolean` values.
34
- * @public
35
- */
36
- export class BooleanValidator<TC = unknown> extends GenericValidator<boolean, TC> {
37
- /**
38
- * Constructs a new {@link Validation.Classes.BooleanValidator | BooleanValidator}.
39
- * @param params - Optional {@link Validation.Classes.BooleanValidatorConstructorParams | init params} for the
40
- * new {@link Validation.Classes.BooleanValidator | BooleanValidator}.
41
- */
42
- public constructor(params?: BooleanValidatorConstructorParams<TC>) {
43
- /* c8 ignore next */
44
- params = params ?? {};
45
- super({
46
- validator: BooleanValidator.validateBoolean,
47
- ...params
48
- });
49
- }
50
-
51
- /**
52
- * Static method which validates that a supplied `unknown` value is a `boolean`.
53
- * @param from - The `unknown` value to be tested.
54
- * @returns Returns `true` if `from` is a `boolean`, or {@link Failure} with an error
55
- * message if not.
56
- */
57
- public static validateBoolean(from: unknown): boolean | Failure<boolean> {
58
- if (typeof from === 'boolean') {
59
- return true;
60
- }
61
- return fail(`"${from}": not a boolean`);
62
- }
63
- }
@@ -1,38 +0,0 @@
1
- /*
2
- * Copyright (c) 2021 Erik Fortune
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in all
12
- * copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
- /* c8 ignore start */
24
-
25
- export { ArrayValidator, ArrayValidatorConstructorParams } from './array';
26
- export { BooleanValidator, BooleanValidatorConstructorParams } from './boolean';
27
- export { NumberValidator, NumberValidatorConstructorParams } from './number';
28
- export {
29
- FieldValidators,
30
- ObjectValidator,
31
- ObjectValidatorConstructorParams,
32
- ObjectValidatorOptions
33
- } from './object';
34
- export { OneOfValidator, OneOfValidatorConstructorParams } from './oneOf';
35
- export { StringValidator, StringValidatorConstructorParams } from './string';
36
- export { TypeGuardValidator, TypeGuardValidatorConstructorParams } from './typeGuard';
37
-
38
- /* c8 ignore stop */
@@ -1,28 +0,0 @@
1
- /*
2
- * Copyright (c) 2022 Erik Fortune
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in all
12
- * copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
- /**
24
- * A type guard function which validates a specific type, with an optional context
25
- * that can be used to shape the validation.
26
- * @public
27
- */
28
- export type TypeGuardWithContext<T, TC = unknown> = (from: unknown, context?: TC) => from is T;
@@ -1,99 +0,0 @@
1
- /*
2
- * Copyright (c) 2020 Erik Fortune
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in all
12
- * copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
- import { Failure, fail, isKeyOf } from '../base';
24
- import { Validator, ValidatorOptions } from './validator';
25
- import { ValidatorBase } from './validatorBase';
26
-
27
- /**
28
- * Parameters used to construct a {@link Validation.FieldValidator | FieldValidator}.
29
- * @public
30
- */
31
- // eslint-disable-next-line @typescript-eslint/naming-convention
32
- export interface FieldValidatorOptions<TC> extends ValidatorOptions<TC> {
33
- optional?: boolean;
34
- }
35
-
36
- /**
37
- * An in-place {@link Validation.Validator | Validator} for properties
38
- * an an object.
39
- * @public
40
- */
41
- export class FieldValidator<T, TC = unknown> extends ValidatorBase<T, TC> {
42
- /**
43
- * The name of the property that this validator should validate.
44
- */
45
- public readonly fieldName: string;
46
- /**
47
- * The {@link Validation.Validator | Validator} to be applied against the named property.
48
- */
49
- public readonly fieldValidator: Validator<T, TC>;
50
- /**
51
- * @internal
52
- */
53
- protected readonly _fieldOptions: FieldValidatorOptions<TC>;
54
-
55
- /**
56
- * Constructs a new {@link Validation.FieldValidator | FieldValidator.}.
57
- * @param fieldName - The name of the property that this validator should validate.
58
- * @param fieldValidator - The {@link Validation.Validator | Validator} to be applied
59
- * against the named property.
60
- * @param options - Additional {@link Validation.FieldValidatorOptions | options} to be
61
- * applied to this validation.
62
- */
63
- public constructor(
64
- fieldName: string,
65
- fieldValidator: Validator<T, TC>,
66
- options?: FieldValidatorOptions<TC>
67
- ) {
68
- super({ options });
69
- this.fieldName = fieldName;
70
- this.fieldValidator = fieldValidator;
71
- /* c8 ignore next */
72
- this._fieldOptions = options ?? {};
73
- }
74
-
75
- /**
76
- * {@inheritdoc Validation.ValidatorBase._validate}
77
- */
78
- protected _validate(from: unknown, context?: TC, self?: Validator<T, TC>): boolean | Failure<T> {
79
- if (typeof from === 'object' && !Array.isArray(from) && from !== null) {
80
- const optional = this._fieldOptions.optional === true;
81
-
82
- if (isKeyOf(this.fieldName, from)) {
83
- if (!optional || from[this.fieldName] !== undefined) {
84
- const result = this.fieldValidator
85
- .validate(from[this.fieldName], context)
86
- .onFailure((message: string) => {
87
- return fail(`${this.fieldName}: ${message}`);
88
- });
89
-
90
- return result.success ? true : result;
91
- }
92
- }
93
-
94
- return optional ? true : fail(`"${this.fieldName}": Field not found in "${JSON.stringify(from)}`);
95
- }
96
- /* c8 ignore next 2 -- defense in depth */
97
- return fail(`Cannot validate field '${this.fieldName}' from non-object "${JSON.stringify(from)}"`);
98
- }
99
- }
@@ -1,204 +0,0 @@
1
- /*
2
- * Copyright (c) 2021 Erik Fortune
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in all
12
- * copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
- import { Brand, Failure, Result, fail, succeed } from '../base';
24
- import { ConstraintTrait, ValidatorTraits } from './traits';
25
- import {
26
- Constraint,
27
- ValidationErrorFormatter,
28
- Validator,
29
- ValidatorFunc,
30
- ValidatorOptions
31
- } from './validator';
32
-
33
- /**
34
- * Options used to initialize a {@link Validation.Base.GenericValidator | GenericValidator}.
35
- * @public
36
- */
37
- // eslint-disable-next-line @typescript-eslint/naming-convention
38
- export interface GenericValidatorConstructorParams<T, TC> {
39
- options?: ValidatorOptions<TC>;
40
- traits?: Partial<ValidatorTraits>;
41
- validator?: ValidatorFunc<T, TC>;
42
- }
43
-
44
- /**
45
- * Generic base implementation for an in-place {@link Validation.Validator | Validator}.
46
- * @public
47
- */
48
- export class GenericValidator<T, TC = unknown> implements Validator<T, TC> {
49
- /**
50
- * {@inheritdoc Validation.Validator.traits}
51
- */
52
- public readonly traits: ValidatorTraits;
53
-
54
- /**
55
- * @internal
56
- */
57
- protected readonly _validator: ValidatorFunc<T, TC>;
58
- /**
59
- * @internal
60
- */
61
- protected readonly _options: ValidatorOptions<TC>;
62
-
63
- /**
64
- * Constructs a new {@link Validation.Base.GenericValidator | GenericValidator<T>}.
65
- * @param params - The {@link Validation.Base.GenericValidatorConstructorParams | constructor params}
66
- * used to configure validation.
67
- */
68
- public constructor(params: Partial<GenericValidatorConstructorParams<T, TC>>) {
69
- if (!params.validator) {
70
- throw new Error('No validator function supplied');
71
- }
72
- this._validator = params.validator;
73
- this._options = params.options ?? {};
74
- this.traits = new ValidatorTraits(params.traits);
75
- }
76
-
77
- /**
78
- * {@inheritdoc Validation.Validator.isOptional}
79
- */
80
- public get isOptional(): boolean {
81
- return this.traits.isOptional;
82
- }
83
-
84
- /**
85
- * {@inheritdoc Validation.Validator.brand}
86
- */
87
- public get brand(): string | undefined {
88
- return this.traits.brand;
89
- }
90
-
91
- /**
92
- * {@inheritdoc Validation.Validator.validate}
93
- */
94
- public validate(from: unknown, context?: TC): Result<T> {
95
- const result = this._validator(from, this._context(context), this);
96
- if (typeof result === 'boolean') {
97
- return result ? succeed(from as T) : fail<T>('Invalid value');
98
- }
99
- return result;
100
- }
101
-
102
- /**
103
- * {@inheritdoc Validation.Validator.convert}
104
- */
105
- public convert(from: unknown, context?: TC): Result<T> {
106
- const result = this._validator(from, this._context(context), this);
107
- if (typeof result === 'boolean') {
108
- return result ? succeed(from as T) : fail<T>('Invalid value');
109
- }
110
- return result;
111
- }
112
-
113
- /**
114
- * {@inheritdoc Validation.Validator.validateOptional}
115
- */
116
- public validateOptional(from: unknown, context?: TC): Result<T | undefined> {
117
- return from === undefined ? succeed(undefined) : this.validate(from, context);
118
- }
119
-
120
- /**
121
- * {@inheritdoc Validation.Validator.guard}
122
- */
123
- public guard(from: unknown, context?: TC): from is T {
124
- return this._validator(from, this._context(context), this) === true;
125
- }
126
-
127
- /**
128
- * {@inheritdoc Validation.Validator.optional}
129
- */
130
- public optional(): Validator<T | undefined, TC> {
131
- return new GenericValidator({
132
- validator: (from: unknown, context?: TC, self?: Validator<T | undefined, TC>) => {
133
- return from === undefined || this._validator(from, this._context(context), this);
134
- },
135
- traits: { isOptional: true }
136
- });
137
- }
138
-
139
- /**
140
- * {@inheritdoc Validation.Validator.withConstraint}
141
- */
142
- public withConstraint(constraint: Constraint<T>, trait?: ConstraintTrait): Validator<T, TC> {
143
- trait = trait ?? { type: 'function' };
144
- return new GenericValidator({
145
- validator: (from: unknown, context?: TC, self?: Validator<T, TC>): boolean | Failure<T> => {
146
- const result = this._validator(from, this._context(context), this);
147
- if (result === true) {
148
- const constraintResult = constraint(from as T);
149
- if (typeof constraintResult === 'boolean') {
150
- return constraintResult
151
- ? true
152
- : fail(`Invalid value "${JSON.stringify(from)}": does not meet constraint.`);
153
- }
154
- return constraintResult;
155
- }
156
- return result;
157
- },
158
- traits: { constraints: [trait] }
159
- });
160
- }
161
-
162
- /**
163
- * {@inheritdoc Validation.Validator.brand}
164
- */
165
- public withBrand<B extends string>(brand: B): Validator<Brand<T, B>, TC> {
166
- if (this.brand) {
167
- throw new Error(`Cannot replace existing brand "${this.brand}" with "${brand}".`);
168
- }
169
-
170
- return new GenericValidator<Brand<T, B>, TC>({
171
- validator: (from: unknown, context?: TC, self?: Validator<Brand<T, B>, TC>) => {
172
- return this._validator(from, this._context(context), this) as boolean | Failure<Brand<T, B>>;
173
- },
174
- traits: { brand }
175
- });
176
- }
177
-
178
- /**
179
- * {@inheritdoc Validation.Validator.withFormattedError}
180
- */
181
- public withFormattedError(formatter: ValidationErrorFormatter<TC>): Validator<T, TC> {
182
- return new GenericValidator<T, TC>({
183
- validator: (from: unknown, context?: TC, self?: Validator<T, TC>) => {
184
- const result = this._validator(from, this._context(context), this);
185
- if (result === true) {
186
- return true;
187
- }
188
- /* c8 ignore next - defense in depth */
189
- const message = result === false ? undefined : result.message;
190
- return fail(formatter(from, message, this._context(context)));
191
- }
192
- });
193
- }
194
-
195
- /**
196
- * Gets a default or explicit context.
197
- * @param explicitContext - Optional explicit context.
198
- * @returns The appropriate context to use.
199
- * @internal
200
- */
201
- protected _context(explicitContext?: TC): TC | undefined {
202
- return explicitContext ?? this._options.defaultContext;
203
- }
204
- }
@@ -1,31 +0,0 @@
1
- /*
2
- * Copyright (c) 2021 Erik Fortune
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in all
12
- * copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
- export * from './common';
24
- export * from './traits';
25
- export * from './validator';
26
-
27
- import * as Classes from './classes';
28
- import * as Base from './genericValidator';
29
- import * as Validators from './validators';
30
-
31
- export { Base, Classes, Validators };
@@ -1,66 +0,0 @@
1
- /*
2
- * Copyright (c) 2021 Erik Fortune
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in all
12
- * copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
- import { Failure, fail } from '../base';
24
- import { GenericValidator, GenericValidatorConstructorParams } from './genericValidator';
25
-
26
- /**
27
- * Parameters used to construct a {@link Validation.Classes.NumberValidator | NumberValidator}.
28
- * @public
29
- */
30
- export type NumberValidatorConstructorParams<
31
- T extends number = number,
32
- TC = unknown
33
- > = GenericValidatorConstructorParams<T, TC>;
34
-
35
- /**
36
- * An in-place {@link Validation.Validator | Validator} for `number` values.
37
- * @public
38
- */
39
- export class NumberValidator<T extends number = number, TC = unknown> extends GenericValidator<T, TC> {
40
- /**
41
- * Constructs a new {@link Validation.Classes.NumberValidator | NumberValidator}.
42
- * @param params - Optional {@link Validation.Classes.NumberValidatorConstructorParams | init params} for the
43
- * new {@link Validation.Classes.NumberValidator | NumberValidator}.
44
- */
45
- public constructor(params?: NumberValidatorConstructorParams<T, TC>) {
46
- /* c8 ignore next 1 */
47
- params = params ?? {};
48
- super({
49
- validator: NumberValidator.validateNumber,
50
- ...params
51
- });
52
- }
53
-
54
- /**
55
- * Static method which validates that a supplied `unknown` value is a `number`.
56
- * @param from - The `unknown` value to be tested.
57
- * @returns Returns `true` if `from` is a `number`, or {@link Failure} with an error
58
- * message if not.
59
- */
60
- public static validateNumber<T extends number>(from: unknown): boolean | Failure<T> {
61
- if (typeof from === 'number') {
62
- return true;
63
- }
64
- return fail<T>(`"${from}": not a number`);
65
- }
66
- }