forked from ianstormtaylor/superstruct
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change coercions to include more type safety (ianstormtaylor#551)
* change coercions to include more type safety * add trimmed * update docs * fix linting
- Loading branch information
1 parent
f764272
commit 1f3164e
Showing
17 changed files
with
472 additions
and
353 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
.DS_Store | ||
.vscode | ||
lib/ | ||
node_modules/ | ||
npm-debug.log | ||
package-lock.json | ||
site/ | ||
tmp/ | ||
umd/ | ||
yarn-error.log | ||
yarn-error.log |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.vscode/ | ||
lib/ | ||
node_modules/ | ||
site/ | ||
|
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
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { assert, coerce, string } from '../..' | ||
import { assert, coerce, string, number } from '../..' | ||
import { test } from '..' | ||
|
||
test<string>((x) => { | ||
test<number>((x) => { | ||
assert( | ||
x, | ||
coerce(string(), (x) => x) | ||
coerce(number(), string(), (x) => parseFloat(x)) | ||
) | ||
return x | ||
}) |
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,7 @@ | ||
import { assert, string, trimmed } from '../..' | ||
import { test } from '..' | ||
|
||
test<string>((x) => { | ||
assert(x, trimmed(string())) | ||
return x | ||
}) |
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,17 @@ | ||
import { string, number, coerce } from '../../..' | ||
|
||
export const Struct = coerce(string(), number(), (x) => 'known') | ||
|
||
export const data = false | ||
|
||
export const failures = [ | ||
{ | ||
value: false, | ||
type: 'string', | ||
refinement: undefined, | ||
path: [], | ||
branch: [data], | ||
}, | ||
] | ||
|
||
export const create = true |
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,17 @@ | ||
import { string, trimmed } from '../../..' | ||
|
||
export const Struct = trimmed(string()) | ||
|
||
export const data = false | ||
|
||
export const failures = [ | ||
{ | ||
value: false, | ||
type: 'string', | ||
refinement: undefined, | ||
path: [], | ||
branch: [data], | ||
}, | ||
] | ||
|
||
export const create = true |
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,9 @@ | ||
import { string, trimmed } from '../../..' | ||
|
||
export const Struct = trimmed(string()) | ||
|
||
export const data = ' valid ' | ||
|
||
export const output = 'valid' | ||
|
||
export const create = true |
Oops, something went wrong.