@amekusa/util.js 1.2.1 → 2.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 +37 -20
- package/dist/{import/bundle.js → amekusa.util.br.es.js} +164 -177
- package/dist/amekusa.util.br.es.min.js +73 -0
- package/dist/{require/bundle.cjs → amekusa.util.br.js} +163 -188
- package/dist/amekusa.util.br.min.js +73 -0
- package/dist/amekusa.util.cjs +926 -0
- package/dist/amekusa.util.js +926 -0
- package/package.json +8 -7
|
@@ -1,8 +1,166 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
this.amekusa=this.amekusa||{};this.amekusa.util=(function(exports){'use strict';/*!
|
|
2
|
+
* === @amekusa/util.js/gen === *
|
|
3
|
+
* MIT License
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2024 Satoshi Soma
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
2
25
|
|
|
3
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Coerces the given value into an array.
|
|
28
|
+
* @param {any} x
|
|
29
|
+
* @return {any[]}
|
|
30
|
+
*/
|
|
31
|
+
function arr(x) {
|
|
32
|
+
return Array.isArray(x) ? x : [x];
|
|
33
|
+
}
|
|
4
34
|
|
|
5
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Checks the type of the given value matches with one of the given types.
|
|
37
|
+
* If a constructor is given to `types`, it checks if `x` is `instanceof` the constructor.
|
|
38
|
+
* @param {any} x
|
|
39
|
+
* @param {...string|function} types - Type or Constructor
|
|
40
|
+
* @return {boolean}
|
|
41
|
+
*/
|
|
42
|
+
function is(x, ...types) {
|
|
43
|
+
let t = typeof x;
|
|
44
|
+
for (let i = 0; i < types.length; i++) {
|
|
45
|
+
let v = types[i];
|
|
46
|
+
if (typeof v == 'string') {
|
|
47
|
+
if (v == 'array') {
|
|
48
|
+
if (Array.isArray(x)) return true;
|
|
49
|
+
} else if (t == v) return true;
|
|
50
|
+
} else if (x instanceof v) return true;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Returns whether the given value can be considered as "empty".
|
|
57
|
+
* @param {any} x
|
|
58
|
+
* @return {boolean}
|
|
59
|
+
*/
|
|
60
|
+
function isEmpty(x) {
|
|
61
|
+
if (Array.isArray(x)) return x.length == 0;
|
|
62
|
+
switch (typeof x) {
|
|
63
|
+
case 'string':
|
|
64
|
+
return !x;
|
|
65
|
+
case 'object':
|
|
66
|
+
for (let _ in x) return false;
|
|
67
|
+
return true;
|
|
68
|
+
case 'undefined':
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Returns whether the given value can be considered as "empty" or "falsy".
|
|
76
|
+
* Faster than {@link isEmpty}.
|
|
77
|
+
* @param {any} x
|
|
78
|
+
* @return {boolean}
|
|
79
|
+
*/
|
|
80
|
+
function isEmptyOrFalsy(x) {
|
|
81
|
+
if (!x) return true;
|
|
82
|
+
if (Array.isArray(x)) return x.length == 0;
|
|
83
|
+
if (typeof x == 'object') {
|
|
84
|
+
for (let _ in x) return false;
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @function isEmptyOrFalsey
|
|
91
|
+
* Alias of {@link isEmptyOrFalsy}.
|
|
92
|
+
*/
|
|
93
|
+
const isEmptyOrFalsey = isEmptyOrFalsy;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Removes "empty" values from the given object or array.
|
|
97
|
+
* @param {object|any[]} x
|
|
98
|
+
* @param {number} recurse - Recursion limit
|
|
99
|
+
* @return {object|any[]} modified `x`
|
|
100
|
+
*/
|
|
101
|
+
function clean(x, recurse = 8) {
|
|
102
|
+
if (recurse) {
|
|
103
|
+
if (Array.isArray(x)) {
|
|
104
|
+
let r = [];
|
|
105
|
+
for (let i = 0; i < x.length; i++) {
|
|
106
|
+
let v = clean(x[i], recurse - 1);
|
|
107
|
+
if (!isEmpty(v)) r.push(v);
|
|
108
|
+
}
|
|
109
|
+
return r;
|
|
110
|
+
}
|
|
111
|
+
if (typeof x == 'object') {
|
|
112
|
+
let r = {};
|
|
113
|
+
for (let k in x) {
|
|
114
|
+
let v = clean(x[k], recurse - 1);
|
|
115
|
+
if (!isEmpty(v)) r[k] = v;
|
|
116
|
+
}
|
|
117
|
+
return r;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return x;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Merges the 2nd object into the 1st object recursively (deep-merge). The 1st object will be modified.
|
|
125
|
+
* @param {object} x - The 1st object
|
|
126
|
+
* @param {object} y - The 2nd object
|
|
127
|
+
* @param {object} [opts] - Options
|
|
128
|
+
* @param {number} opts.recurse=8 - Recurstion limit. Negative number means unlimited
|
|
129
|
+
* @param {boolean|string} opts.mergeArrays - How to merge arrays
|
|
130
|
+
* - `true`: merge x with y
|
|
131
|
+
* - 'push': push y elements to x
|
|
132
|
+
* - 'concat': concat x and y
|
|
133
|
+
* - other: replace x with y
|
|
134
|
+
* @return {object} The 1st object
|
|
135
|
+
*/
|
|
136
|
+
function merge(x, y, opts = {}) {
|
|
137
|
+
if (!('recurse' in opts)) opts.recurse = 8;
|
|
138
|
+
switch (Array.isArray(x) + Array.isArray(y)) {
|
|
139
|
+
case 0: // no array
|
|
140
|
+
if (opts.recurse && x && y && typeof x == 'object' && typeof y == 'object') {
|
|
141
|
+
opts.recurse--;
|
|
142
|
+
for (let k in y) x[k] = merge(x[k], y[k], opts);
|
|
143
|
+
opts.recurse++;
|
|
144
|
+
return x;
|
|
145
|
+
}
|
|
146
|
+
case 1: // 1 array
|
|
147
|
+
return y;
|
|
148
|
+
}
|
|
149
|
+
// 2 arrays
|
|
150
|
+
switch (opts.mergeArrays) {
|
|
151
|
+
case true:
|
|
152
|
+
for (let i = 0; i < y.length; i++) {
|
|
153
|
+
if (!x.includes(y[i])) x.push(y[i]);
|
|
154
|
+
}
|
|
155
|
+
return x;
|
|
156
|
+
case 'push':
|
|
157
|
+
x.push(...y);
|
|
158
|
+
return x;
|
|
159
|
+
case 'concat':
|
|
160
|
+
return x.concat(y);
|
|
161
|
+
}
|
|
162
|
+
return y;
|
|
163
|
+
}var gen=/*#__PURE__*/Object.freeze({__proto__:null,arr:arr,clean:clean,is:is,isEmpty:isEmpty,isEmptyOrFalsey:isEmptyOrFalsey,isEmptyOrFalsy:isEmptyOrFalsy,merge:merge});/*!
|
|
6
164
|
* === @amekusa/util.js/web === *
|
|
7
165
|
* MIT License
|
|
8
166
|
*
|
|
@@ -51,15 +209,7 @@ const escHTML_find = new RegExp(`["'<>]|(&(?!${Object.values(escHTML_map).join('
|
|
|
51
209
|
// - This avoids double-escaping '&' symbols
|
|
52
210
|
// - Regex negative match: (?!word)
|
|
53
211
|
|
|
54
|
-
const escHTML_replace = found => `&${escHTML_map[found]};`;
|
|
55
|
-
|
|
56
|
-
var web = /*#__PURE__*/Object.freeze({
|
|
57
|
-
__proto__: null,
|
|
58
|
-
escHTML: escHTML,
|
|
59
|
-
escHtml: escHtml
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
/*!
|
|
212
|
+
const escHTML_replace = found => `&${escHTML_map[found]};`;var web=/*#__PURE__*/Object.freeze({__proto__:null,escHTML:escHTML,escHtml:escHtml});/*!
|
|
63
213
|
* === @amekusa/util.js/time === *
|
|
64
214
|
* MIT License
|
|
65
215
|
*
|
|
@@ -229,179 +379,4 @@ function hms(d, format = null) {
|
|
|
229
379
|
*/
|
|
230
380
|
function iso9075(d) {
|
|
231
381
|
return ymd(d, '-') + ' ' + hms(d, ':');
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
var time = /*#__PURE__*/Object.freeze({
|
|
235
|
-
__proto__: null,
|
|
236
|
-
addTime: addTime,
|
|
237
|
-
ceil: ceil,
|
|
238
|
-
date: date,
|
|
239
|
-
floor: floor,
|
|
240
|
-
hms: hms,
|
|
241
|
-
iso9075: iso9075,
|
|
242
|
-
localize: localize,
|
|
243
|
-
ms: ms,
|
|
244
|
-
quantize: quantize,
|
|
245
|
-
round: round,
|
|
246
|
-
ymd: ymd
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
/*!
|
|
250
|
-
* === @amekusa/util.js === *
|
|
251
|
-
* MIT License
|
|
252
|
-
*
|
|
253
|
-
* Copyright (c) 2024 Satoshi Soma
|
|
254
|
-
*
|
|
255
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
256
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
257
|
-
* in the Software without restriction, including without limitation the rights
|
|
258
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
259
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
260
|
-
* furnished to do so, subject to the following conditions:
|
|
261
|
-
*
|
|
262
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
263
|
-
* copies or substantial portions of the Software.
|
|
264
|
-
*
|
|
265
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
266
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
267
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
268
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
269
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
270
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
271
|
-
* SOFTWARE.
|
|
272
|
-
*/
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Coerces the given value into an array.
|
|
276
|
-
* @param {any} x
|
|
277
|
-
* @return {any[]}
|
|
278
|
-
*/
|
|
279
|
-
function arr(x) {
|
|
280
|
-
return Array.isArray(x) ? x : [x];
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Alias of `Array.isArray`.
|
|
285
|
-
* @return {boolean}
|
|
286
|
-
*/
|
|
287
|
-
const isArray = Array.isArray;
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Returns whether the given value is a number or a string.
|
|
291
|
-
* @param {any} x
|
|
292
|
-
* @return {boolean}
|
|
293
|
-
*/
|
|
294
|
-
function isNumOrStr(x) {
|
|
295
|
-
switch (typeof x) {
|
|
296
|
-
case 'number':
|
|
297
|
-
case 'string':
|
|
298
|
-
return true;
|
|
299
|
-
}
|
|
300
|
-
return false;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Returns whether the given value can be considered as "empty".
|
|
305
|
-
* @param {any} x
|
|
306
|
-
* @return {boolean}
|
|
307
|
-
*/
|
|
308
|
-
function isEmpty(x) {
|
|
309
|
-
if (Array.isArray(x)) return x.length == 0;
|
|
310
|
-
switch (typeof x) {
|
|
311
|
-
case 'string':
|
|
312
|
-
return !x;
|
|
313
|
-
case 'object':
|
|
314
|
-
if (x === null) return true;
|
|
315
|
-
for (let i in x) return false;
|
|
316
|
-
case 'undefined':
|
|
317
|
-
return true;
|
|
318
|
-
}
|
|
319
|
-
return false;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Removes "empty" values from the given object or array.
|
|
324
|
-
* @param {object|any[]} x
|
|
325
|
-
* @param {number} recurse - Recursion limit
|
|
326
|
-
* @return {object|any[]} modified `x`
|
|
327
|
-
*/
|
|
328
|
-
function clean(x, recurse = 8) {
|
|
329
|
-
if (recurse) {
|
|
330
|
-
if (Array.isArray(x)) {
|
|
331
|
-
let r = [];
|
|
332
|
-
for (let i = 0; i < x.length; i++) {
|
|
333
|
-
let I = clean(x[i], recurse - 1);
|
|
334
|
-
if (!isEmpty(I)) r.push(I);
|
|
335
|
-
}
|
|
336
|
-
return r;
|
|
337
|
-
}
|
|
338
|
-
if (typeof x == 'object') {
|
|
339
|
-
let r = {};
|
|
340
|
-
for (let k in x) {
|
|
341
|
-
let v = clean(x[k], recurse - 1);
|
|
342
|
-
if (!isEmpty(v)) r[k] = v;
|
|
343
|
-
}
|
|
344
|
-
return r;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
return x;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
* Merges the 2nd object into the 1st object recursively (deep-merge). The 1st object will be modified.
|
|
352
|
-
* @param {object} x - The 1st object
|
|
353
|
-
* @param {object} y - The 2nd object
|
|
354
|
-
* @param {object} [opts] - Options
|
|
355
|
-
* @param {number} opts.recurse=8 - Recurstion limit. Negative number means unlimited
|
|
356
|
-
* @param {boolean|string} opts.mergeArrays - How to merge arrays
|
|
357
|
-
* - `true`: merge x with y
|
|
358
|
-
* - 'push': push y elements to x
|
|
359
|
-
* - 'concat': concat x and y
|
|
360
|
-
* - other: replace x with y
|
|
361
|
-
* @return {object} The 1st object
|
|
362
|
-
*/
|
|
363
|
-
function merge(x, y, opts = {}) {
|
|
364
|
-
if (!('recurse' in opts)) opts.recurse = 8;
|
|
365
|
-
switch (Array.isArray(x) + Array.isArray(y)) {
|
|
366
|
-
case 0: // no array
|
|
367
|
-
if (opts.recurse && x && y && typeof x == 'object' && typeof y == 'object') {
|
|
368
|
-
opts.recurse--;
|
|
369
|
-
for (let k in y) x[k] = merge(x[k], y[k], opts);
|
|
370
|
-
opts.recurse++;
|
|
371
|
-
return x;
|
|
372
|
-
}
|
|
373
|
-
case 1: // 1 array
|
|
374
|
-
return y;
|
|
375
|
-
}
|
|
376
|
-
// 2 arrays
|
|
377
|
-
switch (opts.mergeArrays) {
|
|
378
|
-
case true:
|
|
379
|
-
for (let i = 0; i < y.length; i++) {
|
|
380
|
-
if (!x.includes(y[i])) x.push(y[i]);
|
|
381
|
-
}
|
|
382
|
-
return x;
|
|
383
|
-
case 'push':
|
|
384
|
-
x.push(...y);
|
|
385
|
-
return x;
|
|
386
|
-
case 'concat':
|
|
387
|
-
return x.concat(y);
|
|
388
|
-
}
|
|
389
|
-
return y;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
var main = {
|
|
393
|
-
arr,
|
|
394
|
-
isEmpty,
|
|
395
|
-
clean,
|
|
396
|
-
merge,
|
|
397
|
-
};
|
|
398
|
-
|
|
399
|
-
exports.arr = arr;
|
|
400
|
-
exports.clean = clean;
|
|
401
|
-
exports.default = main;
|
|
402
|
-
exports.isArray = isArray;
|
|
403
|
-
exports.isEmpty = isEmpty;
|
|
404
|
-
exports.isNumOrStr = isNumOrStr;
|
|
405
|
-
exports.merge = merge;
|
|
406
|
-
exports.time = time;
|
|
407
|
-
exports.web = web;
|
|
382
|
+
}var time=/*#__PURE__*/Object.freeze({__proto__:null,addTime:addTime,ceil:ceil,date:date,floor:floor,hms:hms,iso9075:iso9075,localize:localize,ms:ms,quantize:quantize,round:round,ymd:ymd});exports.arr=arr;exports.clean=clean;exports.gen=gen;exports.is=is;exports.isEmpty=isEmpty;exports.isEmptyOrFalsey=isEmptyOrFalsey;exports.isEmptyOrFalsy=isEmptyOrFalsy;exports.merge=merge;exports.time=time;exports.web=web;return exports;})({});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
this.amekusa=this.amekusa||{},this.amekusa.util=function(e){"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* === @amekusa/util.js/gen === *
|
|
4
|
+
* MIT License
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2024 Satoshi Soma
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
* furnished to do so, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
* copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
* SOFTWARE.
|
|
25
|
+
*/function t(e){return Array.isArray(e)?e:[e]}function r(e,...t){let r=typeof e;for(let n=0;n<t.length;n++){let i=t[n];if("string"==typeof i){if("array"==i){if(Array.isArray(e))return!0}else if(r==i)return!0}else if(e instanceof i)return!0}return!1}function n(e){if(Array.isArray(e))return 0==e.length;switch(typeof e){case"string":return!e;case"object":for(let t in e)return!1;return!0;case"undefined":return!0}return!1}function i(e){if(!e)return!0;if(Array.isArray(e))return 0==e.length;if("object"==typeof e)for(let t in e)return!1;return!1}const u=i;function o(e,t=8){if(t){if(Array.isArray(e)){let r=[];for(let i=0;i<e.length;i++){let u=o(e[i],t-1);n(u)||r.push(u)}return r}if("object"==typeof e){let r={};for(let i in e){let u=o(e[i],t-1);n(u)||(r[i]=u)}return r}}return e}function a(e,t,r={}){switch("recurse"in r||(r.recurse=8),Array.isArray(e)+Array.isArray(t)){case 0:if(r.recurse&&e&&t&&"object"==typeof e&&"object"==typeof t){r.recurse--;for(let n in t)e[n]=a(e[n],t[n],r);return r.recurse++,e}case 1:return t}switch(r.mergeArrays){case!0:for(let r=0;r<t.length;r++)e.includes(t[r])||e.push(t[r]);return e;case"push":return e.push(...t),e;case"concat":return e.concat(t)}return t}var s=Object.freeze({__proto__:null,arr:t,clean:o,is:r,isEmpty:n,isEmptyOrFalsey:u,isEmptyOrFalsy:i,merge:a});
|
|
26
|
+
/*!
|
|
27
|
+
* === @amekusa/util.js/web === *
|
|
28
|
+
* MIT License
|
|
29
|
+
*
|
|
30
|
+
* Copyright (c) 2024 Satoshi Soma
|
|
31
|
+
*
|
|
32
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
33
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
34
|
+
* in the Software without restriction, including without limitation the rights
|
|
35
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
36
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
37
|
+
* furnished to do so, subject to the following conditions:
|
|
38
|
+
*
|
|
39
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
40
|
+
* copies or substantial portions of the Software.
|
|
41
|
+
*
|
|
42
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
43
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
44
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
45
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
46
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
47
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
48
|
+
* SOFTWARE.
|
|
49
|
+
*/function c(e){return`${e}`.replace(y,g)}const f=c,l={"&":"amp",'"':"quot","'":"apos","<":"lt",">":"gt"},y=new RegExp(`["'<>]|(&(?!${Object.values(l).join("|")};))`,"g"),g=e=>`&${l[e]};`;var p=Object.freeze({__proto__:null,escHTML:c,escHtml:f});
|
|
50
|
+
/*!
|
|
51
|
+
* === @amekusa/util.js/time === *
|
|
52
|
+
* MIT License
|
|
53
|
+
*
|
|
54
|
+
* Copyright (c) 2024 Satoshi Soma
|
|
55
|
+
*
|
|
56
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
57
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
58
|
+
* in the Software without restriction, including without limitation the rights
|
|
59
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
60
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
61
|
+
* furnished to do so, subject to the following conditions:
|
|
62
|
+
*
|
|
63
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
64
|
+
* copies or substantial portions of the Software.
|
|
65
|
+
*
|
|
66
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
67
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
68
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
69
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
70
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
71
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
72
|
+
* SOFTWARE.
|
|
73
|
+
*/function m(e,t,r="round"){return e.setTime(Math[r](e.getTime()/t)*t),e}function h(e,t=null){let r=[e.getFullYear().toString(),(e.getMonth()+1).toString().padStart(2,"0"),e.getDate().toString().padStart(2,"0")];switch(typeof t){case"string":return r.join(t);case"object":return t?(t.Y=r[0],t.M=r[1],t.D=r[2],t):r;default:if(!t)return r;throw"invalid type"}}function d(e,t=null){let r=[e.getHours().toString().padStart(2,"0"),e.getMinutes().toString().padStart(2,"0"),e.getSeconds().toString().padStart(2,"0")];switch(typeof t){case"string":return r.join(t);case"object":return t?(t.h=r[0],t.m=r[1],t.s=r[2],t):r;default:if(!t)return r;throw"invalid type"}}var A=Object.freeze({__proto__:null,addTime:function(e,t){return e.setTime(e.getTime()+t),e},ceil:function(e,t){return m(e,t,"ceil")},date:function(...e){return e.length&&e[0]?e[0]instanceof Date?e[0]:new Date(...e):new Date},floor:function(e,t){return m(e,t,"floor")},hms:d,iso9075:function(e){return h(e,"-")+" "+d(e,":")},localize:function(e){return e.setTime(e.getTime()-6e4*e.getTimezoneOffset()),e},ms:function(...e){if(!e.length||!e[0])return Date.now();let t=e[0];return"number"==typeof t?t:t instanceof Date?t.getTime():new Date(...e).getTime()},quantize:m,round:function(e,t){return m(e,t,"round")},ymd:h});return e.arr=t,e.clean=o,e.gen=s,e.is=r,e.isEmpty=n,e.isEmptyOrFalsey=u,e.isEmptyOrFalsy=i,e.merge=a,e.time=A,e.web=p,e}({});
|