-
-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validator ideas #4
Comments
Great! I was actually going to open this exact issue yesterday, but got busy. I've been having this draft for a while:
|
Never needed it. Was just going through @kevva and your packages to see what we could use :).
👌 Me neither.
I'm fine with both. I might have a slight preference for
One thing I thought about as well is to have an const ow = require('ow');
const inRange = require('in-range');
const validDate = require('vali-date');
const positive = require('is-positive');
ow(5, ow.number.is(positive).is(x => inRange(x, 0, 10));
ow('2017-05-21', ow.string.is(validDate)); It's just an example though, I think having things like |
Good idea! I agree it would be useful. I've added it to the proposal. |
I agree. It shows the intent better, and |
Thinking about it, I believe
The intent of |
I never implied they were.
I think it does. There's a reason we have both |
But maybe |
So we should add |
That's my suggestion, yes. The latter is a bit verbose but good for readability, and better than |
Good idea! Added! |
We're almost done with this list, so I was looking into the ones that we didn't implement yet. I have a question regarding
Should it be
Or both of course. If we go for either 2 or 3 (both), this mean we could write something like |
Lets go with |
I think it's better to just do #71 |
Want to open a thread to discuss and think about all the nice validators/predicates we want to implement. Feel free to provide feedback, add new things, remove things etc. It's just a draft about things we could add.
all
optional
(Meansundefined
is allowed) (Note: I don't think we should allownull
, to align with default parameters) (Tracked by Addoptional
predicate #58)not
(Inverts the following predicates) (Addnot
predicate #12)notType(type)
(Inverts just the argument) (Example:ow.string.notType(ow.empty)
)any
(For multiple predicates, for example, when something can be both a string and array) (Addany
predicate #56)is(function)
(Accepts a function that receives the value fromow
and is expected to return a boolean) (Addis
predicate to provide custom validation functions #55)create(predicate)
(Create reusable validators) (Add reusable validators - fixes #41 #42)Primitives
string
length(number)
(Add more string validators #15)minLength(number)
(Add more string validators #15)maxLength(number)
(Add more string validators #15)match(regex: RegExp)
(Seems likematches
would better align with other names likeincludes
,startsWidth
?) (Add more string validators #15)startsWith(string)
(Add more string validators #15)endsWith(string)
(Add more string validators #15)includes(string)
(Add more string validators #15)empty
(Only useful when used with.not
) (Add more string validators #15)nonEmpty
(Add more string validators #15)equal(string)
(Add more string validators #15)alphanumeric
(Bundle dependencies #16)numeric
(Add more string validators #15)date
(vali-date) (Add more string validators #15)number
inRange(start: number, end: number)
(Add number validator #10)equal(x: number)
(Add number validator #10)greaterThan(x: number)
(Add number validator #10)greaterThanOrEqual(x: number)
(Add number validator #10)lessThan(x: number)
(Add number validator #10)lessThanOrEqual(x: number)
(Add number validator #10)integer
(Add number validator #10)finite
(Add number validator #10)infinite
(Add number validator #10)positive
(Add number validator #10)negative
(Add number validator #10)boolean
true
(Add boolean validator #13)false
(Add boolean validator #13)symbol (#28)
undefined (#28)
null (#28)
Built-in types
array
ofType(type, …)
(Accepts anyis.x
type) (TODO: Would be useful if this could also support anyow
predicate for each element, so you could do:ow.array.ofType(ow.string.minLength(5)))
(Add array validators #20)length(number)
(Add array validators #20)minLength(number)
(Add array validators #20)maxLength(number)
(Add array validators #20)startsWith(string)
(Add array validators #20)endsWith(string)
(Add array validators #20)includes(string, …)
(Add array validators #20)includesAny(string, …)
(Add array validators #20)empty
(Only useful when used with.not
) (Add array validators #20)nonEmpty
(Add array validators #20)deepEqual(array)
(Add array validators #20)Date
before(date)
(Add date predicate #26)after(date)
(Add date predicate #26)Error
evalError
(Add error predicate #27)rangeError
(Add error predicate #27)referenceError
(Add error predicate #27)syntaxError
(Add error predicate #27)typeError
(Add error predicate #27)uriError
(Add error predicate #27)name(string)
(Add error predicate #27)message(string)
(Add error predicate #27)messageIncludes(string)
(Add error predicate #27)Map
size(number)
(Add Map predicate #36)minSize(number)
(Add Map predicate #36)maxSize(number)
(Add Map predicate #36)keysOfType(type, …)
(Add Map predicate #36)valuesOfType(type, …)
(Add Map predicate #36)valuesOfTypeDeep(type, …)
(Add object.deepValuesOfType validator - fixes #51 #53)hasKeys(string, …)
(Add Map predicate #36)hasValues(string, …)
(Add Map predicate #36)hasAnyKeys(string, …)
(Add Map predicate #36)hasAnyValues(string, …)
(Add Map predicate #36)empty
(Only useful when used with.not
) (Add Map predicate #36)nonEmpty
(Add Map predicate #36)deepEqual(map)
(Add Map predicate #36)object
valuesOfType(type, …)
(Accepts anyis.x
type) (Add object predicate #48)plain
(Add object predicate #48)empty
(Only useful when used with.not
) (Add object predicate #48)nonEmpty
(Add object predicate #48)deepEqual(object)
(Add object predicate #48)instanceOf(object)
(Add object predicate #48)hasKeys(property, …)
(Add object predicate #48)hasAnyKeys(property, …)
(Add object predicate #48)set
size(number)
(Add Set predicate #39)minSize(number)
(Add Set predicate #39)maxSize(number)
(Add Set predicate #39)ofType(type, …)
(Add Set predicate #39)has(string, …)
(Add Set predicate #39)hasAny(string, …)
(Add Set predicate #39)empty
(Only useful when used with.not
) (Add Set predicate #39)nonEmpty
(Add Set predicate #39)deepEqual(set)
(Add Set predicate #39)weakMap
Not able to iterate over the keys in akeysOfType(type, …)
WeakMap
.hasKeys(string, …)
(Add WeakMap predicate #43)hasAnyKeys(string, …)
(Add WeakMap predicate #43)weakSet
Not able to iterate over the keys in aofType(type, …)
WeakSet
.has(string, …)
(Add WeakSet predicate #44)hasAny(string, …)
(Add WeakSet predicate #44)function
(#30)buffer
(#30)regExp
(#30)promise
(#30)typedArray
(#30)int8Array(value)
(#30)uint8Array(value)
(#30)uint8ClampedArray(value)
(#30)int16Array(value)
(#30)uint16Array(value)
(#30)int32Array(value)
(#30)uint32Array(value)
(#30)float32Array(value)
(#30)float64Array(value)
(#30)arrayBuffer(value)
(#30)sharedArrayBuffer(value)
dataView(value)
(#38)nan(value)
(#38)nullOrUndefined(value)
(#38)iterable(value)
(#30)The text was updated successfully, but these errors were encountered: