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

shades

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shades - npm Package Compare versions

Comparing version 1.7.1 to 1.8.0

14

lib/traversals/all.js

@@ -7,7 +7,15 @@ 'use strict';

var _compile = require('../compiler/compile');
var _compile2 = _interopRequireDefault(_compile);
var _utils = require('../utils');
exports.default = {
get: _utils.identity,
mod: _utils.map
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = function (lens) {
return {
get: (0, _utils.map)(lens ? (0, _compile2.default)(lens).get : _utils.identity),
mod: _utils.map
};
};
{
"name": "shades",
"version": "1.7.1",
"version": "1.8.0",
"description": "Lens-like functionality with a lodash-style interface.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -8,4 +8,3 @@ ## shades

```
```js
const store = {

@@ -30,3 +29,3 @@ users: [

```
```js
const userIdx = 0;

@@ -56,3 +55,3 @@ const postIdx = 0;

```
```js
mod(`.users[${userIdx}].posts[${postIdx}]`)

@@ -76,3 +75,3 @@ (capitalize)

```
```js
> ".a.b[3].d" // focus is the d field

@@ -87,3 +86,3 @@

```
``` js
> get('.a.b.c')({a: {b: {c: 7}}})

@@ -96,3 +95,3 @@ 7

```
```js
> set('.a.b.c')(10)({a: {b: {c: 7}}})

@@ -105,3 +104,3 @@ {a: {b: {c: 10}}}

```
```js
> const inc = n => n + 1

@@ -119,3 +118,3 @@ > mod('.a.b.c')(inc)({a: {b: {c: 7}}})

_Note: It is unlikely that you will ever need to call this directly_
```
```js
> const l = compose('.a.b', '.c.d')

@@ -132,3 +131,3 @@ > get(l)({a: {b: {c: {d: 10}}}})

```
```js
> const even = n => n % 2 == 0

@@ -149,3 +148,3 @@ > get(matching(even))([1, 2, 3, 4])

```
```js
> const even = n => n % 2 == 0

@@ -160,13 +159,18 @@ > get(all))([1, 2, 3, 4])

#### all :: Lens
`all` is the identity traversal. It acts over every element.
#### all :: Lens? -> Lens
`all` is the identity traversal. It acts over every element. It optionally takes an additional lens, and for each element in the result set will apply the given lens.
_Note: this is only necessary for `get`. `mod` and `set` will already do the appropriate thing if `all` appears in the middle of a lens
```
```js
> const mul10 = n => n * 10
> mod(all())(mul10)({a: 1, b: 2, c: 3, d: 4})
{a: 10, b: 20, c: 30, d: 40}
> const even = n => n % 2 == 0
> get(all)([1, 2, 3, 4])
[1, 2, 3, 4]
> get('a', all('b.c'))({a: [{b: {c: 1}}, {b: {c: 2}}, {b: {c: 3}}]})
[1, 2, 3]
> const mul10 = n => n * 10
> mod(all)(mul10)({a: 1, b: 2, c: 3, d: 4})
{a: 10, b: 20, c: 30, d: 40}
> mod('a', all(), 'b.c')(mul10)({a: [{b: {c: 1}}, {b: {c: 2}}, {b: {c: 3}}]})
[10, 20, 30]
```

@@ -180,3 +184,3 @@

```
```js
> has({a: {b: 3}})({a: {b: 3, c: 4}, d: 5})

@@ -186,3 +190,3 @@ true

`has` composes well `filter` and `matching` pipelines
```
```js
> [{type: 'oper': expr: '+'}, {type: 'lambda', expr: 'a => a + 1'}].filter(has({type: 'oper'}))

@@ -196,6 +200,12 @@ [{type: 'oper': expr: '+'}]

```
The keys in the pattern may also be predicate functions. In this case, values from the input object will be passed to the predicates.
```js
> users.map(has({name: _.isString, likes: n => n > 1000}))
[true, false, false]
```
#### map :: (a, ?c -> b) -> (List a | Object c, a) -> (List b | Object c, b)
A more generic, curried `map`. If applied to a list, it behaves like `Array::map`. Applied to a an object, it transforms the values (although the key will be supplied as a second argument)
```
```js
> map(inc)([1, 2, 3, 4])

@@ -211,3 +221,3 @@ [2, 3, 4, 5]

```
```js
> filter(isEven)([1, 2, 3, 4])

@@ -221,3 +231,3 @@ [2, 4]

Consumes a variadic number of transformers (i.e. `Lens`es that have already been applied to a path and a transforming function) and a state function and applies each of them in order to a state object, producing a transformed object
```
```js
> const state = {

@@ -246,3 +256,3 @@ modal: {

Negates a boolean
```
```js
> toggle(true)

@@ -253,3 +263,3 @@ false

Increments a number
```
```js
> inc(5)

@@ -264,3 +274,3 @@ 6

```
```js
> and(isEven, greaterThan(3))(6)

@@ -273,3 +283,3 @@ true

A function level equivalent of the `||` operator. It consumes an arbitrary number of functions that take the same argument types and produce booleans, and returns a single function that takes the same arguments, and returns `true ` if any of the functions return `true`
```
```js
> or(isEven, greaterThan(3))(5)

@@ -282,3 +292,3 @@ true

A function level equivalent of the `!` operator. It consumes a function that produces a boolean, and returns a function that takes the same arguments, and returns the negation of the output
```
```js
const isOdd = not(isEven)

@@ -288,3 +298,3 @@ ```

Produces the given value forever
```
```js
> [1, 2, 3].map(always(5))

@@ -295,4 +305,4 @@ [5, 5, 5]

Takes a 2-curried function and flips the order of the arguments
```
```js
> const lessThanEq = flip(greaterThanEq)
```
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