Merge branch 'renaming'
This commit is contained in:
commit
629da53bef
5
.changeset/neat-actors-tease.md
Normal file
5
.changeset/neat-actors-tease.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@yanick/updeep": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
rename module as @yanick/updeep
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
"@yanick/updeep-remeda": minor
|
"@yanick/updeep": minor
|
||||||
---
|
---
|
||||||
|
|
||||||
update Remeda dependency
|
update Remeda dependency
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
"@yanick/updeep-remeda": patch
|
"@yanick/updeep": patch
|
||||||
---
|
---
|
||||||
|
|
||||||
upgrade all dependencies
|
upgrade all dependencies
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Changelog for [updeep-remeda](https://github.com/yanick/updeep-remeda)
|
# Changelog for [@yanick/updeep](https://github.com/yanick/updeep)
|
||||||
|
|
||||||
## 2.3.1
|
## 2.3.1
|
||||||
|
|
||||||
|
96
README.md
96
README.md
@ -1,11 +1,14 @@
|
|||||||
# updeep-remeda
|
# @yanick/updeep
|
||||||
|
|
||||||
> Easily update nested frozen objects and arrays in a declarative and immutable
|
> Easily update nested frozen objects and arrays in a declarative and immutable
|
||||||
> manner.
|
> manner.
|
||||||
|
|
||||||
## About
|
## About
|
||||||
|
|
||||||
> 💡 This is a fork of the main [updeep](https://github.com/substantial/updeep) package. For ease of reading — not to mention ease of shamelessly lifting large pieces of the original documentation — in this documentation all mentions of `updeep` refers to this fork.
|
> 💡 This is a fork of the main [updeep](https://github.com/substantial/updeep)
|
||||||
|
> package. For ease of reading — not to mention ease of shamelessly
|
||||||
|
> lifting large pieces of the original documentation — in this
|
||||||
|
> documentation all mentions of `updeep` refers to this fork.
|
||||||
|
|
||||||
updeep makes updating deeply nested objects/arrays painless by allowing you to
|
updeep makes updating deeply nested objects/arrays painless by allowing you to
|
||||||
declare the updates you would like to make and it will take care of the rest. It
|
declare the updates you would like to make and it will take care of the rest. It
|
||||||
@ -17,16 +20,19 @@ updeep assumes that every object passed in to update is immutable, so it may
|
|||||||
freeze objects passed in as well. Note that the freezing only happens in
|
freeze objects passed in as well. Note that the freezing only happens in
|
||||||
development.
|
development.
|
||||||
|
|
||||||
This fork of updeep requires Remeda, but works very well with any other utility function ([lodash], [Ramda], etc).
|
This fork of updeep requires Remeda, but works very well with any other utility
|
||||||
|
function ([lodash], [Ramda], etc).
|
||||||
|
|
||||||
## Differences with the original Updeep
|
## Differences with the original Updeep
|
||||||
|
|
||||||
- Under the hood, the use of lodash has
|
- Under the hood, the use of lodash has been replaced by Remeda (for better type
|
||||||
been replaced by Remeda (for better type support and tree-shaking abilities).
|
support and tree-shaking abilities).
|
||||||
|
|
||||||
- The codebase has been ported to TypeScript (mostly for the lulz).
|
- The codebase has been ported to TypeScript (mostly for the lulz).
|
||||||
|
|
||||||
- The order of parameters in the non-curryied invocation of functions has been modified. In the original updeep the input object is the last parameter, whereas here it's the first.
|
- The order of parameters in the non-curryied invocation of functions has been
|
||||||
|
modified. In the original updeep the input object is the last parameter,
|
||||||
|
whereas here it's the first.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// original updeep
|
// original updeep
|
||||||
@ -35,7 +41,7 @@ const dataIn = { a: 1, b: 2 };
|
|||||||
let dataOut = u({ c: 3 }, dataIn); // simple call
|
let dataOut = u({ c: 3 }, dataIn); // simple call
|
||||||
dataOut = u({ c: 3 })(dataIn); // curried
|
dataOut = u({ c: 3 })(dataIn); // curried
|
||||||
|
|
||||||
// updeep-remeda
|
// @yanick/updeep
|
||||||
dataOut = u(dataIn, { c: 3 }); // simple call
|
dataOut = u(dataIn, { c: 3 }); // simple call
|
||||||
dataOut = u({ c: 3 })(dataIn); // curried
|
dataOut = u({ c: 3 })(dataIn); // curried
|
||||||
```
|
```
|
||||||
@ -48,15 +54,15 @@ dataOut = u({ c: 3 })(dataIn); // curried
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm install @yanick/updeep-remeda
|
$ npm install @yanick/updeep
|
||||||
# or
|
# or
|
||||||
$ pnpm install @yanick/updeep-remeda
|
$ pnpm install @yanick/updeep
|
||||||
```
|
```
|
||||||
|
|
||||||
## Full example
|
## Full example
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import u from "@yanick/updeep-remeda";
|
import u from "@yanick/updeep";
|
||||||
|
|
||||||
const person = {
|
const person = {
|
||||||
name: { first: "Bill", last: "Sagat" },
|
name: { first: "Bill", last: "Sagat" },
|
||||||
@ -101,15 +107,17 @@ const newPerson = u(person, {
|
|||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
> 💡 All functions are curried, Remeda-style, so if you see `f(dataIn, ...others)`, it can be called with either `f(dataIn, ...others)` or `f(...others)(dataIn)`.
|
> 💡 All functions are curried, Remeda-style, so if you see
|
||||||
|
> `f(dataIn, ...others)`, it can be called with either `f(dataIn, ...others)` or
|
||||||
|
> `f(...others)(dataIn)`.
|
||||||
|
|
||||||
### Importing
|
### Importing
|
||||||
|
|
||||||
`updeep-remeda` exports a default function that is an alias to `u.update` and
|
`@yanick/updeep` exports a default function that is an alias to `u.update` and
|
||||||
has all the other functions available as props.
|
has all the other functions available as props.
|
||||||
|
|
||||||
```
|
```
|
||||||
import u from '@yanick/updeep-remeda';
|
import u from '@yanick/updeep';
|
||||||
|
|
||||||
const foo = u({a:1}, { a: x => x + 1 });
|
const foo = u({a:1}, { a: x => x + 1 });
|
||||||
|
|
||||||
@ -119,22 +127,28 @@ const bar = u.updateIn({ a: { b: 2 } }, 'a.b', 3 );
|
|||||||
Or you can import the functions piecemeal:
|
Or you can import the functions piecemeal:
|
||||||
|
|
||||||
```
|
```
|
||||||
import { updateIn, omit } from '@yanick/updeep-remeda';
|
import { updateIn, omit } from '@yanick/updeep';
|
||||||
```
|
```
|
||||||
|
|
||||||
### `u(dataIn, updates)`
|
### `u(dataIn, updates)`
|
||||||
|
|
||||||
### `u.update(dataIn, updates)`
|
### `u.update(dataIn, updates)`
|
||||||
|
|
||||||
Update as many values as you want, as deeply as you want. The `updates` parameter can either be an object, a function, or a value. Everything returned from `u` is frozen recursively.
|
Update as many values as you want, as deeply as you want. The `updates`
|
||||||
|
parameter can either be an object, a function, or a value. Everything returned
|
||||||
|
from `u` is frozen recursively.
|
||||||
|
|
||||||
If `updates` is an object, for each key/value, it will apply the updates specified in the value to `object[key]`.
|
If `updates` is an object, for each key/value, it will apply the updates
|
||||||
|
specified in the value to `object[key]`.
|
||||||
|
|
||||||
If `updates` is a function, it will call the function with `object` and return the value.
|
If `updates` is a function, it will call the function with `object` and return
|
||||||
|
the value.
|
||||||
|
|
||||||
If `updates` is a value, it will return that value.
|
If `updates` is a value, it will return that value.
|
||||||
|
|
||||||
Sometimes, you may want to set an entire object to a property, or a function. In that case, you'll need to use a function to return that value, otherwise it would be interpreted as an update. Ex. `function() { return { a: 0 }; }`.
|
Sometimes, you may want to set an entire object to a property, or a function. In
|
||||||
|
that case, you'll need to use a function to return that value, otherwise it
|
||||||
|
would be interpreted as an update. Ex. `function() { return { a: 0 }; }`.
|
||||||
|
|
||||||
Also available at `u.update(...)`.
|
Also available at `u.update(...)`.
|
||||||
|
|
||||||
@ -205,7 +219,10 @@ expect(result).to.eql({ scores: { team1: 0, team2: 1 } });
|
|||||||
|
|
||||||
#### Array Manipulation
|
#### Array Manipulation
|
||||||
|
|
||||||
Non-trivial array manipulations, such as element removal/insertion/sorting, can be implemented with functions. Because there are so many possible manipulations, we don't provide any helpers and leave this up to you. Simply ensure your function is pure and does not mutate its arguments.
|
Non-trivial array manipulations, such as element removal/insertion/sorting, can
|
||||||
|
be implemented with functions. Because there are so many possible manipulations,
|
||||||
|
we don't provide any helpers and leave this up to you. Simply ensure your
|
||||||
|
function is pure and does not mutate its arguments.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
function addTodo(todos) {
|
function addTodo(todos) {
|
||||||
@ -223,8 +240,8 @@ expect(result).to.eql({
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
Remeda is one of the many libraries providing good utility functions for
|
Remeda is one of the many libraries providing good utility functions for such
|
||||||
such manipulations.
|
manipulations.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { reject, concat, prop } from "remeda";
|
import { reject, concat, prop } from "remeda";
|
||||||
@ -266,7 +283,9 @@ expect(result).to.eql({ name: "Shannon Barnes", age: 63 });
|
|||||||
|
|
||||||
### `u.freeze(dataIn)`
|
### `u.freeze(dataIn)`
|
||||||
|
|
||||||
Freeze your initial state to protect against mutations. Only performs the freezing in development, and returns the original object unchanged in production.
|
Freeze your initial state to protect against mutations. Only performs the
|
||||||
|
freezing in development, and returns the original object unchanged in
|
||||||
|
production.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const state = u.freeze({ someKey: "Some Value" });
|
const state = u.freeze({ someKey: "Some Value" });
|
||||||
@ -275,7 +294,9 @@ state.someKey = "Mutate"; // ERROR in development
|
|||||||
|
|
||||||
### `u.updateIn(dataIn, path, value)`
|
### `u.updateIn(dataIn, path, value)`
|
||||||
|
|
||||||
Update a single value with a simple string or array path. Can be use to update nested objects, arrays, or a combination. Can also be used to update every element of a nested array with `'*'`.
|
Update a single value with a simple string or array path. Can be use to update
|
||||||
|
nested objects, arrays, or a combination. Can also be used to update every
|
||||||
|
element of a nested array with `'*'`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const result = u.updateIn(
|
const result = u.updateIn(
|
||||||
@ -328,9 +349,9 @@ expect(result).to.eql({
|
|||||||
|
|
||||||
### `u.constant(dataIn)`
|
### `u.constant(dataIn)`
|
||||||
|
|
||||||
Sometimes, you want to replace an object outright rather than merging it.
|
Sometimes, you want to replace an object outright rather than merging it. You'll
|
||||||
You'll need to use a function that returns the new object.
|
need to use a function that returns the new object. `u.constant` creates that
|
||||||
`u.constant` creates that function for you.
|
function for you.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const user = {
|
const user = {
|
||||||
@ -357,10 +378,9 @@ expect(alwaysFour(32)).to.eql(4);
|
|||||||
|
|
||||||
### `u.if(dataIn, predicate, updates)`
|
### `u.if(dataIn, predicate, updates)`
|
||||||
|
|
||||||
Apply `updates` if `predicate` evaluates to true. The `predicate` can
|
Apply `updates` if `predicate` evaluates to true. The `predicate` can be a
|
||||||
be a boolean, or a function taking in `dataIn` and returning a boolean,
|
boolean, or a function taking in `dataIn` and returning a boolean, or an object,
|
||||||
or an object, in which case it'll be treated as a shortcut for
|
in which case it'll be treated as a shortcut for `u.matches(predicate)`.
|
||||||
`u.matches(predicate)`.
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
function isEven(x) {
|
function isEven(x) {
|
||||||
@ -387,9 +407,8 @@ expect(result).to.eql({ value: 3 });
|
|||||||
|
|
||||||
### `u.omit(objectIn, keys)`
|
### `u.omit(objectIn, keys)`
|
||||||
|
|
||||||
Essentially the same as their Remeda counterparts. The difference being
|
Essentially the same as their Remeda counterparts. The difference being that if
|
||||||
that if the transformation results in no change, the original object/array is
|
the transformation results in no change, the original object/array is returned.
|
||||||
returned.
|
|
||||||
|
|
||||||
### `u.map(objectIn, updates)`
|
### `u.map(objectIn, updates)`
|
||||||
|
|
||||||
@ -405,13 +424,12 @@ Shorthand for `u.map( objectIn, u.ifElse(predicate,updates,updatesElse) )`.
|
|||||||
|
|
||||||
### `u.matches(dataIn, condition)`
|
### `u.matches(dataIn, condition)`
|
||||||
|
|
||||||
Do a deep comparison with `condition`, and returns
|
Do a deep comparison with `condition`, and returns `true` if the `dataIn` object
|
||||||
`true` if the `dataIn` object matches.
|
matches.
|
||||||
|
|
||||||
Scalar values are verified for equality (i.e., `{foo: 12}`
|
Scalar values are verified for equality (i.e., `{foo: 12}` will verify that the
|
||||||
will verify that the object has the prop `foo` set to `12`), and
|
object has the prop `foo` set to `12`), and functions are going to be invoked
|
||||||
functions are going to be invoked with the object value of the object and
|
with the object value of the object and expected to return `true` upon matching.
|
||||||
expected to return `true` upon matching.
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
u.matches(
|
u.matches(
|
||||||
|
16
package.json
16
package.json
@ -1,19 +1,19 @@
|
|||||||
{
|
{
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"name": "@yanick/updeep-remeda",
|
"name": "@yanick/updeep",
|
||||||
"version": "2.3.1",
|
"version": "2.3.1",
|
||||||
"description": "Easily update nested frozen objects and arrays in a declarative and immutable manner.",
|
"description": "Easily update nested frozen objects and arrays in a declarative and immutable manner.",
|
||||||
"homepage": "https://yanick.github.io/updeep-remeda",
|
"homepage": "https://github.com/yanick/updeep",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/yanick/updeep-remeda"
|
"url": "https://github.com/yanick/updeep"
|
||||||
},
|
},
|
||||||
"authors": [
|
"authors": [
|
||||||
"Aaron Jensen",
|
"Aaron Jensen",
|
||||||
"Yanick Champoux"
|
"Yanick Champoux"
|
||||||
],
|
],
|
||||||
"files": [
|
"files": [
|
||||||
"esm",
|
"dist",
|
||||||
"src"
|
"src"
|
||||||
],
|
],
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@ -23,16 +23,16 @@
|
|||||||
"declarative"
|
"declarative"
|
||||||
],
|
],
|
||||||
"source": "./src/index.ts",
|
"source": "./src/index.ts",
|
||||||
"types": "./esm/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"types": "./esm/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./esm/index.js"
|
"import": "./dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/yanick/updeep-remeda/issues"
|
"url": "https://github.com/yanick/updeep/issues"
|
||||||
},
|
},
|
||||||
"scripts": {},
|
"scripts": {},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
Loading…
Reference in New Issue
Block a user