@awsless/validate 0.0.4 → 0.0.5
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/index.cjs +101 -181
- package/dist/index.d.cts +29 -0
- package/dist/index.d.ts +20 -12
- package/dist/index.js +111 -179
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -15,221 +15,141 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
}
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
20
|
|
|
20
21
|
// src/index.ts
|
|
21
22
|
var src_exports = {};
|
|
22
23
|
__export(src_exports, {
|
|
23
|
-
Struct: () => import_superstruct7.Struct,
|
|
24
|
-
StructError: () => import_superstruct7.StructError,
|
|
25
|
-
any: () => import_superstruct7.any,
|
|
26
|
-
array: () => import_superstruct7.array,
|
|
27
|
-
assert: () => import_superstruct7.assert,
|
|
28
|
-
assign: () => import_superstruct7.assign,
|
|
29
24
|
bigfloat: () => bigfloat,
|
|
30
|
-
bigint: () => import_superstruct7.bigint,
|
|
31
|
-
boolean: () => import_superstruct7.boolean,
|
|
32
|
-
coerce: () => import_superstruct7.coerce,
|
|
33
|
-
create: () => import_superstruct7.create,
|
|
34
25
|
date: () => date,
|
|
35
|
-
defaulted: () => import_superstruct7.defaulted,
|
|
36
|
-
define: () => import_superstruct7.define,
|
|
37
|
-
deprecated: () => import_superstruct7.deprecated,
|
|
38
|
-
dynamic: () => import_superstruct7.dynamic,
|
|
39
|
-
empty: () => import_superstruct7.empty,
|
|
40
|
-
enums: () => import_superstruct7.enums,
|
|
41
|
-
func: () => import_superstruct7.func,
|
|
42
|
-
instance: () => import_superstruct7.instance,
|
|
43
|
-
integer: () => import_superstruct7.integer,
|
|
44
|
-
intersection: () => import_superstruct7.intersection,
|
|
45
|
-
is: () => import_superstruct7.is,
|
|
46
26
|
json: () => json,
|
|
47
|
-
lazy: () => import_superstruct7.lazy,
|
|
48
|
-
literal: () => import_superstruct7.literal,
|
|
49
|
-
lowercase: () => lowercase,
|
|
50
|
-
map: () => import_superstruct7.map,
|
|
51
|
-
mask: () => import_superstruct7.mask,
|
|
52
|
-
max: () => import_superstruct7.max,
|
|
53
|
-
min: () => import_superstruct7.min,
|
|
54
|
-
never: () => import_superstruct7.never,
|
|
55
|
-
nonempty: () => import_superstruct7.nonempty,
|
|
56
|
-
nullable: () => import_superstruct7.nullable,
|
|
57
|
-
number: () => import_superstruct7.number,
|
|
58
|
-
object: () => import_superstruct7.object,
|
|
59
|
-
omit: () => import_superstruct7.omit,
|
|
60
|
-
optional: () => import_superstruct7.optional,
|
|
61
|
-
partial: () => import_superstruct7.partial,
|
|
62
|
-
pattern: () => import_superstruct7.pattern,
|
|
63
|
-
pick: () => import_superstruct7.pick,
|
|
64
27
|
positive: () => positive,
|
|
65
28
|
precision: () => precision,
|
|
66
|
-
record: () => import_superstruct7.record,
|
|
67
|
-
refine: () => import_superstruct7.refine,
|
|
68
|
-
regexp: () => import_superstruct7.regexp,
|
|
69
|
-
set: () => import_superstruct7.set,
|
|
70
|
-
size: () => import_superstruct7.size,
|
|
71
|
-
string: () => import_superstruct7.string,
|
|
72
|
-
struct: () => import_superstruct7.struct,
|
|
73
|
-
trimmed: () => import_superstruct7.trimmed,
|
|
74
|
-
tuple: () => import_superstruct7.tuple,
|
|
75
|
-
type: () => import_superstruct7.type,
|
|
76
|
-
union: () => import_superstruct7.union,
|
|
77
29
|
unique: () => unique,
|
|
78
|
-
unknown: () => import_superstruct7.unknown,
|
|
79
|
-
uppercase: () => uppercase,
|
|
80
30
|
uuid: () => uuid
|
|
81
31
|
});
|
|
82
32
|
module.exports = __toCommonJS(src_exports);
|
|
33
|
+
__reExport(src_exports, require("valibot"), module.exports);
|
|
83
34
|
|
|
84
|
-
// src/
|
|
85
|
-
var
|
|
86
|
-
var
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}), (value) => {
|
|
95
|
-
return new import_big_float.BigFloat(value);
|
|
96
|
-
});
|
|
97
|
-
return (0, import_superstruct.coerce)(bigFloatLike, (0, import_superstruct.union)([(0, import_superstruct.string)(), (0, import_superstruct.number)()]), (value) => {
|
|
98
|
-
if (typeof value === "string" && value !== "" || typeof value === "number") {
|
|
99
|
-
if (!isNaN(Number(value))) {
|
|
100
|
-
return new import_big_float.BigFloat(value);
|
|
35
|
+
// src/schema/json.ts
|
|
36
|
+
var import_valibot = require("valibot");
|
|
37
|
+
var json = (schema) => {
|
|
38
|
+
return (0, import_valibot.transform)(
|
|
39
|
+
(0, import_valibot.string)(),
|
|
40
|
+
(value) => {
|
|
41
|
+
try {
|
|
42
|
+
return JSON.parse(value);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
return null;
|
|
101
45
|
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
};
|
|
106
|
-
var positive = (struct2) => {
|
|
107
|
-
const expected = `Expected a positive ${struct2.type}`;
|
|
108
|
-
const ZERO = new import_big_float.BigFloat(0);
|
|
109
|
-
return (0, import_superstruct.refine)(struct2, "positive", (value) => {
|
|
110
|
-
return (0, import_big_float.gt)(value, ZERO) || `${expected} but received '${value}'`;
|
|
111
|
-
});
|
|
112
|
-
};
|
|
113
|
-
var precision = (struct2, decimals) => {
|
|
114
|
-
const expected = `Expected a ${struct2.type}`;
|
|
115
|
-
return (0, import_superstruct.refine)(struct2, "precision", (value) => {
|
|
116
|
-
const big = new import_big_float.BigFloat(value);
|
|
117
|
-
return -big.exponent <= decimals || `${expected} with ${decimals} decimals`;
|
|
118
|
-
});
|
|
46
|
+
},
|
|
47
|
+
schema
|
|
48
|
+
);
|
|
119
49
|
};
|
|
120
50
|
|
|
121
|
-
// src/
|
|
122
|
-
var
|
|
123
|
-
var
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
51
|
+
// src/schema/bigfloat.ts
|
|
52
|
+
var import_big_float = require("@awsless/big-float");
|
|
53
|
+
var import_valibot2 = require("valibot");
|
|
54
|
+
var make = (value) => new import_big_float.BigFloat(value);
|
|
55
|
+
function bigfloat(arg1, arg2) {
|
|
56
|
+
const [msg, pipe] = (0, import_valibot2.getDefaultArgs)(arg1, arg2);
|
|
57
|
+
const error = msg ?? "Invalid bigfloat";
|
|
58
|
+
return (0, import_valibot2.union)(
|
|
59
|
+
[
|
|
60
|
+
(0, import_valibot2.instance)(import_big_float.BigFloat, pipe),
|
|
61
|
+
(0, import_valibot2.transform)(
|
|
62
|
+
(0, import_valibot2.string)([
|
|
63
|
+
(input) => {
|
|
64
|
+
if (input === "" || isNaN(Number(input))) {
|
|
65
|
+
return (0, import_valibot2.getPipeIssues)("bigfloat", error, input);
|
|
66
|
+
}
|
|
67
|
+
return (0, import_valibot2.getOutput)(input);
|
|
68
|
+
}
|
|
69
|
+
]),
|
|
70
|
+
make,
|
|
71
|
+
pipe
|
|
72
|
+
),
|
|
73
|
+
(0, import_valibot2.transform)((0, import_valibot2.number)(), make, pipe),
|
|
74
|
+
(0, import_valibot2.transform)(
|
|
75
|
+
(0, import_valibot2.object)({
|
|
76
|
+
exponent: (0, import_valibot2.number)(),
|
|
77
|
+
coefficient: (0, import_valibot2.bigint)()
|
|
78
|
+
}),
|
|
79
|
+
make,
|
|
80
|
+
pipe
|
|
81
|
+
)
|
|
82
|
+
],
|
|
83
|
+
error
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/schema/date.ts
|
|
88
|
+
var import_valibot3 = require("valibot");
|
|
89
|
+
function date(arg1, arg2) {
|
|
90
|
+
const [error, pipe] = (0, import_valibot3.getDefaultArgs)(arg1, arg2);
|
|
91
|
+
return (0, import_valibot3.union)(
|
|
92
|
+
[
|
|
93
|
+
(0, import_valibot3.date)(pipe),
|
|
94
|
+
(0, import_valibot3.transform)(
|
|
95
|
+
(0, import_valibot3.string)(),
|
|
96
|
+
(input) => {
|
|
97
|
+
return new Date(input);
|
|
98
|
+
},
|
|
99
|
+
(0, import_valibot3.date)(pipe)
|
|
100
|
+
)
|
|
101
|
+
],
|
|
102
|
+
error ?? "Invalid date"
|
|
103
|
+
);
|
|
104
|
+
}
|
|
128
105
|
|
|
129
|
-
// src/
|
|
130
|
-
var
|
|
106
|
+
// src/schema/uuid.ts
|
|
107
|
+
var import_valibot4 = require("valibot");
|
|
131
108
|
var uuid = () => {
|
|
132
|
-
return (0,
|
|
133
|
-
return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(String(value));
|
|
134
|
-
});
|
|
109
|
+
return (0, import_valibot4.transform)((0, import_valibot4.string)([(0, import_valibot4.uuid)()]), (v) => v);
|
|
135
110
|
};
|
|
136
111
|
|
|
137
|
-
// src/
|
|
138
|
-
var
|
|
139
|
-
var
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
};
|
|
112
|
+
// src/validation/positive.ts
|
|
113
|
+
var import_big_float2 = require("@awsless/big-float");
|
|
114
|
+
var import_valibot5 = require("valibot");
|
|
115
|
+
function positive(error) {
|
|
116
|
+
return (input) => {
|
|
117
|
+
return (0, import_big_float2.gt)(input, import_big_float2.ZERO) ? (0, import_valibot5.getOutput)(input) : (0, import_valibot5.getPipeIssues)("positive", error ?? "Invalid positive number", input);
|
|
118
|
+
};
|
|
119
|
+
}
|
|
148
120
|
|
|
149
|
-
// src/
|
|
150
|
-
var
|
|
151
|
-
var
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
};
|
|
121
|
+
// src/validation/precision.ts
|
|
122
|
+
var import_big_float3 = require("@awsless/big-float");
|
|
123
|
+
var import_valibot6 = require("valibot");
|
|
124
|
+
function precision(decimals, error) {
|
|
125
|
+
return (input) => {
|
|
126
|
+
const big = new import_big_float3.BigFloat(input.toString());
|
|
127
|
+
return -big.exponent <= decimals ? (0, import_valibot6.getOutput)(input) : (0, import_valibot6.getPipeIssues)("precision", error ?? `Invalid ${decimals} precision number`, input);
|
|
128
|
+
};
|
|
129
|
+
}
|
|
157
130
|
|
|
158
|
-
// src/
|
|
159
|
-
var
|
|
160
|
-
function unique(
|
|
161
|
-
return (
|
|
162
|
-
for (const x in
|
|
163
|
-
for (const y in
|
|
164
|
-
if (x !== y && compare(
|
|
165
|
-
return
|
|
131
|
+
// src/validation/unique.ts
|
|
132
|
+
var import_valibot7 = require("valibot");
|
|
133
|
+
function unique(compare = (a, b) => a === b, error) {
|
|
134
|
+
return (input) => {
|
|
135
|
+
for (const x in input) {
|
|
136
|
+
for (const y in input) {
|
|
137
|
+
if (x !== y && compare(input[x], input[y])) {
|
|
138
|
+
return (0, import_valibot7.getPipeIssues)("unique", error ?? "None unique array", input);
|
|
166
139
|
}
|
|
167
140
|
}
|
|
168
141
|
}
|
|
169
|
-
return
|
|
170
|
-
}
|
|
142
|
+
return (0, import_valibot7.getOutput)(input);
|
|
143
|
+
};
|
|
171
144
|
}
|
|
172
|
-
|
|
173
|
-
// src/index.ts
|
|
174
|
-
var import_superstruct7 = require("superstruct");
|
|
175
145
|
// Annotate the CommonJS export names for ESM import in node:
|
|
176
146
|
0 && (module.exports = {
|
|
177
|
-
Struct,
|
|
178
|
-
StructError,
|
|
179
|
-
any,
|
|
180
|
-
array,
|
|
181
|
-
assert,
|
|
182
|
-
assign,
|
|
183
147
|
bigfloat,
|
|
184
|
-
bigint,
|
|
185
|
-
boolean,
|
|
186
|
-
coerce,
|
|
187
|
-
create,
|
|
188
148
|
date,
|
|
189
|
-
defaulted,
|
|
190
|
-
define,
|
|
191
|
-
deprecated,
|
|
192
|
-
dynamic,
|
|
193
|
-
empty,
|
|
194
|
-
enums,
|
|
195
|
-
func,
|
|
196
|
-
instance,
|
|
197
|
-
integer,
|
|
198
|
-
intersection,
|
|
199
|
-
is,
|
|
200
149
|
json,
|
|
201
|
-
lazy,
|
|
202
|
-
literal,
|
|
203
|
-
lowercase,
|
|
204
|
-
map,
|
|
205
|
-
mask,
|
|
206
|
-
max,
|
|
207
|
-
min,
|
|
208
|
-
never,
|
|
209
|
-
nonempty,
|
|
210
|
-
nullable,
|
|
211
|
-
number,
|
|
212
|
-
object,
|
|
213
|
-
omit,
|
|
214
|
-
optional,
|
|
215
|
-
partial,
|
|
216
|
-
pattern,
|
|
217
|
-
pick,
|
|
218
150
|
positive,
|
|
219
151
|
precision,
|
|
220
|
-
record,
|
|
221
|
-
refine,
|
|
222
|
-
regexp,
|
|
223
|
-
set,
|
|
224
|
-
size,
|
|
225
|
-
string,
|
|
226
|
-
struct,
|
|
227
|
-
trimmed,
|
|
228
|
-
tuple,
|
|
229
|
-
type,
|
|
230
|
-
union,
|
|
231
152
|
unique,
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
uuid
|
|
153
|
+
uuid,
|
|
154
|
+
...require("valibot")
|
|
235
155
|
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BaseSchema, SchemaWithTransform, StringSchema, Output, Pipe, ErrorMessage, PipeResult } from 'valibot';
|
|
2
|
+
export * from 'valibot';
|
|
3
|
+
import { BigFloat } from '@awsless/big-float';
|
|
4
|
+
import { UUID } from 'crypto';
|
|
5
|
+
|
|
6
|
+
type JsonSchema<T extends BaseSchema> = SchemaWithTransform<StringSchema, Output<T>>;
|
|
7
|
+
declare const json: <T extends BaseSchema<any, any>>(schema: T) => JsonSchema<T>;
|
|
8
|
+
|
|
9
|
+
type BigFloatSchema = BaseSchema<string | number | BigFloat | {
|
|
10
|
+
exponent: number;
|
|
11
|
+
coefficient: bigint;
|
|
12
|
+
}, BigFloat>;
|
|
13
|
+
declare function bigfloat(pipe?: Pipe<BigFloat>): BigFloatSchema;
|
|
14
|
+
declare function bigfloat(error?: ErrorMessage, pipe?: Pipe<BigFloat>): BigFloatSchema;
|
|
15
|
+
|
|
16
|
+
type DateSchema = BaseSchema<string | Date, Date>;
|
|
17
|
+
declare function date(pipe?: Pipe<Date>): DateSchema;
|
|
18
|
+
declare function date(error?: ErrorMessage, pipe?: Pipe<Date>): DateSchema;
|
|
19
|
+
|
|
20
|
+
type UuidSchema = SchemaWithTransform<StringSchema | BaseSchema<UUID>, UUID>;
|
|
21
|
+
declare const uuid: () => UuidSchema;
|
|
22
|
+
|
|
23
|
+
declare function positive<T extends BigFloat | number>(error?: ErrorMessage): (input: T) => PipeResult<T>;
|
|
24
|
+
|
|
25
|
+
declare function precision<T extends BigFloat | number>(decimals: number, error?: ErrorMessage): (input: T) => PipeResult<T>;
|
|
26
|
+
|
|
27
|
+
declare function unique<T extends any[]>(compare?: (a: T[number], b: T[number]) => boolean, error?: ErrorMessage): (input: T) => PipeResult<T>;
|
|
28
|
+
|
|
29
|
+
export { bigfloat, date, json, positive, precision, unique, uuid };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
1
|
+
import { BaseSchema, SchemaWithTransform, StringSchema, Output, Pipe, ErrorMessage, PipeResult } from 'valibot';
|
|
2
|
+
export * from 'valibot';
|
|
3
3
|
import { BigFloat } from '@awsless/big-float';
|
|
4
4
|
import { UUID } from 'crypto';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
declare const
|
|
8
|
-
declare const precision: <T extends number | BigFloat, S extends unknown>(struct: Struct<T, S>, decimals: number) => Struct<T, S>;
|
|
6
|
+
type JsonSchema<T extends BaseSchema> = SchemaWithTransform<StringSchema, Output<T>>;
|
|
7
|
+
declare const json: <T extends BaseSchema<any, any>>(schema: T) => JsonSchema<T>;
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
type BigFloatSchema = BaseSchema<string | number | BigFloat | {
|
|
10
|
+
exponent: number;
|
|
11
|
+
coefficient: bigint;
|
|
12
|
+
}, BigFloat>;
|
|
13
|
+
declare function bigfloat(pipe?: Pipe<BigFloat>): BigFloatSchema;
|
|
14
|
+
declare function bigfloat(error?: ErrorMessage, pipe?: Pipe<BigFloat>): BigFloatSchema;
|
|
11
15
|
|
|
12
|
-
|
|
16
|
+
type DateSchema = BaseSchema<string | Date, Date>;
|
|
17
|
+
declare function date(pipe?: Pipe<Date>): DateSchema;
|
|
18
|
+
declare function date(error?: ErrorMessage, pipe?: Pipe<Date>): DateSchema;
|
|
13
19
|
|
|
14
|
-
|
|
20
|
+
type UuidSchema = SchemaWithTransform<StringSchema | BaseSchema<UUID>, UUID>;
|
|
21
|
+
declare const uuid: () => UuidSchema;
|
|
15
22
|
|
|
16
|
-
declare
|
|
17
|
-
declare const uppercase: <T, S>(struct: Struct<T, S>) => Struct<T, S>;
|
|
23
|
+
declare function positive<T extends BigFloat | number>(error?: ErrorMessage): (input: T) => PipeResult<T>;
|
|
18
24
|
|
|
19
|
-
declare function
|
|
25
|
+
declare function precision<T extends BigFloat | number>(decimals: number, error?: ErrorMessage): (input: T) => PipeResult<T>;
|
|
20
26
|
|
|
21
|
-
|
|
27
|
+
declare function unique<T extends any[]>(compare?: (a: T[number], b: T[number]) => boolean, error?: ErrorMessage): (input: T) => PipeResult<T>;
|
|
28
|
+
|
|
29
|
+
export { bigfloat, date, json, positive, precision, unique, uuid };
|
package/dist/index.js
CHANGED
|
@@ -1,201 +1,133 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return coerce(bigFloatLike, union([string(), number()]), (value) => {
|
|
15
|
-
if (typeof value === "string" && value !== "" || typeof value === "number") {
|
|
16
|
-
if (!isNaN(Number(value))) {
|
|
17
|
-
return new BigFloat(value);
|
|
1
|
+
// src/index.ts
|
|
2
|
+
export * from "valibot";
|
|
3
|
+
|
|
4
|
+
// src/schema/json.ts
|
|
5
|
+
import { string, transform } from "valibot";
|
|
6
|
+
var json = (schema) => {
|
|
7
|
+
return transform(
|
|
8
|
+
string(),
|
|
9
|
+
(value) => {
|
|
10
|
+
try {
|
|
11
|
+
return JSON.parse(value);
|
|
12
|
+
} catch (error) {
|
|
13
|
+
return null;
|
|
18
14
|
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
var positive = (struct2) => {
|
|
24
|
-
const expected = `Expected a positive ${struct2.type}`;
|
|
25
|
-
const ZERO = new BigFloat(0);
|
|
26
|
-
return refine(struct2, "positive", (value) => {
|
|
27
|
-
return gt(value, ZERO) || `${expected} but received '${value}'`;
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
var precision = (struct2, decimals) => {
|
|
31
|
-
const expected = `Expected a ${struct2.type}`;
|
|
32
|
-
return refine(struct2, "precision", (value) => {
|
|
33
|
-
const big = new BigFloat(value);
|
|
34
|
-
return -big.exponent <= decimals || `${expected} with ${decimals} decimals`;
|
|
35
|
-
});
|
|
15
|
+
},
|
|
16
|
+
schema
|
|
17
|
+
);
|
|
36
18
|
};
|
|
37
19
|
|
|
38
|
-
// src/
|
|
39
|
-
import {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
20
|
+
// src/schema/bigfloat.ts
|
|
21
|
+
import { BigFloat } from "@awsless/big-float";
|
|
22
|
+
import {
|
|
23
|
+
bigint,
|
|
24
|
+
getDefaultArgs,
|
|
25
|
+
instance,
|
|
26
|
+
number,
|
|
27
|
+
object,
|
|
28
|
+
string as string2,
|
|
29
|
+
transform as transform2,
|
|
30
|
+
union,
|
|
31
|
+
getPipeIssues,
|
|
32
|
+
getOutput
|
|
33
|
+
} from "valibot";
|
|
34
|
+
var make = (value) => new BigFloat(value);
|
|
35
|
+
function bigfloat(arg1, arg2) {
|
|
36
|
+
const [msg, pipe] = getDefaultArgs(arg1, arg2);
|
|
37
|
+
const error = msg ?? "Invalid bigfloat";
|
|
38
|
+
return union(
|
|
39
|
+
[
|
|
40
|
+
instance(BigFloat, pipe),
|
|
41
|
+
transform2(
|
|
42
|
+
string2([
|
|
43
|
+
(input) => {
|
|
44
|
+
if (input === "" || isNaN(Number(input))) {
|
|
45
|
+
return getPipeIssues("bigfloat", error, input);
|
|
46
|
+
}
|
|
47
|
+
return getOutput(input);
|
|
48
|
+
}
|
|
49
|
+
]),
|
|
50
|
+
make,
|
|
51
|
+
pipe
|
|
52
|
+
),
|
|
53
|
+
transform2(number(), make, pipe),
|
|
54
|
+
transform2(
|
|
55
|
+
object({
|
|
56
|
+
exponent: number(),
|
|
57
|
+
coefficient: bigint()
|
|
58
|
+
}),
|
|
59
|
+
make,
|
|
60
|
+
pipe
|
|
61
|
+
)
|
|
62
|
+
],
|
|
63
|
+
error
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/schema/date.ts
|
|
68
|
+
import { getDefaultArgs as getDefaultArgs2, date as base, string as string3, union as union2, transform as transform3 } from "valibot";
|
|
69
|
+
function date(arg1, arg2) {
|
|
70
|
+
const [error, pipe] = getDefaultArgs2(arg1, arg2);
|
|
71
|
+
return union2(
|
|
72
|
+
[
|
|
73
|
+
base(pipe),
|
|
74
|
+
transform3(
|
|
75
|
+
string3(),
|
|
76
|
+
(input) => {
|
|
77
|
+
return new Date(input);
|
|
78
|
+
},
|
|
79
|
+
base(pipe)
|
|
80
|
+
)
|
|
81
|
+
],
|
|
82
|
+
error ?? "Invalid date"
|
|
83
|
+
);
|
|
84
|
+
}
|
|
45
85
|
|
|
46
|
-
// src/
|
|
47
|
-
import {
|
|
86
|
+
// src/schema/uuid.ts
|
|
87
|
+
import { string as string4, uuid as base2, transform as transform4 } from "valibot";
|
|
48
88
|
var uuid = () => {
|
|
49
|
-
return
|
|
50
|
-
return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(String(value));
|
|
51
|
-
});
|
|
89
|
+
return transform4(string4([base2()]), (v) => v);
|
|
52
90
|
};
|
|
53
91
|
|
|
54
|
-
// src/
|
|
55
|
-
import {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
};
|
|
92
|
+
// src/validation/positive.ts
|
|
93
|
+
import { ZERO, gt } from "@awsless/big-float";
|
|
94
|
+
import { getOutput as getOutput2, getPipeIssues as getPipeIssues2 } from "valibot";
|
|
95
|
+
function positive(error) {
|
|
96
|
+
return (input) => {
|
|
97
|
+
return gt(input, ZERO) ? getOutput2(input) : getPipeIssues2("positive", error ?? "Invalid positive number", input);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
65
100
|
|
|
66
|
-
// src/
|
|
67
|
-
import {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
};
|
|
101
|
+
// src/validation/precision.ts
|
|
102
|
+
import { BigFloat as BigFloat3 } from "@awsless/big-float";
|
|
103
|
+
import { getOutput as getOutput3, getPipeIssues as getPipeIssues3 } from "valibot";
|
|
104
|
+
function precision(decimals, error) {
|
|
105
|
+
return (input) => {
|
|
106
|
+
const big = new BigFloat3(input.toString());
|
|
107
|
+
return -big.exponent <= decimals ? getOutput3(input) : getPipeIssues3("precision", error ?? `Invalid ${decimals} precision number`, input);
|
|
108
|
+
};
|
|
109
|
+
}
|
|
74
110
|
|
|
75
|
-
// src/
|
|
76
|
-
import {
|
|
77
|
-
function unique(
|
|
78
|
-
return
|
|
79
|
-
for (const x in
|
|
80
|
-
for (const y in
|
|
81
|
-
if (x !== y && compare(
|
|
82
|
-
return
|
|
111
|
+
// src/validation/unique.ts
|
|
112
|
+
import { getOutput as getOutput4, getPipeIssues as getPipeIssues4 } from "valibot";
|
|
113
|
+
function unique(compare = (a, b) => a === b, error) {
|
|
114
|
+
return (input) => {
|
|
115
|
+
for (const x in input) {
|
|
116
|
+
for (const y in input) {
|
|
117
|
+
if (x !== y && compare(input[x], input[y])) {
|
|
118
|
+
return getPipeIssues4("unique", error ?? "None unique array", input);
|
|
83
119
|
}
|
|
84
120
|
}
|
|
85
121
|
}
|
|
86
|
-
return
|
|
87
|
-
}
|
|
122
|
+
return getOutput4(input);
|
|
123
|
+
};
|
|
88
124
|
}
|
|
89
|
-
|
|
90
|
-
// src/index.ts
|
|
91
|
-
import {
|
|
92
|
-
coerce as coerce5,
|
|
93
|
-
defaulted,
|
|
94
|
-
trimmed,
|
|
95
|
-
empty,
|
|
96
|
-
max,
|
|
97
|
-
min,
|
|
98
|
-
nonempty,
|
|
99
|
-
pattern,
|
|
100
|
-
size,
|
|
101
|
-
refine as refine3,
|
|
102
|
-
any,
|
|
103
|
-
array,
|
|
104
|
-
bigint as bigint2,
|
|
105
|
-
boolean,
|
|
106
|
-
enums,
|
|
107
|
-
func,
|
|
108
|
-
instance,
|
|
109
|
-
integer,
|
|
110
|
-
intersection,
|
|
111
|
-
literal,
|
|
112
|
-
map,
|
|
113
|
-
never,
|
|
114
|
-
nullable,
|
|
115
|
-
number as number2,
|
|
116
|
-
object as object2,
|
|
117
|
-
optional,
|
|
118
|
-
record,
|
|
119
|
-
regexp,
|
|
120
|
-
set,
|
|
121
|
-
string as string5,
|
|
122
|
-
tuple,
|
|
123
|
-
type,
|
|
124
|
-
union as union2,
|
|
125
|
-
unknown,
|
|
126
|
-
assign,
|
|
127
|
-
define as define3,
|
|
128
|
-
deprecated,
|
|
129
|
-
dynamic,
|
|
130
|
-
lazy,
|
|
131
|
-
omit,
|
|
132
|
-
partial,
|
|
133
|
-
pick,
|
|
134
|
-
struct,
|
|
135
|
-
assert,
|
|
136
|
-
create,
|
|
137
|
-
mask,
|
|
138
|
-
is,
|
|
139
|
-
Struct as Struct7,
|
|
140
|
-
StructError
|
|
141
|
-
} from "superstruct";
|
|
142
125
|
export {
|
|
143
|
-
Struct7 as Struct,
|
|
144
|
-
StructError,
|
|
145
|
-
any,
|
|
146
|
-
array,
|
|
147
|
-
assert,
|
|
148
|
-
assign,
|
|
149
126
|
bigfloat,
|
|
150
|
-
bigint2 as bigint,
|
|
151
|
-
boolean,
|
|
152
|
-
coerce5 as coerce,
|
|
153
|
-
create,
|
|
154
127
|
date,
|
|
155
|
-
defaulted,
|
|
156
|
-
define3 as define,
|
|
157
|
-
deprecated,
|
|
158
|
-
dynamic,
|
|
159
|
-
empty,
|
|
160
|
-
enums,
|
|
161
|
-
func,
|
|
162
|
-
instance,
|
|
163
|
-
integer,
|
|
164
|
-
intersection,
|
|
165
|
-
is,
|
|
166
128
|
json,
|
|
167
|
-
lazy,
|
|
168
|
-
literal,
|
|
169
|
-
lowercase,
|
|
170
|
-
map,
|
|
171
|
-
mask,
|
|
172
|
-
max,
|
|
173
|
-
min,
|
|
174
|
-
never,
|
|
175
|
-
nonempty,
|
|
176
|
-
nullable,
|
|
177
|
-
number2 as number,
|
|
178
|
-
object2 as object,
|
|
179
|
-
omit,
|
|
180
|
-
optional,
|
|
181
|
-
partial,
|
|
182
|
-
pattern,
|
|
183
|
-
pick,
|
|
184
129
|
positive,
|
|
185
130
|
precision,
|
|
186
|
-
record,
|
|
187
|
-
refine3 as refine,
|
|
188
|
-
regexp,
|
|
189
|
-
set,
|
|
190
|
-
size,
|
|
191
|
-
string5 as string,
|
|
192
|
-
struct,
|
|
193
|
-
trimmed,
|
|
194
|
-
tuple,
|
|
195
|
-
type,
|
|
196
|
-
union2 as union,
|
|
197
131
|
unique,
|
|
198
|
-
unknown,
|
|
199
|
-
uppercase,
|
|
200
132
|
uuid
|
|
201
133
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@awsless/validate",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@awsless/big-float": "^0.0.
|
|
27
|
+
"@awsless/big-float": "^0.0.4"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@awsless/big-float": "^0.0.
|
|
30
|
+
"@awsless/big-float": "^0.0.4"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"
|
|
33
|
+
"valibot": "^0.20.1"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"test": "pnpm code test",
|