Skip to content

Commit 49f8e16

Browse files
committed
Using klona for object cloning.
1 parent fe004e7 commit 49f8e16

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"eslint-config-prettier": "^8.10.0",
101101
"eslint-plugin-dci-lint": "^0.3.1",
102102
"eslint-plugin-svelte": "^2.35.1",
103+
"klona": "^2.0.6",
103104
"prettier": "^2.8.8",
104105
"prettier-plugin-svelte": "^2.10.1",
105106
"publint": "^0.1.16",

pnpm-lock.yaml

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

src/lib/utils.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
import { parse, stringify } from 'devalue';
1+
import { klona } from 'klona';
22

33
// Thanks to: https://dev.to/tylim88/typescript-numeric-range-type-15a5#comment-22mld
44
export type NumericRange<
5-
START extends number,
6-
END extends number,
7-
ARR extends unknown[] = [],
8-
ACC extends number = never
5+
START extends number,
6+
END extends number,
7+
ARR extends unknown[] = [],
8+
ACC extends number = never
99
> = ARR['length'] extends END
10-
? ACC | START | END
11-
: NumericRange<START, END, [...ARR, 1], ARR[START] extends undefined ? ACC : ACC | ARR['length']>
10+
? ACC | START | END
11+
: NumericRange<
12+
START,
13+
END,
14+
[...ARR, 1],
15+
ARR[START] extends undefined ? ACC : ACC | ARR['length']
16+
>;
1217

1318
export function clone<T>(data: T): T {
14-
if ('structuredClone' in globalThis) {
15-
return structuredClone(data);
16-
}
17-
return parse(stringify(data));
19+
return klona(data);
1820
}

0 commit comments

Comments
 (0)