@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
package/src/query.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import {isPlainObject} from './internal/is';
|
|
2
|
-
import {getNumber} from './internal/number';
|
|
3
|
-
import {getString, ignoreKey, join, tryDecode, tryEncode} from './internal/string';
|
|
4
|
-
import {setValue} from './internal/value/set';
|
|
5
|
-
import type {ArrayOrPlainObject, PlainObject} from './models';
|
|
6
|
-
|
|
7
|
-
// #region Functions
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Convert a query string to a plain _(nested)_ object
|
|
11
|
-
*
|
|
12
|
-
* @param query Query string to convert
|
|
13
|
-
* @returns Plain object representation of the query string
|
|
14
|
-
*/
|
|
15
|
-
export function fromQuery(query: string): PlainObject {
|
|
16
|
-
if (typeof query !== 'string' || query.trim().length === 0) {
|
|
17
|
-
return {};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const parts = query
|
|
21
|
-
.split(AMPERSAND)
|
|
22
|
-
.map(part => part.split(EQUAL).map(tryDecode))
|
|
23
|
-
.sort(([first], [second]) => first.localeCompare(second));
|
|
24
|
-
|
|
25
|
-
const {length} = parts;
|
|
26
|
-
|
|
27
|
-
const parameters: PlainObject = {};
|
|
28
|
-
|
|
29
|
-
let position = 0;
|
|
30
|
-
let array: string | undefined;
|
|
31
|
-
|
|
32
|
-
for (let index = 0; index < length; index += 1) {
|
|
33
|
-
const [key, value] = parts[index];
|
|
34
|
-
|
|
35
|
-
if (EXPRESSION_ARRAY_SUFFIX.test(key)) {
|
|
36
|
-
const named = key.replace(EXPRESSION_ARRAY_SUFFIX, '');
|
|
37
|
-
|
|
38
|
-
if (named !== array) {
|
|
39
|
-
array = named;
|
|
40
|
-
position = 0;
|
|
41
|
-
}
|
|
42
|
-
} else {
|
|
43
|
-
array = undefined;
|
|
44
|
-
position = 0;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const full = array == null ? key : `${array}.${position}`;
|
|
48
|
-
|
|
49
|
-
if (!ignoreKey(full)) {
|
|
50
|
-
setValue(parameters, full, getQueryValue(value));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
position += 1;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return parameters;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function getParts(value: ArrayOrPlainObject, fromArray: boolean, prefix?: string): string[] {
|
|
60
|
-
const keys = Object.keys(value);
|
|
61
|
-
const {length} = keys;
|
|
62
|
-
|
|
63
|
-
const parts: string[] = [];
|
|
64
|
-
|
|
65
|
-
for (let index = 0; index < length; index += 1) {
|
|
66
|
-
const key = keys[index];
|
|
67
|
-
const val = value[key as never];
|
|
68
|
-
|
|
69
|
-
const fullKey = join([prefix, fromArray ? undefined : key], DOT);
|
|
70
|
-
|
|
71
|
-
const encodedKey = getString(tryEncode(fullKey));
|
|
72
|
-
const prefixedKey = fromArray ? join([encodedKey, index], DOT) : encodedKey;
|
|
73
|
-
|
|
74
|
-
if (Array.isArray(val)) {
|
|
75
|
-
parts.push(...getParts(val, true, fullKey));
|
|
76
|
-
} else if (isPlainObject(val)) {
|
|
77
|
-
parts.push(...getParts(val, false, fullKey));
|
|
78
|
-
} else if (isDecodable(val)) {
|
|
79
|
-
parts.push(`${prefixedKey}=${getString(tryEncode(val))}`);
|
|
80
|
-
} else if (val instanceof Date) {
|
|
81
|
-
parts.push(`${prefixedKey}=${val.toJSON()}`);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return parts;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function getQueryValue(value: string): unknown {
|
|
89
|
-
if (EXPRESSION_BOOLEAN.test(value)) {
|
|
90
|
-
return value === TRUE;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const asNumber = getNumber(value);
|
|
94
|
-
|
|
95
|
-
if (!Number.isNaN(asNumber)) {
|
|
96
|
-
return asNumber;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const parsed = Date.parse(value);
|
|
100
|
-
|
|
101
|
-
if (Number.isNaN(parsed)) {
|
|
102
|
-
return value;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const date = new Date(parsed);
|
|
106
|
-
|
|
107
|
-
return date.toJSON() === value ? date : value;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function isDecodable(value: unknown): value is boolean | number | string {
|
|
111
|
-
return TYPES.has(typeof value);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Convert a plain _(nested)_ object to a query string
|
|
116
|
-
*
|
|
117
|
-
* @param parameters Plain object to convert
|
|
118
|
-
* @returns Query string representation of the object
|
|
119
|
-
*/
|
|
120
|
-
export function toQuery(parameters: PlainObject): string {
|
|
121
|
-
return isPlainObject(parameters)
|
|
122
|
-
? join(
|
|
123
|
-
getParts(parameters, false).filter(part => part.length > 0),
|
|
124
|
-
AMPERSAND,
|
|
125
|
-
)
|
|
126
|
-
: '';
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// #endregion
|
|
130
|
-
|
|
131
|
-
// #region Variables
|
|
132
|
-
|
|
133
|
-
const AMPERSAND = '&';
|
|
134
|
-
|
|
135
|
-
const DOT = '.';
|
|
136
|
-
|
|
137
|
-
const EQUAL = '=';
|
|
138
|
-
|
|
139
|
-
const EXPRESSION_ARRAY_SUFFIX = /\[\]$/;
|
|
140
|
-
|
|
141
|
-
const EXPRESSION_BOOLEAN = /^(false|true)$/;
|
|
142
|
-
|
|
143
|
-
const TRUE = 'true';
|
|
144
|
-
|
|
145
|
-
const TYPES = new Set(['boolean', 'number', 'string']);
|
|
146
|
-
|
|
147
|
-
// #endregion
|