@kizmann/pico-js 2.0.7 → 2.0.9
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/dist/pico-js.browser.js +1 -1
- package/dist/pico-js.browser.js.map +1 -1
- package/dist/pico-js.esm.js +1 -1
- package/dist/pico-js.esm.js.map +1 -1
- package/package.json +4 -6
- package/src/dom/{DomAttribute.js → DomAttribute.ts} +40 -63
- package/src/dom/{DomBuilder.js → DomBuilder.ts} +27 -44
- package/src/dom/{DomEvent.js → DomEvent.ts} +101 -76
- package/src/dom/{DomFinder.js → DomFinder.ts} +103 -139
- package/src/dom/DomForm.ts +38 -0
- package/src/dom/{DomGlobal.js → DomGlobal.ts} +34 -51
- package/src/dom/{DomInview.js → DomInview.ts} +37 -57
- package/src/dom/DomMeta.ts +48 -0
- package/src/dom/DomObserver.ts +17 -0
- package/src/dom/{DomPopover.js → DomPopover.ts} +20 -39
- package/src/dom/{DomRectangle.js → DomRectangle.ts} +70 -87
- package/src/format/{FormatFile.js → FormatFile.ts} +12 -23
- package/src/format/{FormatOption.js → FormatOption.ts} +15 -24
- package/src/format/{FormatParam.js → FormatParam.ts} +14 -25
- package/src/format/{FormatParser.js → FormatParser.ts} +29 -39
- package/src/format/{FormatUrl.js → FormatUrl.ts} +9 -21
- package/src/index.browser.ts +32 -0
- package/src/index.esm.ts +64 -0
- package/src/now/{NowDefault.js → NowDefault.ts} +86 -121
- package/src/now/{NowFormat.js → NowFormat.ts} +23 -28
- package/src/now/{NowGrid.js → NowGrid.ts} +41 -58
- package/src/now/{NowHuman.js → NowHuman.ts} +18 -27
- package/src/now/{NowMatch.js → NowMatch.ts} +22 -28
- package/src/now/{NowRange.js → NowRange.ts} +13 -22
- package/src/now/{NowWalker.js → NowWalker.ts} +65 -71
- package/src/tool/{scope.js → scope.ts} +41 -11
- package/src/utils/{Array.js → Array.ts} +187 -152
- package/src/utils/{Cookie.js → Cookie.ts} +15 -12
- package/src/utils/{Data.js → Data.ts} +17 -17
- package/src/utils/Dom.ts +204 -0
- package/src/utils/Format.ts +48 -0
- package/src/utils/{Hash.js → Hash.ts} +20 -20
- package/src/utils/{Locale.js → Locale.ts} +21 -21
- package/src/utils/{Mixed.js → Mixed.ts} +104 -61
- package/src/utils/{Now.js → Now.ts} +68 -69
- package/src/utils/{Number.js → Number.ts} +34 -36
- package/src/utils/{Object.js → Object.ts} +68 -122
- package/src/utils/{Route.js → Route.ts} +11 -9
- package/src/utils/{Runner.js → Runner.ts} +89 -77
- package/src/utils/{Signal.js → Signal.ts} +35 -22
- package/src/utils/{String.js → String.ts} +79 -69
- package/src/wip/{Element.js → Element.ts} +2 -2
- package/src/wip/{Map.js → Map.ts} +1 -1
- package/types/dom/DomAttribute.d.ts +16 -27
- package/types/dom/DomBuilder.d.ts +6 -9
- package/types/dom/DomEvent.d.ts +19 -24
- package/types/dom/DomFinder.d.ts +38 -61
- package/types/dom/DomForm.d.ts +7 -10
- package/types/dom/DomGlobal.d.ts +8 -15
- package/types/dom/DomInview.d.ts +9 -19
- package/types/dom/DomMeta.d.ts +9 -16
- package/types/dom/DomObserver.d.ts +4 -8
- package/types/dom/DomPopover.d.ts +8 -11
- package/types/dom/DomRectangle.d.ts +21 -35
- package/types/format/FormatFile.d.ts +5 -8
- package/types/format/FormatOption.d.ts +6 -8
- package/types/format/FormatParam.d.ts +6 -9
- package/types/format/FormatParser.d.ts +10 -18
- package/types/format/FormatUrl.d.ts +5 -8
- package/types/index.esm.d.ts +25 -37
- package/types/now/NowDefault.d.ts +30 -99
- package/types/now/NowFormat.d.ts +8 -21
- package/types/now/NowGrid.d.ts +24 -46
- package/types/now/NowHuman.d.ts +10 -11
- package/types/now/NowMatch.d.ts +6 -4
- package/types/now/NowRange.d.ts +5 -8
- package/types/now/NowWalker.d.ts +6 -4
- package/types/tool/scope.d.ts +11 -3
- package/types/utils/Array.d.ts +83 -101
- package/types/utils/Cookie.d.ts +11 -8
- package/types/utils/Data.d.ts +7 -7
- package/types/utils/Dom.d.ts +63 -96
- package/types/utils/Format.d.ts +15 -28
- package/types/utils/Hash.d.ts +21 -21
- package/types/utils/Locale.d.ts +9 -9
- package/types/utils/Mixed.d.ts +19 -32
- package/types/utils/Now.d.ts +51 -56
- package/types/utils/Number.d.ts +9 -20
- package/types/utils/Object.d.ts +21 -36
- package/types/utils/Route.d.ts +5 -2
- package/types/utils/Runner.d.ts +45 -38
- package/types/utils/Signal.d.ts +16 -16
- package/types/utils/String.d.ts +40 -76
- package/src/dom/DomForm.js +0 -59
- package/src/dom/DomMeta.js +0 -68
- package/src/dom/DomObserver.js +0 -38
- package/src/index.browser.js +0 -36
- package/src/index.esm.js +0 -80
- package/src/utils/Dom.js +0 -214
- package/src/utils/Format.js +0 -62
- package/types/wip/Element.d.ts +0 -119
- package/types/wip/Map.d.ts +0 -254
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { For, Arr, Now, Mix } from "../index.esm.
|
|
1
|
+
import { For, Arr, Now, Mix } from "../index.esm.ts";
|
|
2
2
|
|
|
3
3
|
export const COOKIE_REGEX = {
|
|
4
4
|
entry: /(?<=^|;)\s*(?<key>.*?)\s*=\s*(?<value>[^;$]+)/g
|
|
@@ -6,7 +6,10 @@ export const COOKIE_REGEX = {
|
|
|
6
6
|
|
|
7
7
|
export class PicoCookie
|
|
8
8
|
{
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @type {Record<string, any>}
|
|
11
|
+
*/
|
|
12
|
+
static $cookie : any;
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
15
|
* Read raw document.cookie
|
|
@@ -15,7 +18,7 @@ export class PicoCookie
|
|
|
15
18
|
*
|
|
16
19
|
* @returns {string} Cookie string
|
|
17
20
|
*/
|
|
18
|
-
static global()
|
|
21
|
+
static global() : string
|
|
19
22
|
{
|
|
20
23
|
if ( globalThis.document == null ) {
|
|
21
24
|
return '';
|
|
@@ -33,7 +36,7 @@ export class PicoCookie
|
|
|
33
36
|
* @param {boolean} [fresh] Force refresh
|
|
34
37
|
* @returns {Record<string, any>} Cookie map
|
|
35
38
|
*/
|
|
36
|
-
static parse(fresh = false)
|
|
39
|
+
static parse(fresh : boolean = false) : Record<string, any>
|
|
37
40
|
{
|
|
38
41
|
if ( !fresh && this.$cookie ) {
|
|
39
42
|
return this.$cookie;
|
|
@@ -49,7 +52,7 @@ export class PicoCookie
|
|
|
49
52
|
return this.$cookie;
|
|
50
53
|
}
|
|
51
54
|
|
|
52
|
-
let fn = (value) => {
|
|
55
|
+
let fn = (value : any) => {
|
|
53
56
|
return value.replaceAll('{:}', ';');
|
|
54
57
|
}
|
|
55
58
|
|
|
@@ -71,7 +74,7 @@ export class PicoCookie
|
|
|
71
74
|
* @param {string} [decode] Decode mode
|
|
72
75
|
* @returns {any} Cookie value
|
|
73
76
|
*/
|
|
74
|
-
static get(key, fallback = null, decode = 'string')
|
|
77
|
+
static get(key : string, fallback : any = null, decode : string = 'string') : any
|
|
75
78
|
{
|
|
76
79
|
if ( !this.$cookie ) {
|
|
77
80
|
this.parse();
|
|
@@ -110,9 +113,9 @@ export class PicoCookie
|
|
|
110
113
|
* @param {any} value Cookie value
|
|
111
114
|
* @param {any} [expire] Expire date spec
|
|
112
115
|
* @param {any} [options] Cookie options
|
|
113
|
-
* @returns {
|
|
116
|
+
* @returns {PicoCookie} Cookie class
|
|
114
117
|
*/
|
|
115
|
-
static set(key, value, expire = null, options = {})
|
|
118
|
+
static set(key : string, value : any, expire : any = null, options : any = {}) : PicoCookie
|
|
116
119
|
{
|
|
117
120
|
if ( !this.$cookie ) {
|
|
118
121
|
this.parse();
|
|
@@ -138,7 +141,7 @@ export class PicoCookie
|
|
|
138
141
|
';', '{:}'
|
|
139
142
|
]);
|
|
140
143
|
|
|
141
|
-
Arr.each(options, (value, key) => {
|
|
144
|
+
Arr.each(options, (value : any, key : any) => {
|
|
142
145
|
plain += `;${key}=${value}`;
|
|
143
146
|
});
|
|
144
147
|
|
|
@@ -154,9 +157,9 @@ export class PicoCookie
|
|
|
154
157
|
*
|
|
155
158
|
* @param {string} key Cookie key
|
|
156
159
|
* @param {any} [options] Cookie options
|
|
157
|
-
* @returns {
|
|
160
|
+
* @returns {PicoCookie} Cookie class
|
|
158
161
|
*/
|
|
159
|
-
static forget(key, options = {})
|
|
162
|
+
static forget(key : string, options : any = {}) : PicoCookie
|
|
160
163
|
{
|
|
161
164
|
let expires = 'Thu, 01 Jan 1970 00:00:01 GMT';
|
|
162
165
|
|
|
@@ -170,7 +173,7 @@ export class PicoCookie
|
|
|
170
173
|
|
|
171
174
|
let plain = `${key}=null`;
|
|
172
175
|
|
|
173
|
-
Arr.each(options, (value, key) => {
|
|
176
|
+
Arr.each(options, (value : any, key : any) => {
|
|
174
177
|
plain += `;${key}=${value}`;
|
|
175
178
|
});
|
|
176
179
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Arr, Num,
|
|
1
|
+
import { Arr, Num, Signal, Mix, Obj } from "../index.esm.ts";
|
|
2
2
|
|
|
3
3
|
export class PicoData
|
|
4
4
|
{
|
|
5
5
|
/**
|
|
6
6
|
* In-memory data store
|
|
7
7
|
*
|
|
8
|
-
* @type {
|
|
8
|
+
* @type {any}
|
|
9
9
|
*/
|
|
10
|
-
static $data = {};
|
|
10
|
+
static $data : any = {};
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Check if store key exists
|
|
@@ -17,7 +17,7 @@ export class PicoData
|
|
|
17
17
|
* @param {any} input Store key input
|
|
18
18
|
* @returns {boolean} True if exists
|
|
19
19
|
*/
|
|
20
|
-
static has(input)
|
|
20
|
+
static has(input : any) : boolean
|
|
21
21
|
{
|
|
22
22
|
return Obj.has(this.$data, ...[
|
|
23
23
|
Arr.first(input)
|
|
@@ -34,7 +34,7 @@ export class PicoData
|
|
|
34
34
|
* @param {any} value Value to set
|
|
35
35
|
* @returns {void} No return value
|
|
36
36
|
*/
|
|
37
|
-
static set(input, value)
|
|
37
|
+
static set(input : any, value : any) : void
|
|
38
38
|
{
|
|
39
39
|
let [stored, key] = [
|
|
40
40
|
null, Arr.first(input)
|
|
@@ -52,7 +52,7 @@ export class PicoData
|
|
|
52
52
|
this.$data, key, value
|
|
53
53
|
]);
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
Signal.fire('store:' + key, value, key);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
@@ -63,7 +63,7 @@ export class PicoData
|
|
|
63
63
|
* @param {any} input Store key input
|
|
64
64
|
* @returns {void} No return value
|
|
65
65
|
*/
|
|
66
|
-
static unset(input)
|
|
66
|
+
static unset(input : any) : void
|
|
67
67
|
{
|
|
68
68
|
Obj.unset(this.$data, [
|
|
69
69
|
...Arr.first(input)
|
|
@@ -81,7 +81,7 @@ export class PicoData
|
|
|
81
81
|
* @param {boolean} [forceSet] Set if missing
|
|
82
82
|
* @returns {any} Stored value
|
|
83
83
|
*/
|
|
84
|
-
static get(input, fallback = null, forceSet = false)
|
|
84
|
+
static get(input : any, fallback : any = null, forceSet : boolean = false) : any
|
|
85
85
|
{
|
|
86
86
|
let key = Arr.first(input);
|
|
87
87
|
|
|
@@ -112,7 +112,7 @@ export class PicoData
|
|
|
112
112
|
* @param {any} [fallback] Fallback value
|
|
113
113
|
* @returns {any} Found item
|
|
114
114
|
*/
|
|
115
|
-
static find(input, value, fallback = null)
|
|
115
|
+
static find(input : any, value : any, fallback : any = null) : any
|
|
116
116
|
{
|
|
117
117
|
let key = Arr.first(input);
|
|
118
118
|
|
|
@@ -128,7 +128,7 @@ export class PicoData
|
|
|
128
128
|
id: value.id
|
|
129
129
|
});
|
|
130
130
|
|
|
131
|
-
if ( index === -
|
|
131
|
+
if ( index === -1 ) {
|
|
132
132
|
return fallback;
|
|
133
133
|
}
|
|
134
134
|
|
|
@@ -144,7 +144,7 @@ export class PicoData
|
|
|
144
144
|
* @param {any} value Item to replace
|
|
145
145
|
* @returns {void} No return value
|
|
146
146
|
*/
|
|
147
|
-
static replace(input, value)
|
|
147
|
+
static replace(input : any, value : any) : void
|
|
148
148
|
{
|
|
149
149
|
let key = Arr.first(input);
|
|
150
150
|
|
|
@@ -160,7 +160,7 @@ export class PicoData
|
|
|
160
160
|
id: Num.int(value.id)
|
|
161
161
|
});
|
|
162
162
|
|
|
163
|
-
if ( index === -
|
|
163
|
+
if ( index === -1 ) {
|
|
164
164
|
return;
|
|
165
165
|
}
|
|
166
166
|
|
|
@@ -173,12 +173,12 @@ export class PicoData
|
|
|
173
173
|
* @example Data.add(["list"], 1, 2)
|
|
174
174
|
*
|
|
175
175
|
* @param {any} input Store key input
|
|
176
|
-
* @param {...any} args Items to add
|
|
176
|
+
* @param {[...any]} args Items to add
|
|
177
177
|
* @returns {void} No return value
|
|
178
178
|
*/
|
|
179
|
-
static add(input, ...args)
|
|
179
|
+
static add(input : any, ...args : [...any]) : void
|
|
180
180
|
{
|
|
181
|
-
this.set(input, Arr.
|
|
181
|
+
this.set(input, Arr.merge(this.get(input, []), args));
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
/**
|
|
@@ -187,10 +187,10 @@ export class PicoData
|
|
|
187
187
|
* @example Data.remove(["list"], 1)
|
|
188
188
|
*
|
|
189
189
|
* @param {any} input Store key input
|
|
190
|
-
* @param {...any} args Items to remove
|
|
190
|
+
* @param {[...any]} args Items to remove
|
|
191
191
|
* @returns {void} No return value
|
|
192
192
|
*/
|
|
193
|
-
static remove(input, ...args)
|
|
193
|
+
static remove(input : any, ...args : [...any]) : void
|
|
194
194
|
{
|
|
195
195
|
this.set(input, Arr.diff(this.get(input, []), args));
|
|
196
196
|
}
|
package/src/utils/Dom.ts
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { trait } from "../tool/scope.ts";
|
|
2
|
+
import { Mix, Dom, Arr } from "../index.esm.ts";
|
|
3
|
+
import { PicoDomFinder } from "../dom/DomFinder.ts";
|
|
4
|
+
import { PicoDomForm } from "../dom/DomForm.ts";
|
|
5
|
+
import { PicoDomEvent } from "../dom/DomEvent.ts";
|
|
6
|
+
import { PicoDomBuilder } from "../dom/DomBuilder.ts";
|
|
7
|
+
import { PicoDomGlobal } from "../dom/DomGlobal.ts";
|
|
8
|
+
import { PicoDomRectangle } from "../dom/DomRectangle.ts";
|
|
9
|
+
import { PicoDomAttribute } from "../dom/DomAttribute.ts";
|
|
10
|
+
import { PicoDomInview } from "../dom/DomInview.ts";
|
|
11
|
+
import { PicoDomMeta } from "../dom/DomMeta.ts";
|
|
12
|
+
import { PicoDomObserver } from "../dom/DomObserver.ts";
|
|
13
|
+
import { PicoDomPopover } from "../dom/DomPopover.ts";
|
|
14
|
+
|
|
15
|
+
export const PicoDomPlugins = [
|
|
16
|
+
PicoDomFinder,
|
|
17
|
+
PicoDomGlobal,
|
|
18
|
+
PicoDomForm,
|
|
19
|
+
PicoDomEvent,
|
|
20
|
+
PicoDomBuilder,
|
|
21
|
+
PicoDomRectangle,
|
|
22
|
+
PicoDomAttribute,
|
|
23
|
+
PicoDomInview,
|
|
24
|
+
PicoDomMeta,
|
|
25
|
+
PicoDomObserver,
|
|
26
|
+
PicoDomPopover,
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
export interface PicoDomInterface
|
|
30
|
+
{
|
|
31
|
+
el: any;
|
|
32
|
+
els: any[];
|
|
33
|
+
extend(plugin : Function) : void;
|
|
34
|
+
win() : any;
|
|
35
|
+
doc() : any;
|
|
36
|
+
body() : any;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface PicoDom extends
|
|
40
|
+
PicoDomFinder,
|
|
41
|
+
PicoDomGlobal,
|
|
42
|
+
PicoDomForm,
|
|
43
|
+
PicoDomEvent,
|
|
44
|
+
PicoDomBuilder,
|
|
45
|
+
PicoDomRectangle,
|
|
46
|
+
PicoDomAttribute,
|
|
47
|
+
PicoDomInview,
|
|
48
|
+
PicoDomMeta,
|
|
49
|
+
PicoDomObserver,
|
|
50
|
+
PicoDomPopover
|
|
51
|
+
{
|
|
52
|
+
//
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @class PicoDom
|
|
57
|
+
*
|
|
58
|
+
* @mixes PicoDomFinder
|
|
59
|
+
* @mixes PicoDomGlobal
|
|
60
|
+
* @mixes PicoDomForm
|
|
61
|
+
* @mixes PicoDomEvent
|
|
62
|
+
* @mixes PicoDomBuilder
|
|
63
|
+
* @mixes PicoDomRectangle
|
|
64
|
+
* @mixes PicoDomAttribute
|
|
65
|
+
* @mixes PicoDomInview
|
|
66
|
+
* @mixes PicoDomMeta
|
|
67
|
+
* @mixes PicoDomObserver
|
|
68
|
+
* @mixes PicoDomPopover
|
|
69
|
+
*/
|
|
70
|
+
export class PicoDom extends trait(PicoDomPlugins)
|
|
71
|
+
{
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Init hooks for constructor
|
|
75
|
+
*
|
|
76
|
+
* @type {Function[]}
|
|
77
|
+
*/
|
|
78
|
+
static init : Function[] = [];
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* First selected element
|
|
82
|
+
*
|
|
83
|
+
* @type {any}
|
|
84
|
+
*/
|
|
85
|
+
el : any = null;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* All selected elements
|
|
89
|
+
*
|
|
90
|
+
* @type {any[]}
|
|
91
|
+
*/
|
|
92
|
+
els : any[] = [];
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Create Dom wrapper from input
|
|
96
|
+
*
|
|
97
|
+
* @example new Dom("body").get(0) // => HTMLElement
|
|
98
|
+
*
|
|
99
|
+
* @param {any} el Element or selector
|
|
100
|
+
* @param {[...any]} args Plugin args
|
|
101
|
+
*/
|
|
102
|
+
constructor(el : any, ...args : [...any])
|
|
103
|
+
{
|
|
104
|
+
super(el, ...args);
|
|
105
|
+
|
|
106
|
+
if ( typeof el === 'string' ) {
|
|
107
|
+
el = document.querySelectorAll(el);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if ( el instanceof NodeList ) {
|
|
111
|
+
el = Mix.nodes(el);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if ( el instanceof Dom ) {
|
|
115
|
+
el = el.el;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if ( !Mix.isArr(el) ) {
|
|
119
|
+
el = [el];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
(this.el = el[0], this.els = el);
|
|
123
|
+
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Create new Dom wrapper
|
|
129
|
+
*
|
|
130
|
+
* @example Dom.find("body") // => Dom
|
|
131
|
+
*
|
|
132
|
+
* @param {any} el Element or selector
|
|
133
|
+
* @param {[...any]} args Plugin args
|
|
134
|
+
* @returns {PicoDom} Dom wrapper
|
|
135
|
+
*/
|
|
136
|
+
static find(el : any, ...args : [...any]) : PicoDom
|
|
137
|
+
{
|
|
138
|
+
return new Dom(el, ...args);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Extend Dom with a plugin
|
|
143
|
+
*
|
|
144
|
+
* @example Dom.extend(fn)
|
|
145
|
+
*
|
|
146
|
+
* @param {Function} plugin Plugin function
|
|
147
|
+
* @returns {void} No return value
|
|
148
|
+
*/
|
|
149
|
+
static extend(plugin : Function) : void
|
|
150
|
+
{
|
|
151
|
+
plugin.call({}, this);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Get window or empty object
|
|
156
|
+
*
|
|
157
|
+
* @example Dom.win().innerWidth // => number|undefined
|
|
158
|
+
*
|
|
159
|
+
* @returns {any} Window or {}
|
|
160
|
+
*/
|
|
161
|
+
static win() : any
|
|
162
|
+
{
|
|
163
|
+
if ( globalThis.window == null ) {
|
|
164
|
+
return {};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return window;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Get document or empty object
|
|
172
|
+
*
|
|
173
|
+
* @example Dom.doc().body // => HTMLElement
|
|
174
|
+
*
|
|
175
|
+
* @returns {any} Document or {}
|
|
176
|
+
*/
|
|
177
|
+
static doc() : any
|
|
178
|
+
{
|
|
179
|
+
if ( globalThis.document == null ) {
|
|
180
|
+
return {};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return document;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Get document.body or empty
|
|
188
|
+
*
|
|
189
|
+
* @example Dom.body().nodeType // => 1|undefined
|
|
190
|
+
*
|
|
191
|
+
* @returns {any} Body or {}
|
|
192
|
+
*/
|
|
193
|
+
static body() : any
|
|
194
|
+
{
|
|
195
|
+
if ( !this.doc().body ) {
|
|
196
|
+
return {};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return this.doc().body;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export default PicoDom;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { trait } from "../tool/scope.ts";
|
|
2
|
+
import { PicoFormatParser } from "../format/FormatParser.ts";
|
|
3
|
+
import { PicoFormatParam } from "../format/FormatParam.ts";
|
|
4
|
+
import { PicoFormatOption } from "../format/FormatOption.ts";
|
|
5
|
+
import { PicoFormatUrl } from "../format/FormatUrl.ts";
|
|
6
|
+
import { PicoFormatFile } from "../format/FormatFile.ts";
|
|
7
|
+
|
|
8
|
+
export const PicoFormatPlugins = [
|
|
9
|
+
PicoFormatParser,
|
|
10
|
+
PicoFormatParam,
|
|
11
|
+
PicoFormatOption,
|
|
12
|
+
PicoFormatUrl,
|
|
13
|
+
PicoFormatFile,
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
export interface PicoFormatInterface
|
|
17
|
+
{
|
|
18
|
+
extend(plugin : Function) : void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface PicoFormat extends PicoFormatParser,
|
|
22
|
+
PicoFormatParam,
|
|
23
|
+
PicoFormatOption,
|
|
24
|
+
PicoFormatUrl,
|
|
25
|
+
PicoFormatFile
|
|
26
|
+
{
|
|
27
|
+
//
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class PicoFormat extends trait(PicoFormatPlugins)
|
|
31
|
+
{
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Extend format with a plugin
|
|
35
|
+
*
|
|
36
|
+
* @example For.extend(fn)
|
|
37
|
+
*
|
|
38
|
+
* @param {Function} plugin Plugin function
|
|
39
|
+
* @returns {void} No return value
|
|
40
|
+
*/
|
|
41
|
+
static extend(plugin : Function) : void
|
|
42
|
+
{
|
|
43
|
+
plugin.call({}, this);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default PicoFormat;
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { Str } from "../index.esm.
|
|
1
|
+
import { Str } from "../index.esm.ts";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @var {
|
|
4
|
+
* @var {string[]} RADIX_NUMBER Radix from 0 to 9
|
|
5
5
|
*/
|
|
6
6
|
export const RADIX_NUMBER = [
|
|
7
7
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
|
|
8
8
|
];
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* @var {
|
|
11
|
+
* @var {string[]} RADIX_LETTER_LC Radix from a to z
|
|
12
12
|
*/
|
|
13
13
|
export const RADIX_LETTER_LC = [
|
|
14
14
|
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
|
15
15
|
];
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* @var {
|
|
18
|
+
* @var {string[]} RADIX_LETTER_UC Radix from A to Z
|
|
19
19
|
*/
|
|
20
20
|
export const RADIX_LETTER_UC = [
|
|
21
21
|
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
|
|
22
22
|
];
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* @var {
|
|
25
|
+
* @var {string[]} RADIX_UUID Radix from 0-9, a-f and A-F
|
|
26
26
|
*/
|
|
27
27
|
export const RADIX_UUID = [
|
|
28
28
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', 'E', 'F',
|
|
@@ -30,14 +30,14 @@ export const RADIX_UUID = [
|
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
* @var {
|
|
33
|
+
* @var {string[]} RADIX_UP19 Radix with 8, 9, a and b
|
|
34
34
|
*/
|
|
35
35
|
export const RADIX_UP19 = [
|
|
36
36
|
'8', '9', 'a', 'b',
|
|
37
37
|
];
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
|
-
* @var {
|
|
40
|
+
* @var {string[]} radix_symbol_pass Radix for passwords
|
|
41
41
|
*/
|
|
42
42
|
export const radix_symbol_pass = [
|
|
43
43
|
'@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '-', '=', '[', ']', '{', '}', ';', ':', ',', '.', '/', '<', '>', '?'
|
|
@@ -47,9 +47,9 @@ export class PicoHash
|
|
|
47
47
|
{
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
* @
|
|
50
|
+
* @type {string[]}
|
|
51
51
|
*/
|
|
52
|
-
static RADIX = [
|
|
52
|
+
static RADIX : string[] = [
|
|
53
53
|
...RADIX_NUMBER, ...RADIX_LETTER_LC, ...RADIX_LETTER_UC
|
|
54
54
|
];
|
|
55
55
|
|
|
@@ -59,10 +59,10 @@ export class PicoHash
|
|
|
59
59
|
* @example Hash.radix(2, ['R', 'f']) // => 'R' or 'f'
|
|
60
60
|
*
|
|
61
61
|
* @param {number} [limit=60] Maximum radix char index
|
|
62
|
-
* @param {
|
|
62
|
+
* @param {string[]} [radix=null] A defined radix or null for default
|
|
63
63
|
* @returns {string} Returns random char from radix
|
|
64
64
|
*/
|
|
65
|
-
static radix(limit = 60, radix = null)
|
|
65
|
+
static radix(limit : number = 60, radix : string[] = null) : string
|
|
66
66
|
{
|
|
67
67
|
return (radix || this.RADIX)[this.number(limit - 1)];
|
|
68
68
|
}
|
|
@@ -76,7 +76,7 @@ export class PicoHash
|
|
|
76
76
|
* @param {number} [start=0] Minimum value
|
|
77
77
|
* @returns {number} Returns a random number between start and limit
|
|
78
78
|
*/
|
|
79
|
-
static number(limit = 1024, start = 0)
|
|
79
|
+
static number(limit : number = 1024, start : number = 0) : number
|
|
80
80
|
{
|
|
81
81
|
return Math.floor(Math.random() * (limit - start + 1)) + start;
|
|
82
82
|
}
|
|
@@ -88,14 +88,14 @@ export class PicoHash
|
|
|
88
88
|
*
|
|
89
89
|
* @param {number} [length] Length of generated hash
|
|
90
90
|
* @param {number} [radix] Maximum radix char index (10 for 0-9, 36 incl. a-z, 62 incl. A-Z)
|
|
91
|
-
* @param {
|
|
91
|
+
* @param {any} [map] Remap for generated string
|
|
92
92
|
* @returns {string} Returns a random hash with fixed length
|
|
93
93
|
*/
|
|
94
|
-
static make(length = 6, radix = 62, map = {})
|
|
94
|
+
static make(length : number = 6, radix : number = 62, map : any = {}) : string
|
|
95
95
|
{
|
|
96
96
|
let hash = '';
|
|
97
97
|
|
|
98
|
-
for ( let i = 0; i < length; i
|
|
98
|
+
for ( let i = 0; i < length; i++ ) {
|
|
99
99
|
hash += this.radix(radix);
|
|
100
100
|
}
|
|
101
101
|
|
|
@@ -114,12 +114,12 @@ export class PicoHash
|
|
|
114
114
|
* @param {string|number} [version] UUID version number
|
|
115
115
|
* @returns {string} Returns a valid UUID
|
|
116
116
|
*/
|
|
117
|
-
static uuid(version = 4)
|
|
117
|
+
static uuid(version : number = 4) : string
|
|
118
118
|
{
|
|
119
119
|
let hash = '';
|
|
120
120
|
|
|
121
121
|
// Use only selected chars from the radix store
|
|
122
|
-
for ( let i = 0; i < 31; i
|
|
122
|
+
for ( let i = 0; i < 31; i++ ) {
|
|
123
123
|
if ( i === 15 ) {
|
|
124
124
|
hash += this.radix(RADIX_UP19.length, RADIX_UP19);
|
|
125
125
|
} else {
|
|
@@ -141,10 +141,10 @@ export class PicoHash
|
|
|
141
141
|
* @example Hash.password(12, ['%', '&']) // => '0unJ%VDi2RJX'
|
|
142
142
|
*
|
|
143
143
|
* @param {number} [length=24] Length of password
|
|
144
|
-
* @param {
|
|
144
|
+
* @param {string[]} [symbols=null] Defined symbols or null for default
|
|
145
145
|
* @returns {string} A random password with fixed length
|
|
146
146
|
*/
|
|
147
|
-
static password(length = 24, symbols = null)
|
|
147
|
+
static password(length : number = 24, symbols : string[] = null) : string
|
|
148
148
|
{
|
|
149
149
|
let radix = [
|
|
150
150
|
...this.RADIX, ...(symbols || radix_symbol_pass)
|
|
@@ -152,7 +152,7 @@ export class PicoHash
|
|
|
152
152
|
|
|
153
153
|
let hash = '';
|
|
154
154
|
|
|
155
|
-
for ( let i = 0; i < length; i
|
|
155
|
+
for ( let i = 0; i < length; i++ ) {
|
|
156
156
|
hash += this.radix(radix.length, radix);
|
|
157
157
|
}
|
|
158
158
|
|