@kizmann/pico-js 1.0.13 → 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.
Files changed (125) hide show
  1. package/README.md +27 -7
  2. package/dist/pico-js.browser.js +2 -0
  3. package/dist/pico-js.browser.js.map +1 -0
  4. package/dist/pico-js.esm.js +2 -0
  5. package/dist/pico-js.esm.js.map +1 -0
  6. package/package.json +20 -7
  7. package/src/dom/DomAttribute.js +374 -0
  8. package/src/dom/DomBuilder.js +152 -0
  9. package/src/dom/DomEvent.js +253 -0
  10. package/src/dom/DomFinder.js +669 -0
  11. package/src/dom/DomForm.js +57 -0
  12. package/src/dom/DomGlobal.js +193 -0
  13. package/src/dom/DomInview.js +332 -0
  14. package/src/dom/DomMeta.js +66 -0
  15. package/src/dom/DomObserver.js +57 -0
  16. package/src/dom/DomRectangle.js +657 -0
  17. package/src/format/FormatFile.js +54 -0
  18. package/src/format/FormatOption.js +108 -0
  19. package/src/format/FormatParam.js +107 -0
  20. package/src/format/FormatParser.js +156 -0
  21. package/src/format/FormatUrl.js +75 -0
  22. package/src/index.browser.js +10 -0
  23. package/src/index.esm.js +138 -0
  24. package/src/now/NowDefault.js +533 -0
  25. package/src/now/NowFormat.js +196 -0
  26. package/src/now/NowGrid.js +251 -0
  27. package/src/now/NowHuman.js +118 -0
  28. package/src/now/NowMatch.js +175 -0
  29. package/src/now/NowRange.js +70 -0
  30. package/src/now/NowWalker.js +544 -0
  31. package/src/tool/scope.js +103 -0
  32. package/src/utils/Array.js +986 -0
  33. package/src/utils/Cookie.js +184 -0
  34. package/src/utils/Data.js +200 -0
  35. package/src/utils/Dom.js +208 -0
  36. package/src/utils/Event.js +140 -0
  37. package/src/utils/Format.js +62 -0
  38. package/src/utils/Hash.js +164 -0
  39. package/src/utils/Locale.js +229 -0
  40. package/src/utils/Mixed.js +887 -0
  41. package/src/utils/Now.js +234 -0
  42. package/src/utils/Number.js +238 -0
  43. package/src/utils/Object.js +655 -0
  44. package/src/utils/Route.js +67 -0
  45. package/src/utils/Runner.js +327 -0
  46. package/src/utils/String.js +618 -0
  47. package/src/{library/element.js → wip/Element.js} +90 -16
  48. package/src/{library/map.js → wip/Map.js} +256 -40
  49. package/types/dom/DomAttribute.d.ts +137 -0
  50. package/types/dom/DomBuilder.d.ts +67 -0
  51. package/types/dom/DomEvent.d.ts +103 -0
  52. package/types/dom/DomFinder.d.ts +321 -0
  53. package/types/dom/DomForm.d.ts +21 -0
  54. package/types/dom/DomGlobal.d.ts +79 -0
  55. package/types/dom/DomInview.d.ts +114 -0
  56. package/types/dom/DomMeta.d.ts +29 -0
  57. package/types/dom/DomObserver.d.ts +21 -0
  58. package/types/dom/DomRectangle.d.ts +270 -0
  59. package/types/format/FormatFile.d.ts +18 -0
  60. package/types/format/FormatOption.d.ts +40 -0
  61. package/types/format/FormatParam.d.ts +39 -0
  62. package/types/format/FormatParser.d.ts +46 -0
  63. package/types/format/FormatUrl.d.ts +17 -0
  64. package/types/index.browser.d.ts +1 -0
  65. package/types/index.esm.d.ts +52 -0
  66. package/types/now/NowDefault.d.ts +183 -0
  67. package/types/now/NowFormat.d.ts +70 -0
  68. package/types/now/NowGrid.d.ts +107 -0
  69. package/types/now/NowHuman.d.ts +37 -0
  70. package/types/now/NowMatch.d.ts +108 -0
  71. package/types/now/NowRange.d.ts +21 -0
  72. package/types/now/NowWalker.d.ts +301 -0
  73. package/types/tool/scope.d.ts +24 -0
  74. package/types/utils/Array.d.ts +480 -0
  75. package/types/utils/Cookie.d.ts +60 -0
  76. package/types/utils/Data.d.ts +91 -0
  77. package/types/utils/Dom.d.ts +138 -0
  78. package/types/utils/Event.d.ts +58 -0
  79. package/types/utils/Format.d.ts +37 -0
  80. package/types/utils/Hash.d.ts +81 -0
  81. package/types/utils/Locale.d.ts +115 -0
  82. package/types/utils/Mixed.d.ts +469 -0
  83. package/types/utils/Now.d.ts +125 -0
  84. package/types/utils/Number.d.ts +127 -0
  85. package/types/utils/Object.d.ts +255 -0
  86. package/types/utils/Route.d.ts +37 -0
  87. package/types/utils/Runner.d.ts +139 -0
  88. package/types/utils/String.d.ts +330 -0
  89. package/types/wip/Element.d.ts +119 -0
  90. package/types/wip/Map.d.ts +254 -0
  91. package/dist/.ignore.js +0 -0
  92. package/dist/pico-js.js +0 -2
  93. package/dist/pico-js.js.map +0 -1
  94. package/src/element/default.js +0 -46
  95. package/src/element/example.js +0 -58
  96. package/src/index.js +0 -90
  97. package/src/library/cookie.js +0 -123
  98. package/src/library/data.js +0 -111
  99. package/src/library/event.js +0 -91
  100. package/src/library/locale.js +0 -84
  101. package/src/library/queue.js +0 -64
  102. package/src/library/route.js +0 -28
  103. package/src/utility/any.js +0 -369
  104. package/src/utility/array.js +0 -410
  105. package/src/utility/dom.js +0 -1425
  106. package/src/utility/now.js +0 -544
  107. package/src/utility/number.js +0 -128
  108. package/src/utility/object.js +0 -429
  109. package/src/utility/string.js +0 -328
  110. package/types/index.d.ts +0 -77
  111. package/types/library/cookie.d.ts +0 -10
  112. package/types/library/data.d.ts +0 -15
  113. package/types/library/element.d.ts +0 -22
  114. package/types/library/event.d.ts +0 -13
  115. package/types/library/locale.d.ts +0 -14
  116. package/types/library/map.d.ts +0 -43
  117. package/types/library/queue.d.ts +0 -18
  118. package/types/library/route.d.ts +0 -11
  119. package/types/utility/any.d.ts +0 -35
  120. package/types/utility/array.d.ts +0 -46
  121. package/types/utility/dom.d.ts +0 -101
  122. package/types/utility/now.d.ts +0 -79
  123. package/types/utility/number.d.ts +0 -17
  124. package/types/utility/object.d.ts +0 -29
  125. package/types/utility/string.d.ts +0 -26
