-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add optional checkIfValidYupMethod to config * Add null type handler
- Loading branch information
1 parent
e63f59d
commit bbb9e9b
Showing
12 changed files
with
91 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "schema-to-yup", | ||
"version": "1.12.18", | ||
"version": "1.12.19", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
|
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,15 @@ | ||
import { YupNull } from "./null"; | ||
|
||
export class NullHandler { | ||
constructor(config) { | ||
this.config = config; | ||
} | ||
|
||
isBoolean(obj) { | ||
return this.config.isNull(obj); | ||
} | ||
|
||
handle(obj) { | ||
return this.isNull(obj) && YupNull.create(obj).createSchemaEntry(); | ||
} | ||
} |
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 { NullHandler } from "./handler"; | ||
|
||
export function toYupNull(obj, config = {}) { | ||
return obj && new NullHandler(config).handle(obj); | ||
} | ||
|
||
export { YupNull } from "./null"; |
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,21 @@ | ||
import { YupMixed } from "../mixed"; | ||
|
||
export class YupNull extends YupMixed { | ||
constructor(obj) { | ||
super(obj); | ||
this.type = this.baseType; | ||
this.base = this.validatorInstance; | ||
} | ||
|
||
get baseType() { | ||
return "null"; | ||
} | ||
|
||
get validatorInstance() { | ||
return this.validator.null(); | ||
} | ||
|
||
static create(obj) { | ||
return new YupNull(obj); | ||
} | ||
} |
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,19 +1,20 @@ | ||
const defaults = { | ||
getProps: obj => obj && obj.properties, | ||
getType: obj => obj && obj.type, | ||
getName: obj => obj && (obj.name || obj.title), | ||
getConstraints: obj => obj, | ||
isString: obj => obj && obj.type === "string", | ||
isArray: obj => obj && obj.type === "array", | ||
isInteger: obj => obj && (obj.type === "integer" || obj.type === "int"), | ||
isBoolean: obj => obj && obj.type === "boolean", | ||
hasDateFormat: obj => | ||
obj && ["date", "date-time"].find(t => t === obj.format), | ||
isDate: obj => | ||
getProps: (obj) => obj && obj.properties, | ||
getType: (obj) => obj && obj.type, | ||
getName: (obj) => obj && (obj.name || obj.title), | ||
getConstraints: (obj) => obj, | ||
isString: (obj) => obj && obj.type === "string", | ||
isArray: (obj) => obj && obj.type === "array", | ||
isInteger: (obj) => obj && (obj.type === "integer" || obj.type === "int"), | ||
isBoolean: (obj) => obj && obj.type === "boolean", | ||
isNull: (obj) => obj && obj.type === "null", | ||
hasDateFormat: (obj) => | ||
obj && ["date", "date-time"].find((t) => t === obj.format), | ||
isDate: (obj) => | ||
obj && obj.type === "string" && defaults.hasDateFormat(obj.format), | ||
isNumber: obj => obj && (obj.type === "number" || defaults.isInteger(obj)), | ||
isObject: obj => obj && obj.type === "object", | ||
isRequired: obj => obj && obj.required | ||
isNumber: (obj) => obj && (obj.type === "number" || defaults.isInteger(obj)), | ||
isObject: (obj) => obj && obj.type === "object", | ||
isRequired: (obj) => obj && obj.required, | ||
}; | ||
|
||
export default defaults; |
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