Skip to content

Instantly share code, notes, and snippets.

@jquense
Created April 8, 2015 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jquense/7cd0757b783acaa65f77 to your computer and use it in GitHub Desktop.
Save jquense/7cd0757b783acaa65f77 to your computer and use it in GitHub Desktop.
// there are a few methods that you need to implement/override to create a new type
// The main one is `_coerce`, which passing in the raw value and returns the type back.
// _coerce should not throw errors, and should return the default invalid object for a type if it exists (NaN, etc)
//here is the date `_coerce()` (I need to change it to return an InvalidDate instead of null)
_coerce(value) {
if(value == null ) return value
if(isDate(value) ) return new Date(value)
value = isoParse(value)
return value ? new Date(value) : null
}
// create new schema Type
var myDateType = yup.date.extend({
coerce(value){
var baseVal = yup.date.prototype._coerce.call(this,val)
//do whatever if you didn't get a date
}
})
//mutate existing
var baseDateCoerce = yup.date.prototype._coerce;
yup.date.prototype._coerce = function(value){
baseDateCoerce.call(this)
// blah blah
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment