Open hastebrot opened 5 years ago
Maybe ow.not
can be introduced:
ow(1, ow.not.undefined)
ow(undefined, ow.optional.not.undefined)
Then again, my usecase might be too specific. Are there any other usecases where ow.not
might be useful?
Hi guys,
i just create PR with not
modifier: https://github.com/sindresorhus/ow/pull/158
For anyone that wants to work on this, see the initial attempt and feedback in https://github.com/sindresorhus/ow/pull/158.
I tried to define a shape predicate to check the values of a
node
created byd3.hierarchy()
.node
has adata
property which can be any type (e.g.undefined
,null
,object
,string
). As this property can be anything we might not need a validator for this, however I wanted to keep it inobject.exactShape()
for documentation purposes.There were different candidates for my purpose. I can use
undefined
instead of aow
predicate, but it could confuse when it is used for documentation. I could useow.any()
with no arguments, but it will always fail, when not at least one of the predicate arguments passed. So I came up withOwDefined
andOwOptional
.I defined a new
OwNotPredicate
. As the constructor ofow.Predicate
requirestype
to be an existingis
validator whenow
adds a new validator, we'll useundefined
inOwDefined
andOwOptional
.Just thought this might be useful, even when it does not fit perfectly in the API.