@amekusa/util.js 1.2.1 → 2.1.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 CHANGED
@@ -10,30 +10,47 @@ npm i @amekusa/util.js
10
10
 
11
11
  ### ES
12
12
  ```js
13
- // A) import functions
14
- import {
15
- arr,
16
- isEmpty,
17
- clean,
18
- merge,
19
- } from '@amekusa/util.js';
20
-
21
- // B) import as an object
22
- import util from '@amekusa/util.js';
13
+ // Import functions
14
+ import {merge, arr, isEmpty} from '@amekusa/util.js';
15
+
16
+ // Import categories
17
+ import {gen, time, web, io, sh} from '@amekusa/util.js';
18
+
19
+ // Import only browser-compatible categories
20
+ import {gen, time, web} from '@amekusa/util.js/browser';
23
21
  ```
24
22
 
25
23
  ### CJS
26
24
  ```js
27
- // A) import functions
28
- const {
29
- arr,
30
- isEmpty,
31
- clean,
32
- merge,
33
- } = require('@amekusa/util.js');
34
-
35
- // B) import as an object
36
- const util = require('@amekusa/util.js');
25
+ // Import functions
26
+ const {merge, arr, isEmpty} = require('@amekusa/util.js');
27
+
28
+ // Import categories
29
+ const {gen, time, web, io, sh} = require('@amekusa/util.js');
30
+
31
+ // Import only browser-compatible categories
32
+ const {gen, time, web} = require('@amekusa/util.js/browser');
33
+ ```
34
+
35
+ ### Browser
36
+ ```html
37
+ <script src="amekusa.util.br.js"></script>
38
+ <script src="your-script.js"></script>
39
+ ```
40
+
41
+ ```js
42
+ // your-script.js
43
+ const {gen, time, web} = amekusa.util;
44
+ ```
45
+
46
+ ### Browser with module loading
47
+ ```html
48
+ <script type="module" src="your-script.js"></script>
49
+ ```
50
+
51
+ ```js
52
+ // your-script.js
53
+ import {gen, time, web} from './amekusa.util.br.es.js';
37
54
  ```
38
55
 
39
56
  ## LICENSE
@@ -1,4 +1,202 @@
1
1
  /*!
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
+ */
25
+
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
+ }
34
+
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
+ }
164
+
165
+ /**
166
+ * Gets a property from the given object by the given string path.
167
+ * @param {object} obj - Object to traverse
168
+ * @param {string} path - Property names separated with '.'
169
+ * @return {any} value of the found property, or undefined if it's not found
170
+ */
171
+ function dig(obj, path) {
172
+ path = path.split('.');
173
+ for (let i = 0; i < path.length; i++) {
174
+ let p = path[i];
175
+ if (typeof obj == 'object' && p in obj) obj = obj[p];
176
+ else return undefined;
177
+ }
178
+ return obj;
179
+ }
180
+
181
+ /**
182
+ * Substitutes the properties of the given data for the references in the given string.
183
+ * @param {string} str - String that contains references to the properties
184
+ * @param {object} data - Object that contains properties to replace the references
185
+ * @param {object} [opts] - Options
186
+ * @return {string} a modified `str`
187
+ */
188
+ function subst(str, data, opts = {}) {
189
+ let {
190
+ modifier = null,
191
+ start = '{{',
192
+ end = '}}',
193
+ } = opts;
194
+ let ref = new RegExp(start + '\\s*([-.\\w]+)\\s*' + end, 'g');
195
+ return str.replaceAll(ref, modifier
196
+ ? (_, m1) => (modifier(dig(data, m1), m1, data) || '')
197
+ : (_, m1) => (dig(data, m1) || '')
198
+ );
199
+ }var gen=/*#__PURE__*/Object.freeze({__proto__:null,arr:arr,clean:clean,dig:dig,is:is,isEmpty:isEmpty,isEmptyOrFalsey:isEmptyOrFalsey,isEmptyOrFalsy:isEmptyOrFalsy,merge:merge,subst:subst});/*!
2
200
  * === @amekusa/util.js/web === *
3
201
  * MIT License
4
202
  *
@@ -47,15 +245,7 @@ const escHTML_find = new RegExp(`["'<>]|(&(?!${Object.values(escHTML_map).join('
47
245
  // - This avoids double-escaping '&' symbols
48
246
  // - Regex negative match: (?!word)
49
247
 
50
- const escHTML_replace = found => `&${escHTML_map[found]};`;
51
-
52
- var web = /*#__PURE__*/Object.freeze({
53
- __proto__: null,
54
- escHTML: escHTML,
55
- escHtml: escHtml
56
- });
57
-
58
- /*!
248
+ const escHTML_replace = found => `&${escHTML_map[found]};`;var web=/*#__PURE__*/Object.freeze({__proto__:null,escHTML:escHTML,escHtml:escHtml});/*!
59
249
  * === @amekusa/util.js/time === *
60
250
  * MIT License
61
251
  *
@@ -225,171 +415,4 @@ function hms(d, format = null) {
225
415
  */
