@oscarpalmer/atoms 0.173.2 → 0.173.3
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.mjs +8 -9
- package/dist/internal/number.mjs +1 -3
- package/dist/query.mjs +7 -6
- package/package.json +1 -1
- package/src/internal/number.ts +1 -7
- package/src/query.ts +9 -9
package/dist/index.mjs
CHANGED
|
@@ -1198,12 +1198,10 @@ function getNumber(value) {
|
|
|
1198
1198
|
if (EXPRESSION_ZEROISH.test(parsed)) return 0;
|
|
1199
1199
|
const isBinary = EXPRESSION_BINARY.test(trimmed);
|
|
1200
1200
|
if (isBinary || EXPRESSION_OCTAL.test(trimmed)) return Number.parseInt(trimmed.slice(2), isBinary ? 2 : OCTAL_VALUE);
|
|
1201
|
-
return Number(
|
|
1201
|
+
return Number(trimmed);
|
|
1202
1202
|
}
|
|
1203
1203
|
const EXPRESSION_BINARY = /^0b[01]+$/i;
|
|
1204
|
-
const EXPRESSION_HEX = /^0x[0-9a-f]+$/i;
|
|
1205
1204
|
const EXPRESSION_OCTAL = /^0o[0-7]+$/i;
|
|
1206
|
-
const EXPRESSION_UNDERSCORE = /_/g;
|
|
1207
1205
|
const EXPRESSION_ZEROISH = /^\s*0+\s*$/;
|
|
1208
1206
|
const OCTAL_VALUE = 8;
|
|
1209
1207
|
//#endregion
|
|
@@ -4058,11 +4056,11 @@ async function resultPromises(items, signal) {
|
|
|
4058
4056
|
*/
|
|
4059
4057
|
function fromQuery(query) {
|
|
4060
4058
|
if (typeof query !== "string" || query.trim().length === 0) return {};
|
|
4061
|
-
const parts = query.split(
|
|
4059
|
+
const parts = query.split(AMPERSAND);
|
|
4062
4060
|
const { length } = parts;
|
|
4063
4061
|
const parameters = {};
|
|
4064
4062
|
for (let index = 0; index < length; index += 1) {
|
|
4065
|
-
const decoded = parts[index].split(
|
|
4063
|
+
const decoded = parts[index].split(EQUAL).map(tryDecode);
|
|
4066
4064
|
const key = decoded[0].replace(EXPRESSION_ARRAY_SUFFIX, "");
|
|
4067
4065
|
if (!ignoreKey(key)) setQueryValue(parameters, key, decoded[1]);
|
|
4068
4066
|
}
|
|
@@ -4085,7 +4083,6 @@ function getParts(value, fromArray, prefix) {
|
|
|
4085
4083
|
}
|
|
4086
4084
|
function getQueryValue(value) {
|
|
4087
4085
|
if (EXPRESSION_BOOLEAN.test(value)) return value === TRUE;
|
|
4088
|
-
if (EXPRESSION_NOPARSE.test(value)) return value;
|
|
4089
4086
|
const asNumber = getNumber(value);
|
|
4090
4087
|
if (!Number.isNaN(asNumber)) return asNumber;
|
|
4091
4088
|
const parsed = Date.parse(value);
|
|
@@ -4097,7 +4094,7 @@ function isDecodable(value) {
|
|
|
4097
4094
|
return TYPES.has(typeof value);
|
|
4098
4095
|
}
|
|
4099
4096
|
function setQueryValue(parameters, key, value) {
|
|
4100
|
-
if (
|
|
4097
|
+
if (EXPRESSION_DOT.test(key)) setValue(parameters, key, getQueryValue(value));
|
|
4101
4098
|
else if (key in parameters) {
|
|
4102
4099
|
if (!Array.isArray(parameters[key])) parameters[key] = [parameters[key]];
|
|
4103
4100
|
parameters[key].push(getQueryValue(value));
|
|
@@ -4109,11 +4106,13 @@ function setQueryValue(parameters, key, value) {
|
|
|
4109
4106
|
* @returns Query string representation of the object
|
|
4110
4107
|
*/
|
|
4111
4108
|
function toQuery(parameters) {
|
|
4112
|
-
return isPlainObject(parameters) ? join(getParts(parameters, false).filter((part) => part.length > 0),
|
|
4109
|
+
return isPlainObject(parameters) ? join(getParts(parameters, false).filter((part) => part.length > 0), AMPERSAND) : "";
|
|
4113
4110
|
}
|
|
4111
|
+
const AMPERSAND = "&";
|
|
4112
|
+
const EQUAL = "=";
|
|
4114
4113
|
const EXPRESSION_ARRAY_SUFFIX = /\[\]$/;
|
|
4115
4114
|
const EXPRESSION_BOOLEAN = /^(false|true)$/;
|
|
4116
|
-
const
|
|
4115
|
+
const EXPRESSION_DOT = /\./g;
|
|
4117
4116
|
const TRUE = "true";
|
|
4118
4117
|
const TYPES = new Set([
|
|
4119
4118
|
"boolean",
|
package/dist/internal/number.mjs
CHANGED
|
@@ -51,12 +51,10 @@ function getNumber(value) {
|
|
|
51
51
|
if (EXPRESSION_ZEROISH.test(parsed)) return 0;
|
|
52
52
|
const isBinary = EXPRESSION_BINARY.test(trimmed);
|
|
53
53
|
if (isBinary || EXPRESSION_OCTAL.test(trimmed)) return Number.parseInt(trimmed.slice(2), isBinary ? 2 : OCTAL_VALUE);
|
|
54
|
-
return Number(
|
|
54
|
+
return Number(trimmed);
|
|
55
55
|
}
|
|
56
56
|
const EXPRESSION_BINARY = /^0b[01]+$/i;
|
|
57
|
-
const EXPRESSION_HEX = /^0x[0-9a-f]+$/i;
|
|
58
57
|
const EXPRESSION_OCTAL = /^0o[0-7]+$/i;
|
|
59
|
-
const EXPRESSION_UNDERSCORE = /_/g;
|
|
60
58
|
const EXPRESSION_ZEROISH = /^\s*0+\s*$/;
|
|
61
59
|
const OCTAL_VALUE = 8;
|
|
62
60
|
//#endregion
|
package/dist/query.mjs
CHANGED
|
@@ -10,11 +10,11 @@ import { setValue } from "./internal/value/set.mjs";
|
|
|
10
10
|
*/
|
|
11
11
|
function fromQuery(query) {
|
|
12
12
|
if (typeof query !== "string" || query.trim().length === 0) return {};
|
|
13
|
-
const parts = query.split(
|
|
13
|
+
const parts = query.split(AMPERSAND);
|
|
14
14
|
const { length } = parts;
|
|
15
15
|
const parameters = {};
|
|
16
16
|
for (let index = 0; index < length; index += 1) {
|
|
17
|
-
const decoded = parts[index].split(
|
|
17
|
+
const decoded = parts[index].split(EQUAL).map(tryDecode);
|
|
18
18
|
const key = decoded[0].replace(EXPRESSION_ARRAY_SUFFIX, "");
|
|
19
19
|
if (!ignoreKey(key)) setQueryValue(parameters, key, decoded[1]);
|
|
20
20
|
}
|
|
@@ -37,7 +37,6 @@ function getParts(value, fromArray, prefix) {
|
|
|
37
37
|
}
|
|
38
38
|
function getQueryValue(value) {
|
|
39
39
|
if (EXPRESSION_BOOLEAN.test(value)) return value === TRUE;
|
|
40
|
-
if (EXPRESSION_NOPARSE.test(value)) return value;
|
|
41
40
|
const asNumber = getNumber(value);
|
|
42
41
|
if (!Number.isNaN(asNumber)) return asNumber;
|
|
43
42
|
const parsed = Date.parse(value);
|
|
@@ -49,7 +48,7 @@ function isDecodable(value) {
|
|
|
49
48
|
return TYPES.has(typeof value);
|
|
50
49
|
}
|
|
51
50
|
function setQueryValue(parameters, key, value) {
|
|
52
|
-
if (
|
|
51
|
+
if (EXPRESSION_DOT.test(key)) setValue(parameters, key, getQueryValue(value));
|
|
53
52
|
else if (key in parameters) {
|
|
54
53
|
if (!Array.isArray(parameters[key])) parameters[key] = [parameters[key]];
|
|
55
54
|
parameters[key].push(getQueryValue(value));
|
|
@@ -61,11 +60,13 @@ function setQueryValue(parameters, key, value) {
|
|
|
61
60
|
* @returns Query string representation of the object
|
|
62
61
|
*/
|
|
63
62
|
function toQuery(parameters) {
|
|
64
|
-
return isPlainObject(parameters) ? join(getParts(parameters, false).filter((part) => part.length > 0),
|
|
63
|
+
return isPlainObject(parameters) ? join(getParts(parameters, false).filter((part) => part.length > 0), AMPERSAND) : "";
|
|
65
64
|
}
|
|
65
|
+
const AMPERSAND = "&";
|
|
66
|
+
const EQUAL = "=";
|
|
66
67
|
const EXPRESSION_ARRAY_SUFFIX = /\[\]$/;
|
|
67
68
|
const EXPRESSION_BOOLEAN = /^(false|true)$/;
|
|
68
|
-
const
|
|
69
|
+
const EXPRESSION_DOT = /\./g;
|
|
69
70
|
const TRUE = "true";
|
|
70
71
|
const TYPES = new Set([
|
|
71
72
|
"boolean",
|
package/package.json
CHANGED
package/src/internal/number.ts
CHANGED
|
@@ -94,9 +94,7 @@ export function getNumber(value: unknown): number {
|
|
|
94
94
|
return Number.parseInt(trimmed.slice(2), isBinary ? 2 : OCTAL_VALUE);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
return Number(
|
|
98
|
-
EXPRESSION_HEX.test(trimmed) ? trimmed : trimmed.replace(EXPRESSION_UNDERSCORE, ''),
|
|
99
|
-
);
|
|
97
|
+
return Number(trimmed);
|
|
100
98
|
}
|
|
101
99
|
|
|
102
100
|
// #endregion
|
|
@@ -105,12 +103,8 @@ export function getNumber(value: unknown): number {
|
|
|
105
103
|
|
|
106
104
|
const EXPRESSION_BINARY = /^0b[01]+$/i;
|
|
107
105
|
|
|
108
|
-
const EXPRESSION_HEX = /^0x[0-9a-f]+$/i;
|
|
109
|
-
|
|
110
106
|
const EXPRESSION_OCTAL = /^0o[0-7]+$/i;
|
|
111
107
|
|
|
112
|
-
const EXPRESSION_UNDERSCORE = /_/g;
|
|
113
|
-
|
|
114
108
|
const EXPRESSION_ZEROISH = /^\s*0+\s*$/;
|
|
115
109
|
|
|
116
110
|
const OCTAL_VALUE = 8;
|
package/src/query.ts
CHANGED
|
@@ -16,13 +16,13 @@ export function fromQuery(query: string): PlainObject {
|
|
|
16
16
|
return {};
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const parts = query.split(
|
|
19
|
+
const parts = query.split(AMPERSAND);
|
|
20
20
|
const {length} = parts;
|
|
21
21
|
|
|
22
22
|
const parameters: PlainObject = {};
|
|
23
23
|
|
|
24
24
|
for (let index = 0; index < length; index += 1) {
|
|
25
|
-
const decoded = parts[index].split(
|
|
25
|
+
const decoded = parts[index].split(EQUAL).map(tryDecode);
|
|
26
26
|
const key = decoded[0].replace(EXPRESSION_ARRAY_SUFFIX, '');
|
|
27
27
|
|
|
28
28
|
if (!ignoreKey(key)) {
|
|
@@ -64,10 +64,6 @@ function getQueryValue(value: string): unknown {
|
|
|
64
64
|
return value === TRUE;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
if (EXPRESSION_NOPARSE.test(value)) {
|
|
68
|
-
return value;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
67
|
const asNumber = getNumber(value);
|
|
72
68
|
|
|
73
69
|
if (!Number.isNaN(asNumber)) {
|
|
@@ -90,7 +86,7 @@ function isDecodable(value: unknown): value is boolean | number | string {
|
|
|
90
86
|
}
|
|
91
87
|
|
|
92
88
|
function setQueryValue(parameters: PlainObject, key: string, value: string): void {
|
|
93
|
-
if (
|
|
89
|
+
if (EXPRESSION_DOT.test(key)) {
|
|
94
90
|
setValue(parameters, key, getQueryValue(value));
|
|
95
91
|
} else {
|
|
96
92
|
if (key in parameters) {
|
|
@@ -114,7 +110,7 @@ export function toQuery(parameters: PlainObject): string {
|
|
|
114
110
|
return isPlainObject(parameters)
|
|
115
111
|
? join(
|
|
116
112
|
getParts(parameters, false).filter(part => part.length > 0),
|
|
117
|
-
|
|
113
|
+
AMPERSAND,
|
|
118
114
|
)
|
|
119
115
|
: '';
|
|
120
116
|
}
|
|
@@ -123,11 +119,15 @@ export function toQuery(parameters: PlainObject): string {
|
|
|
123
119
|
|
|
124
120
|
// #region Variables
|
|
125
121
|
|
|
122
|
+
const AMPERSAND = '&';
|
|
123
|
+
|
|
124
|
+
const EQUAL = '=';
|
|
125
|
+
|
|
126
126
|
const EXPRESSION_ARRAY_SUFFIX = /\[\]$/;
|
|
127
127
|
|
|
128
128
|
const EXPRESSION_BOOLEAN = /^(false|true)$/;
|
|
129
129
|
|
|
130
|
-
const
|
|
130
|
+
const EXPRESSION_DOT = /\./g;
|
|
131
131
|
|
|
132
132
|
const TRUE = 'true';
|
|
133
133
|
|