ignore-if
A higher-order function that allows you to ignore higher-order function when
a condition is met, such as NODE_ENV === 'test'
.
Installation
$ npm install --save-dev ignore-if
Usage
One use case for this is in React when you want to wrap your component in a higher-order component, but you'd like to ignore the wrapper in testing. This is useful for things like react-css-modules.
import cssModules from 'react-css-modules'import ignoreIf from 'ignore-if'import styles from './styles.css' { return <div></div> } const isTest = processenvNODE_ENV === 'test' isTest )
Automatically Curried
If you omit the second argument, the wrapper, ignoreIf will automatically return a curried function that allows you to call it again with the second argument:
import cssModules from 'react-css-modules'import ignoreIf from 'ignore-if'import styles from './styles.css' const ignoreIfTest = { return <div></div> } )
Compose and Pipe
You can use this tool easily with compose() or pipe() from functional libraries like Ramda:
import pipe from 'ramda'import connect from 'react-redux'import cssModules from 'react-css-modules'import ignoreIf from 'ignore-if'import styles from './styles.css' const ignoreIfTest = { return <div></div> } MyComponent
License
The MIT License (MIT)
Copyright (c) 2015 Brainspace Corporation