226
416
  function iso9075(d) {
227
417
  return ymd(d, '-') + ' ' + hms(d, ':');
228
- }
229
-
230
- var time = /*#__PURE__*/Object.freeze({
231
- __proto__: null,
232
- addTime: addTime,
233
- ceil: ceil,
234
- date: date,
235
- floor: floor,
236
- hms: hms,
237
- iso9075: iso9075,
238
- localize: localize,
239
- ms: ms,
240
- quantize: quantize,
241
- round: round,
242
- ymd: ymd
243
- });
244
-
245
- /*!
246
- * === @amekusa/util.js === *
247
- * MIT License
248
- *
249
- * Copyright (c) 2024 Satoshi Soma
250
- *
251
- * Permission is hereby granted, free of charge, to any person obtaining a copy
252
- * of this software and associated documentation files (the "Software"), to deal
253
- * in the Software without restriction, including without limitation the rights
254
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
255
- * copies of the Software, and to permit persons to whom the Software is
256
- * furnished to do so, subject to the following conditions:
257
- *
258
- * The above copyright notice and this permission notice shall be included in all
259
- * copies or substantial portions of the Software.
260
- *
261
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
262
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
263
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
264
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
265
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
266
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
267
- * SOFTWARE.
268
- */
269
-
270
- /**
271
- * Coerces the given value into an array.
272
- * @param {any} x
273
- * @return {any[]}
274
- */
275
- function arr(x) {
276
- return Array.isArray(x) ? x : [x];
277
- }
278
-
279
- /**
280
- * Alias of `Array.isArray`.
281
- * @return {boolean}
282
- */
283
- const isArray = Array.isArray;
284
-
285
- /**
286
- * Returns whether the given value is a number or a string.
287
- * @param {any} x
288
- * @return {boolean}
289
- */
290
- function isNumOrStr(x) {
291
- switch (typeof x) {
292
- case 'number':
293
- case 'string':
294
- return true;
295
- }
296
- return false;
297
- }
298
-
299
- /**
300
- * Returns whether the given value can be considered as "empty".
301
- * @param {any} x
302
- * @return {boolean}
303
- */
304
- function isEmpty(x) {
305
- if (Array.isArray(x)) return x.length == 0;
306
- switch (typeof x) {
307
- case 'string':
308
- return !x;
309
- case 'object':
310
- if (x === null) return true;
311
- for (let i in x) return false;
312
- case 'undefined':
313
- return true;
314
- }
315
- return false;
316
- }
317
-
318
- /**
319
- * Removes "empty" values from the given object or array.
320
- * @param {object|any[]} x
321
- * @param {number} recurse - Recursion limit
322
- * @return {object|any[]} modified `x`
323
- */
324
- function clean(x, recurse = 8) {
325
- if (recurse) {
326
- if (Array.isArray(x)) {
327
- let r = [];
328
- for (let i = 0; i < x.length; i++) {
329
- let I = clean(x[i], recurse - 1);
330
- if (!isEmpty(I)) r.push(I);
331
- }
332
- return r;
333
- }
334
- if (typeof x == 'object') {
335
- let r = {};
336
- for (let k in x) {
337
- let v = clean(x[k], recurse - 1);
338
- if (!isEmpty(v)) r[k] = v;
339
- }
340
- return r;
341
- }
342
- }
343
- return x;
344
- }
345
-
346
- /**
347
- * Merges the 2nd object into the 1st object recursively (deep-merge). The 1st object will be modified.
348
- * @param {object} x - The 1st object
349
- * @param {object} y - The 2nd object
350
- * @param {object} [opts] - Options
351
- * @param {number} opts.recurse=8 - Recurstion limit. Negative number means unlimited
352
- * @param {boolean|string} opts.mergeArrays - How to merge arrays
353
- * - `true`: merge x with y
354
- * - 'push': push y elements to x
355
- * - 'concat': concat x and y
356
- * - other: replace x with y
357
- * @return {object} The 1st object
358
- */
359
- function merge(x, y, opts = {}) {
360
- if (!('recurse' in opts)) opts.recurse = 8;
361
- switch (Array.isArray(x) + Array.isArray(y)) {
362
- case 0: // no array
363
- if (opts.recurse && x && y && typeof x == 'object' && typeof y == 'object') {
364
- opts.recurse--;
365
- for (let k in y) x[k] = merge(x[k], y[k], opts);
366
- opts.recurse++;
367
- return x;
368
- }
369
- case 1: // 1 array
370
- return y;
371
- }
372
- // 2 arrays
373
- switch (opts.mergeArrays) {
374
- case true:
375
- for (let i = 0; i < y.length; i++) {
376
- if (!x.includes(y[i])) x.push(y[i]);
377
- }
378
- return x;
379
- case 'push':
380
- x.push(...y);
381
- return x;
382
- case 'concat':
383
- return x.concat(y);
384
- }
385
- return y;
386
- }
387
-
388
- var main = {
389
- arr,
390
- isEmpty,
391
- clean,
392
- merge,
393
- };
394
-
395
- export { arr, clean, main as default, isArray, isEmpty, isNumOrStr, merge, time, web };
418
+ }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});export{arr,clean,dig,gen,is,isEmpty,isEmptyOrFalsey,isEmptyOrFalsy,merge,subst,time,web};
@@ -0,0 +1,73 @@
1
+ /*!
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
+ */
25
+ function e(e){return Array.isArray(e)?e:[e]}function t(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 r(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 n(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 i=n;function u(e,t=8){if(t){if(Array.isArray(e)){let n=[];for(let i=0;i<e.length;i++){let o=u(e[i],t-1);r(o)||n.push(o)}return n}if("object"==typeof e){let n={};for(let i in e){let o=u(e[i],t-1);r(o)||(n[i]=o)}return n}}return e}function o(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]=o(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}function a(e,t){t=t.split(".");for(let r=0;r<t.length;r++){let n=t[r];if("object"!=typeof e||!(n in e))return;e=e[n]}return e}function c(e,t,r={}){let{modifier:n=null,start:i="{{",end:u="}}"}=r,o=new RegExp(i+"\\s*([-.\\w]+)\\s*"+u,"g");return e.replaceAll(o,n?(e,r)=>n(a(t,r),r,t)||"":(e,r)=>a(t,r)||"")}var s=Object.freeze({__proto__:null,arr:e,clean:u,dig:a,is:t,isEmpty:r,isEmptyOrFalsey:i,isEmptyOrFalsy:n,merge:o,subst:c});
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 f(e){return`${e}`.replace(p,y)}const l=f,g={"&":"amp",'"':"quot","'":"apos","<":"lt",">":"gt"},p=new RegExp(`["'<>]|(&(?!${Object.values(g).join("|")};))`,"g"),y=e=>`&${g[e]};`;var d=Object.freeze({__proto__:null,escHTML:f,escHtml:l});
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 h(e,t,r="round"){return e.setTime(Math[r](e.getTime()/t)*t),e}function m(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 A(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 j=Object.freeze({__proto__:null,addTime:function(e,t){return e.setTime(e.getTime()+t),e},ceil:function(e,t){return h(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 h(e,t,"floor")},hms:A,iso9075:function(e){return m(e,"-")+" "+A(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:h,round:function(e,t){return h(e,t,"round")},ymd:m});export{e as arr,u as clean,a as dig,s as gen,t as is,r as isEmpty,i as isEmptyOrFalsey,n as isEmptyOrFalsy,o as merge,c as subst,j as time,d as web};