Merge branch 'remeda-update'

This commit is contained in:
Yanick Champoux 2025-01-29 17:20:40 -05:00
commit fca80060d6
10 changed files with 36 additions and 18 deletions

View File

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

View File

@ -36,7 +36,7 @@
},
"scripts": {},
"dependencies": {
"remeda": "^1.3.0"
"remeda": "^2.20.0"
},
"devDependencies": {
"@changesets/cli": "^2.27.1",

View File

@ -6,8 +6,8 @@ import wrap from "./wrap.js";
const sizeOf = (obj) => obj.length;
function filter(dataIn, predicate) {
const result = _filter.indexed(dataIn, buildPredicate(predicate));
const result = _filter(dataIn, buildPredicate(predicate));
return sizeOf(result) === sizeOf(dataIn) ? dataIn : result;
}
export default wrap(filter) as typeof _filter.indexed;
export default wrap(filter) as typeof _filter;

View File

@ -1,8 +1,8 @@
import { identity } from "remeda";
import ifElse from "./ifElse.js";
import wrap from "./wrap.js";
const identity = (x: unknown) => x;
export interface If {
(object, predicate, trueUpdates): unknown;
(predicate, trueUpdates): (unknown) => unknown;

View File

@ -13,7 +13,7 @@ function shallowEqual(object, otherObject) {
function map(object, iteratee) {
const updater = typeof iteratee === "function" ? iteratee : update(iteratee);
const mapper = Array.isArray(object) ? _map.indexed : mapValues;
const mapper: any = Array.isArray(object) ? _map : mapValues;
const newObject = mapper(object, updater);
const equal = shallowEqual(object, newObject);

View File

@ -18,6 +18,6 @@ it("freezes the result", () => {
it("doesn't change the obj if nothing is modified", () => {
const orig = { a: 1 };
const result = pick<any, string>(["a"])(orig);
const result = pick(["a"])(orig);
expect(result).to.be.equal(orig);
});

View File

@ -4,9 +4,19 @@ import wrap from "./wrap.js";
const sizeOf = (obj) => Object.keys(obj).length;
export interface UPick {
<S extends string | number | symbol>(
keys: S[]
): <O>(dataIn: O) => Pick<O, S & keyof O>;
<S extends string | number | symbol, O>(
dataIn: O,
keys: S[]
): Pick<O, S & keyof O>;
}
function pick(dataIn, keys) {
const result = _pick(dataIn, keys);
return sizeOf(result) === sizeOf(dataIn) ? dataIn : result;
}
export default wrap(pick) as typeof _pick;
export default wrap(pick) as UPick;

View File

@ -1,20 +1,22 @@
import { expect, it } from "vitest";
import { expect, test } from "vitest";
import reject from "./reject.js";
import u from "./index.js";
it("can reject", () => {
const result = u({ foo: reject((v, k) => k === 1) })({
test("can reject", () => {
const result = u({
foo: reject((_, k) => k === 1),
})({
foo: ["a", "b"],
});
expect(result).to.eql({ foo: ["a"] });
});
it("freezes the result", () => {
test("freezes the result", () => {
expect(Object.isFrozen(reject([1], () => true))).to.be.true;
});
it("doesn't change the obj if nothing is modified", () => {
test("doesn't change the obj if nothing is modified", () => {
const orig = [1, 2, 3];
const result = reject(() => false)(orig);
expect(result).to.be.equal(orig);

View File

@ -1,4 +1,4 @@
import { reject as _reject } from "remeda";
import { filter } from "remeda";
import { buildPredicate } from "./predicate.js";
import wrap from "./wrap.js";
@ -6,8 +6,9 @@ import wrap from "./wrap.js";
const sizeOf = (obj) => obj.length;
function reject(dataIn, predicate) {
const result = _reject.indexed(dataIn, buildPredicate(predicate));
const pred = buildPredicate(predicate);
const result = filter(dataIn, (...args) => !pred(...args));
return sizeOf(result) === sizeOf(dataIn) ? dataIn : result;
}
export default wrap(reject) as typeof _reject.indexed;
export default wrap(reject) as typeof filter;

View File

@ -2,7 +2,7 @@ import wrap from "./wrap.js";
import constant from "./constant.js";
import * as R from "remeda";
import { omitBy, isObject, merge } from "remeda";
import { omitBy, merge } from "remeda";
const innerOmitted = { __skip: true };
export const skip = constant(innerOmitted);
@ -78,7 +78,7 @@ function update(object, updates) {
return updates(object);
}
if (Array.isArray(object) && R.equals(object, updates)) return object;
if (Array.isArray(object) && R.isDeepEqual(object, updates)) return object;
if (!isPlainObject(updates)) {
return updates;