Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cond-flow

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cond-flow - npm Package Compare versions

Comparing version 0.1.2 to 1.0.0

build/index.d.ts

38

package.json
{
"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

[![CI status](https://circleci.com/gh/erikmueller/cond-flow.svg?style=shield)](LINK)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
[![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest)
[![codecov](https://codecov.io/gh/erikmueller/cond-flow/branch/master/graph/badge.svg)](https://codecov.io/gh/erikmueller/cond-flow)
[![codecov](https://codecov.io/gh/erikmueller/cond-flow/branch/master/graph/badge.svg?token=WCNYJSZK51)](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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc