Merge branch 'renaming'

This commit is contained in:
Yanick Champoux 2025-01-31 12:47:59 -05:00
commit 629da53bef
6 changed files with 73 additions and 50 deletions

View File

@ -0,0 +1,5 @@
---
"@yanick/updeep": minor
---
rename module as @yanick/updeep

View File

@ -1,5 +1,5 @@
---
"@yanick/updeep-remeda": minor
"@yanick/updeep": minor
---
update Remeda dependency

View File

@ -1,5 +1,5 @@
---
"@yanick/updeep-remeda": patch
"@yanick/updeep": patch
---
upgrade all dependencies

View File

@ -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

View File

@ -1,11 +1,14 @@
# updeep-remeda
# @yanick/updeep
> Easily update nested frozen objects and arrays in a declarative and immutable
> manner.
## 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
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
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
- Under the hood, the use of lodash has
been replaced by Remeda (for better type support and tree-shaking abilities).
- Under the hood, the use of lodash has been replaced by Remeda (for better type
support and tree-shaking abilities).
- 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
// original updeep
@ -35,7 +41,7 @@ const dataIn = { a: 1, b: 2 };
let dataOut = u({ c: 3 }, dataIn); // simple call
dataOut = u({ c: 3 })(dataIn); // curried
// updeep-remeda
// @yanick/updeep
dataOut = u(dataIn, { c: 3 }); // simple call
dataOut = u({ c: 3 })(dataIn); // curried
```
@ -48,15 +54,15 @@ dataOut = u({ c: 3 })(dataIn); // curried
## Installation
```bash
$ npm install @yanick/updeep-remeda
$ npm install @yanick/updeep
# or
$ pnpm install @yanick/updeep-remeda
$ pnpm install @yanick/updeep
```
## Full example
```js
import u from "@yanick/updeep-remeda";
import u from "@yanick/updeep";
const person = {
name: { first: "Bill", last: "Sagat" },
@ -101,15 +107,17 @@ const newPerson = u(person, {
## 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
`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.
```
import u from '@yanick/updeep-remeda';
import u from '@yanick/updeep';
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:
```
import { updateIn, omit } from '@yanick/updeep-remeda';
import { updateIn, omit } from '@yanick/updeep';
```
### `u(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.
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(...)`.
@ -205,7 +219,10 @@ expect(result).to.eql({ scores: { team1: 0, team2: 1 } });
#### 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
function addTodo(todos) {
@ -223,8 +240,8 @@ expect(result).to.eql({
});
```
Remeda is one of the many libraries providing good utility functions for
such manipulations.
Remeda is one of the many libraries providing good utility functions for such
manipulations.
```js
import { reject, concat, prop } from "remeda";
@ -266,7 +283,9 @@ expect(result).to.eql({ name: "Shannon Barnes", age: 63 });
### `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
const state = u.freeze({ someKey: "Some Value" });
@ -275,7 +294,9 @@ state.someKey = "Mutate"; // ERROR in development
### `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
const result = u.updateIn(
@ -328,9 +349,9 @@ expect(result).to.eql({
### `u.constant(dataIn)`
Sometimes, you want to replace an object outright rather than merging it.
You'll need to use a function that returns the new object.
`u.constant` creates that function for you.
Sometimes, you want to replace an object outright rather than merging it. You'll
need to use a function that returns the new object. `u.constant` creates that
function for you.
```js
const user = {
@ -357,10 +378,9 @@ expect(alwaysFour(32)).to.eql(4);
### `u.if(dataIn, predicate, updates)`
Apply `updates` if `predicate` evaluates to true. The `predicate` can
be a boolean, or a function taking in `dataIn` and returning a boolean,
or an object, in which case it'll be treated as a shortcut for
`u.matches(predicate)`.
Apply `updates` if `predicate` evaluates to true. The `predicate` can be a
boolean, or a function taking in `dataIn` and returning a boolean, or an object,
in which case it'll be treated as a shortcut for `u.matches(predicate)`.
```js
function isEven(x) {
@ -387,9 +407,8 @@ expect(result).to.eql({ value: 3 });
### `u.omit(objectIn, keys)`
Essentially the same as their Remeda counterparts. The difference being
that if the transformation results in no change, the original object/array is
returned.
Essentially the same as their Remeda counterparts. The difference being that if
the transformation results in no change, the original object/array is returned.
### `u.map(objectIn, updates)`
@ -405,13 +424,12 @@ Shorthand for `u.map( objectIn, u.ifElse(predicate,updates,updatesElse) )`.
### `u.matches(dataIn, condition)`
Do a deep comparison with `condition`, and returns
`true` if the `dataIn` object matches.
Do a deep comparison with `condition`, and returns `true` if the `dataIn` object
matches.
Scalar values are verified for equality (i.e., `{foo: 12}`
will verify that the object has the prop `foo` set to `12`), and
functions are going to be invoked with the object value of the object and
expected to return `true` upon matching.
Scalar values are verified for equality (i.e., `{foo: 12}` will verify that the
object has the prop `foo` set to `12`), and functions are going to be invoked
with the object value of the object and expected to return `true` upon matching.
```js
u.matches(

View File

@ -1,19 +1,19 @@
{
"type": "module",
"name": "@yanick/updeep-remeda",
"name": "@yanick/updeep",
"version": "2.3.1",
"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": {
"type": "git",
"url": "https://github.com/yanick/updeep-remeda"
"url": "https://github.com/yanick/updeep"
},
"authors": [
"Aaron Jensen",
"Yanick Champoux"
],
"files": [
"esm",
"dist",
"src"
],
"keywords": [
@ -23,16 +23,16 @@
"declarative"
],
"source": "./src/index.ts",
"types": "./esm/index.d.ts",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./esm/index.d.ts",
"import": "./esm/index.js"
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
}
},
"license": "MIT",
"bugs": {
"url": "https://github.com/yanick/updeep-remeda/issues"
"url": "https://github.com/yanick/updeep/issues"
},
"scripts": {},
"dependencies": {