Skip to content

cursormove/flow-is-helpers

Repository files navigation

Predicate truthy Function via %check

wercker status

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-helpers

Usage

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 either Number.NEGATIVE_INFINITY or Number.POSITIVE_INFINITY.

Nil Checks

  • isNotNil 🠲 Opposite of Lodash's isNil in that it's not null or undefined.

Miscellaneous Checks

  • isIterable 🠲 Checks if value is an Iterable
  • isAction 🠲 Checks if value is a Redux Action

API 🠲 Lodash Checks

Includes all Lodash is Predicate Functions


Best, te