@rzl-zone/utils-js 3.4.0 → 3.5.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/LICENSE.md +1 -1
- package/README.md +94 -45
- package/dist/assertions/index.cjs +41 -1
- package/dist/assertions/index.d.ts +11 -2
- package/dist/assertions/index.js +14 -1
- package/dist/chunk-2CQX5CBG.js +262 -1
- package/dist/chunk-2IOOEY45.cjs +30 -1
- package/dist/chunk-2WA36TC5.cjs +189 -0
- package/dist/chunk-3IBQ5MOM.js +16 -1
- package/dist/chunk-3VA554KW.js +34 -1
- package/dist/chunk-5757UBXJ.cjs +157 -1
- package/dist/chunk-5IGC6PBH.js +33 -1
- package/dist/chunk-5KJFVIQT.cjs +65 -1
- package/dist/chunk-6JFCSH7J.js +35 -1
- package/dist/chunk-6JFZL7YE.cjs +24 -1
- package/dist/chunk-7ODAAXX5.cjs +397 -1
- package/dist/chunk-BAV5T2E3.cjs +15 -1
- package/dist/chunk-CAH33WOQ.cjs +36 -1
- package/dist/chunk-CDCERIZ2.js +177 -0
- package/dist/chunk-CKTLUNWX.js +22 -1
- package/dist/chunk-CMW2TBOQ.js +567 -1
- package/dist/chunk-D3ENH7H6.cjs +101 -1
- package/dist/chunk-DEZZUYE2.js +152 -1
- package/dist/chunk-DVMHRLKP.cjs +16 -1
- package/dist/chunk-DWF2R5GD.cjs +225 -1
- package/dist/chunk-E55EQK2U.cjs +18 -1
- package/dist/chunk-E74U6CYP.cjs +18 -1
- package/dist/chunk-EL6A35UR.cjs +64 -1
- package/dist/chunk-F6IPNNSJ.cjs +554 -1
- package/dist/chunk-FJZGG54N.cjs +267 -1
- package/dist/chunk-FWCKOJZM.js +542 -1
- package/dist/chunk-FWHNWL2P.cjs +419 -1
- package/dist/chunk-GGEADHZO.js +90 -1
- package/dist/chunk-GQR4R5WY.js +31 -1
- package/dist/chunk-H66AC7GK.cjs +93 -1
- package/dist/chunk-HQWOFR56.cjs +33 -1
- package/dist/chunk-HYRQMTRH.cjs +24 -1
- package/dist/chunk-IRFL4MAX.js +63 -1
- package/dist/chunk-IVL7CKVH.cjs +37 -1
- package/dist/chunk-IZPBKKPO.js +16 -1
- package/dist/chunk-JBQMXC5I.cjs +106 -1
- package/dist/chunk-JEQEF5WD.js +95 -1
- package/dist/chunk-JMJQCN74.js +370 -1
- package/dist/chunk-KHO2SBNA.cjs +16 -1
- package/dist/chunk-KVAL5PAG.cjs +26 -1
- package/dist/chunk-L5RDAVVH.js +14 -1
- package/dist/chunk-LS6U7FAY.cjs +110 -1
- package/dist/chunk-NBZWMBO6.js +101 -1
- package/dist/chunk-NRF6LWBC.cjs +56 -1
- package/dist/chunk-OI5XKNZO.js +53 -1
- package/dist/chunk-ONZFBJVW.js +14 -1
- package/dist/chunk-OYTYSY7G.js +106 -1
- package/dist/chunk-PET42Z7W.js +119 -1
- package/dist/chunk-PZQ6I4JJ.cjs +605 -1
- package/dist/chunk-QBKAEVYG.js +113 -1
- package/dist/chunk-QNKGP5DY.js +14 -1
- package/dist/chunk-RIPKY4RU.js +417 -1
- package/dist/chunk-RZW35UN5.cjs +116 -1
- package/dist/chunk-SBFNXGTJ.js +220 -1
- package/dist/chunk-SBKGWRS5.js +22 -1
- package/dist/chunk-SIM77PU4.js +59 -1
- package/dist/chunk-T2T7K3KR.js +28 -1
- package/dist/chunk-T7PU2V7X.cjs +123 -1
- package/dist/chunk-UDA26MCU.cjs +16 -1
- package/dist/chunk-V45XJKHW.cjs +18 -1
- package/dist/chunk-VJDDGRIK.cjs +16 -1
- package/dist/chunk-W2WNBUDE.js +16 -1
- package/dist/chunk-WVSPXFTY.js +14 -1
- package/dist/chunk-XABCB3Y7.cjs +582 -1
- package/dist/chunk-XEDXFSGI.js +24 -1
- package/dist/chunk-YKPSRP5G.js +571 -1
- package/dist/chunk-YWHHVDT4.js +13 -1
- package/dist/chunk-ZETAZZLD.cjs +38 -1
- package/dist/conversions/index.cjs +104 -1
- package/dist/conversions/index.d.ts +10 -1
- package/dist/conversions/index.js +25 -1
- package/dist/events/index.cjs +32 -1
- package/dist/events/index.d.ts +10 -1
- package/dist/events/index.js +13 -1
- package/dist/formatters/index.cjs +62 -1
- package/dist/formatters/index.d.ts +10 -1
- package/dist/formatters/index.js +19 -1
- package/dist/generators/index.cjs +38 -1
- package/dist/generators/index.d.ts +10 -1
- package/dist/generators/index.js +15 -1
- package/dist/index.d.ts +39 -12
- package/dist/{isPlainObject-CEPWPiXh.d.ts → isPlainObject-FWmcJF6k.d.ts} +13 -4
- package/dist/next/index.cjs +218 -1
- package/dist/next/index.d.ts +10 -1
- package/dist/next/index.js +213 -1
- package/dist/next/server/index.cjs +43 -1
- package/dist/next/server/index.d.ts +10 -1
- package/dist/next/server/index.js +41 -1
- package/dist/operations/index.cjs +33 -1
- package/dist/operations/index.d.ts +10 -1
- package/dist/operations/index.js +18 -1
- package/dist/parsers/index.cjs +18 -1
- package/dist/parsers/index.d.ts +10 -1
- package/dist/parsers/index.js +11 -1
- package/dist/predicates/index.cjs +299 -1
- package/dist/predicates/index.d.ts +13 -4
- package/dist/predicates/index.js +24 -1
- package/dist/promises/index.cjs +25 -1
- package/dist/promises/index.d.ts +10 -1
- package/dist/promises/index.js +14 -1
- package/dist/rzl-utils.global.js +25 -1
- package/dist/strings/index.cjs +82 -1
- package/dist/strings/index.d.ts +10 -1
- package/dist/strings/index.js +15 -1
- package/dist/tailwind/index.cjs +43 -1
- package/dist/tailwind/index.d.ts +10 -1
- package/dist/tailwind/index.js +12 -1
- package/dist/urls/index.cjs +51 -1
- package/dist/urls/index.d.ts +10 -1
- package/dist/urls/index.js +24 -1
- package/package.json +60 -179
- package/dist/chunk-JYQTCICM.js +0 -1
- package/dist/chunk-YLA3DURS.cjs +0 -1
package/dist/chunk-FJZGG54N.cjs
CHANGED
|
@@ -1 +1,267 @@
|
|
|
1
|
-
|
|
1
|
+
/*!
|
|
2
|
+
* ====================================================
|
|
3
|
+
* Rzl Utils-JS.
|
|
4
|
+
* ----------------------------------------------------
|
|
5
|
+
* Version: 3.5.1.
|
|
6
|
+
* Author: Rizalvin Dwiky.
|
|
7
|
+
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
|
+
* ====================================================
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
var chunkZETAZZLD_cjs = require('./chunk-ZETAZZLD.cjs');
|
|
13
|
+
var chunkBAV5T2E3_cjs = require('./chunk-BAV5T2E3.cjs');
|
|
14
|
+
var chunkT7PU2V7X_cjs = require('./chunk-T7PU2V7X.cjs');
|
|
15
|
+
var chunkPZQ6I4JJ_cjs = require('./chunk-PZQ6I4JJ.cjs');
|
|
16
|
+
|
|
17
|
+
var parseCustomDate = (dateString, format) => {
|
|
18
|
+
if (!chunkPZQ6I4JJ_cjs.isNonEmptyString(dateString) || !chunkPZQ6I4JJ_cjs.isNonEmptyString(format)) {
|
|
19
|
+
throw new TypeError(
|
|
20
|
+
`Parameter \`dateString\` and \`format\` must be of type \`string\` and not empty-string, but received: "['dateString': \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
21
|
+
dateString
|
|
22
|
+
)}\` - (current value: \`${chunkT7PU2V7X_cjs.safeStableStringify(
|
|
23
|
+
dateString
|
|
24
|
+
)}\`), 'format': \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
25
|
+
format
|
|
26
|
+
)}\` - (current value: \`${chunkT7PU2V7X_cjs.safeStableStringify(format)}\`)]".`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
const dateParts = dateString.split(/[-/]/).map(Number);
|
|
30
|
+
if (dateParts.length !== 3 || dateParts.some(isNaN)) return null;
|
|
31
|
+
let day, month, year;
|
|
32
|
+
if (format === "DD/MM/YYYY") {
|
|
33
|
+
[day, month, year] = dateParts;
|
|
34
|
+
} else if (format === "MM/DD/YYYY") {
|
|
35
|
+
[month, day, year] = dateParts;
|
|
36
|
+
} else {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
month -= 1;
|
|
40
|
+
const date = new Date(year, month, day);
|
|
41
|
+
if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return date;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
var validateJsonParsingOptions = (optionsValue = {}) => {
|
|
48
|
+
chunkPZQ6I4JJ_cjs.assertIsPlainObject(optionsValue, {
|
|
49
|
+
message: ({ currentType, validType }) => `Second parameter (\`options\`) must be of type \`${validType}\`, but received: \`${currentType}\`.`
|
|
50
|
+
});
|
|
51
|
+
const convertBooleans = chunkPZQ6I4JJ_cjs.hasOwnProp(optionsValue, "convertBooleans") ? optionsValue.convertBooleans : false;
|
|
52
|
+
const convertDates = chunkPZQ6I4JJ_cjs.hasOwnProp(optionsValue, "convertDates") ? optionsValue.convertDates : false;
|
|
53
|
+
const convertNumbers = chunkPZQ6I4JJ_cjs.hasOwnProp(optionsValue, "convertNumbers") ? optionsValue.convertNumbers : false;
|
|
54
|
+
const loggingOnFail = chunkPZQ6I4JJ_cjs.hasOwnProp(optionsValue, "loggingOnFail") ? optionsValue.loggingOnFail : false;
|
|
55
|
+
const removeEmptyArrays = chunkPZQ6I4JJ_cjs.hasOwnProp(optionsValue, "removeEmptyArrays") ? optionsValue.removeEmptyArrays : false;
|
|
56
|
+
const removeEmptyObjects = chunkPZQ6I4JJ_cjs.hasOwnProp(optionsValue, "removeEmptyObjects") ? optionsValue.removeEmptyObjects : false;
|
|
57
|
+
const removeNulls = chunkPZQ6I4JJ_cjs.hasOwnProp(optionsValue, "removeNulls") ? optionsValue.removeNulls : false;
|
|
58
|
+
const removeUndefined = chunkPZQ6I4JJ_cjs.hasOwnProp(optionsValue, "removeUndefined") ? optionsValue.removeUndefined : false;
|
|
59
|
+
const strictMode = chunkPZQ6I4JJ_cjs.hasOwnProp(optionsValue, "strictMode") ? optionsValue.strictMode : false;
|
|
60
|
+
const checkSymbols = chunkPZQ6I4JJ_cjs.hasOwnProp(optionsValue, "checkSymbols") ? optionsValue.checkSymbols : false;
|
|
61
|
+
const convertNaN = chunkPZQ6I4JJ_cjs.hasOwnProp(optionsValue, "convertNaN") ? optionsValue.convertNaN : false;
|
|
62
|
+
const customDateFormats = chunkPZQ6I4JJ_cjs.hasOwnProp(optionsValue, "customDateFormats") ? optionsValue.customDateFormats : [];
|
|
63
|
+
const onError = chunkPZQ6I4JJ_cjs.hasOwnProp(optionsValue, "onError") ? optionsValue.onError : chunkBAV5T2E3_cjs.noop;
|
|
64
|
+
if (!(chunkPZQ6I4JJ_cjs.isBoolean(convertBooleans) && chunkPZQ6I4JJ_cjs.isBoolean(convertDates) && chunkPZQ6I4JJ_cjs.isBoolean(convertNumbers) && chunkPZQ6I4JJ_cjs.isBoolean(convertNaN) && chunkPZQ6I4JJ_cjs.isBoolean(checkSymbols) && chunkPZQ6I4JJ_cjs.isBoolean(loggingOnFail) && chunkPZQ6I4JJ_cjs.isBoolean(removeEmptyArrays) && chunkPZQ6I4JJ_cjs.isBoolean(removeEmptyObjects) && chunkPZQ6I4JJ_cjs.isBoolean(removeNulls) && chunkPZQ6I4JJ_cjs.isBoolean(removeUndefined) && chunkPZQ6I4JJ_cjs.isBoolean(strictMode) && chunkPZQ6I4JJ_cjs.isArray(customDateFormats) && chunkPZQ6I4JJ_cjs.isFunction(onError))) {
|
|
65
|
+
throw new TypeError(
|
|
66
|
+
`Invalid \`options\` parameter (second argument): \`convertBooleans\`, \`convertDates\`, \`convertNumbers\`, \`loggingOnFail\`, \`removeEmptyArrays\`, \`removeEmptyObjects\`, \`removeNulls\`, \`removeUndefined\`, \`strictMode\` expected to be a \`boolean\` type, \`customDateFormats\` expected to be a \`array\` type and \`onError\` expected to be a \`void function\` type. But received: ['convertBooleans': \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
67
|
+
convertBooleans
|
|
68
|
+
)}\`, 'convertDates': \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
69
|
+
convertDates
|
|
70
|
+
)}\`, 'convertNumbers': \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
71
|
+
convertNumbers
|
|
72
|
+
)}\`, 'loggingOnFail': \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
73
|
+
loggingOnFail
|
|
74
|
+
)}\`, 'removeEmptyArrays': \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
75
|
+
removeEmptyArrays
|
|
76
|
+
)}\`, 'removeEmptyObjects': \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
77
|
+
removeEmptyObjects
|
|
78
|
+
)}\`, 'removeNulls': \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
79
|
+
removeNulls
|
|
80
|
+
)}\`, 'removeUndefined': \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
81
|
+
removeUndefined
|
|
82
|
+
)}\`, 'strictMode': \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
83
|
+
strictMode
|
|
84
|
+
)}\`, 'customDateFormats': \`${chunkPZQ6I4JJ_cjs.getPreciseType(
|
|
85
|
+
customDateFormats
|
|
86
|
+
)}\`, 'onError': \`${chunkPZQ6I4JJ_cjs.getPreciseType(onError)}\`].`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
convertBooleans,
|
|
91
|
+
convertDates,
|
|
92
|
+
convertNumbers,
|
|
93
|
+
convertNaN,
|
|
94
|
+
loggingOnFail,
|
|
95
|
+
removeEmptyArrays,
|
|
96
|
+
removeEmptyObjects,
|
|
97
|
+
removeNulls,
|
|
98
|
+
removeUndefined,
|
|
99
|
+
strictMode,
|
|
100
|
+
customDateFormats,
|
|
101
|
+
onError,
|
|
102
|
+
checkSymbols
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
var cleanParsedData = (data, options = {}) => {
|
|
107
|
+
const validOptions = validateJsonParsingOptions(options);
|
|
108
|
+
if (chunkPZQ6I4JJ_cjs.isNull(data)) return validOptions.removeNulls ? void 0 : null;
|
|
109
|
+
if (chunkPZQ6I4JJ_cjs.isUndefined(data)) return validOptions.removeUndefined ? void 0 : void 0;
|
|
110
|
+
if (chunkPZQ6I4JJ_cjs.isString(data)) {
|
|
111
|
+
const trimmed = data.trim();
|
|
112
|
+
if (validOptions.convertNaN && trimmed === "NaN") return NaN;
|
|
113
|
+
if (validOptions.convertNumbers && !isNaN(Number(trimmed))) {
|
|
114
|
+
return Number(trimmed);
|
|
115
|
+
}
|
|
116
|
+
if (validOptions.convertBooleans) {
|
|
117
|
+
if (trimmed === "true") return true;
|
|
118
|
+
if (trimmed === "false") return false;
|
|
119
|
+
}
|
|
120
|
+
if (validOptions.convertDates) {
|
|
121
|
+
if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(trimmed)) {
|
|
122
|
+
return new Date(trimmed);
|
|
123
|
+
}
|
|
124
|
+
if (validOptions.customDateFormats?.length) {
|
|
125
|
+
for (const format of validOptions.customDateFormats) {
|
|
126
|
+
const date = parseCustomDate(trimmed, format);
|
|
127
|
+
if (date) return date;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return validOptions.strictMode ? void 0 : trimmed;
|
|
132
|
+
}
|
|
133
|
+
if (chunkPZQ6I4JJ_cjs.isArray(data)) {
|
|
134
|
+
const cleanedArray = data.map((item) => cleanParsedData(item, validOptions)).filter((item) => !chunkPZQ6I4JJ_cjs.isUndefined(item));
|
|
135
|
+
return validOptions.removeEmptyArrays && chunkZETAZZLD_cjs.isEmptyArray(cleanedArray) ? void 0 : cleanedArray;
|
|
136
|
+
}
|
|
137
|
+
if (chunkPZQ6I4JJ_cjs.isObject(data)) {
|
|
138
|
+
const cleanedObject = {};
|
|
139
|
+
for (const key in data) {
|
|
140
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
141
|
+
const cleanedValue = cleanParsedData(data[key], validOptions);
|
|
142
|
+
if (!chunkPZQ6I4JJ_cjs.isUndefined(cleanedValue)) {
|
|
143
|
+
cleanedObject[key] = cleanedValue;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return validOptions.removeEmptyObjects && chunkZETAZZLD_cjs.isEmptyObject(cleanedObject, { checkSymbols: validOptions.checkSymbols }) ? void 0 : cleanedObject;
|
|
148
|
+
}
|
|
149
|
+
return validOptions.strictMode ? void 0 : data;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
var extractDigits = (value) => {
|
|
153
|
+
if (!chunkPZQ6I4JJ_cjs.isString(value) && !chunkPZQ6I4JJ_cjs.isNumber(value)) return 0;
|
|
154
|
+
const cleaned = String(value).trim().replace(/[^0-9]/g, "");
|
|
155
|
+
return Number(cleaned) || 0;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
function fixSingleQuotesEscapeBackslash(input) {
|
|
159
|
+
const validEscapes = /* @__PURE__ */ new Set(["\\", '"', "/", "b", "f", "n", "r", "t", "u"]);
|
|
160
|
+
let output = "";
|
|
161
|
+
let inSingleQuote = false;
|
|
162
|
+
let inDoubleQuote = false;
|
|
163
|
+
let escapeNext = false;
|
|
164
|
+
for (let i = 0; i < input.length; i++) {
|
|
165
|
+
const c = input[i];
|
|
166
|
+
if (escapeNext) {
|
|
167
|
+
if (inSingleQuote) {
|
|
168
|
+
if (c === "'") {
|
|
169
|
+
output += "'";
|
|
170
|
+
} else if (validEscapes.has(c)) {
|
|
171
|
+
if (c === "\\") {
|
|
172
|
+
output += "\\\\";
|
|
173
|
+
} else if (c === '"') {
|
|
174
|
+
output += '\\"';
|
|
175
|
+
} else {
|
|
176
|
+
output += "\\" + c;
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
output += "\\\\" + c;
|
|
180
|
+
}
|
|
181
|
+
} else if (inDoubleQuote) {
|
|
182
|
+
if (c === '"') {
|
|
183
|
+
output += '\\"';
|
|
184
|
+
} else if (validEscapes.has(c)) {
|
|
185
|
+
output += "\\" + c;
|
|
186
|
+
} else {
|
|
187
|
+
output += "\\\\" + c;
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
output += "\\" + c;
|
|
191
|
+
}
|
|
192
|
+
escapeNext = false;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (c === "\\") {
|
|
196
|
+
escapeNext = true;
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (!inSingleQuote && !inDoubleQuote) {
|
|
200
|
+
if (c === "'") {
|
|
201
|
+
output += '"';
|
|
202
|
+
inSingleQuote = true;
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if (c === '"') {
|
|
206
|
+
output += '"';
|
|
207
|
+
inDoubleQuote = true;
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
} else if (inSingleQuote) {
|
|
211
|
+
if (c === "'") {
|
|
212
|
+
output += '"';
|
|
213
|
+
inSingleQuote = false;
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
} else if (inDoubleQuote) {
|
|
217
|
+
if (c === '"') {
|
|
218
|
+
output += '"';
|
|
219
|
+
inDoubleQuote = false;
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
output += c;
|
|
224
|
+
}
|
|
225
|
+
return output;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function safeJsonParse(value, options = {}) {
|
|
229
|
+
if (chunkPZQ6I4JJ_cjs.isNull(value)) return null;
|
|
230
|
+
const validOptions = validateJsonParsingOptions(options);
|
|
231
|
+
if (validOptions.convertNaN && (chunkPZQ6I4JJ_cjs.isNaN(value) || chunkPZQ6I4JJ_cjs.isNonEmptyString(value) && value === "NaN")) {
|
|
232
|
+
return NaN;
|
|
233
|
+
}
|
|
234
|
+
if (validOptions.convertNumbers && !chunkPZQ6I4JJ_cjs.isNaN(Number(value)) && chunkPZQ6I4JJ_cjs.isNumber(extractDigits(value))) {
|
|
235
|
+
return Number(value);
|
|
236
|
+
}
|
|
237
|
+
if (!chunkPZQ6I4JJ_cjs.isString(value)) return void 0;
|
|
238
|
+
try {
|
|
239
|
+
let normalized = fixSingleQuotesEscapeBackslash(value);
|
|
240
|
+
if (validOptions.removeUndefined) {
|
|
241
|
+
normalized = normalized.replace(/,\s*"[^"]*"\s*:\s*undefined(?=\s*[},])/g, "").replace(/"[^"]*"\s*:\s*undefined\s*(,)?/g, "");
|
|
242
|
+
} else {
|
|
243
|
+
normalized = normalized.replace(/:\s*undefined(?=\s*[,}])/g, ":null");
|
|
244
|
+
}
|
|
245
|
+
if (validOptions.convertNaN) {
|
|
246
|
+
normalized = normalized.replace(/:\s*NaN(?=\s*[,}])/g, ':"NaN"');
|
|
247
|
+
} else {
|
|
248
|
+
normalized = normalized.replace(/:\s*NaN(?=\s*[,}])/g, ':"NaN"').replace(/,\s*"[^"]*"\s*:\s*NaN(?=\s*[},])/g, "").replace(/"[^"]*"\s*:\s*NaN\s*(,)?/g, "");
|
|
249
|
+
}
|
|
250
|
+
normalized = normalized.replace(/,(\s*[}\]])/g, "$1");
|
|
251
|
+
const parsed = JSON.parse(normalized);
|
|
252
|
+
return cleanParsedData(parsed, validOptions);
|
|
253
|
+
} catch (error) {
|
|
254
|
+
if (validOptions.loggingOnFail) {
|
|
255
|
+
console.error("Failed to parsing at `safeJsonParse`:", error);
|
|
256
|
+
}
|
|
257
|
+
validOptions.onError(
|
|
258
|
+
chunkPZQ6I4JJ_cjs.isError(error) ? new Error(error.message.replace(/^JSON\.parse:/, "Failed to parsing")) : new Error(String(error))
|
|
259
|
+
);
|
|
260
|
+
return void 0;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
exports.cleanParsedData = cleanParsedData;
|
|
265
|
+
exports.extractDigits = extractDigits;
|
|
266
|
+
exports.parseCustomDate = parseCustomDate;
|
|
267
|
+
exports.safeJsonParse = safeJsonParse;
|