Skip to content

Commit 68543e5

Browse files
committed
Merge in development state
2 parents ed5b3c0 + f5b764b commit 68543e5

14 files changed

+856
-208
lines changed

.mocharc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"extension": ["ts"],
3-
"require": "ts-node/register"
3+
"require": "ts-node/register",
4+
"use_strict": true
45
}

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
Copyright (c) 2022 Michael Federczuk
2+
Copyright (c) 2023 Michael Federczuk
33
SPDX-License-Identifier: CC-BY-SA-4.0
44
-->
55

@@ -11,6 +11,14 @@ All notable changes to this project will be documented in this file.
1111
The format is based on [**Keep a Changelog v1.0.0**](https://keepachangelog.com/en/1.0.0/),
1212
and this project adheres to [**Semantic Versioning v2.0.0**](https://semver.org/spec/v2.0.0.html).
1313

14+
## Unreleased ##
15+
16+
Minor internal improvements.
17+
18+
### Security ###
19+
20+
* Update dependencies
21+
1422
## [v2.0.0-indev02] - 2023-01-27 ##
1523

1624
[v2.0.0-indev02]: https://github.com/mfederczuk/deeptools/releases/v2.0.0-indev02

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44
"description": "A set of utility functions that recursively operate on objects",
55
"keywords": [
66
"deep",
7+
"clone",
78
"copy",
8-
"freeze"
9+
"freeze",
10+
"deepclone",
11+
"deepcopy",
12+
"deepequal",
13+
"deepequals",
14+
"deepfreeze"
915
],
1016
"homepage": "https://github.com/mfederczuk/deeptools#readme",
1117
"bugs": {
@@ -26,9 +32,6 @@
2632
],
2733
"main": "out/index.js",
2834
"types": "types/index.d.ts",
29-
"directories": {
30-
"lib": "out"
31-
},
3235
"repository": {
3336
"type": "git",
3437
"url": "https://github.com/mfederczuk/deeptools.git"
@@ -55,7 +58,7 @@
5558
"@types/node": "^18.11.18",
5659
"@typescript-eslint/eslint-plugin": "^5.49.0",
5760
"@typescript-eslint/parser": "^5.49.0",
58-
"eslint": "^8.32.0",
61+
"eslint": "^8.33.0",
5962
"mocha": "^10.2.0",
6063
"npm-check-updates": "^16.6.3",
6164
"ts-node": "^10.9.1",

src/_internal/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*
2-
* Copyright (c) 2022 Michael Federczuk
2+
* Copyright (c) 2023 Michael Federczuk
33
* SPDX-License-Identifier: GPL-3.0-or-later
44
*/
55

6-
import { GenericKey } from "../types";
6+
import type { GenericKey } from "../types";
77

88
export type NonEmptyArray<T> = ([T, ...T[]] | [...T[], T]);
99

src/deepCopy.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022 Michael Federczuk
2+
* Copyright (c) 2023 Michael Federczuk
33
* SPDX-License-Identifier: GPL-3.0-or-later
44
*/
55

@@ -82,7 +82,6 @@ const initCopy = (obj: NonNullable<object>): NonNullable<object> => {
8282

8383
return Object.create(obj);
8484
};
85-
8685
deepFreeze(initCopy);
8786

8887
/**
@@ -92,7 +91,7 @@ deepFreeze(initCopy);
9291
*
9392
* @returns A deep copy of **obj**.
9493
*/
95-
function deepCopy<T>(obj: T): T {
94+
export function deepCopy<T>(obj: T): T {
9695
if (!(canValueHaveProperties(obj))) {
9796
return obj;
9897
}
@@ -124,7 +123,4 @@ function deepCopy<T>(obj: T): T {
124123

125124
return (copy as T);
126125
}
127-
128126
deepFreeze(deepCopy);
129-
130-
export { deepCopy };

src/deepEquals.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
2-
* Copyright (c) 2022 Michael Federczuk
2+
* Copyright (c) 2023 Michael Federczuk
33
* SPDX-License-Identifier: GPL-3.0-or-later
44
*/
55

66
import { deepFreeze } from "./deepFreeze";
7-
import { GenericKey } from "./types";
7+
import type { GenericKey } from "./types";
88
import { canValueHaveProperties, getPropertyKeys } from "./_internal/utils";
99

1010
export type DeepEqualsOptions = {
@@ -25,7 +25,7 @@ export type DeepEqualsOptions = {
2525
*
2626
* @returns `true` if **obj1** and **obj2** are deeply equal, `false` if otherwise.
2727
*/
28-
function deepEquals(
28+
export function deepEquals(
2929
obj1: unknown,
3030
obj2: unknown,
3131
options?: Readonly<DeepEqualsOptions>,
@@ -88,7 +88,7 @@ function deepEquals(
8888
}
8989

9090
if ((obj1PropDescriptor.get !== obj2PropDescriptor.get) ||
91-
(obj1PropDescriptor.set !== obj2PropDescriptor.set)) {
91+
(obj1PropDescriptor.set !== obj2PropDescriptor.set)) {
9292

9393
return false;
9494
}
@@ -98,5 +98,3 @@ function deepEquals(
9898
}
9999

100100
deepFreeze(deepEquals);
101-
102-
export { deepEquals };

src/deepFreeze.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*
2-
* Copyright (c) 2022 Michael Federczuk
2+
* Copyright (c) 2023 Michael Federczuk
33
* SPDX-License-Identifier: GPL-3.0-or-later
44
*/
55

6-
import { GenericKey } from "./types";
6+
import type { GenericKey } from "./types";
77
import { canValueHaveProperties, getPropertyKeys } from "./_internal/utils";
88

99
const deepFreezeKeysOfObject = (obj: Record<GenericKey, unknown>, keys: readonly GenericKey[]) => {
@@ -15,7 +15,6 @@ const deepFreezeKeysOfObject = (obj: Record<GenericKey, unknown>, keys: readonly
1515
deepFreeze(descriptor.value);
1616
}
1717
};
18-
1918
deepFreeze(deepFreezeKeysOfObject);
2019

2120
const deepFreezePrototypeExcludingConstructor = (prototype: Record<GenericKey, unknown>) => {
@@ -24,7 +23,6 @@ const deepFreezePrototypeExcludingConstructor = (prototype: Record<GenericKey, u
2423

2524
deepFreezeKeysOfObject(prototype, keys);
2625
};
27-
2826
deepFreeze(deepFreezePrototypeExcludingConstructor);
2927

3028
// eslint-disable-next-line @typescript-eslint/ban-types
@@ -40,9 +38,9 @@ const deepFreezeFunctionWithPrototype = <F extends Function>(func: F): Readonly<
4038

4139
return Object.freeze(func);
4240
};
43-
4441
deepFreeze(deepFreezeFunctionWithPrototype);
4542

43+
4644
/**
4745
* Recursively freezes **arr** and all of its items & other properties.
4846
*

src/deepWalk.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
2-
* Copyright (c) 2022 Michael Federczuk
2+
* Copyright (c) 2023 Michael Federczuk
33
* SPDX-License-Identifier: GPL-3.0-or-later
44
*/
55

66
import { deepFreeze } from "./deepFreeze";
7-
import { GenericKey } from "./types";
7+
import type { GenericKey } from "./types";
88
import { canValueHaveProperties, getPropertyKeys, NonEmptyArray } from "./_internal/utils";
99

1010
export type KeyPath = NonEmptyArray<GenericKey>;
@@ -65,24 +65,22 @@ const deepWalkInternal = (
6565
}
6666
}
6767
};
68-
6968
deepFreeze(deepWalkInternal);
7069

7170
/**
7271
* Recursively walks through **obj**.
7372
*
73+
* ### This is an experimental function, use with caution. ###
74+
*
7475
* @param obj The object to walk through.
7576
* @param visitorFunc The visitor callback function to call on every property.
7677
* @param options Options object to change the behavior of `deepWalk`.
7778
*/
78-
function deepWalk(
79+
export function deepWalk(
7980
obj: unknown,
8081
visitorFunc: PropertyVisitorFunc,
8182
options?: Readonly<DeepWalkOptions>,
8283
) {
8384
return deepWalkInternal([], obj, visitorFunc, options, obj);
8485
}
85-
8686
deepFreeze(deepWalk);
87-
88-
export { deepWalk };

src/safeCopy.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import { deepFreeze } from "./deepFreeze";
1212
* @param arr The 3-dimensional array to create a deeply frozen copy of.
1313
*
1414
* @returns A deeply frozen copy of **arr**.
15+
*
16+
* @see {@link deepCopy}
17+
* @see {@link deepFreeze}
1518
*/
1619
function safeCopy<T>(arr: readonly (readonly (readonly T[])[])[]): readonly (readonly (readonly Readonly<T>[])[])[];
1720

@@ -21,6 +24,9 @@ function safeCopy<T>(arr: readonly (readonly (readonly T[])[])[]): readonly (rea
2124
* @param arr The 2-dimensional array to create a deeply frozen copy of.
2225
*
2326
* @returns A deeply frozen copy of **arr**.
27+
*
28+
* @see {@link deepCopy}
29+
* @see {@link deepFreeze}
2430
*/
2531
function safeCopy<T>(arr: readonly (readonly T[])[]): readonly (readonly Readonly<T>[])[];
2632

@@ -30,6 +36,9 @@ function safeCopy<T>(arr: readonly (readonly T[])[]): readonly (readonly Readonl
3036
* @param arr The 1-dimensional array to create a deeply frozen copy of.
3137
*
3238
* @returns A deeply frozen copy of **arr**.
39+
*
40+
* @see {@link deepCopy}
41+
* @see {@link deepFreeze}
3342
*/
3443
function safeCopy<T>(arr: readonly T[]): readonly Readonly<T>[];
3544

@@ -39,6 +48,9 @@ function safeCopy<T>(arr: readonly T[]): readonly Readonly<T>[];
3948
* @param obj The object to create a deeply frozen copy of.
4049
*
4150
* @returns A deeply frozen copy of **obj**.
51+
*
52+
* @see {@link deepCopy}
53+
* @see {@link deepFreeze}
4254
*/
4355
function safeCopy<T>(obj: T): Readonly<T>;
4456

0 commit comments

Comments
 (0)