Skip to content

Commit

Permalink
feat(validator): update demo
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm authored and AliMD committed Jan 3, 2023
1 parent 720dbb7 commit cc21a90
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
6 changes: 3 additions & 3 deletions core/validator/src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function validator<T extends ValidType>(
else {
throw new Error('invalid_type', {
cause: {
itemPath,
itemPath: itemPath,
itemSchema: 'Boolean',
itemValue: String(itemValue),
},
Expand All @@ -63,7 +63,7 @@ export function validator<T extends ValidType>(
else {
throw new Error('invalid_type', {
cause: {
itemPath,
itemPath: itemPath,
itemSchema: 'Number',
itemValue: String(itemValue),
},
Expand All @@ -78,7 +78,7 @@ export function validator<T extends ValidType>(
else {
throw new Error('invalid_type', {
cause: {
itemPath,
itemPath: itemPath,
itemSchema: 'String',
itemValue: String(itemValue),
},
Expand Down
16 changes: 8 additions & 8 deletions demo/validator/validator.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import {validator} from '@alwatr/validator';

// number
console.log(validator<{a: number}>({a: 2}, {a: 'number'}));
console.log(validator<{a: number}>({a: '2'}, {a: 'number'}));
console.log(validator<{a: number}>({a: Number}, {a: 2}));
console.log(validator<{a: number}>({a: Number}, {a: '2'}));

// boolean
console.log(validator<{a: boolean}>({a: true}, {a: 'boolean'}));
console.log(validator<{a: boolean}>({a: false}, {a: 'boolean'}));
console.log(validator<{a: boolean}>({a: Boolean}, {a: 'false'}));
console.log(validator<{a: boolean}>({a: Boolean}, {a: 'true'}));

// string
console.log(validator<{a: string}>({a: 'salam'}, {a: 'string'}));
console.log(validator<{a: string}>({a: String}, {a: 'salam'}));

// nested object
console.log(
validator<{a: number; b: {c: boolean, d: {e: number}}}>(
{a: Number, b: {c: Boolean, d: {e: Number}}},
{a: '2', b: {c: true, d: {e: 1}}},
{a: 'number', b: {c: 'boolean', d: {e: 'number'}}},
),
);

// not valid
try {
console.log(
validator<{a: number; b: {c: boolean, d: {e: number}}}>(
{a: Number, b: {c: Boolean, d: {e: Number}}},
{a: '2', b: {c: true, d: {e: true}}},
{a: 'number', b: {c: 'boolean', d: {e: 'number'}}},
),
);
}
Expand All @@ -33,7 +33,7 @@ catch (error) {
}

try {
console.log(validator<{a: boolean}>({a: 'test'}, {a: 'boolean'}));
console.log(validator<{a: boolean}>({a: Boolean}, {a: 'test'}));
}
catch (error) {
console.log(error);
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
# yarn lockfile v1


"@alwatr/math@~0.26.0":
version "0.26.1"
resolved "https://registry.yarnpkg.com/@alwatr/math/-/math-0.26.1.tgz#9165b9212fdf5a7c0576d8fa6aa2b58dc9a3d750"
integrity sha512-BPxV+Kl6Z3ErQVEH2JqLMEdhRNr70u0vXma/dPx81J+YbXiM5RP6ftxZto2wSuTvIcB++Wajg3KhIUke/wmJ7g==
dependencies:
tslib "~2.4.1"

"@ampproject/remapping@^2.1.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@ampproject/remapping/-/remapping-2.2.0.tgz#56c133824780de3174aed5ab6834f3026790154d"
Expand Down

0 comments on commit cc21a90

Please sign in to comment.