Socket
Socket
Sign inDemoInstall

simple-update-in

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-update-in - npm Package Compare versions

Comparing version 1.2.1-master.f2ba331 to 1.3.0

6

CHANGELOG.md

@@ -9,2 +9,8 @@ # Changelog

## [1.3.0] - 2018-08-17
### Added
- Support predicate function
- `updateIn([1, 2, 3, 4, 5], [v => v % 2], v => v * 10)` will return `[10, 2, 30, 4, 50]`
- Predicate function can be used as branching function to update multiple subtrees in a single call
## [1.2.0] - 2018-04-14

@@ -11,0 +17,0 @@ ### Added

@@ -29,3 +29,23 @@ 'use strict';

var accessor = path.shift();
if (typeof accessor === 'function') {
if (Array.isArray(obj)) {
obj.forEach(function (value, index) {
if (accessor.call(obj, value, index)) {
obj = setIn(obj, [index].concat(_toConsumableArray(path)), updater);
}
});
} else {
Object.keys(obj).forEach(function (key) {
if (accessor.call(obj, obj[key], key)) {
obj = setIn(obj, [key].concat(_toConsumableArray(path)), updater);
}
});
}
return obj;
}
var value = typeof obj !== 'undefined' && obj[accessor];
var nextObj = obj;

@@ -32,0 +52,0 @@

13

package.json
{
"name": "simple-update-in",
"version": "1.2.1-master.f2ba331",
"version": "1.3.0",
"description": "",
"main": "lib/index.js",
"files": "lib/**/*",
"files": [
"lib/**/*"
],
"scripts": {

@@ -33,10 +35,7 @@ "build": "babel --out-dir lib src --ignore **/*.spec.js,**/*.test.js",

"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.6.1",
"babel-preset-stage-3": "^6.24.1",
"gulp": "^3.9.1",
"gulp-exec": "^3.0.1",
"jest": "^22.4.2",
"last-commit-log": "^1.0.3"
"jest": "^22.4.3"
}
}

@@ -5,3 +5,3 @@ # simple-update-in

[![Build Status](https://travis-ci.org/compulim/simple-update-in.svg?branch=master)](https://travis-ci.org/compulim/simple-update-in)
[![npm version](https://badge.fury.io/js/simple-update-in.svg)](https://badge.fury.io/js/simple-update-in) [![Build Status](https://travis-ci.org/compulim/simple-update-in.svg?branch=master)](https://travis-ci.org/compulim/simple-update-in)

@@ -161,2 +161,26 @@ We love [ImmutableJS](https://facebook.github.io/immutable-js). But sometimes, we want to start something from small. Thus, we created this package with zero dependencies.

## Using predicate
For path accessor, instead of `number` and `string`, you can also use `function`.
Predicate for array has signature of `(value, index) => truthy/falsy`. And for map, `(value, key) => truthy/falsy`.
```js
const from = [1, 2, 3, 4, 5];
const actual = updateIn(from, [value => value % 2], value => value * 10);
expect(actual).toEqual([10, 2, 30, 4, 50]);
```
### Branching with predicate
You can also use predicate to update multiple subsets at the same time.
```js
const from = [{ v: 1 }, { v: 2 }, { v: 3 }];
const actual = updateIn(from, [() => true, 'v'], v => v * 10);
expect(actual).toEqual([{ v: 10 }, { v: 20 }, { v: 30 }]);
```
# Contributions

@@ -163,0 +187,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