New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cond-spread

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cond-spread - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

4

package.json
{
"name": "cond-spread",
"version": "0.1.0",
"description": "Conditionally spread elements",
"version": "0.1.1",
"description": "Conditionally spread object and array items.",
"main": "index.js",

@@ -6,0 +6,0 @@ "types": "index.d.ts",

@@ -1,10 +0,8 @@

# Conditional Spread
# cond-spread [![npm](https://img.shields.io/npm/v/cond-spread)](https://www.npmjs.com/package/cond-spread) [![downloads](https://img.shields.io/npm/dw/cond-spread)](https://www.npmjs.com/package/cond-spread)
[![npm](https://img.shields.io/npm/v/cond-spread)](https://www.npmjs.com/package/cond-spread) [![downloads](https://img.shields.io/npm/dw/cond-spread)](https://www.npmjs.com/package/cond-spread)
Conditionally spread object and array items.
> Conditionally spread elements
## Installation
To install with npm, run:
### npm

@@ -15,3 +13,3 @@ ```sh

To install with yarn, run:
### yarn

@@ -30,51 +28,10 @@ ```sh

The `condSpread` function takes a boolean as its argument, and returns another function, which can then take either an array or an object as its argument. If the first boolean was true, then the second function will return its argument. If the boolean was false, then the second function will return an empty array if the argument was an array, or an empty object if the argument was an object.
`condSpread` is a curried function that takes a boolean, and an object or array. It returns the object or array is the boolean was true, otherwise it returns an empty object or array.
### Example with arrays
### Example with webpack
```js
const myNum = 5;
...
const isFive = condSpread(myNum === 5);
const isNotFive = condSpread(myNum !== 5);
const myArray = [
'a',
...isFive(['num is five']),
'b',
...isNotFive(['num is not five']),
'c',
...condSpread(true)([123]),
];
console.log(myArray); // ['a', 'num is five', 'b', 'c', 123]
```
### Example with objects
```js
const myNum = 5;
const isFive = condSpread(myNum === 5);
const isNotFive = condSpread(myNum !== 5);
const myObject = {
a: 0,
...isFive({ msg1: 'num is five' }),
b: 1,
...isNotFive({ msg2: 'num is not five' }),
c: 2,
...condSpread(true)({ d: 123 }),
};
console.log(myObject); // {a: 0, msg1: 'num is five', b: 1, c: 2, d: 123}
```
### Example with webpack
```js
import condSpread from 'cond-spread';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import CopyPlugin from 'copy-webpack-plugin';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';

@@ -90,10 +47,3 @@ export default (env, { mode }) => {

new CleanWebpackPlugin(),
new CopyPlugin({
patterns: [
{
from: './assets/icons',
to: './icons',
},
],
}),
new CopyPlugin(),
]),

@@ -100,0 +50,0 @@ ],

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