@oscarpalmer/atoms 0.125.0 → 0.126.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/atoms.full.js +89 -89
- package/dist/index.js +1 -1
- package/dist/value/index.js +1 -1
- package/package.json +1 -1
- package/src/beacon.ts +4 -1
- package/src/function.ts +4 -1
- package/src/internal/value/equal.ts +4 -1
- package/src/string/index.ts +1 -1
- package/src/string/template.ts +4 -1
- package/src/value/diff.ts +5 -2
- package/src/value/index.ts +3 -3
- package/src/value/merge.ts +1 -1
- package/types/beacon.d.ts +4 -1
- package/types/function.d.ts +4 -1
- package/types/internal/value/equal.d.ts +4 -1
- package/types/string/index.d.ts +1 -1
- package/types/string/template.d.ts +4 -1
- package/types/value/diff.d.ts +5 -2
- package/types/value/index.d.ts +3 -3
- package/types/value/merge.d.ts +1 -1
package/dist/atoms.full.js
CHANGED
|
@@ -1819,95 +1819,6 @@ function getEqualOptions(input) {
|
|
|
1819
1819
|
}
|
|
1820
1820
|
const ARRAY_PEEK_PERCENTAGE = 10;
|
|
1821
1821
|
const ARRAY_THRESHOLD = 100;
|
|
1822
|
-
function diff(first, second, options) {
|
|
1823
|
-
const relaxedNullish = typeof options === "object" && options?.relaxedNullish === true;
|
|
1824
|
-
const result = {
|
|
1825
|
-
original: {
|
|
1826
|
-
from: first,
|
|
1827
|
-
to: second
|
|
1828
|
-
},
|
|
1829
|
-
type: "partial",
|
|
1830
|
-
values: {}
|
|
1831
|
-
};
|
|
1832
|
-
const same = relaxedNullish && first == null && second == null || Object.is(first, second);
|
|
1833
|
-
const firstIsArrayOrObject = isArrayOrPlainObject(first);
|
|
1834
|
-
const secondIsArrayOrObject = isArrayOrPlainObject(second);
|
|
1835
|
-
if (same || !(firstIsArrayOrObject || secondIsArrayOrObject)) {
|
|
1836
|
-
result.type = same ? "none" : "full";
|
|
1837
|
-
return result;
|
|
1838
|
-
}
|
|
1839
|
-
if (firstIsArrayOrObject !== secondIsArrayOrObject) {
|
|
1840
|
-
result.type = "full";
|
|
1841
|
-
return result;
|
|
1842
|
-
}
|
|
1843
|
-
const diffs = getDiffs(first, second, relaxedNullish);
|
|
1844
|
-
const { length } = diffs;
|
|
1845
|
-
if (length === 0) result.type = "none";
|
|
1846
|
-
for (let index = 0; index < length; index += 1) {
|
|
1847
|
-
const differences = diffs[index];
|
|
1848
|
-
result.values[differences.key] = {
|
|
1849
|
-
from: differences.from,
|
|
1850
|
-
to: differences.to
|
|
1851
|
-
};
|
|
1852
|
-
}
|
|
1853
|
-
return result;
|
|
1854
|
-
}
|
|
1855
|
-
function getChanges(changes, first, second, relaxedNullish, prefix) {
|
|
1856
|
-
const checked = /* @__PURE__ */ new Set();
|
|
1857
|
-
for (let outerIndex = 0; outerIndex < 2; outerIndex += 1) {
|
|
1858
|
-
const value = (outerIndex === 0 ? first : second) ?? {};
|
|
1859
|
-
const keys = [...Object.keys(value), ...Object.getOwnPropertySymbols(value)];
|
|
1860
|
-
const { length } = keys;
|
|
1861
|
-
for (let innerIndex = 0; innerIndex < length; innerIndex += 1) {
|
|
1862
|
-
const key = keys[innerIndex];
|
|
1863
|
-
if (checked.has(key)) continue;
|
|
1864
|
-
checked.add(key);
|
|
1865
|
-
setChanges({
|
|
1866
|
-
changes,
|
|
1867
|
-
key,
|
|
1868
|
-
relaxedNullish,
|
|
1869
|
-
prefix,
|
|
1870
|
-
values: {
|
|
1871
|
-
first,
|
|
1872
|
-
second
|
|
1873
|
-
}
|
|
1874
|
-
});
|
|
1875
|
-
}
|
|
1876
|
-
}
|
|
1877
|
-
return changes;
|
|
1878
|
-
}
|
|
1879
|
-
function getDiffs(first, second, relaxedNullish, prefix) {
|
|
1880
|
-
const changes = [];
|
|
1881
|
-
if (Array.isArray(first) && Array.isArray(second)) {
|
|
1882
|
-
const maximumLength = Math.max(first.length, second.length);
|
|
1883
|
-
const minimumLength = Math.min(first.length, second.length);
|
|
1884
|
-
for (let index = minimumLength; index < maximumLength; index += 1) {
|
|
1885
|
-
const key = join([prefix, index], ".");
|
|
1886
|
-
changes.push({
|
|
1887
|
-
key,
|
|
1888
|
-
from: index >= first.length ? void 0 : first[index],
|
|
1889
|
-
to: index >= first.length ? second[index] : void 0
|
|
1890
|
-
});
|
|
1891
|
-
}
|
|
1892
|
-
}
|
|
1893
|
-
return getChanges(changes, first, second, relaxedNullish, prefix);
|
|
1894
|
-
}
|
|
1895
|
-
function setChanges(parameters) {
|
|
1896
|
-
const { changes, key, prefix, relaxedNullish, values } = parameters;
|
|
1897
|
-
const from = values.first?.[key];
|
|
1898
|
-
const to = values.second?.[key];
|
|
1899
|
-
if (equal(from, to, { relaxedNullish })) return;
|
|
1900
|
-
const prefixed = join([prefix, key], ".");
|
|
1901
|
-
const change = {
|
|
1902
|
-
from,
|
|
1903
|
-
to,
|
|
1904
|
-
key: prefixed
|
|
1905
|
-
};
|
|
1906
|
-
const diffs = isArrayOrPlainObject(from) || isArrayOrPlainObject(to) ? getDiffs(from, to, relaxedNullish, prefixed) : [];
|
|
1907
|
-
changes.push(change);
|
|
1908
|
-
const diffsLength = diffs.length;
|
|
1909
|
-
for (let diffIndex = 0; diffIndex < diffsLength; diffIndex += 1) changes.push(diffs[diffIndex]);
|
|
1910
|
-
}
|
|
1911
1822
|
function clone(value) {
|
|
1912
1823
|
return cloneValue(value, 0, /* @__PURE__ */ new WeakMap());
|
|
1913
1824
|
}
|
|
@@ -2003,6 +1914,95 @@ function tryStructuredClone(value, depth, references) {
|
|
|
2003
1914
|
}
|
|
2004
1915
|
}
|
|
2005
1916
|
const MAX_CLONE_DEPTH = 100;
|
|
1917
|
+
function diff(first, second, options) {
|
|
1918
|
+
const relaxedNullish = typeof options === "object" && options?.relaxedNullish === true;
|
|
1919
|
+
const result = {
|
|
1920
|
+
original: {
|
|
1921
|
+
from: first,
|
|
1922
|
+
to: second
|
|
1923
|
+
},
|
|
1924
|
+
type: "partial",
|
|
1925
|
+
values: {}
|
|
1926
|
+
};
|
|
1927
|
+
const same = relaxedNullish && first == null && second == null || Object.is(first, second);
|
|
1928
|
+
const firstIsArrayOrObject = isArrayOrPlainObject(first);
|
|
1929
|
+
const secondIsArrayOrObject = isArrayOrPlainObject(second);
|
|
1930
|
+
if (same || !(firstIsArrayOrObject || secondIsArrayOrObject)) {
|
|
1931
|
+
result.type = same ? "none" : "full";
|
|
1932
|
+
return result;
|
|
1933
|
+
}
|
|
1934
|
+
if (firstIsArrayOrObject !== secondIsArrayOrObject) {
|
|
1935
|
+
result.type = "full";
|
|
1936
|
+
return result;
|
|
1937
|
+
}
|
|
1938
|
+
const diffs = getDiffs(first, second, relaxedNullish);
|
|
1939
|
+
const { length } = diffs;
|
|
1940
|
+
if (length === 0) result.type = "none";
|
|
1941
|
+
for (let index = 0; index < length; index += 1) {
|
|
1942
|
+
const differences = diffs[index];
|
|
1943
|
+
result.values[differences.key] = {
|
|
1944
|
+
from: differences.from,
|
|
1945
|
+
to: differences.to
|
|
1946
|
+
};
|
|
1947
|
+
}
|
|
1948
|
+
return result;
|
|
1949
|
+
}
|
|
1950
|
+
function getChanges(changes, first, second, relaxedNullish, prefix) {
|
|
1951
|
+
const checked = /* @__PURE__ */ new Set();
|
|
1952
|
+
for (let outerIndex = 0; outerIndex < 2; outerIndex += 1) {
|
|
1953
|
+
const value = (outerIndex === 0 ? first : second) ?? {};
|
|
1954
|
+
const keys = [...Object.keys(value), ...Object.getOwnPropertySymbols(value)];
|
|
1955
|
+
const { length } = keys;
|
|
1956
|
+
for (let innerIndex = 0; innerIndex < length; innerIndex += 1) {
|
|
1957
|
+
const key = keys[innerIndex];
|
|
1958
|
+
if (checked.has(key)) continue;
|
|
1959
|
+
checked.add(key);
|
|
1960
|
+
setChanges({
|
|
1961
|
+
changes,
|
|
1962
|
+
key,
|
|
1963
|
+
relaxedNullish,
|
|
1964
|
+
prefix,
|
|
1965
|
+
values: {
|
|
1966
|
+
first,
|
|
1967
|
+
second
|
|
1968
|
+
}
|
|
1969
|
+
});
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
return changes;
|
|
1973
|
+
}
|
|
1974
|
+
function getDiffs(first, second, relaxedNullish, prefix) {
|
|
1975
|
+
const changes = [];
|
|
1976
|
+
if (Array.isArray(first) && Array.isArray(second)) {
|
|
1977
|
+
const maximumLength = Math.max(first.length, second.length);
|
|
1978
|
+
const minimumLength = Math.min(first.length, second.length);
|
|
1979
|
+
for (let index = minimumLength; index < maximumLength; index += 1) {
|
|
1980
|
+
const key = join([prefix, index], ".");
|
|
1981
|
+
changes.push({
|
|
1982
|
+
key,
|
|
1983
|
+
from: index >= first.length ? void 0 : first[index],
|
|
1984
|
+
to: index >= first.length ? second[index] : void 0
|
|
1985
|
+
});
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
return getChanges(changes, first, second, relaxedNullish, prefix);
|
|
1989
|
+
}
|
|
1990
|
+
function setChanges(parameters) {
|
|
1991
|
+
const { changes, key, prefix, relaxedNullish, values } = parameters;
|
|
1992
|
+
const from = values.first?.[key];
|
|
1993
|
+
const to = values.second?.[key];
|
|
1994
|
+
if (equal(from, to, { relaxedNullish })) return;
|
|
1995
|
+
const prefixed = join([prefix, key], ".");
|
|
1996
|
+
const change = {
|
|
1997
|
+
from,
|
|
1998
|
+
to,
|
|
1999
|
+
key: prefixed
|
|
2000
|
+
};
|
|
2001
|
+
const diffs = isArrayOrPlainObject(from) || isArrayOrPlainObject(to) ? getDiffs(from, to, relaxedNullish, prefixed) : [];
|
|
2002
|
+
changes.push(change);
|
|
2003
|
+
const diffsLength = diffs.length;
|
|
2004
|
+
for (let diffIndex = 0; diffIndex < diffsLength; diffIndex += 1) changes.push(diffs[diffIndex]);
|
|
2005
|
+
}
|
|
2006
2006
|
function getMergeOptions(options) {
|
|
2007
2007
|
const actual = {
|
|
2008
2008
|
replaceableObjects: void 0,
|
package/dist/index.js
CHANGED
|
@@ -46,8 +46,8 @@ import { getValue } from "./internal/value/get.js";
|
|
|
46
46
|
import { template } from "./string/template.js";
|
|
47
47
|
import "./string/index.js";
|
|
48
48
|
import { equal } from "./internal/value/equal.js";
|
|
49
|
-
import { diff } from "./value/diff.js";
|
|
50
49
|
import { clone } from "./value/clone.js";
|
|
50
|
+
import { diff } from "./value/diff.js";
|
|
51
51
|
import { merge } from "./value/merge.js";
|
|
52
52
|
import { partial } from "./value/partial.js";
|
|
53
53
|
import { smush } from "./value/smush.js";
|
package/dist/value/index.js
CHANGED
|
@@ -2,8 +2,8 @@ import { compare } from "../internal/value/compare.js";
|
|
|
2
2
|
import { setValue } from "../internal/value/set.js";
|
|
3
3
|
import { getValue } from "../internal/value/get.js";
|
|
4
4
|
import { equal } from "../internal/value/equal.js";
|
|
5
|
-
import { diff } from "./diff.js";
|
|
6
5
|
import { clone } from "./clone.js";
|
|
6
|
+
import { diff } from "./diff.js";
|
|
7
7
|
import { merge } from "./merge.js";
|
|
8
8
|
import { partial } from "./partial.js";
|
|
9
9
|
import { smush } from "./smush.js";
|
package/package.json
CHANGED
package/src/beacon.ts
CHANGED
|
@@ -99,6 +99,9 @@ class Beacon<Value> {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Options for Beacon
|
|
104
|
+
*/
|
|
102
105
|
type BeaconOptions<Value> = {
|
|
103
106
|
/**
|
|
104
107
|
* Method for comparing values for equality
|
|
@@ -321,4 +324,4 @@ const DESTROYED_BEACON = 'Cannot retrieve observable from a destroyed beacon';
|
|
|
321
324
|
|
|
322
325
|
const DESTROYED_OBSERVABLE = 'Cannot subscribe to a destroyed observable';
|
|
323
326
|
|
|
324
|
-
export type {Beacon, Observable, Observer, Subscription};
|
|
327
|
+
export type {Beacon, BeaconOptions, Observable, Observer, Subscription};
|
package/src/function.ts
CHANGED
|
@@ -108,6 +108,9 @@ class Memoized<Callback extends GenericCallback> {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Options for memoized functions
|
|
113
|
+
*/
|
|
111
114
|
type MemoizedOptions<Callback extends GenericCallback> = {
|
|
112
115
|
/**
|
|
113
116
|
* Callback for getting a cache key for the provided parameters
|
|
@@ -228,7 +231,7 @@ export function throttle<Callback extends GenericCallback>(
|
|
|
228
231
|
return getLimiter(callback, true, time);
|
|
229
232
|
}
|
|
230
233
|
|
|
231
|
-
export type {CancellableCallback, GenericCallback, Memoized};
|
|
234
|
+
export type {CancellableCallback, GenericCallback, Memoized, MemoizedOptions};
|
|
232
235
|
export {noop} from './internal/function';
|
|
233
236
|
|
|
234
237
|
//
|
|
@@ -2,7 +2,10 @@ import type {ArrayOrPlainObject, PlainObject, TypedArray} from '../../models';
|
|
|
2
2
|
import {chunk} from '../array/chunk';
|
|
3
3
|
import {isPlainObject, isTypedArray} from '../is';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Options for value equality comparison
|
|
7
|
+
*/
|
|
8
|
+
export type EqualOptions = {
|
|
6
9
|
/**
|
|
7
10
|
* When `true`, strings are compared case-insensitively
|
|
8
11
|
*/
|
package/src/string/index.ts
CHANGED
|
@@ -2,4 +2,4 @@ export {getString, join, words} from '../internal/string';
|
|
|
2
2
|
export type {PlainObject} from '../models';
|
|
3
3
|
export {camelCase, capitalize, kebabCase, pascalCase, snakeCase, titleCase} from './case';
|
|
4
4
|
export {createUuid, getUuid, parse, truncate} from './misc';
|
|
5
|
-
export {template} from './template';
|
|
5
|
+
export {template, type TemplateOptions} from './template';
|
package/src/string/template.ts
CHANGED
|
@@ -3,7 +3,10 @@ import {getValue} from '../internal/value/get';
|
|
|
3
3
|
import {isPlainObject} from '../is';
|
|
4
4
|
import type {PlainObject} from '../models';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Options for templating strings
|
|
8
|
+
*/
|
|
9
|
+
export type TemplateOptions = {
|
|
7
10
|
/**
|
|
8
11
|
* Ignore case when searching for variables?
|
|
9
12
|
*/
|
package/src/value/diff.ts
CHANGED
|
@@ -2,7 +2,10 @@ import {isArrayOrPlainObject} from '../internal/is';
|
|
|
2
2
|
import {join} from '../internal/string';
|
|
3
3
|
import {equal} from '../internal/value/equal';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Options for value comparison
|
|
7
|
+
*/
|
|
8
|
+
export type DiffOptions = {
|
|
6
9
|
/**
|
|
7
10
|
* Should `null` and `undefined` be considered equal and ignored in results?
|
|
8
11
|
*/
|
|
@@ -29,7 +32,7 @@ export type DiffResult<First, Second = First> = {
|
|
|
29
32
|
values: Record<string, DiffValue>;
|
|
30
33
|
};
|
|
31
34
|
|
|
32
|
-
|
|
35
|
+
type DiffType = 'full' | 'none' | 'partial';
|
|
33
36
|
|
|
34
37
|
/**
|
|
35
38
|
* The difference between two values
|
package/src/value/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export {compare} from '../internal/value/compare';
|
|
2
|
-
export {
|
|
3
|
-
export {equal} from '../internal/value/equal';
|
|
2
|
+
export {equal, type EqualOptions} from '../internal/value/equal';
|
|
4
3
|
export {getValue} from '../internal/value/get';
|
|
5
4
|
export {setValue} from '../internal/value/set';
|
|
6
5
|
export type {ArrayOrPlainObject, NestedPartial, PlainObject} from '../models';
|
|
7
6
|
export {clone} from './clone';
|
|
8
|
-
export {
|
|
7
|
+
export {diff, type DiffOptions, type DiffResult, type DiffValue} from './diff';
|
|
8
|
+
export {merge, type MergeOptions} from './merge';
|
|
9
9
|
export {partial} from './partial';
|
|
10
10
|
export {smush} from './smush';
|
|
11
11
|
export {unsmush} from './unsmush';
|
package/src/value/merge.ts
CHANGED
package/types/beacon.d.ts
CHANGED
|
@@ -34,6 +34,9 @@ declare class Beacon<Value> {
|
|
|
34
34
|
*/
|
|
35
35
|
finish(): void;
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Options for Beacon
|
|
39
|
+
*/
|
|
37
40
|
type BeaconOptions<Value> = {
|
|
38
41
|
/**
|
|
39
42
|
* Method for comparing values for equality
|
|
@@ -108,4 +111,4 @@ declare class Subscription<Value> {
|
|
|
108
111
|
* @returns Beacon instance
|
|
109
112
|
*/
|
|
110
113
|
export declare function beacon<Value>(value: Value, options?: BeaconOptions<Value>): Beacon<Value>;
|
|
111
|
-
export type { Beacon, Observable, Observer, Subscription };
|
|
114
|
+
export type { Beacon, BeaconOptions, Observable, Observer, Subscription };
|
package/types/function.d.ts
CHANGED
|
@@ -49,6 +49,9 @@ declare class Memoized<Callback extends GenericCallback> {
|
|
|
49
49
|
*/
|
|
50
50
|
run(...parameters: Parameters<Callback>): ReturnType<Callback>;
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Options for memoized functions
|
|
54
|
+
*/
|
|
52
55
|
type MemoizedOptions<Callback extends GenericCallback> = {
|
|
53
56
|
/**
|
|
54
57
|
* Callback for getting a cache key for the provided parameters
|
|
@@ -86,5 +89,5 @@ export declare function memoize<Callback extends GenericCallback>(callback: Call
|
|
|
86
89
|
* @returns Throttled callback with a `cancel` method
|
|
87
90
|
*/
|
|
88
91
|
export declare function throttle<Callback extends GenericCallback>(callback: Callback, time?: number): CancellableCallback<Callback>;
|
|
89
|
-
export type { CancellableCallback, GenericCallback, Memoized };
|
|
92
|
+
export type { CancellableCallback, GenericCallback, Memoized, MemoizedOptions };
|
|
90
93
|
export { noop } from './internal/function';
|
package/types/string/index.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export { getString, join, words } from '../internal/string';
|
|
|
2
2
|
export type { PlainObject } from '../models';
|
|
3
3
|
export { camelCase, capitalize, kebabCase, pascalCase, snakeCase, titleCase } from './case';
|
|
4
4
|
export { createUuid, getUuid, parse, truncate } from './misc';
|
|
5
|
-
export { template } from './template';
|
|
5
|
+
export { template, type TemplateOptions } from './template';
|
package/types/value/diff.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Options for value comparison
|
|
3
|
+
*/
|
|
4
|
+
export type DiffOptions = {
|
|
2
5
|
/**
|
|
3
6
|
* Should `null` and `undefined` be considered equal and ignored in results?
|
|
4
7
|
*/
|
|
@@ -23,7 +26,7 @@ export type DiffResult<First, Second = First> = {
|
|
|
23
26
|
*/
|
|
24
27
|
values: Record<string, DiffValue>;
|
|
25
28
|
};
|
|
26
|
-
|
|
29
|
+
type DiffType = 'full' | 'none' | 'partial';
|
|
27
30
|
/**
|
|
28
31
|
* The difference between two values
|
|
29
32
|
*/
|
package/types/value/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { compare } from '../internal/value/compare';
|
|
2
|
-
export {
|
|
3
|
-
export { equal } from '../internal/value/equal';
|
|
2
|
+
export { equal, type EqualOptions } from '../internal/value/equal';
|
|
4
3
|
export { getValue } from '../internal/value/get';
|
|
5
4
|
export { setValue } from '../internal/value/set';
|
|
6
5
|
export type { ArrayOrPlainObject, NestedPartial, PlainObject } from '../models';
|
|
7
6
|
export { clone } from './clone';
|
|
8
|
-
export {
|
|
7
|
+
export { diff, type DiffOptions, type DiffResult, type DiffValue } from './diff';
|
|
8
|
+
export { merge, type MergeOptions } from './merge';
|
|
9
9
|
export { partial } from './partial';
|
|
10
10
|
export { smush } from './smush';
|
|
11
11
|
export { unsmush } from './unsmush';
|
package/types/value/merge.d.ts
CHANGED