This is a Flow helper library for Lodash is
and additional Flow predicate type %checks
functions. Simply put, this library contains converted truthy
predicate functions through the use of Flow %check
annotations. By doing so it aids and increases the ability for The Flow Parser to properly check the defined predicate functions.
Flow and Lodash's predicate functions (is***
) don't work well together (if at all in some cases) resulting in duplicate logic. Ideally a fix will be implemented into the main flow-type
Lodash library but until that time comes (if ever) this library acts as a stopgap solution. In addition, this library includes some helpful custom predicate check functions.
# npm
npm i --save @cursormove/flow-is-helpers
# yarn
yarn add @cursormove/flow-is-helpers
This Library is a drop-in replacement for Lodash's predicate functions. You should be able to just swap out Lodash predicate functions like isString
with this library. I recommend you take a quick look at the code base just so you have a better understanding of what is going on but the gist of it is pretty simple.
import {
isString,
} from '@cursormove/flow-is-helpers';
// Flow Type Check & truthy predicate function check
const hello = (val: string) => isString(val) ? `Hello ${val}` : 'Hello Nobody';
hello('World'); // 'Hello World'
hello(null); // 'Hello Nobody'
Array Checks
isEmptyArray
🠲 Checks if Array is empty.isNonEmptyArray
🠲 Checks if Array is empty.
Function Checks
isPromise
🠲 Checks if Function type is a Promise.isAsync
🠲 Checks if Function type is Async.isGenerator
🠲 Checks if Function type is a Generator Iterator.isGeneratorFunction
🠲 Checks if Function type is a Generator.
Plain Object Checks (Not ObjectLike)
isEmptyObject
🠲 Checks if Object is empty.isNonEmptyObject
🠲 Checks if Object is not empty.isFrozen
🠲 Checks if Object is Frozen.isFrozen
🠲 Checks if Object is Sealed.isFrozen
🠲 Checks if Object is Extensible.
String Checks
isEmptyString
🠲 Checks if String is empty.isNonEmptyString
🠲 Checks if String is not empty.
Number Checks
isNan
🠲 Checks if value is not a Number.isInfinity
🠲 Checks if value is eitherNumber.NEGATIVE_INFINITY
orNumber.POSITIVE_INFINITY
.
Nil Checks
isNotNil
🠲 Opposite of Lodash'sisNil
in that it's notnull
orundefined
.
Miscellaneous Checks
Includes all Lodash is
Predicate Functions
isArguments
isArray
isArrayBuffer
isArrayLike
isArrayLikeObject
isBoolean
isBuffer
isDate
isElement
isEmpty
isEqual
isEqualWith
isError
isFinite
isFunction
isInteger
isLength
isMap
isMatch
isMatchWith
isNaN
isNative
isNil
isNull
isNumber
isObject
isObjectLike
isPlainObject
isRegExp
isSafeInteger
isSet
isString
isSymbol
isTypedArray
isUndefined
isWeakMap
isWeakSet
Best, te