-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #459 from shimataro/develop
version 3.0.0-rc.4
- Loading branch information
Showing
9 changed files
with
3,592 additions
and
1,444 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import * as assert from "https://deno.land/std/testing/asserts.ts"; | ||
import vs from "../mod.ts"; | ||
|
||
const schemaObject: vs.SchemaObject = { // schema for input | ||
id: vs.number({ // number, >=1 | ||
minValue: 1, | ||
}), | ||
name: vs.string({ // string, max 16 characters (trims if over) | ||
maxLength: { | ||
length: 16, | ||
trims: true, | ||
}, | ||
}), | ||
age: vs.number({ // number, integer (trims if decimal), >=0 | ||
integer: vs.NUMBER.INTEGER.FLOOR_RZ, | ||
minValue: 0, | ||
}), | ||
email: vs.email(), // email | ||
state: vs.string({ // string, accepts only "active" and "inactive" | ||
only: ["active", "inactive"], | ||
}), | ||
classes: vs.array({ // array of number, separated by ",", ignores errors | ||
separatedBy: ",", | ||
each: { | ||
schema: vs.number(), | ||
ignoresErrors: true, | ||
}, | ||
}), | ||
skills: vs.array({ // array of string, separated by ",", ignores errors | ||
separatedBy: ",", | ||
each: { | ||
schema: vs.string(), | ||
ignoresErrors: true, | ||
}, | ||
}), | ||
creditCard: vs.numericString({ // numeric string, separated by "-", checks by Luhn algorithm | ||
separatedBy: "-", | ||
checksum: vs.NUMERIC_STRING.CHECKSUM_ALGORITHM.CREDIT_CARD, | ||
}), | ||
remoteAddr: vs.string({ // IPv4 | ||
pattern: vs.STRING.PATTERN.IPV4, | ||
}), | ||
remoteAddrIpv6: vs.string({ // IPv6 | ||
pattern: vs.STRING.PATTERN.IPV6, | ||
}), | ||
limit: vs.number({ // number, integer, omittable (sets 10 if omitted), >=1 (sets 1 if less), <=100 (sets 100 if greater) | ||
ifUndefined: 10, | ||
integer: true, | ||
minValue: { | ||
value: 1, | ||
adjusts: true, | ||
}, | ||
maxValue: { | ||
value: 100, | ||
adjusts: true, | ||
}, | ||
}), | ||
offset: vs.number({ // number, integer, omittable (sets 0 if omitted), >=0 (sets 0 if less) | ||
ifUndefined: 0, | ||
integer: true, | ||
minValue: { | ||
value: 0, | ||
adjusts: true, | ||
}, | ||
}), | ||
}; | ||
const input = { // input values | ||
id: "1", | ||
name: "Pablo Diego José Francisco de Paula Juan Nepomuceno María de los Remedios Ciprin Cipriano de la Santísima Trinidad Ruiz y Picasso", | ||
age: 20.5, | ||
email: "picasso@example.com", | ||
state: "active", | ||
classes: "1,3,abc,4", | ||
skills: "c,c++,javascript,python,,swift,kotlin", | ||
creditCard: "4111-1111-1111-1111", | ||
remoteAddr: "127.0.0.1", | ||
remoteAddrIpv6: "::1", | ||
limit: "0", | ||
}; | ||
const expected = { // should be converted to this | ||
id: 1, | ||
name: "Pablo Diego José", | ||
age: 20, | ||
email: "picasso@example.com", | ||
state: "active", | ||
classes: [1, 3, 4], | ||
skills: ["c", "c++", "javascript", "python", "swift", "kotlin"], | ||
creditCard: "4111111111111111", | ||
remoteAddr: "127.0.0.1", | ||
remoteAddrIpv6: "::1", | ||
limit: 1, | ||
offset: 0, | ||
}; | ||
|
||
// Let's apply! | ||
const actual = vs.applySchemaObject(schemaObject, input); | ||
|
||
// verification | ||
assert.assertEquals(actual, expected); | ||
|
||
console.log("Deno: OK!🎉"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {default} from "./dist/index.ts"; |
Oops, something went wrong.