deno fmt
This commit is contained in:
@@ -102,39 +102,37 @@ Deno.test("validate schema (no match)", async () => {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Deno.test("validate doConversion (match)", async () => {
|
||||
const values: [any, Validatable, any][] = [
|
||||
[
|
||||
1,
|
||||
isNumber(),
|
||||
1
|
||||
1,
|
||||
],
|
||||
[
|
||||
"2",
|
||||
isNumber(),
|
||||
2
|
||||
2,
|
||||
],
|
||||
[
|
||||
"03",
|
||||
isNumber(),
|
||||
3
|
||||
3,
|
||||
],
|
||||
[
|
||||
{ foo: 3, bar: { baz: "4", other: "val" } },
|
||||
{ foo: isNumber(), bar: { baz: isNumber() } },
|
||||
{ foo: 3, bar: { baz: 4 } }
|
||||
{ foo: 3, bar: { baz: 4 } },
|
||||
],
|
||||
];
|
||||
for (const [value, constraints, conv] of values) {
|
||||
const valueBefore = JSON.stringify(value);
|
||||
const converted: any = {};
|
||||
assertEquals(await validate(value, constraints, {doConversion: true, converted}), [], String(value));
|
||||
assertEquals(
|
||||
await validate(value, constraints, { doConversion: true, converted }),
|
||||
[],
|
||||
String(value),
|
||||
);
|
||||
const valueAfter = JSON.stringify(value);
|
||||
assertEquals(valueAfter, valueBefore);
|
||||
assertEquals(converted.hasOwnProperty("output"), true);
|
||||
@@ -156,10 +154,14 @@ Deno.test("validate doConversion (no match)", async () => {
|
||||
for (const [value, constraints] of values) {
|
||||
const valueBefore = JSON.stringify(value);
|
||||
const converted: any = {};
|
||||
assertNotEquals(await validate(value, constraints, {doConversion: true, converted}), [], String(value));
|
||||
assertNotEquals(
|
||||
await validate(value, constraints, { doConversion: true, converted }),
|
||||
[],
|
||||
String(value),
|
||||
);
|
||||
const valueAfter = JSON.stringify(value);
|
||||
assertEquals(valueAfter, valueBefore);
|
||||
assertEquals(converted.hasOwnProperty("output"), true);
|
||||
assertEquals(converted?.output, value);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
14
mod.ts
14
mod.ts
@@ -6,8 +6,18 @@ export {
|
||||
Validatable,
|
||||
ArraySymbol,
|
||||
} from "./Validator.ts";
|
||||
export { isString, isUrl, isEmail, fulfillsRegex } from "./validators/string.ts";
|
||||
export { isNumber, isInteger, isInRange, hasParity } from "./validators/number.ts";
|
||||
export {
|
||||
isString,
|
||||
isUrl,
|
||||
isEmail,
|
||||
fulfillsRegex,
|
||||
} from "./validators/string.ts";
|
||||
export {
|
||||
isNumber,
|
||||
isInteger,
|
||||
isInRange,
|
||||
hasParity,
|
||||
} from "./validators/number.ts";
|
||||
export { isArray } from "./validators/array.ts";
|
||||
export { or } from "./validators/logic.ts";
|
||||
export { isRequired, isDefined, isNotEmpty } from "./validators/empty.ts";
|
||||
|
||||
11
t.ts
11
t.ts
@@ -1,11 +0,0 @@
|
||||
import {
|
||||
ValidationError, validate,
|
||||
isBoolean
|
||||
} from "./mod.ts";
|
||||
|
||||
const converted: any = {};
|
||||
const errors: ValidationError[] = await validate("foobar", isBoolean(), { doConversion: true, converted });
|
||||
console.log(errors);
|
||||
// [ { type: "isBoolean", args: {}, message: "This value has to be a boolean." } ]
|
||||
console.log(converted);
|
||||
// { output: "foobar" }
|
||||
Reference in New Issue
Block a user