Skip to content

Commit

Permalink
Upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Vovan-VE committed Dec 14, 2023
1 parent c21a7f9 commit c5b1bf7
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

npm test \
&& npx lint-staged \
&& npx tsdx lint
&& npm run lint
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 2.0.0 (2023-12-14)

- **BREAKING**: Drop Node < 18.
- **BREAKING**: Add `typescript` from 3 to 5 to optional `peerDependencies`.

## 1.2.0 (2023-12-14)

- Add: `updateDefault()` now allows different type for `default` value.
Expand Down
43 changes: 26 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cubux/readonly-map",
"version": "1.2.0",
"version": "2.0.0",
"description": "Functions to work with read-only maps",
"keywords": [
"map",
Expand Down Expand Up @@ -31,27 +31,36 @@
"README.md"
],
"engines": {
"node": ">=14"
"node": ">=18"
},
"scripts": {
"start": "tsdx watch",
"build": "tsdx build",
"test": "tsdx test",
"test:watch": "tsdx test --watch",
"test:coverage": "tsdx test --coverage",
"lint": "tsdx lint",
"prepare": "tsdx build",
"size": "size-limit",
"analyze": "size-limit --why"
"build": "dts build",
"start": "dts watch",
"prepare": "dts build",
"test": "tsc --noEmit && dts test --passWithNoTests",
"test:watch": "npm test -- --watch",
"test:coverage": "npm test -- --coverage",
"analyze": "size-limit --why",
"lint": "dts lint",
"size": "size-limit"
},
"peerDependencies": {
"typescript": "^3 || ^4 || ^5"
},
"peerDependenciesMeta": {
"typescript": {
"optional": true
}
},
"devDependencies": {
"@size-limit/preset-small-lib": "^7.0.8",
"@size-limit/preset-small-lib": "^11.0.0",
"@tsconfig/recommended": "^1.0.3",
"dts-cli": "^2.0.3",
"husky": "^8.0.1",
"lint-staged": "^13.0.2",
"size-limit": "^7.0.8",
"tsdx": "^0.14.1",
"tslib": "^2.4.0",
"typescript": "^3.9.10"
"lint-staged": "^15.2.0",
"size-limit": "^11.0.0",
"tslib": "^2.6.2",
"typescript": "~5.0"
},
"lint-staged": {
"src/**/*.{js,ts,json}": [
Expand Down
2 changes: 1 addition & 1 deletion src/deep/setDeep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function setDeepInner<T extends ReadonlyMap<any, any>>(
return map;
}

return (new Map(map).set(key, nextChild) as ReadonlyMap<any, any>) as T;
return new Map(map).set(key, nextChild) as ReadonlyMap<any, any> as T;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/fromArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function fromArray<T, K>(
array: readonly T[],
calcKey: (item: T) => K,
): ReadonlyMap<K, T> {
return new Map(array.map(item => [calcKey(item), item]));
return new Map(array.map((item) => [calcKey(item), item]));
}

export default fromArray;
2 changes: 1 addition & 1 deletion test/deep/setDeep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const orig = new Map([

const copyMap = <M extends ReadonlyMap<any, ReadonlyMap<any, any>>>(
map: M,
): M => mapFn(map, m => new Map(m)) as any;
): M => mapFn(map, (m) => new Map(m)) as any;

it('does not change original map', () => {
const prev = copyMap(orig);
Expand Down
6 changes: 3 additions & 3 deletions test/deep/updateDeep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const orig: ReadonlyMap<number, ReadonlyMap<number, string>> = new Map([

const copyMap = <M extends ReadonlyMap<any, ReadonlyMap<any, any>>>(
map: M,
): M => mapFn(map, m => new Map(m)) as any;
): M => mapFn(map, (m) => new Map(m)) as any;

it('does not change original map', () => {
const prev = copyMap(orig);

expect(updateDeep(prev, [97, 37], v => v + v)).toEqual(
expect(updateDeep(prev, [97, 37], (v) => v + v)).toEqual(
new Map([
[
97,
Expand All @@ -37,7 +37,7 @@ it('does not change original map', () => {
expect(prev).toEqual(orig);

expect(
updateDeep(prev, [97], m => setFn(setFn(m, 10, 'xx'), 20, 'zz')),
updateDeep(prev, [97], (m) => setFn(setFn(m, 10, 'xx'), 20, 'zz')),
).toEqual(
new Map([
[
Expand Down
10 changes: 5 additions & 5 deletions test/deep/updateDefaultDeep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ const orig: ReadonlyMap<number, ReadonlyMap<number, string>> = new Map([

const copyMap = <M extends ReadonlyMap<any, ReadonlyMap<any, any>>>(
map: M,
): M => mapFn(map, m => new Map(m)) as any;
): M => mapFn(map, (m) => new Map(m)) as any;

it('does not change original map', () => {
const prev = copyMap(orig);

expect(updateDefaultDeep(prev, [97, 47], '?', v => v + v)).toEqual(
expect(updateDefaultDeep(prev, [97, 47], '?', (v) => v + v)).toEqual(
new Map([
[
97,
Expand All @@ -40,7 +40,7 @@ it('does not change original map', () => {
it('will create new maps', () => {
const prev = copyMap(orig);

expect(updateDefaultDeep(prev, [91, 17], '?', v => v + 'q')).toEqual(
expect(updateDefaultDeep(prev, [91, 17], '?', (v) => v + 'q')).toEqual(
new Map([
[97, origA],
[41, origB],
Expand All @@ -55,8 +55,8 @@ it("does nothing when it's nothing to change", () => {

const noop = jest.fn((v: any) => v);
expect(updateDefaultDeep(prev, [97, 42], '?', noop)).toBe(prev);
expect(updateDefaultDeep(prev, [97, 42], null, v => v)).toBe(prev);
expect(updateDefaultDeep(prev, [97, 42], null, v => v ?? '')).toBe(prev);
expect(updateDefaultDeep(prev, [97, 42], null, (v) => v)).toBe(prev);
expect(updateDefaultDeep(prev, [97, 42], null, (v) => v ?? '')).toBe(prev);
expect(updateDefaultDeep(prev, [97], null as any, noop)).toBe(prev);
expect(noop).toHaveBeenCalledTimes(2);
expect(noop).toHaveBeenNthCalledWith(1, 'x');
Expand Down
2 changes: 1 addition & 1 deletion test/fromArray.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ it('creates map', () => {
{ id: 30, name: 'Lu Lu' },
];

expect(fromArray(array, v => v.id)).toEqual(
expect(fromArray(array, (v) => v.id)).toEqual(
new Map([
[10, { id: 10, name: 'John Random' }],
[20, { id: 20, name: 'Pupkin Vasily' }],
Expand Down
6 changes: 3 additions & 3 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ it('common', () => {
expect(M.fromArray([], Boolean)).toEqual(EMPTY);
expect(M.getOr(EMPTY, 42, DEF)).toBe(DEF);
expect(M.includes(EMPTY, 42)).toBeFalsy();
expect(M.map(EMPTY, v => v)).toBe(EMPTY);
expect(M.map(EMPTY, (v) => v)).toBe(EMPTY);
expect(M.merge(EMPTY, EMPTY, EMPTY)).toBe(EMPTY);
expect(M.reduce(EMPTY, () => null, DEF)).toBe(DEF);
expect(M.remove(EMPTY, 42)).toBe(EMPTY);
expect(M.set(EMPTY, 42, 37)).toEqual(new Map([[42, 37]]));
expect(M.some(EMPTY, Boolean)).toBeFalsy();
expect(M.update(EMPTY, 42, () => DEF)).toBe(EMPTY);
expect(M.updateDefault(new Map<number, any>(), 42, DEF, v => [v])).toEqual(
expect(M.updateDefault(new Map<number, any>(), 42, DEF, (v) => [v])).toEqual(
new Map([[42, [DEF]]]),
);

Expand All @@ -32,7 +32,7 @@ it('common', () => {
10: { 20: 42 },
});
expect(M.updateDeep(EMPTY, [10, 20], () => DEF)).toBe(EMPTY);
expect(M.updateDefaultDeep(EMPTY, [10, 20], DEF, v => [v] as any)).toEqual(
expect(M.updateDefaultDeep(EMPTY, [10, 20], DEF, (v) => [v] as any)).toEqual(
new Map([[10, new Map([[20, [DEF]]])]]),
);
});
4 changes: 2 additions & 2 deletions test/updateDefault.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ it("alternate 'default' type", () => {
[42, 'x'],
[37, 'y'],
]);
const next0 = updateDefault(orig, 42, 'def', v => v + '*');
const next0 = updateDefault(orig, 42, 'def', (v) => v + '*');
const expected0: ReadonlyMap<number, string> = next0;
expect(expected0.get(42)).toBe('x*');

const next1 = updateDefault(orig, 42, null, (v): string => (v ?? '') + '*');
const expected1: ReadonlyMap<number, string> = next1;
expect(expected1.get(42)).toBe('x*');

const next2 = updateDefault(orig, 42, false, v => v + '*');
const next2 = updateDefault(orig, 42, false, (v) => v + '*');
const expected2: ReadonlyMap<number, string> = next2;
expect(expected2.get(42)).toBe('x*');
});

0 comments on commit c5b1bf7

Please sign in to comment.