ramda-asserters
Collection of curried assert functions
Usage
assert
// use assert with some test function without custom error message and it will try to be smart making error messageassertR.identity1 // returns 1assertR.identitynull // throws `Unexpected "null" after applying test function "f1" on value "null"` // note: there is no way to make uncurried version of assert without user message// so this is not valid// const validate = assert(R.identity, 1) // or use assert with custom error messageassertR.identity, 'Custom message'null // throws error with name 'Assert error'assertR.identity, 'Custom message', null // throws error with name 'Assert error' // or overwrite error complitely assertR.identity, MyErrornullassertR.identity, MyError, null
assertNotNil
// chack if null, undefined or NaN assertNotNil1 // returns 1assertNotNilnull // throws 'Got unexpected null'
assertType
// uses R.type function// will infer type using this TypeMap// interface TypeMap {// Object: object// Number: number// Boolean: boolean// String: string// Null: null// Array: Array<any>// RegExp: RegExp// Function: Function// Undefined: undefined// Symbol: symbol// }
Installation
npm i ramda-asserters
or yarn add ramda-asserters
Corresponding .babelrc
, if you want to use it with babel (using babel-plugin-transform-imports):