@@ -1,369 +0,0 @@
1
- import { Arr, Obj, Now } from "../index.js";
2
-
3
- export class Any
4
- {
5
- static global(fallback = {})
6
- {
7
- if ( window !== undefined ) {
8
- return window;
9
- }
10
-
11
- if ( global !== undefined ) {
12
- return global;
13
- }
14
-
15
- return fallback;
16
- }
17
-
18
- static isEmpty(val)
19
- {
20
- if ( this.isNumber(val) ) {
21
- return false;
22
- }
23
-
24
- if ( this.isString(val) ) {
25
- return val === '';
26
- }
27
-
28
- if ( this.isBool(val) ) {
29
- return val === null;
30
- }
31
-
32
- if ( this.isPlain(val) ) {
33
- return Object.keys(val).length === 0;
34
- }
35
-
36
- if ( this.isArray(val) ) {
37
- return Object.keys(val).length === 0;
38
- }
39
-
40
- return val === null || val === undefined;
41
- }
42
-
43
- static isNull(val)
44
- {
45
- return val === null;
46
- }
47
-
48
- static isEqual(obj, val)
49
- {
50
- if ( obj instanceof Node ) {
51
- return obj.isEqualNode(val);
52
- }
53
-
54
- if ( this.isPlain(obj) ) {
55
- return Object.is(obj, val)
56
- }
57
-
58
- if ( this.isArray(obj) ) {
59
- return Object.is(obj, val)
60
- }
61
-
62
- return obj === val;
63
- }
64
-
65
- static isString(val)
66
- {
67
- return typeof val === 'string';
68
- }
69
-
70
- static isNumber(val)
71
- {
72
- return typeof val === 'number' ||
73
- (typeof val === 'string' && val.match(/^\-?[0-9]+$/));
74
- }
75
-
76
- static isBool(val)
77
- {
78
- return typeof val === 'boolean' ||
79
- (typeof val === 'string' && val.match(/^(true|false)$/));
80
- }
81
-
82
- static isFunction(val)
83
- {
84
- return typeof val === 'function';
85
- }
86
-
87
- static isObject(val)
88
- {
89
- return val !== null && typeof val === 'object';
90
- }
91
-
92
- static isPlain(val)
93
- {
94
- return this.isObject(val) && val.constructor === Object;
95
- }
96
-
97
- static isArray(val)
98
- {
99
- return this.isObject(val) && val.constructor === Array;
100
- }
101
-
102
- static isDate(val)
103
- {
104
- return val instanceof Date;
105
- }
106
-
107
- static string(val)
108
- {
109
- return String(val);
110
- }
111
-
112
- static convertString(val, empty = '-')
113
- {
114
- return this.isEmpty(val) ? empty : this.string(val);
115
- }
116
-
117
- static number(val, fallback = NaN)
118
- {
119
- let res = ! val || typeof val.toString === 'undefined' ?
120
- String(val) : val.toString();
121
-
122
- if ( ! Any.isString(res) ) {
123
- return fallback;
124
- }
125
-
126
- if ( res.match(/^[0-9]+$/) ) {
127
- return this.integer(val);
128
- }
129
-
130
- if ( res.match(/^[0-9.,]+$/) ) {
131
- return this.float(val);
132
- }
133
-
134
- if ( ! this.isNumber(res) || Number.isNaN(res) ) {
135
- return fallback;
136
- }
137
-
138
- return res;
139
- }
140
-
141
- static integer(val)
142
- {
143
- let res = ! val || typeof val.toString === 'undefined' ?
144
- String(val) : val.toString();
145
-
146
- if ( ! Any.isString(res) ) {
147
- return NaN;
148
- }
149
-
150
- return parseInt(val);
151
- }
152
-
153
- static float(val)
154
- {
155
- let res = typeof val.toString === 'undefined' ?
156
- String(val) : val.toString();
157
-
158
- if ( ! Any.isString(res) ) {
159
- return NaN;
160
- }
161
-
162
- if ( res.match(/^[0-9,]+$/) ) {
163
- res = res.replace(/,/g, '.');
164
- }
165
-
166
- return parseFloat(res);
167
- }
168
-
169
- static bool(val)
170
- {
171
- let result = String(val).match(/^(true|1|yes|ja)$/i);
172
-
173
- return result === null ? false : result.length !== 0;
174
- }
175
-
176
- static boolean(val)
177
- {
178
- let result = String(val).match(/^(true|1|yes|ja)$/i);
179
-
180
- return result === null ? false : result.length !== 0;
181
- }
182
-
183
- static convertBool(val, yes = 'Yes', no = 'No')
184
- {
185
- let result = String(val).match(/^(true|1|yes|ja)$/i);
186
-
187
- return result === null || result.length === 0 ? no : yes;
188
- }
189
-
190
- static convertBoolean(val, yes = 'Yes', no = 'No')
191
- {
192
- let result = String(val).match(/^(true|1|yes|ja)$/i);
193
-
194
- return result === null || result.length === 0 ? no : yes;
195
- }
196
-
197
- static convertDatetime(val, format = 'YYYY-MM-DD hh:mm:ss', empty = '-')
198
- {
199
- if ( Any.isEmpty(val) === true ) {
200
- return empty;
201
- }
202
-
203
- return Now.make(val).format(format);
204
- }
205
-
206
- static vals(obj)
207
- {
208
- let keys = [];
209
-
210
- for ( let key in obj ) {
211
- if ( obj.hasOwnProperty(key) ) {
212
- keys.push(obj[key]);
213
- }
214
- }
215
-
216
- return keys;
217
- }
218
-
219
- static keys(obj)
220
- {
221
- let keys = [];
222
-
223
- for ( let key in obj ) {
224
- if ( obj.hasOwnProperty(key) ) {
225
- keys.push(key);
226
- }
227
- }
228
-
229
- return keys;
230
- }
231
-
232
- static async(callback, ...args)
233
- {
234
- setTimeout(function() {
235
- callback(...args);
236
- }, 0);
237
-
238
- return this;
239
- }
240
-
241
- static delay(callback, delay = 100, ...args)
242
- {
243
- setTimeout(function() {
244
- callback(...args);
245
- }, delay);
246
-
247
- return this;
248
- }
249
-
250
- static debounce(callback, delay = 100, ref = null)
251
- {
252
- let debounce = null;
253
-
254
- if ( ! Any.isEmpty(ref) ) {
255
- debounce = ref();
256
- }
257
-
258
- if ( ref !== null && ref.__debouce !== undefined ) {
259
- debounce = ref.__debouce;
260
- }
261
-
262
- return (...args) => {
263
-
264
- clearTimeout(debounce);
265
-
266
- debounce = setTimeout(() => {
267
- callback(...args);
268
- }, delay);
269
-
270
- if ( ! Any.isEmpty(ref) ) {
271
- ref(debounce);
272
- }
273
- };
274
- }
275
-
276
- static throttle(callback, delay = 100, ref = null)
277
- {
278
- let throttle = null;
279
-
280
- if ( ! Any.isEmpty(ref) ) {
281
- throttle = ref();
282
- }
283
-
284
- let timer = null;
285
-
286
- return (...args) => {
287
-
288
- clearTimeout(timer);
289
-
290
- timer = setTimeout(() => {
291
- throttle = null;
292
- }, delay);
293
-
294
- if ( throttle === true ) {
295
- return;
296
- }
297
-
298
- throttle = true;
299
-
300
- if ( ! Any.isEmpty(ref) ) {
301
- ref(throttle);
302
- }
303
-
304
- callback(...args);
305
- };
306
- }
307
-
308
- static framerate(callback, rate = 30, ref = null)
309
- {
310
- let latest = 0;
311
-
312
- if ( ! Any.isEmpty(ref) ) {
313
- latest = ref();
314
- }
315
-
316
- return (...args) => {
317
-
318
- if ( Date.now() - latest <= (1000 / rate) ) {
319
- return;
320
- }
321
-
322
- callback(...args);
323
-
324
- latest = Date.now();
325
-
326
- if ( ! Any.isEmpty(ref) ) {
327
- ref(latest);
328
- }
329
-
330
- };
331
- }
332
-
333
- static form(obj)
334
- {
335
- let form = new FormData();
336
-
337
- let appendField = (values, keys = []) => {
338
- Obj.each(values, (value, index) => {
339
-
340
- let inner = Arr.merge([], keys, index);
341
-
342
- if ( Any.isPlain(value) ) {
343
- return appendField(value, inner);
344
- }
345
-
346
- if ( Any.isArray(value) ) {
347
- return appendField(value, inner);
348
- }
349
-
350
- let key = inner.splice(0, 1)[0];
351
-
352
- Arr.each(inner, (index) => {
353
- key += '[' + index + ']';
354
- });
355
-
356
- if ( value !== null ) {
357
- form.append(key, value);
358
- }
359
- });
360
-
361
- return form;
362
- };
363
-
364
- return appendField(obj);
365
- }
366
-
367
- }
368
-
369
- export default Any;