deno fmt
This commit is contained in:
@@ -102,39 +102,37 @@ Deno.test("validate schema (no match)", async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Deno.test("validate doConversion (match)", async () => {
|
Deno.test("validate doConversion (match)", async () => {
|
||||||
const values: [any, Validatable, any][] = [
|
const values: [any, Validatable, any][] = [
|
||||||
[
|
[
|
||||||
1,
|
1,
|
||||||
isNumber(),
|
isNumber(),
|
||||||
1
|
1,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"2",
|
"2",
|
||||||
isNumber(),
|
isNumber(),
|
||||||
2
|
2,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"03",
|
"03",
|
||||||
isNumber(),
|
isNumber(),
|
||||||
3
|
3,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
{ foo: 3, bar: { baz: "4", other: "val" } },
|
{ foo: 3, bar: { baz: "4", other: "val" } },
|
||||||
{ foo: isNumber(), bar: { baz: isNumber() } },
|
{ foo: isNumber(), bar: { baz: isNumber() } },
|
||||||
{ foo: 3, bar: { baz: 4 } }
|
{ foo: 3, bar: { baz: 4 } },
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
for (const [value, constraints, conv] of values) {
|
for (const [value, constraints, conv] of values) {
|
||||||
const valueBefore = JSON.stringify(value);
|
const valueBefore = JSON.stringify(value);
|
||||||
const converted: any = {};
|
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);
|
const valueAfter = JSON.stringify(value);
|
||||||
assertEquals(valueAfter, valueBefore);
|
assertEquals(valueAfter, valueBefore);
|
||||||
assertEquals(converted.hasOwnProperty("output"), true);
|
assertEquals(converted.hasOwnProperty("output"), true);
|
||||||
@@ -156,7 +154,11 @@ Deno.test("validate doConversion (no match)", async () => {
|
|||||||
for (const [value, constraints] of values) {
|
for (const [value, constraints] of values) {
|
||||||
const valueBefore = JSON.stringify(value);
|
const valueBefore = JSON.stringify(value);
|
||||||
const converted: any = {};
|
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);
|
const valueAfter = JSON.stringify(value);
|
||||||
assertEquals(valueAfter, valueBefore);
|
assertEquals(valueAfter, valueBefore);
|
||||||
assertEquals(converted.hasOwnProperty("output"), true);
|
assertEquals(converted.hasOwnProperty("output"), true);
|
||||||
|
|||||||
14
mod.ts
14
mod.ts
@@ -6,8 +6,18 @@ export {
|
|||||||
Validatable,
|
Validatable,
|
||||||
ArraySymbol,
|
ArraySymbol,
|
||||||
} from "./Validator.ts";
|
} from "./Validator.ts";
|
||||||
export { isString, isUrl, isEmail, fulfillsRegex } from "./validators/string.ts";
|
export {
|
||||||
export { isNumber, isInteger, isInRange, hasParity } from "./validators/number.ts";
|
isString,
|
||||||
|
isUrl,
|
||||||
|
isEmail,
|
||||||
|
fulfillsRegex,
|
||||||
|
} from "./validators/string.ts";
|
||||||
|
export {
|
||||||
|
isNumber,
|
||||||
|
isInteger,
|
||||||
|
isInRange,
|
||||||
|
hasParity,
|
||||||
|
} from "./validators/number.ts";
|
||||||
export { isArray } from "./validators/array.ts";
|
export { isArray } from "./validators/array.ts";
|
||||||
export { or } from "./validators/logic.ts";
|
export { or } from "./validators/logic.ts";
|
||||||
export { isRequired, isDefined, isNotEmpty } from "./validators/empty.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