@oscarpalmer/atoms 0.192.0 → 0.193.1
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/index.d.mts +25 -23
- package/dist/index.mjs +30 -31
- package/dist/queue.d.mts +25 -23
- package/dist/queue.mjs +27 -28
- package/package.json +3 -4
- package/src/array/difference.ts +0 -73
- package/src/array/exists.ts +0 -93
- package/src/array/filter.ts +0 -182
- package/src/array/find.ts +0 -183
- package/src/array/first.ts +0 -196
- package/src/array/flatten.ts +0 -20
- package/src/array/from.ts +0 -129
- package/src/array/get.ts +0 -131
- package/src/array/group-by.ts +0 -369
- package/src/array/index.ts +0 -26
- package/src/array/insert.ts +0 -52
- package/src/array/intersection.ts +0 -72
- package/src/array/last.ts +0 -194
- package/src/array/match.ts +0 -436
- package/src/array/move.ts +0 -315
- package/src/array/partition.ts +0 -91
- package/src/array/push.ts +0 -23
- package/src/array/reverse.ts +0 -33
- package/src/array/select.ts +0 -260
- package/src/array/single.ts +0 -93
- package/src/array/slice.ts +0 -335
- package/src/array/sort.ts +0 -607
- package/src/array/splice.ts +0 -106
- package/src/array/swap.ts +0 -322
- package/src/array/to-map.ts +0 -371
- package/src/array/to-record.ts +0 -351
- package/src/array/to-set.ts +0 -80
- package/src/array/toggle.ts +0 -79
- package/src/array/union.ts +0 -72
- package/src/array/unique.ts +0 -67
- package/src/array/update.ts +0 -75
- package/src/beacon.ts +0 -378
- package/src/color/constants.ts +0 -137
- package/src/color/index.ts +0 -83
- package/src/color/instance.ts +0 -162
- package/src/color/misc/alpha.ts +0 -56
- package/src/color/misc/format.ts +0 -29
- package/src/color/misc/get.ts +0 -210
- package/src/color/misc/is.ts +0 -221
- package/src/color/misc/state.ts +0 -243
- package/src/color/models.ts +0 -389
- package/src/color/space/hex.ts +0 -184
- package/src/color/space/hsl.ts +0 -174
- package/src/color/space/hwb.ts +0 -153
- package/src/color/space/rgb.ts +0 -240
- package/src/function/assert.ts +0 -174
- package/src/function/index.ts +0 -2
- package/src/function/limit.ts +0 -83
- package/src/function/memoize.ts +0 -202
- package/src/function/once.ts +0 -200
- package/src/function/retry.ts +0 -175
- package/src/function/work.ts +0 -1007
- package/src/herald.ts +0 -216
- package/src/index.ts +0 -68
- package/src/internal/array/callbacks.ts +0 -46
- package/src/internal/array/chunk.ts +0 -51
- package/src/internal/array/compact.ts +0 -56
- package/src/internal/array/find.ts +0 -200
- package/src/internal/array/group.ts +0 -42
- package/src/internal/array/index-of.ts +0 -182
- package/src/internal/array/insert.ts +0 -80
- package/src/internal/array/overlap.ts +0 -35
- package/src/internal/array/sets.ts +0 -74
- package/src/internal/array/shuffle.ts +0 -33
- package/src/internal/array/update.ts +0 -52
- package/src/internal/function/misc.ts +0 -8
- package/src/internal/function/timer.ts +0 -168
- package/src/internal/is.ts +0 -244
- package/src/internal/math/aggregate.ts +0 -164
- package/src/internal/math/misc.ts +0 -28
- package/src/internal/number.ts +0 -129
- package/src/internal/random.ts +0 -49
- package/src/internal/result.ts +0 -92
- package/src/internal/sized.ts +0 -25
- package/src/internal/string.ts +0 -128
- package/src/internal/subscription.ts +0 -264
- package/src/internal/value/compare.ts +0 -170
- package/src/internal/value/equal.ts +0 -465
- package/src/internal/value/get.ts +0 -57
- package/src/internal/value/handlers.ts +0 -95
- package/src/internal/value/has.ts +0 -118
- package/src/internal/value/misc.ts +0 -125
- package/src/internal/value/partial.ts +0 -46
- package/src/internal/value/set.ts +0 -132
- package/src/is.ts +0 -182
- package/src/logger.ts +0 -230
- package/src/math.ts +0 -281
- package/src/models.ts +0 -286
- package/src/number.ts +0 -1
- package/src/promise/delay.ts +0 -62
- package/src/promise/helpers.ts +0 -96
- package/src/promise/index.ts +0 -300
- package/src/promise/misc.ts +0 -96
- package/src/promise/models.ts +0 -195
- package/src/promise/timed.ts +0 -91
- package/src/query.ts +0 -147
- package/src/queue.ts +0 -814
- package/src/random.ts +0 -125
- package/src/result/index.ts +0 -105
- package/src/result/match.ts +0 -124
- package/src/result/misc.ts +0 -129
- package/src/result/models.ts +0 -83
- package/src/result/work/flow.ts +0 -488
- package/src/result/work/pipe.ts +0 -496
- package/src/sized/map.ts +0 -110
- package/src/sized/set.ts +0 -107
- package/src/string/case.ts +0 -236
- package/src/string/fuzzy.ts +0 -444
- package/src/string/index.ts +0 -199
- package/src/string/match.ts +0 -80
- package/src/string/normalize.ts +0 -205
- package/src/string/template.ts +0 -161
- package/src/value/clone.ts +0 -319
- package/src/value/collection.ts +0 -63
- package/src/value/diff.ts +0 -232
- package/src/value/freeze.ts +0 -322
- package/src/value/handle.ts +0 -3
- package/src/value/index.ts +0 -5
- package/src/value/merge.ts +0 -278
- package/src/value/omit.ts +0 -20
- package/src/value/pick.ts +0 -20
- package/src/value/shake.ts +0 -45
- package/src/value/smush.ts +0 -89
- package/src/value/transform.ts +0 -153
- package/src/value/unsmush.ts +0 -84
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import type {NestedKeys, NestedValue, PlainObject, ToString} from '../../models';
|
|
2
|
-
import type {Result} from '../../result/models';
|
|
3
|
-
import {getNestedValue} from './misc';
|
|
4
|
-
|
|
5
|
-
// #region Functions
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Check if a property is defined in an object
|
|
9
|
-
*
|
|
10
|
-
* @param data Object to check in
|
|
11
|
-
* @param path Path for property, e.g., `foo.bar.baz`
|
|
12
|
-
* @returns `true` if the property exists, otherwise `false`
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* const data = {foo: {bar: {baz: 42}}};
|
|
17
|
-
*
|
|
18
|
-
* hasValue(data, 'foo'); // => true
|
|
19
|
-
* hasValue(data, 'foo.bar'); // => true
|
|
20
|
-
* hasValue(data, 'foo.bar.baz'); // => true
|
|
21
|
-
* hasValue(data, 'foo.nope'); // => false
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export function hasValue<Data extends PlainObject, Path extends NestedKeys<Data>>(
|
|
25
|
-
data: Data,
|
|
26
|
-
path: Path,
|
|
27
|
-
): boolean;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Check if a property is defined in an object
|
|
31
|
-
*
|
|
32
|
-
* @param data Object to check in
|
|
33
|
-
* @param path Path for property, e.g., `foo.bar.baz`
|
|
34
|
-
* @param ignoreCase If `true`, the path matching is case-insensitive
|
|
35
|
-
* @returns `true` if the property exists, otherwise `false`
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```typescript
|
|
39
|
-
* const data = {foo: {bar: {baz: 42}}};
|
|
40
|
-
*
|
|
41
|
-
* hasValue(data, 'foo'); // => true
|
|
42
|
-
* hasValue(data, 'foo.bar'); // => true
|
|
43
|
-
* hasValue(data, 'Foo.Bar.Baz', true); // => true
|
|
44
|
-
* hasValue(data, 'foo.nope'); // => false
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
export function hasValue<Data extends PlainObject>(
|
|
48
|
-
data: Data,
|
|
49
|
-
path: string,
|
|
50
|
-
ignoreCase?: boolean,
|
|
51
|
-
): boolean;
|
|
52
|
-
|
|
53
|
-
export function hasValue(data: PlainObject, path: string, ignoreCase?: boolean): boolean {
|
|
54
|
-
return getNestedValue(data, path, ignoreCase === true).ok;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
hasValue.get = hasValueResult;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Check if a property is defined in an object, and get its value if it is
|
|
61
|
-
*
|
|
62
|
-
* _Available as `hasValueResult` and `hasValue.get`_
|
|
63
|
-
*
|
|
64
|
-
* @param data Object to check in
|
|
65
|
-
* @param path Path for property, e.g., `foo.bar.baz`
|
|
66
|
-
* @param ignoreCase If `true`, the path matching is case-insensitive
|
|
67
|
-
* @returns Result object
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```typescript
|
|
71
|
-
* const data = {foo: {bar: {baz: 42}}};
|
|
72
|
-
*
|
|
73
|
-
* hasValueResult(data, 'foo'); // => {ok: true, value: {bar: {baz: 42}}}
|
|
74
|
-
* hasValueResult(data, 'foo.bar'); // => {ok: true, value: {baz: 42}}
|
|
75
|
-
* hasValueResult(data, 'foo.bar.baz'); // => {ok: true, value: 42}
|
|
76
|
-
* hasValueResult(data, 'foo.nope'); // => {ok: false, error: 'Expected property to exist in object'}
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
|
-
export function hasValueResult<Data extends PlainObject, Path extends NestedKeys<Data>>(
|
|
80
|
-
data: Data,
|
|
81
|
-
path: Path,
|
|
82
|
-
): Result<NestedValue<Data, ToString<Path>>, string>;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Check if a property is defined in an object, and get its value if it is
|
|
86
|
-
*
|
|
87
|
-
* _Available as `hasValueResult` and `hasValue.get`_
|
|
88
|
-
*
|
|
89
|
-
* @param data Object to check in
|
|
90
|
-
* @param path Path for property, e.g., `foo.bar.baz`
|
|
91
|
-
* @param ignoreCase If `true`, the path matching is case-insensitive
|
|
92
|
-
* @returns Result object
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```typescript
|
|
96
|
-
* const data = {foo: {bar: {baz: 42}}};
|
|
97
|
-
*
|
|
98
|
-
* hasValueResult(data, 'foo'); // => {ok: true, value: {bar: {baz: 42}}}
|
|
99
|
-
* hasValueResult(data, 'foo.bar'); // => {ok: true, value: {baz: 42}}
|
|
100
|
-
* hasValueResult(data, 'Foo.Bar.Baz', true); // => {ok: true, value: 42}
|
|
101
|
-
* hasValueResult(data, 'foo.nope'); // => {ok: false, error: 'Expected property to exist in object'}
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
export function hasValueResult<Data extends PlainObject>(
|
|
105
|
-
data: Data,
|
|
106
|
-
path: string,
|
|
107
|
-
ignoreCase?: boolean,
|
|
108
|
-
): Result<unknown, string>;
|
|
109
|
-
|
|
110
|
-
export function hasValueResult(
|
|
111
|
-
data: PlainObject,
|
|
112
|
-
path: string,
|
|
113
|
-
ignoreCase?: boolean,
|
|
114
|
-
): Result<unknown, string> {
|
|
115
|
-
return getNestedValue(data, path, ignoreCase === true);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// #endregion
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import type {PlainObject} from '../../models';
|
|
2
|
-
import {error, ok} from '../../result/misc';
|
|
3
|
-
import type {Result} from '../../result/models';
|
|
4
|
-
import {ignoreKey} from '../string';
|
|
5
|
-
|
|
6
|
-
// #region Functions
|
|
7
|
-
|
|
8
|
-
export function findKey(needle: string, haystack: object): string {
|
|
9
|
-
const keys = Object.keys(haystack);
|
|
10
|
-
const normalized = keys.map(key => key.toLowerCase());
|
|
11
|
-
const index = normalized.indexOf(needle.toLowerCase());
|
|
12
|
-
|
|
13
|
-
return index > -1 ? keys[index] : needle;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function getNestedValue(
|
|
17
|
-
data: object,
|
|
18
|
-
path: string,
|
|
19
|
-
ignoreCase: boolean,
|
|
20
|
-
): Result<unknown, string> {
|
|
21
|
-
if (typeof data !== 'object' || data === null) {
|
|
22
|
-
return error(NESTED_MESSAGE_INPUT);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (typeof path !== 'string' || path.trim().length === 0) {
|
|
26
|
-
return error(NESTED_MESSAGE_PATH);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const shouldIgnoreCase = ignoreCase === true;
|
|
30
|
-
const paths = getPaths(path, shouldIgnoreCase);
|
|
31
|
-
|
|
32
|
-
if (typeof paths === 'string') {
|
|
33
|
-
return handleValue(data, paths, null, true, shouldIgnoreCase);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const {length} = paths;
|
|
37
|
-
|
|
38
|
-
let current = data;
|
|
39
|
-
|
|
40
|
-
for (let index = 0; index < length; index += 1) {
|
|
41
|
-
const part = paths[index];
|
|
42
|
-
|
|
43
|
-
const handled = handleValue(current, part, null, true, shouldIgnoreCase);
|
|
44
|
-
|
|
45
|
-
if (!handled.ok) {
|
|
46
|
-
return handled;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
current = handled.value as object;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return ok(current);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function getPaths(path: string, lowercase: boolean): string | string[] {
|
|
56
|
-
const normalized = lowercase ? path.toLowerCase() : path;
|
|
57
|
-
|
|
58
|
-
if (!EXPRESSION_NESTED.test(normalized)) {
|
|
59
|
-
return normalized;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return normalized.replace(EXPRESSION_BRACKET, '.$1').replace(EXPRESSION_DOTS, '').split('.');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function handleValue(
|
|
66
|
-
data: object,
|
|
67
|
-
path: string,
|
|
68
|
-
value: unknown,
|
|
69
|
-
get: true,
|
|
70
|
-
ignoreCase: boolean,
|
|
71
|
-
): Result<unknown, string>;
|
|
72
|
-
|
|
73
|
-
export function handleValue(
|
|
74
|
-
data: object,
|
|
75
|
-
path: string,
|
|
76
|
-
value: unknown,
|
|
77
|
-
get: false,
|
|
78
|
-
ignoreCase: boolean,
|
|
79
|
-
): void;
|
|
80
|
-
|
|
81
|
-
export function handleValue(
|
|
82
|
-
data: object,
|
|
83
|
-
path: string,
|
|
84
|
-
value: unknown,
|
|
85
|
-
get: boolean,
|
|
86
|
-
ignoreCase: boolean,
|
|
87
|
-
): Result<unknown, string> | void {
|
|
88
|
-
if (typeof data === 'object' && data !== null) {
|
|
89
|
-
if (ignoreKey(path)) {
|
|
90
|
-
return error(NESTED_MESSAGE_UNSAFE);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const key = ignoreCase ? findKey(path, data) : path;
|
|
94
|
-
|
|
95
|
-
if (get) {
|
|
96
|
-
return key in data ? ok(data[key as never]) : error(NESTED_MESSAGE_MISSING);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
(data as PlainObject)[key] = typeof value === 'function' ? value(data[key as never]) : value;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (get) {
|
|
103
|
-
return error(NESTED_MESSAGE_MISSING);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// #endregion
|
|
108
|
-
|
|
109
|
-
// #region Variables
|
|
110
|
-
|
|
111
|
-
const EXPRESSION_BRACKET = /\[(\w+)\]/g;
|
|
112
|
-
|
|
113
|
-
const EXPRESSION_DOTS = /^\.|\.$/g;
|
|
114
|
-
|
|
115
|
-
const EXPRESSION_NESTED = /\.|\[\w+\]/;
|
|
116
|
-
|
|
117
|
-
const NESTED_MESSAGE_INPUT = 'Expected data to be an object';
|
|
118
|
-
|
|
119
|
-
const NESTED_MESSAGE_MISSING = 'Expected property to exist in object';
|
|
120
|
-
|
|
121
|
-
const NESTED_MESSAGE_PATH = 'Expected path to be a string';
|
|
122
|
-
|
|
123
|
-
const NESTED_MESSAGE_UNSAFE = 'Access to this property is not allowed';
|
|
124
|
-
|
|
125
|
-
// #endregion
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type {PlainObject} from '../../models';
|
|
2
|
-
|
|
3
|
-
export function partial<Value extends object, ValueKey extends keyof Value>(
|
|
4
|
-
value: unknown,
|
|
5
|
-
keys: ValueKey[],
|
|
6
|
-
omit: true,
|
|
7
|
-
): Omit<Value, ValueKey>;
|
|
8
|
-
|
|
9
|
-
export function partial<Value extends object, ValueKey extends keyof Value>(
|
|
10
|
-
value: unknown,
|
|
11
|
-
keys: ValueKey[],
|
|
12
|
-
omit: false,
|
|
13
|
-
): Pick<Value, ValueKey>;
|
|
14
|
-
|
|
15
|
-
export function partial<Value extends object, ValueKey extends keyof Value>(
|
|
16
|
-
value: unknown,
|
|
17
|
-
providedKeys: ValueKey[],
|
|
18
|
-
omit: boolean,
|
|
19
|
-
): Partial<Value> {
|
|
20
|
-
if (typeof value !== 'object' || value === null) {
|
|
21
|
-
return {} as Partial<Value>;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const keys = omit ? Object.keys(value) : Array.isArray(providedKeys) ? providedKeys : [];
|
|
25
|
-
const {length} = keys;
|
|
26
|
-
|
|
27
|
-
if (length === 0) {
|
|
28
|
-
return omit ? (value as Partial<Value>) : ({} as Partial<Value>);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const partials: Partial<Value> = {};
|
|
32
|
-
|
|
33
|
-
for (let index = 0; index < length; index += 1) {
|
|
34
|
-
const key = keys[index];
|
|
35
|
-
|
|
36
|
-
if (!(key in value)) {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (omit ? !providedKeys.includes(key as ValueKey) : true) {
|
|
41
|
-
(partials as PlainObject)[key] = (value as PlainObject)[key];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return partials;
|
|
46
|
-
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import type {NestedKeys, NestedValue, PlainObject} from '../../models';
|
|
2
|
-
import type {Ok} from '../../result/models';
|
|
3
|
-
import {getPaths, handleValue} from './misc';
|
|
4
|
-
|
|
5
|
-
// #region Functions
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Update the value in an object using a known path
|
|
9
|
-
*
|
|
10
|
-
* @param data Object to set value in
|
|
11
|
-
* @param path Path for value, e.g., `foo.bar.baz`
|
|
12
|
-
* @param updater Function to update the current value
|
|
13
|
-
* @returns Updated object
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* const data = {foo: {bar: {baz: 42}}};
|
|
18
|
-
*
|
|
19
|
-
* setValue(data, 'foo.bar.baz', (current) => current + 1); // => {foo: {bar: {baz: 43}}}
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export function setValue<Data extends PlainObject, Path extends NestedKeys<Data>>(
|
|
23
|
-
data: Data,
|
|
24
|
-
path: Path,
|
|
25
|
-
updater: (current: NestedValue<Data, Path>) => NestedValue<Data, Path>,
|
|
26
|
-
): Data;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Set the value in an object using a known path
|
|
30
|
-
*
|
|
31
|
-
* @param data Object to set value in
|
|
32
|
-
* @param path Path for value, e.g., `foo.bar.baz`
|
|
33
|
-
* @param value Value to set
|
|
34
|
-
* @returns Updated object
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* const data = {foo: {bar: {baz: 42}}};
|
|
39
|
-
*
|
|
40
|
-
* setValue(data, 'foo.bar.baz', 99); // => {foo: {bar: {baz: 99}}}
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export function setValue<Data extends PlainObject, Path extends NestedKeys<Data>>(
|
|
44
|
-
data: Data,
|
|
45
|
-
path: Path,
|
|
46
|
-
value: NestedValue<Data, Path>,
|
|
47
|
-
): Data;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Set the value in an object using an unknown path
|
|
51
|
-
*
|
|
52
|
-
* @param data Object to set value in
|
|
53
|
-
* @param path Path for value, e.g., `foo.bar.baz`
|
|
54
|
-
* @param value Value to set
|
|
55
|
-
* @param ignoreCase If `true`, the path matching is case-insensitive
|
|
56
|
-
* @returns Updated object
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```typescript
|
|
60
|
-
* const data = {foo: {bar: {baz: 42}}};
|
|
61
|
-
*
|
|
62
|
-
* setValue(data, 'Foo.Bar.Baz', 99, true); // => {foo: {bar: {baz: 99}}}
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
export function setValue<Data extends PlainObject>(
|
|
66
|
-
data: Data,
|
|
67
|
-
path: string,
|
|
68
|
-
value: unknown,
|
|
69
|
-
ignoreCase?: boolean,
|
|
70
|
-
): Data;
|
|
71
|
-
|
|
72
|
-
export function setValue(data: object, path: string, value: unknown, ignoreCase?: boolean): object {
|
|
73
|
-
if (
|
|
74
|
-
typeof data !== 'object' ||
|
|
75
|
-
data === null ||
|
|
76
|
-
typeof path !== 'string' ||
|
|
77
|
-
path.trim().length === 0
|
|
78
|
-
) {
|
|
79
|
-
return data;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const shouldIgnoreCase = ignoreCase === true;
|
|
83
|
-
const paths = getPaths(path, shouldIgnoreCase);
|
|
84
|
-
|
|
85
|
-
if (typeof paths === 'string') {
|
|
86
|
-
handleValue(data, paths, value, false, shouldIgnoreCase);
|
|
87
|
-
|
|
88
|
-
return data;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const {length} = paths;
|
|
92
|
-
const lastIndex = length - 1;
|
|
93
|
-
|
|
94
|
-
let target = data;
|
|
95
|
-
|
|
96
|
-
for (let index = 0; index < length; index += 1) {
|
|
97
|
-
const currentPath = paths[index];
|
|
98
|
-
|
|
99
|
-
if (index === lastIndex) {
|
|
100
|
-
handleValue(target, currentPath, value, false, shouldIgnoreCase);
|
|
101
|
-
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
let next = (handleValue(target, currentPath, null, true, shouldIgnoreCase) as Ok<unknown>)
|
|
106
|
-
.value;
|
|
107
|
-
|
|
108
|
-
if (typeof next !== 'object' || next === null) {
|
|
109
|
-
const nextPath = paths[index + 1];
|
|
110
|
-
|
|
111
|
-
if (EXPRESSION_INDEX.test(nextPath)) {
|
|
112
|
-
next = Array.from({length: Number(nextPath) + 1}, () => undefined);
|
|
113
|
-
} else {
|
|
114
|
-
next = {};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
(target as PlainObject)[currentPath] = next;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
target = next as object;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return data;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// #endregion
|
|
127
|
-
|
|
128
|
-
// #region Variables
|
|
129
|
-
|
|
130
|
-
const EXPRESSION_INDEX = /^\d+$/;
|
|
131
|
-
|
|
132
|
-
// #endregion
|
package/src/is.ts
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import {getArray} from './array/get';
|
|
2
|
-
import {isNumber} from './internal/is';
|
|
3
|
-
import {getString} from './internal/string';
|
|
4
|
-
|
|
5
|
-
// #region Functions
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Is the value empty, or only containing `null` or `undefined` values?
|
|
9
|
-
*
|
|
10
|
-
* @param value Value to check
|
|
11
|
-
* @returns `true` if the value is considered empty, otherwise `false`
|
|
12
|
-
*/
|
|
13
|
-
export function isEmpty(value: unknown): boolean {
|
|
14
|
-
if (value == null) {
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (typeof value === 'string') {
|
|
19
|
-
return value.length === 0;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const values = getArray(value);
|
|
23
|
-
const {length} = values;
|
|
24
|
-
|
|
25
|
-
for (let index = 0; index < length; index += 1) {
|
|
26
|
-
const item = values[index];
|
|
27
|
-
|
|
28
|
-
if (Array.isArray(item) ? item[1] != null : item != null) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Is the value not empty, or holding non-empty values?
|
|
38
|
-
*
|
|
39
|
-
* @param value Value to check
|
|
40
|
-
* @returns `true` if the value is not considered empty, otherwise `false`
|
|
41
|
-
*/
|
|
42
|
-
export function isNonEmpty(value: unknown): boolean {
|
|
43
|
-
return !isEmpty(value);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Is the value not `undefined` or `null`?
|
|
48
|
-
*
|
|
49
|
-
* @param value Value to check
|
|
50
|
-
* @returns `true` if the value is not `undefined` or `null`, otherwise `false`
|
|
51
|
-
*/
|
|
52
|
-
export function isNonNullable<Value>(value: Value): value is Exclude<Value, undefined | null> {
|
|
53
|
-
return value != null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Is the value not `undefined`, `null`, or stringified as an empty _(no whitespace)_ string?
|
|
58
|
-
*
|
|
59
|
-
* @param value Value to check
|
|
60
|
-
* @returns `true` if the value is not `undefined`, `null`, or matches an empty string, otherwise `false`
|
|
61
|
-
*/
|
|
62
|
-
export function isNonNullableOrEmpty<Value>(
|
|
63
|
-
value: Value,
|
|
64
|
-
): value is Exclude<Value, undefined | null | ''> {
|
|
65
|
-
return value != null && getString(value) !== '';
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Is the value not `undefined`, `null`, or stringified as a whitespace-only string?
|
|
70
|
-
*
|
|
71
|
-
* @param value Value to check
|
|
72
|
-
* @returns `true` if the value is not `undefined`, `null`, or matches a whitespace-only string, otherwise `false`
|
|
73
|
-
*/
|
|
74
|
-
export function isNonNullableOrWhitespace<Value>(
|
|
75
|
-
value: Value,
|
|
76
|
-
): value is Exclude<Value, undefined | null | ''> {
|
|
77
|
-
return value != null && !EXPRESSION_WHITESPACE.test(getString(value));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Is the value not a number or a number-like string?
|
|
82
|
-
*
|
|
83
|
-
* @param value Value to check
|
|
84
|
-
* @returns `true` if the value is not a number or a number-like string, otherwise `false`
|
|
85
|
-
*/
|
|
86
|
-
export function isNonNumerical<Value>(value: Value): value is Exclude<Value, number | `${number}`> {
|
|
87
|
-
return !isNumerical(value);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Is the value not an object _(or function)_?
|
|
92
|
-
*
|
|
93
|
-
* @param value Value to check
|
|
94
|
-
* @returns `true` if the value is not an object, otherwise `false`
|
|
95
|
-
*/
|
|
96
|
-
export function isNonObject<Value>(value: Value): value is Exclude<Value, object> {
|
|
97
|
-
return !isObject(value);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Is the value `undefined` or `null`?
|
|
102
|
-
*
|
|
103
|
-
* @param value Value to check
|
|
104
|
-
* @returns `true` if the value is `undefined` or `null`, otherwise `false`
|
|
105
|
-
*/
|
|
106
|
-
export function isNullable(value: unknown): value is undefined | null {
|
|
107
|
-
return value == null;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Is the value `undefined`, `null`, or stringified as an empty _(no whitespace)_ string?
|
|
112
|
-
*
|
|
113
|
-
* @param value Value to check
|
|
114
|
-
* @returns `true` if the value is nullable or matches an empty string, otherwise `false`
|
|
115
|
-
*/
|
|
116
|
-
export function isNullableOrEmpty(value: unknown): value is undefined | null | '' {
|
|
117
|
-
return value == null || getString(value) === '';
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Is the value `undefined`, `null`, or stringified as a whitespace-only string?
|
|
122
|
-
*
|
|
123
|
-
* @param value Value to check
|
|
124
|
-
* @returns `true` if the value is nullable or matches a whitespace-only string, otherwise `false`
|
|
125
|
-
*/
|
|
126
|
-
export function isNullableOrWhitespace(value: unknown): value is undefined | null | '' {
|
|
127
|
-
return value == null || EXPRESSION_WHITESPACE.test(getString(value));
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Is the value a number or a number-like string?
|
|
132
|
-
*
|
|
133
|
-
* @param value Value to check
|
|
134
|
-
* @returns `true` if the value is a number or a number-like string, otherwise `false`
|
|
135
|
-
*/
|
|
136
|
-
export function isNumerical(value: unknown): value is number | `${number}` {
|
|
137
|
-
return (
|
|
138
|
-
isNumber(value) ||
|
|
139
|
-
(typeof value === 'string' && value.trim().length > 0 && !Number.isNaN(+value))
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Is the value an object _(or function)_?
|
|
145
|
-
*
|
|
146
|
-
* @param value Value to check
|
|
147
|
-
* @returns `true` if the value matches, otherwise `false`
|
|
148
|
-
*/
|
|
149
|
-
export function isObject(value: unknown): value is object {
|
|
150
|
-
return (typeof value === 'object' && value !== null) || typeof value === 'function';
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// #endregion
|
|
154
|
-
|
|
155
|
-
// #region Variables
|
|
156
|
-
|
|
157
|
-
const EXPRESSION_WHITESPACE = /^\s*$/;
|
|
158
|
-
|
|
159
|
-
// #endregion
|
|
160
|
-
|
|
161
|
-
// #region Exports
|
|
162
|
-
|
|
163
|
-
export {
|
|
164
|
-
isArrayOrPlainObject,
|
|
165
|
-
isConstructor,
|
|
166
|
-
isInstanceOf,
|
|
167
|
-
isKey,
|
|
168
|
-
isNonArrayOrPlainObject,
|
|
169
|
-
isNonConstructor,
|
|
170
|
-
isNonInstanceOf,
|
|
171
|
-
isNonKey,
|
|
172
|
-
isNonNumber,
|
|
173
|
-
isNonPlainObject,
|
|
174
|
-
isNonPrimitive,
|
|
175
|
-
isNonTypedArray,
|
|
176
|
-
isNumber,
|
|
177
|
-
isPlainObject,
|
|
178
|
-
isPrimitive,
|
|
179
|
-
isTypedArray,
|
|
180
|
-
} from './internal/is';
|
|
181
|
-
|
|
182
|
-
// #endregion
|