@cursormove/flow-is-helpers v2.1.0
Predicate truthy Function via %check
Description
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.
Why?
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.
Install
# npm
npm i --save @cursormove/flow-is-helpers
# yarn
yarn add @cursormove/flow-is-helpersUsage
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'API 🠲 Custom Checks
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_INFINITYorNumber.POSITIVE_INFINITY.
Nil Checks
isNotNil🠲 Opposite of Lodash'sisNilin that it's notnullorundefined.
Miscellaneous Checks
API 🠲 Lodash Checks
Includes all Lodash is Predicate Functions
isArgumentsisArrayisArrayBufferisArrayLikeisArrayLikeObjectisBooleanisBufferisDateisElementisEmptyisEqualisEqualWithisErrorisFiniteisFunctionisIntegerisLengthisMapisMatchisMatchWithisNaNisNativeisNilisNullisNumberisObjectisObjectLikeisPlainObjectisRegExpisSafeIntegerisSetisStringisSymbolisTypedArrayisUndefinedisWeakMapisWeakSet
Best, te
7 years ago