@sdkwork/sdk-common 1.0.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/README.md +89 -0
- package/dist/auth/index.d.ts +3 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/token-manager.cjs +127 -0
- package/dist/auth/token-manager.cjs.map +1 -0
- package/dist/auth/token-manager.d.ts +80 -0
- package/dist/auth/token-manager.d.ts.map +1 -0
- package/dist/auth/token-manager.js +127 -0
- package/dist/auth/token-manager.js.map +1 -0
- package/dist/auth.cjs +9 -0
- package/dist/auth.cjs.map +1 -0
- package/dist/auth.js +9 -0
- package/dist/auth.js.map +1 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/types.cjs +54 -0
- package/dist/core/types.cjs.map +1 -0
- package/dist/core/types.d.ts +187 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +54 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core.cjs +11 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.js +11 -0
- package/dist/core.js.map +1 -0
- package/dist/errors/index.d.ts +103 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors.cjs +286 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.js +286 -0
- package/dist/errors.js.map +1 -0
- package/dist/http/base-client.cjs +485 -0
- package/dist/http/base-client.cjs.map +1 -0
- package/dist/http/base-client.d.ts +98 -0
- package/dist/http/base-client.d.ts.map +1 -0
- package/dist/http/base-client.js +485 -0
- package/dist/http/base-client.js.map +1 -0
- package/dist/http/index.d.ts +2 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http.cjs +6 -0
- package/dist/http.cjs.map +1 -0
- package/dist/http.js +6 -0
- package/dist/http.js.map +1 -0
- package/dist/index.cjs +48 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/array.d.ts +146 -0
- package/dist/utils/array.d.ts.map +1 -0
- package/dist/utils/cache.cjs +80 -0
- package/dist/utils/cache.cjs.map +1 -0
- package/dist/utils/cache.d.ts +25 -0
- package/dist/utils/cache.d.ts.map +1 -0
- package/dist/utils/cache.js +80 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/date.cjs +25 -0
- package/dist/utils/date.cjs.map +1 -0
- package/dist/utils/date.d.ts +127 -0
- package/dist/utils/date.d.ts.map +1 -0
- package/dist/utils/date.js +25 -0
- package/dist/utils/date.js.map +1 -0
- package/dist/utils/encoding.cjs +678 -0
- package/dist/utils/encoding.cjs.map +1 -0
- package/dist/utils/encoding.d.ts +107 -0
- package/dist/utils/encoding.d.ts.map +1 -0
- package/dist/utils/encoding.js +679 -0
- package/dist/utils/encoding.js.map +1 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/logger.cjs +110 -0
- package/dist/utils/logger.cjs.map +1 -0
- package/dist/utils/logger.d.ts +28 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +110 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/object.d.ts +131 -0
- package/dist/utils/object.d.ts.map +1 -0
- package/dist/utils/retry.cjs +73 -0
- package/dist/utils/retry.cjs.map +1 -0
- package/dist/utils/retry.d.ts +9 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +73 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/utils/string.cjs +820 -0
- package/dist/utils/string.cjs.map +1 -0
- package/dist/utils/string.d.ts +160 -0
- package/dist/utils/string.d.ts.map +1 -0
- package/dist/utils/string.js +821 -0
- package/dist/utils/string.js.map +1 -0
- package/dist/utils/url.d.ts +106 -0
- package/dist/utils/url.d.ts.map +1 -0
- package/dist/utils/validation.d.ts +157 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils.cjs +52 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.js +46 -0
- package/dist/utils.js.map +1 -0
- package/package.json +80 -0
|
@@ -0,0 +1,678 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
exports.Encoding = void 0;
|
|
4
|
+
((Encoding2) => {
|
|
5
|
+
function base64Encode2(input) {
|
|
6
|
+
let bytes;
|
|
7
|
+
if (typeof input === "string") {
|
|
8
|
+
bytes = new TextEncoder().encode(input);
|
|
9
|
+
} else {
|
|
10
|
+
bytes = input;
|
|
11
|
+
}
|
|
12
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
13
|
+
let result = "";
|
|
14
|
+
let i = 0;
|
|
15
|
+
while (i < bytes.length) {
|
|
16
|
+
const a = bytes[i++] ?? 0;
|
|
17
|
+
const b = i < bytes.length ? bytes[i++] ?? 0 : 0;
|
|
18
|
+
const c = i < bytes.length ? bytes[i++] ?? 0 : 0;
|
|
19
|
+
const bitmap = a << 16 | b << 8 | c;
|
|
20
|
+
result += chars[bitmap >> 18 & 63];
|
|
21
|
+
result += chars[bitmap >> 12 & 63];
|
|
22
|
+
result += i > bytes.length + 1 ? "=" : chars[bitmap >> 6 & 63];
|
|
23
|
+
result += i > bytes.length ? "=" : chars[bitmap & 63];
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
Encoding2.base64Encode = base64Encode2;
|
|
28
|
+
function base64Decode2(input) {
|
|
29
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
30
|
+
input = input.replace(/[^A-Za-z0-9+/]/g, "");
|
|
31
|
+
const len = input.length;
|
|
32
|
+
let result = "";
|
|
33
|
+
let i = 0;
|
|
34
|
+
while (i < len) {
|
|
35
|
+
const a = chars.indexOf(input[i++] ?? "");
|
|
36
|
+
const b = chars.indexOf(input[i++] ?? "");
|
|
37
|
+
const c = chars.indexOf(input[i++] ?? "");
|
|
38
|
+
const d = chars.indexOf(input[i++] ?? "");
|
|
39
|
+
const bitmap = a << 18 | b << 12 | c << 6 | d;
|
|
40
|
+
result += String.fromCharCode(bitmap >> 16 & 255);
|
|
41
|
+
if (c !== 64 && input[i - 2] !== "=") {
|
|
42
|
+
result += String.fromCharCode(bitmap >> 8 & 255);
|
|
43
|
+
}
|
|
44
|
+
if (d !== 64 && input[i - 1] !== "=") {
|
|
45
|
+
result += String.fromCharCode(bitmap & 255);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
Encoding2.base64Decode = base64Decode2;
|
|
51
|
+
function base64UrlEncode2(input) {
|
|
52
|
+
return base64Encode2(input).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
53
|
+
}
|
|
54
|
+
Encoding2.base64UrlEncode = base64UrlEncode2;
|
|
55
|
+
function base64UrlDecode2(input) {
|
|
56
|
+
input = input.replace(/-/g, "+").replace(/_/g, "/");
|
|
57
|
+
const pad = input.length % 4;
|
|
58
|
+
if (pad) {
|
|
59
|
+
input += "=".repeat(4 - pad);
|
|
60
|
+
}
|
|
61
|
+
return base64Decode2(input);
|
|
62
|
+
}
|
|
63
|
+
Encoding2.base64UrlDecode = base64UrlDecode2;
|
|
64
|
+
function base64ToBytes(base64) {
|
|
65
|
+
const binary = atob(base64);
|
|
66
|
+
const bytes = new Uint8Array(binary.length);
|
|
67
|
+
for (let i = 0; i < binary.length; i++) {
|
|
68
|
+
bytes[i] = binary.charCodeAt(i);
|
|
69
|
+
}
|
|
70
|
+
return bytes;
|
|
71
|
+
}
|
|
72
|
+
Encoding2.base64ToBytes = base64ToBytes;
|
|
73
|
+
function bytesToBase64(bytes) {
|
|
74
|
+
let binary = "";
|
|
75
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
76
|
+
binary += String.fromCharCode(bytes[i] ?? 0);
|
|
77
|
+
}
|
|
78
|
+
return btoa(binary);
|
|
79
|
+
}
|
|
80
|
+
Encoding2.bytesToBase64 = bytesToBase64;
|
|
81
|
+
function utf8Encode2(input) {
|
|
82
|
+
return new TextEncoder().encode(input);
|
|
83
|
+
}
|
|
84
|
+
Encoding2.utf8Encode = utf8Encode2;
|
|
85
|
+
function utf8Decode2(input) {
|
|
86
|
+
return new TextDecoder().decode(input);
|
|
87
|
+
}
|
|
88
|
+
Encoding2.utf8Decode = utf8Decode2;
|
|
89
|
+
function hexEncode2(input) {
|
|
90
|
+
const bytes = typeof input === "string" ? utf8Encode2(input) : input;
|
|
91
|
+
return Array.from(bytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
92
|
+
}
|
|
93
|
+
Encoding2.hexEncode = hexEncode2;
|
|
94
|
+
function hexDecode2(input) {
|
|
95
|
+
const bytes = new Uint8Array(input.length / 2);
|
|
96
|
+
for (let i = 0; i < input.length; i += 2) {
|
|
97
|
+
bytes[i / 2] = parseInt(input.substr(i, 2), 16);
|
|
98
|
+
}
|
|
99
|
+
return utf8Decode2(bytes);
|
|
100
|
+
}
|
|
101
|
+
Encoding2.hexDecode = hexDecode2;
|
|
102
|
+
function hexToBytes(hex) {
|
|
103
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
104
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
105
|
+
bytes[i / 2] = parseInt(hex.substr(i, 2), 16);
|
|
106
|
+
}
|
|
107
|
+
return bytes;
|
|
108
|
+
}
|
|
109
|
+
Encoding2.hexToBytes = hexToBytes;
|
|
110
|
+
function bytesToHex(bytes) {
|
|
111
|
+
return Array.from(bytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
112
|
+
}
|
|
113
|
+
Encoding2.bytesToHex = bytesToHex;
|
|
114
|
+
function urlEncode2(input) {
|
|
115
|
+
return encodeURIComponent(input);
|
|
116
|
+
}
|
|
117
|
+
Encoding2.urlEncode = urlEncode2;
|
|
118
|
+
function urlDecode2(input) {
|
|
119
|
+
return decodeURIComponent(input);
|
|
120
|
+
}
|
|
121
|
+
Encoding2.urlDecode = urlDecode2;
|
|
122
|
+
function urlEncodeComponent(input) {
|
|
123
|
+
return encodeURIComponent(input);
|
|
124
|
+
}
|
|
125
|
+
Encoding2.urlEncodeComponent = urlEncodeComponent;
|
|
126
|
+
function urlDecodeComponent(input) {
|
|
127
|
+
return decodeURIComponent(input);
|
|
128
|
+
}
|
|
129
|
+
Encoding2.urlDecodeComponent = urlDecodeComponent;
|
|
130
|
+
function htmlEncode2(input) {
|
|
131
|
+
const htmlEntities = {
|
|
132
|
+
"&": "&",
|
|
133
|
+
"<": "<",
|
|
134
|
+
">": ">",
|
|
135
|
+
'"': """,
|
|
136
|
+
"'": "'",
|
|
137
|
+
"/": "/",
|
|
138
|
+
"`": "`",
|
|
139
|
+
"=": "="
|
|
140
|
+
};
|
|
141
|
+
return input.replace(/[&<>"'`=/]/g, (char) => htmlEntities[char] || char);
|
|
142
|
+
}
|
|
143
|
+
Encoding2.htmlEncode = htmlEncode2;
|
|
144
|
+
function htmlDecode2(input) {
|
|
145
|
+
const htmlEntities = {
|
|
146
|
+
"&": "&",
|
|
147
|
+
"<": "<",
|
|
148
|
+
">": ">",
|
|
149
|
+
""": '"',
|
|
150
|
+
"'": "'",
|
|
151
|
+
"'": "'",
|
|
152
|
+
"/": "/",
|
|
153
|
+
"`": "`",
|
|
154
|
+
"=": "=",
|
|
155
|
+
" ": " "
|
|
156
|
+
};
|
|
157
|
+
return input.replace(/&[^;]+;/g, (entity) => htmlEntities[entity] || entity);
|
|
158
|
+
}
|
|
159
|
+
Encoding2.htmlDecode = htmlDecode2;
|
|
160
|
+
function jsonEncode2(value, replacer, space) {
|
|
161
|
+
return JSON.stringify(value, replacer, space);
|
|
162
|
+
}
|
|
163
|
+
Encoding2.jsonEncode = jsonEncode2;
|
|
164
|
+
function jsonDecode2(input) {
|
|
165
|
+
return JSON.parse(input);
|
|
166
|
+
}
|
|
167
|
+
Encoding2.jsonDecode = jsonDecode2;
|
|
168
|
+
function jsonEncodePretty(value, indent = 2) {
|
|
169
|
+
return JSON.stringify(value, null, indent);
|
|
170
|
+
}
|
|
171
|
+
Encoding2.jsonEncodePretty = jsonEncodePretty;
|
|
172
|
+
function tryJsonDecode(input, defaultValue) {
|
|
173
|
+
try {
|
|
174
|
+
return JSON.parse(input);
|
|
175
|
+
} catch {
|
|
176
|
+
return defaultValue;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
Encoding2.tryJsonDecode = tryJsonDecode;
|
|
180
|
+
function isJson(input) {
|
|
181
|
+
try {
|
|
182
|
+
JSON.parse(input);
|
|
183
|
+
return true;
|
|
184
|
+
} catch {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
Encoding2.isJson = isJson;
|
|
189
|
+
function xmlEncode2(input) {
|
|
190
|
+
const xmlEntities = {
|
|
191
|
+
"&": "&",
|
|
192
|
+
"<": "<",
|
|
193
|
+
">": ">",
|
|
194
|
+
'"': """,
|
|
195
|
+
"'": "'"
|
|
196
|
+
};
|
|
197
|
+
return input.replace(/[&<>"']/g, (char) => xmlEntities[char] || char);
|
|
198
|
+
}
|
|
199
|
+
Encoding2.xmlEncode = xmlEncode2;
|
|
200
|
+
function xmlDecode2(input) {
|
|
201
|
+
const xmlEntities = {
|
|
202
|
+
"&": "&",
|
|
203
|
+
"<": "<",
|
|
204
|
+
">": ">",
|
|
205
|
+
""": '"',
|
|
206
|
+
"'": "'"
|
|
207
|
+
};
|
|
208
|
+
return input.replace(/&[^;]+;/g, (entity) => xmlEntities[entity] || entity);
|
|
209
|
+
}
|
|
210
|
+
Encoding2.xmlDecode = xmlDecode2;
|
|
211
|
+
function escapeRegex2(input) {
|
|
212
|
+
return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
213
|
+
}
|
|
214
|
+
Encoding2.escapeRegex = escapeRegex2;
|
|
215
|
+
function escapeSql2(input) {
|
|
216
|
+
return input.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, (char) => {
|
|
217
|
+
const sqlEscapes = {
|
|
218
|
+
"\0": "\\0",
|
|
219
|
+
"\b": "\\b",
|
|
220
|
+
" ": "\\t",
|
|
221
|
+
"": "\\z",
|
|
222
|
+
"\n": "\\n",
|
|
223
|
+
"\r": "\\r",
|
|
224
|
+
'"': '\\"',
|
|
225
|
+
"'": "\\'",
|
|
226
|
+
"\\": "\\\\",
|
|
227
|
+
"%": "\\%"
|
|
228
|
+
};
|
|
229
|
+
return sqlEscapes[char] || char;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
Encoding2.escapeSql = escapeSql2;
|
|
233
|
+
function escapeShell2(input) {
|
|
234
|
+
return input.replace(/[^A-Za-z0-9_\-.,:\/@\n]/g, (char) => {
|
|
235
|
+
if (char === "\n") {
|
|
236
|
+
return "'\\n'";
|
|
237
|
+
}
|
|
238
|
+
return `\\${char}`;
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
Encoding2.escapeShell = escapeShell2;
|
|
242
|
+
function escapeCString(input) {
|
|
243
|
+
return input.replace(/[\\"'\n\r\t\b\f\v\0]/g, (char) => {
|
|
244
|
+
const cEscapes = {
|
|
245
|
+
"\\": "\\\\",
|
|
246
|
+
'"': '\\"',
|
|
247
|
+
"'": "\\'",
|
|
248
|
+
"\n": "\\n",
|
|
249
|
+
"\r": "\\r",
|
|
250
|
+
" ": "\\t",
|
|
251
|
+
"\b": "\\b",
|
|
252
|
+
"\f": "\\f",
|
|
253
|
+
"\v": "\\v",
|
|
254
|
+
"\0": "\\0"
|
|
255
|
+
};
|
|
256
|
+
return cEscapes[char] || char;
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
Encoding2.escapeCString = escapeCString;
|
|
260
|
+
function unescapeCString(input) {
|
|
261
|
+
return input.replace(/\\([\\\"'nrtbfv0])/g, (_, char) => {
|
|
262
|
+
const cUnescapes = {
|
|
263
|
+
"\\": "\\",
|
|
264
|
+
'"': '"',
|
|
265
|
+
"'": "'",
|
|
266
|
+
"n": "\n",
|
|
267
|
+
"r": "\r",
|
|
268
|
+
"t": " ",
|
|
269
|
+
"b": "\b",
|
|
270
|
+
"f": "\f",
|
|
271
|
+
"v": "\v",
|
|
272
|
+
"0": "\0"
|
|
273
|
+
};
|
|
274
|
+
return cUnescapes[char] || char;
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
Encoding2.unescapeCString = unescapeCString;
|
|
278
|
+
function camelToSnake(input) {
|
|
279
|
+
return input.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
280
|
+
}
|
|
281
|
+
Encoding2.camelToSnake = camelToSnake;
|
|
282
|
+
function snakeToCamel(input) {
|
|
283
|
+
return input.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
284
|
+
}
|
|
285
|
+
Encoding2.snakeToCamel = snakeToCamel;
|
|
286
|
+
function camelToKebab(input) {
|
|
287
|
+
return input.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
288
|
+
}
|
|
289
|
+
Encoding2.camelToKebab = camelToKebab;
|
|
290
|
+
function kebabToCamel(input) {
|
|
291
|
+
return input.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
292
|
+
}
|
|
293
|
+
Encoding2.kebabToCamel = kebabToCamel;
|
|
294
|
+
function camelToPascal(input) {
|
|
295
|
+
return input.charAt(0).toUpperCase() + input.slice(1);
|
|
296
|
+
}
|
|
297
|
+
Encoding2.camelToPascal = camelToPascal;
|
|
298
|
+
function pascalToCamel(input) {
|
|
299
|
+
return input.charAt(0).toLowerCase() + input.slice(1);
|
|
300
|
+
}
|
|
301
|
+
Encoding2.pascalToCamel = pascalToCamel;
|
|
302
|
+
function pascalToSnake(input) {
|
|
303
|
+
return camelToSnake(input);
|
|
304
|
+
}
|
|
305
|
+
Encoding2.pascalToSnake = pascalToSnake;
|
|
306
|
+
function snakeToPascal(input) {
|
|
307
|
+
return camelToPascal(snakeToCamel(input));
|
|
308
|
+
}
|
|
309
|
+
Encoding2.snakeToPascal = snakeToPascal;
|
|
310
|
+
function pascalToKebab(input) {
|
|
311
|
+
return camelToKebab(input);
|
|
312
|
+
}
|
|
313
|
+
Encoding2.pascalToKebab = pascalToKebab;
|
|
314
|
+
function kebabToPascal(input) {
|
|
315
|
+
return camelToPascal(kebabToCamel(input));
|
|
316
|
+
}
|
|
317
|
+
Encoding2.kebabToPascal = kebabToPascal;
|
|
318
|
+
function toSnakeCase(input) {
|
|
319
|
+
return input.replace(/([a-z])([A-Z])/g, "$1_$2").replace(/[-\s]+/g, "_").toLowerCase();
|
|
320
|
+
}
|
|
321
|
+
Encoding2.toSnakeCase = toSnakeCase;
|
|
322
|
+
function toKebabCase(input) {
|
|
323
|
+
return input.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[_\s]+/g, "-").toLowerCase();
|
|
324
|
+
}
|
|
325
|
+
Encoding2.toKebabCase = toKebabCase;
|
|
326
|
+
function toCamelCase(input) {
|
|
327
|
+
return input.replace(/[-_\s]+(.)?/g, (_, char) => char ? char.toUpperCase() : "").replace(/^(.)/, (char) => char.toLowerCase());
|
|
328
|
+
}
|
|
329
|
+
Encoding2.toCamelCase = toCamelCase;
|
|
330
|
+
function toPascalCase(input) {
|
|
331
|
+
const camel = toCamelCase(input);
|
|
332
|
+
return camel.charAt(0).toUpperCase() + camel.slice(1);
|
|
333
|
+
}
|
|
334
|
+
Encoding2.toPascalCase = toPascalCase;
|
|
335
|
+
function toConstantCase(input) {
|
|
336
|
+
return toSnakeCase(input).toUpperCase();
|
|
337
|
+
}
|
|
338
|
+
Encoding2.toConstantCase = toConstantCase;
|
|
339
|
+
function toSentenceCase(input) {
|
|
340
|
+
return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase();
|
|
341
|
+
}
|
|
342
|
+
Encoding2.toSentenceCase = toSentenceCase;
|
|
343
|
+
function toTitleCase(input) {
|
|
344
|
+
return input.replace(/\b\w/g, (char) => char.toUpperCase());
|
|
345
|
+
}
|
|
346
|
+
Encoding2.toTitleCase = toTitleCase;
|
|
347
|
+
function toCapitalCase(input) {
|
|
348
|
+
return input.replace(/[-_\s]+(.)?/g, (_, char) => char ? ` ${char.toUpperCase()}` : "").trim();
|
|
349
|
+
}
|
|
350
|
+
Encoding2.toCapitalCase = toCapitalCase;
|
|
351
|
+
function toDotCase(input) {
|
|
352
|
+
return input.replace(/([a-z])([A-Z])/g, "$1.$2").replace(/[-_\s]+/g, ".").toLowerCase();
|
|
353
|
+
}
|
|
354
|
+
Encoding2.toDotCase = toDotCase;
|
|
355
|
+
function toPathCase(input) {
|
|
356
|
+
return input.replace(/([a-z])([A-Z])/g, "$1/$2").replace(/[-_\s]+/g, "/").toLowerCase();
|
|
357
|
+
}
|
|
358
|
+
Encoding2.toPathCase = toPathCase;
|
|
359
|
+
function rot13(input) {
|
|
360
|
+
return input.replace(/[a-zA-Z]/g, (char) => {
|
|
361
|
+
const start = char <= "Z" ? 65 : 97;
|
|
362
|
+
return String.fromCharCode((char.charCodeAt(0) - start + 13) % 26 + start);
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
Encoding2.rot13 = rot13;
|
|
366
|
+
function caesarCipher(input, shift) {
|
|
367
|
+
return input.replace(/[a-zA-Z]/g, (char) => {
|
|
368
|
+
const start = char <= "Z" ? 65 : 97;
|
|
369
|
+
const shifted = ((char.charCodeAt(0) - start + shift) % 26 + 26) % 26;
|
|
370
|
+
return String.fromCharCode(shifted + start);
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
Encoding2.caesarCipher = caesarCipher;
|
|
374
|
+
function caesarDecipher(input, shift) {
|
|
375
|
+
return caesarCipher(input, -shift);
|
|
376
|
+
}
|
|
377
|
+
Encoding2.caesarDecipher = caesarDecipher;
|
|
378
|
+
function xorEncode(input, key) {
|
|
379
|
+
const inputBytes = utf8Encode2(input);
|
|
380
|
+
const keyBytes = utf8Encode2(key);
|
|
381
|
+
const result = new Uint8Array(inputBytes.length);
|
|
382
|
+
for (let i = 0; i < inputBytes.length; i++) {
|
|
383
|
+
result[i] = (inputBytes[i] ?? 0) ^ (keyBytes[i % keyBytes.length] ?? 0);
|
|
384
|
+
}
|
|
385
|
+
return bytesToHex(result);
|
|
386
|
+
}
|
|
387
|
+
Encoding2.xorEncode = xorEncode;
|
|
388
|
+
function xorDecode(input, key) {
|
|
389
|
+
const inputBytes = hexToBytes(input);
|
|
390
|
+
const keyBytes = utf8Encode2(key);
|
|
391
|
+
const result = new Uint8Array(inputBytes.length);
|
|
392
|
+
for (let i = 0; i < inputBytes.length; i++) {
|
|
393
|
+
result[i] = (inputBytes[i] ?? 0) ^ (keyBytes[i % keyBytes.length] ?? 0);
|
|
394
|
+
}
|
|
395
|
+
return utf8Decode2(result);
|
|
396
|
+
}
|
|
397
|
+
Encoding2.xorDecode = xorDecode;
|
|
398
|
+
function charCodeEncode(input) {
|
|
399
|
+
return Array.from(input).map((char) => char.charCodeAt(0));
|
|
400
|
+
}
|
|
401
|
+
Encoding2.charCodeEncode = charCodeEncode;
|
|
402
|
+
function charCodeDecode(codes) {
|
|
403
|
+
return String.fromCharCode(...codes);
|
|
404
|
+
}
|
|
405
|
+
Encoding2.charCodeDecode = charCodeDecode;
|
|
406
|
+
function binaryEncode(input) {
|
|
407
|
+
return Array.from(input).map((char) => char.charCodeAt(0).toString(2).padStart(8, "0")).join(" ");
|
|
408
|
+
}
|
|
409
|
+
Encoding2.binaryEncode = binaryEncode;
|
|
410
|
+
function binaryDecode(input) {
|
|
411
|
+
return input.split(/\s+/).map((byte) => String.fromCharCode(parseInt(byte, 2))).join("");
|
|
412
|
+
}
|
|
413
|
+
Encoding2.binaryDecode = binaryDecode;
|
|
414
|
+
function octalEncode(input) {
|
|
415
|
+
return Array.from(input).map((char) => char.charCodeAt(0).toString(8).padStart(3, "0")).join(" ");
|
|
416
|
+
}
|
|
417
|
+
Encoding2.octalEncode = octalEncode;
|
|
418
|
+
function octalDecode(input) {
|
|
419
|
+
return input.split(/\s+/).map((byte) => String.fromCharCode(parseInt(byte, 8))).join("");
|
|
420
|
+
}
|
|
421
|
+
Encoding2.octalDecode = octalDecode;
|
|
422
|
+
function decimalEncode(input) {
|
|
423
|
+
return Array.from(input).map((char) => char.charCodeAt(0).toString(10)).join(" ");
|
|
424
|
+
}
|
|
425
|
+
Encoding2.decimalEncode = decimalEncode;
|
|
426
|
+
function decimalDecode(input) {
|
|
427
|
+
return input.split(/\s+/).map((code) => String.fromCharCode(parseInt(code, 10))).join("");
|
|
428
|
+
}
|
|
429
|
+
Encoding2.decimalDecode = decimalDecode;
|
|
430
|
+
function punycodeEncode(input) {
|
|
431
|
+
const prefix = "xn--";
|
|
432
|
+
if (input.startsWith(prefix)) {
|
|
433
|
+
return input;
|
|
434
|
+
}
|
|
435
|
+
const asciiPart = input.replace(/[^\x00-\x7F]/g, "");
|
|
436
|
+
const nonAsciiPart = input.replace(/[\x00-\x7F]/g, "");
|
|
437
|
+
if (!nonAsciiPart) {
|
|
438
|
+
return input;
|
|
439
|
+
}
|
|
440
|
+
return prefix + asciiPart + "-" + nonAsciiPart.split("").map((c) => c.charCodeAt(0).toString(36)).join("");
|
|
441
|
+
}
|
|
442
|
+
Encoding2.punycodeEncode = punycodeEncode;
|
|
443
|
+
function slugify2(input) {
|
|
444
|
+
return input.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
445
|
+
}
|
|
446
|
+
Encoding2.slugify = slugify2;
|
|
447
|
+
function unslugify2(input) {
|
|
448
|
+
return input.replace(/-/g, " ").replace(/\b\w/g, (char) => char.toUpperCase());
|
|
449
|
+
}
|
|
450
|
+
Encoding2.unslugify = unslugify2;
|
|
451
|
+
function queryStringEncode2(params) {
|
|
452
|
+
return Object.entries(params).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => {
|
|
453
|
+
if (Array.isArray(value)) {
|
|
454
|
+
return value.map((v) => `${urlEncode2(key)}=${urlEncode2(String(v))}`).join("&");
|
|
455
|
+
}
|
|
456
|
+
return `${urlEncode2(key)}=${urlEncode2(String(value))}`;
|
|
457
|
+
}).join("&");
|
|
458
|
+
}
|
|
459
|
+
Encoding2.queryStringEncode = queryStringEncode2;
|
|
460
|
+
function queryStringDecode2(query) {
|
|
461
|
+
const result = {};
|
|
462
|
+
if (!query) {
|
|
463
|
+
return result;
|
|
464
|
+
}
|
|
465
|
+
query = query.replace(/^[?#]/, "");
|
|
466
|
+
for (const pair of query.split("&")) {
|
|
467
|
+
const parts = pair.split("=");
|
|
468
|
+
const key = parts[0];
|
|
469
|
+
const value = parts[1];
|
|
470
|
+
if (!key) continue;
|
|
471
|
+
const decodedKey = urlDecode2(key);
|
|
472
|
+
const decodedValue = value ? urlDecode2(value) : "";
|
|
473
|
+
if (result[decodedKey]) {
|
|
474
|
+
if (Array.isArray(result[decodedKey])) {
|
|
475
|
+
result[decodedKey].push(decodedValue);
|
|
476
|
+
} else {
|
|
477
|
+
result[decodedKey] = [result[decodedKey], decodedValue];
|
|
478
|
+
}
|
|
479
|
+
} else {
|
|
480
|
+
result[decodedKey] = decodedValue;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
return result;
|
|
484
|
+
}
|
|
485
|
+
Encoding2.queryStringDecode = queryStringDecode2;
|
|
486
|
+
function formDataEncode(data) {
|
|
487
|
+
return Object.entries(data).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${urlEncode2(key)}=${urlEncode2(String(value))}`).join("&");
|
|
488
|
+
}
|
|
489
|
+
Encoding2.formDataEncode = formDataEncode;
|
|
490
|
+
function mimeTypeToExtension(mimeType) {
|
|
491
|
+
const mimeMap = {
|
|
492
|
+
"application/json": "json",
|
|
493
|
+
"application/xml": "xml",
|
|
494
|
+
"application/pdf": "pdf",
|
|
495
|
+
"application/zip": "zip",
|
|
496
|
+
"application/gzip": "gz",
|
|
497
|
+
"application/x-tar": "tar",
|
|
498
|
+
"application/x-rar-compressed": "rar",
|
|
499
|
+
"application/x-7z-compressed": "7z",
|
|
500
|
+
"application/vnd.ms-excel": "xls",
|
|
501
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
|
|
502
|
+
"application/vnd.ms-powerpoint": "ppt",
|
|
503
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation": "pptx",
|
|
504
|
+
"application/msword": "doc",
|
|
505
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
|
|
506
|
+
"text/plain": "txt",
|
|
507
|
+
"text/html": "html",
|
|
508
|
+
"text/css": "css",
|
|
509
|
+
"text/javascript": "js",
|
|
510
|
+
"text/csv": "csv",
|
|
511
|
+
"text/xml": "xml",
|
|
512
|
+
"image/jpeg": "jpg",
|
|
513
|
+
"image/png": "png",
|
|
514
|
+
"image/gif": "gif",
|
|
515
|
+
"image/svg+xml": "svg",
|
|
516
|
+
"image/webp": "webp",
|
|
517
|
+
"image/bmp": "bmp",
|
|
518
|
+
"image/tiff": "tiff",
|
|
519
|
+
"image/x-icon": "ico",
|
|
520
|
+
"audio/mpeg": "mp3",
|
|
521
|
+
"audio/wav": "wav",
|
|
522
|
+
"audio/ogg": "ogg",
|
|
523
|
+
"audio/aac": "aac",
|
|
524
|
+
"video/mp4": "mp4",
|
|
525
|
+
"video/mpeg": "mpeg",
|
|
526
|
+
"video/webm": "webm",
|
|
527
|
+
"video/ogg": "ogv",
|
|
528
|
+
"video/x-msvideo": "avi",
|
|
529
|
+
"video/quicktime": "mov"
|
|
530
|
+
};
|
|
531
|
+
return mimeMap[mimeType.toLowerCase()] || "";
|
|
532
|
+
}
|
|
533
|
+
Encoding2.mimeTypeToExtension = mimeTypeToExtension;
|
|
534
|
+
function extensionToMimeType(extension) {
|
|
535
|
+
const extMap = {
|
|
536
|
+
"json": "application/json",
|
|
537
|
+
"xml": "application/xml",
|
|
538
|
+
"pdf": "application/pdf",
|
|
539
|
+
"zip": "application/zip",
|
|
540
|
+
"gz": "application/gzip",
|
|
541
|
+
"tar": "application/x-tar",
|
|
542
|
+
"rar": "application/x-rar-compressed",
|
|
543
|
+
"7z": "application/x-7z-compressed",
|
|
544
|
+
"xls": "application/vnd.ms-excel",
|
|
545
|
+
"xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
546
|
+
"ppt": "application/vnd.ms-powerpoint",
|
|
547
|
+
"pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
548
|
+
"doc": "application/msword",
|
|
549
|
+
"docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
550
|
+
"txt": "text/plain",
|
|
551
|
+
"html": "text/html",
|
|
552
|
+
"htm": "text/html",
|
|
553
|
+
"css": "text/css",
|
|
554
|
+
"js": "text/javascript",
|
|
555
|
+
"csv": "text/csv",
|
|
556
|
+
"jpg": "image/jpeg",
|
|
557
|
+
"jpeg": "image/jpeg",
|
|
558
|
+
"png": "image/png",
|
|
559
|
+
"gif": "image/gif",
|
|
560
|
+
"svg": "image/svg+xml",
|
|
561
|
+
"webp": "image/webp",
|
|
562
|
+
"bmp": "image/bmp",
|
|
563
|
+
"tiff": "image/tiff",
|
|
564
|
+
"tif": "image/tiff",
|
|
565
|
+
"ico": "image/x-icon",
|
|
566
|
+
"mp3": "audio/mpeg",
|
|
567
|
+
"wav": "audio/wav",
|
|
568
|
+
"ogg": "audio/ogg",
|
|
569
|
+
"aac": "audio/aac",
|
|
570
|
+
"mp4": "video/mp4",
|
|
571
|
+
"mpeg": "video/mpeg",
|
|
572
|
+
"mpg": "video/mpeg",
|
|
573
|
+
"webm": "video/webm",
|
|
574
|
+
"ogv": "video/ogg",
|
|
575
|
+
"avi": "video/x-msvideo",
|
|
576
|
+
"mov": "video/quicktime"
|
|
577
|
+
};
|
|
578
|
+
return extMap[extension.toLowerCase().replace(/^\./, "")] || "application/octet-stream";
|
|
579
|
+
}
|
|
580
|
+
Encoding2.extensionToMimeType = extensionToMimeType;
|
|
581
|
+
function charsetEncode(input, _charset) {
|
|
582
|
+
const encoder = new TextEncoder();
|
|
583
|
+
return encoder.encode(input);
|
|
584
|
+
}
|
|
585
|
+
Encoding2.charsetEncode = charsetEncode;
|
|
586
|
+
function charsetDecode(input, charset) {
|
|
587
|
+
const decoder = new TextDecoder(charset);
|
|
588
|
+
return decoder.decode(input);
|
|
589
|
+
}
|
|
590
|
+
Encoding2.charsetDecode = charsetDecode;
|
|
591
|
+
function stripBom(input) {
|
|
592
|
+
if (input.charCodeAt(0) === 65279) {
|
|
593
|
+
return input.slice(1);
|
|
594
|
+
}
|
|
595
|
+
return input;
|
|
596
|
+
}
|
|
597
|
+
Encoding2.stripBom = stripBom;
|
|
598
|
+
function addBom(input, bom = "utf-8") {
|
|
599
|
+
const boms = {
|
|
600
|
+
"utf-8": "\uFEFF",
|
|
601
|
+
"utf-16le": "",
|
|
602
|
+
"utf-16be": "\uFEFF"
|
|
603
|
+
};
|
|
604
|
+
return boms[bom] + input;
|
|
605
|
+
}
|
|
606
|
+
Encoding2.addBom = addBom;
|
|
607
|
+
function normalizeEncoding(input, fromEncoding, toEncoding) {
|
|
608
|
+
const bytes = charsetEncode(input);
|
|
609
|
+
return charsetDecode(bytes, toEncoding);
|
|
610
|
+
}
|
|
611
|
+
Encoding2.normalizeEncoding = normalizeEncoding;
|
|
612
|
+
function isValidBase64(input) {
|
|
613
|
+
if (!input || input.length % 4 !== 0) {
|
|
614
|
+
return false;
|
|
615
|
+
}
|
|
616
|
+
const base64Regex = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
617
|
+
return base64Regex.test(input);
|
|
618
|
+
}
|
|
619
|
+
Encoding2.isValidBase64 = isValidBase64;
|
|
620
|
+
function isValidHex(input) {
|
|
621
|
+
return /^[0-9a-fA-F]*$/.test(input) && input.length % 2 === 0;
|
|
622
|
+
}
|
|
623
|
+
Encoding2.isValidHex = isValidHex;
|
|
624
|
+
function isValidUrl(input) {
|
|
625
|
+
try {
|
|
626
|
+
new URL(input);
|
|
627
|
+
return true;
|
|
628
|
+
} catch {
|
|
629
|
+
return false;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
Encoding2.isValidUrl = isValidUrl;
|
|
633
|
+
function isValidEmail(input) {
|
|
634
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
635
|
+
return emailRegex.test(input);
|
|
636
|
+
}
|
|
637
|
+
Encoding2.isValidEmail = isValidEmail;
|
|
638
|
+
function detectEncoding(input) {
|
|
639
|
+
if (input.charCodeAt(0) === 65279) {
|
|
640
|
+
return "utf-8-bom";
|
|
641
|
+
}
|
|
642
|
+
if (input.charCodeAt(0) === 65534) {
|
|
643
|
+
return "utf-16le";
|
|
644
|
+
}
|
|
645
|
+
if (input.charCodeAt(0) === 65279 && input.charCodeAt(1) === 0) {
|
|
646
|
+
return "utf-16be";
|
|
647
|
+
}
|
|
648
|
+
if (/[\u4e00-\u9fa5]/.test(input)) {
|
|
649
|
+
return "utf-8";
|
|
650
|
+
}
|
|
651
|
+
return "ascii";
|
|
652
|
+
}
|
|
653
|
+
Encoding2.detectEncoding = detectEncoding;
|
|
654
|
+
})(exports.Encoding || (exports.Encoding = {}));
|
|
655
|
+
exports.Encoding.base64Encode;
|
|
656
|
+
exports.Encoding.base64Decode;
|
|
657
|
+
exports.Encoding.base64UrlEncode;
|
|
658
|
+
exports.Encoding.base64UrlDecode;
|
|
659
|
+
exports.Encoding.utf8Encode;
|
|
660
|
+
exports.Encoding.utf8Decode;
|
|
661
|
+
exports.Encoding.hexEncode;
|
|
662
|
+
exports.Encoding.hexDecode;
|
|
663
|
+
exports.Encoding.urlEncode;
|
|
664
|
+
exports.Encoding.urlDecode;
|
|
665
|
+
exports.Encoding.htmlEncode;
|
|
666
|
+
exports.Encoding.htmlDecode;
|
|
667
|
+
exports.Encoding.jsonEncode;
|
|
668
|
+
exports.Encoding.jsonDecode;
|
|
669
|
+
exports.Encoding.xmlEncode;
|
|
670
|
+
exports.Encoding.xmlDecode;
|
|
671
|
+
exports.Encoding.escapeRegex;
|
|
672
|
+
exports.Encoding.escapeSql;
|
|
673
|
+
exports.Encoding.escapeShell;
|
|
674
|
+
exports.Encoding.queryStringEncode;
|
|
675
|
+
exports.Encoding.queryStringDecode;
|
|
676
|
+
exports.Encoding.slugify;
|
|
677
|
+
exports.Encoding.unslugify;
|
|
678
|
+
//# sourceMappingURL=encoding.cjs.map
|