Socket
Socket
Sign inDemoInstall

immutable-deep-update

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

immutable-deep-update - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

src/functors/Either.js

8

package.json
{
"name": "immutable-deep-update",
"version": "1.0.0",
"version": "1.0.1",
"main": "src/index.js",

@@ -8,4 +8,4 @@ "author": "Gabriel Vergnaud",

"scripts": {
"start": "node examples/index.js",
"test": "mocha"
"start": "node examples/index.js",
"test": "mocha"
},

@@ -17,4 +17,4 @@ "dependencies": {

"expect": "^1.20.2",
"mocha": "^3.3.0"
"mocha": "^3.4.1"
}
}

@@ -91,3 +91,3 @@ # Immutable Deep Update

- `'aze.rty'` => compose (prop 'aze') (prop 'rty')
- `'aze['rty']'` => compose (prop 'aze') (prop 'rty')
- `'aze["rty"]'` => compose (prop 'aze') (prop 'rty')
- `'0'` => index 0

@@ -94,0 +94,0 @@ - `'[0]'` => index 0

@@ -47,5 +47,2 @@ const curry = require('lodash/fp/curry')

const intValue = parseInt(strFragment)
if (intValue == strFragment) return { type: Token.Num, value: intValue }
const [__, propertyName] = (strFragment.match(squareBracketsPropertyRegexp) || [])

@@ -52,0 +49,0 @@ if (propertyName) return { type: Token.Prop, value: propertyName.replace(quotesRegexp, '') }

@@ -12,2 +12,4 @@ const compose = require('lodash/fp/compose')

const setAtIndex = (index, value, arr) => [ ...arr.slice(0, index), value, ...arr.slice(index + 1) ]
const composeLenses = (...lenses) => curry((point, extract, x) =>

@@ -33,4 +35,3 @@ lenses.map(l => l(point, extract)).reduceRight((acc, l) => l(acc), x))

const createLens = curry((getter, setter, key, point, extract, f, obj) =>
map(value => setter(key, value, obj), f(getter(key, obj)))
)
map(value => setter(key, value, obj), f(getter(key, obj))))

@@ -48,9 +49,10 @@ // identityLens :: (DataStructure s, Functor f) => _ -> _ -> f -> s k a -> f (s k b)

(key, obj) => obj[key],
(key, value, obj) => Object.assign({}, obj, {
[key]: value
})
(key, value, obj) => Array.isArray(obj)
? setAtIndex(key, value, obj)
: Object.assign({}, obj, { [key]: value })
)
// lensProps :: (DataStructure (Object s), Functor f) => [String] -> _ -> _ -> f -> s String a -> f (s String b)
const lensProps = (...keys) => composeLenses(...keys.map(key => lensProp(key)))
const lensProps = (...keys) =>
composeLenses(...keys.map(key => lensProp(key)))

@@ -67,10 +69,12 @@

(index, arr) => arr[index],
(index, value, arr) => [ ...arr.slice(0, index), value, ...arr.slice(index + 1) ]
setAtIndex
)
// mapped :: (DataStructure [s], Functor f) => (c -> f c) -> (f d -> d) -> (a -> f b) -> s k a -> f (s k b)
const mapped = curry((point, extract, f, xs) => point(map(compose(extract, f), xs)))
const mapped = curry((point, extract, f, xs) =>
point(map(compose(extract, f), xs)))
// mapped :: (DataStructure (Object s), Functor f) => (c -> f c) -> (f d -> d) -> (a -> f b) -> s k a -> f (s k b)
const mappedValues = curry((point, extract, f, obj) => point(mapValues(compose(extract, f), obj)))
const mappedValues = curry((point, extract, f, obj) =>
point(mapValues(compose(extract, f), obj)))

@@ -86,9 +90,12 @@

// view :: Lens s k -> s k a -> a
const view = curry((lens, x) => compose(getConst, lens(Const.of, getConst, Const.of))(x))
const view = curry((lens, x) =>
compose(getConst, lens(Const.of, getConst, Const.of))(x))
// over :: Lens s k -> (a -> b) -> s k a -> s k b
const over = curry((lens, f, x) => compose(runIdentity, lens(Identity.of, runIdentity, compose(Identity.of, f)))(x))
const over = curry((lens, f, x) =>
compose(runIdentity, lens(Identity.of, runIdentity, compose(Identity.of, f)))(x))
// set :: Lens s k -> b -> s k a -> s k b
const set = curry((lens, v, x) => over(lens, () => v, x))
const set = curry((lens, v, x) =>
over(lens, () => v, x))

@@ -95,0 +102,0 @@

@@ -141,2 +141,16 @@ const expect = require('expect')

it('should understand `xxx.0.yyy` syntax to access an index or a property in function of the type', () => {
expect(over('friends.0.location.city', city => city + ' City', user)).toEqual({
firstname: 'Han',
location: { city: 'Paris' },
friends: [
{ fisrtname: 'Luke', location: { city: 'New York City' } },
{ fisrtname: 'Darth Vador', location: { city: 'Dark star' } }
]
})
const obj = { prop: { '123': { name: 'lol' } } }
expect(set('prop.123.name', 'Gab', obj)).toEqual({ prop: { '123': { name: 'Gab' } } })
})
it('should understand `xxx[0].yyy` syntax to access an index', () => {

@@ -143,0 +157,0 @@

Sorry, the diff of this file is not supported yet

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