@cursormove/flow-is-helpers

Lodash (is) and additional Flow type %checks helpers.

Usage no npm install needed!

<script type="module">
  import cursormoveFlowIsHelpers from 'https://cdn.skypack.dev/@cursormove/flow-is-helpers';
</script>

README

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