Comparing version 0.1.2 to 1.0.0
{ | ||
"name": "cond-flow", | ||
"version": "0.1.2", | ||
"version": "1.0.0", | ||
"description": "Elixir style cond for easy javascript control flow", | ||
"main": "src/index.js", | ||
"repository": { | ||
"url": "https://github.com/erikmueller/cond-flow" | ||
}, | ||
"main": "build/index.js", | ||
"files": [ | ||
"build/index.js", | ||
"build/index.d.ts", | ||
"package.json", | ||
"README.md" | ||
], | ||
"scripts": { | ||
"test": "eslint src && jest --collect-coverage" | ||
"build": "tsc", | ||
"format": "rome format src", | ||
"lint": "rome check src", | ||
"test": "rome ci src && vitest --run --coverage", | ||
"prepublish": "npm run build" | ||
}, | ||
@@ -15,15 +28,10 @@ "keywords": [ | ||
"author": "Erik Müller", | ||
"license": "ISC", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"jest": "25.1.0", | ||
"eslint": "6.8.0", | ||
"eslint-config-prettier": "6.10.0", | ||
"eslint-config-standard": "14.1.1", | ||
"eslint-plugin-import": "2.20.1", | ||
"eslint-plugin-node": "11.0.0", | ||
"eslint-plugin-prettier": "3.1.2", | ||
"eslint-plugin-promise": "4.2.1", | ||
"eslint-plugin-standard": "4.0.1", | ||
"prettier": "1.19.1" | ||
} | ||
"@vitest/coverage-c8": "^0.25.3", | ||
"typescript": "^4.9.3", | ||
"vitest": "^0.25.3", | ||
"rome": "^10.0.1" | ||
}, | ||
"type": "module" | ||
} |
@@ -5,9 +5,4 @@ # cond-flow | ||
[](LINK) | ||
[](https://github.com/prettier/prettier) | ||
[](https://standardjs.com) | ||
[](https://github.com/facebook/jest) | ||
[](https://codecov.io/gh/erikmueller/cond-flow) | ||
[](https://codecov.io/gh/erikmueller/cond-flow) | ||
## Install | ||
@@ -17,3 +12,3 @@ | ||
``` | ||
```sh | ||
yarn add cond-flow | ||
@@ -24,15 +19,6 @@ ``` | ||
``` | ||
```sh | ||
npm i cond-flow | ||
``` | ||
## API | ||
```ts | ||
type Cond = ( | ||
pairs: Array<[boolean, unknown | (() => unknown)]>, | ||
options: { strict: boolean } | ||
) => unknown | ||
``` | ||
## Usage | ||
@@ -46,3 +32,3 @@ | ||
[true, 'true'], | ||
[true, 'true but too late'] | ||
[true, 'true but too late'], | ||
]) | ||
@@ -53,21 +39,4 @@ | ||
You can disable strict checking by passing options as the second argument: | ||
Also works nicely with React components as you can have the values lazily evaluated by wrapping them in a function: | ||
```js | ||
import cond from 'cond-flow' | ||
const value = cond( | ||
[ | ||
[false, 'false'], | ||
[1, 'truthy'], | ||
[true, 'true but also too late'] | ||
], | ||
{ strict: false } | ||
) | ||
// value === 'truthy' | ||
``` | ||
Also works nicely with React components as you can have the values lazily evaluated by wrapping it in a function: | ||
```jsx | ||
@@ -81,3 +50,3 @@ import cond from 'cond-flow' | ||
[isNew, () => <Create />], | ||
[isDisabled, null] | ||
[isDisabled, null], | ||
])} | ||
@@ -88,5 +57,23 @@ </> | ||
### Default return value | ||
You can provide a `default` fallback which will be returned if no provided conditions are met. | ||
```js | ||
import cond from 'cond-flow' | ||
const value = cond( | ||
[ | ||
[false, () => 'false'], | ||
[false, () => 'also false'], | ||
], | ||
{ default: () => 'fallback' }, | ||
) | ||
// value === 'fallback' | ||
``` | ||
### Note | ||
As all predicates have to be evaluated before the right branch can be chosen, it can have a negative performance impact if you rely on heavy computations here. It's best have simple booleans and resort to `_.cond` for complex use cases. | ||
As all predicates have to be evaluated before the right branch can be chosen, it can have a negative performance impact if you rely on heavy computations. It's best to have simple booleans and resort to [Ramda's](https://ramdajs.com/docs/#cond) `cond` for complex use cases. | ||
@@ -93,0 +80,0 @@ ## Development |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
4
1
Yes
4666
5
31
76
1