@kizmann/pico-js 1.0.14 → 2.0.1
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 +27 -7
- package/dist/pico-js.browser.js +2 -0
- package/dist/pico-js.browser.js.map +1 -0
- package/dist/pico-js.esm.js +2 -0
- package/dist/pico-js.esm.js.map +1 -0
- package/package.json +19 -7
- package/src/dom/DomAttribute.js +376 -0
- package/src/dom/DomBuilder.js +154 -0
- package/src/dom/DomEvent.js +255 -0
- package/src/dom/DomFinder.js +671 -0
- package/src/dom/DomForm.js +59 -0
- package/src/dom/DomGlobal.js +195 -0
- package/src/dom/DomInview.js +334 -0
- package/src/dom/DomMeta.js +68 -0
- package/src/dom/DomObserver.js +59 -0
- package/src/dom/DomRectangle.js +658 -0
- package/src/format/FormatFile.js +56 -0
- package/src/format/FormatOption.js +110 -0
- package/src/format/FormatParam.js +109 -0
- package/src/format/FormatParser.js +158 -0
- package/src/format/FormatUrl.js +77 -0
- package/src/index.browser.js +31 -0
- package/src/index.esm.js +116 -0
- package/src/now/NowDefault.js +535 -0
- package/src/now/NowFormat.js +198 -0
- package/src/now/NowGrid.js +253 -0
- package/src/now/NowHuman.js +120 -0
- package/src/now/NowMatch.js +177 -0
- package/src/now/NowRange.js +72 -0
- package/src/now/NowWalker.js +546 -0
- package/src/tool/scope.js +103 -0
- package/src/utils/Array.js +986 -0
- package/src/utils/Cookie.js +184 -0
- package/src/utils/Data.js +200 -0
- package/src/utils/Dom.js +208 -0
- package/src/utils/Event.js +140 -0
- package/src/utils/Format.js +62 -0
- package/src/utils/Hash.js +164 -0
- package/src/utils/Locale.js +229 -0
- package/src/utils/Mixed.js +887 -0
- package/src/utils/Now.js +234 -0
- package/src/utils/Number.js +238 -0
- package/src/utils/Object.js +655 -0
- package/src/utils/Route.js +67 -0
- package/src/utils/Runner.js +327 -0
- package/src/utils/String.js +618 -0
- package/src/{library/element.js → wip/Element.js} +90 -16
- package/src/{library/map.js → wip/Map.js} +256 -40
- package/types/dom/DomAttribute.d.ts +138 -0
- package/types/dom/DomBuilder.d.ts +68 -0
- package/types/dom/DomEvent.d.ts +104 -0
- package/types/dom/DomFinder.d.ts +322 -0
- package/types/dom/DomForm.d.ts +22 -0
- package/types/dom/DomGlobal.d.ts +80 -0
- package/types/dom/DomInview.d.ts +115 -0
- package/types/dom/DomMeta.d.ts +30 -0
- package/types/dom/DomObserver.d.ts +22 -0
- package/types/dom/DomRectangle.d.ts +271 -0
- package/types/format/FormatFile.d.ts +19 -0
- package/types/format/FormatOption.d.ts +41 -0
- package/types/format/FormatParam.d.ts +40 -0
- package/types/format/FormatParser.d.ts +47 -0
- package/types/format/FormatUrl.d.ts +18 -0
- package/types/index.esm.d.ts +78 -0
- package/types/now/NowDefault.d.ts +184 -0
- package/types/now/NowFormat.d.ts +71 -0
- package/types/now/NowGrid.d.ts +108 -0
- package/types/now/NowHuman.d.ts +38 -0
- package/types/now/NowMatch.d.ts +109 -0
- package/types/now/NowRange.d.ts +22 -0
- package/types/now/NowWalker.d.ts +302 -0
- package/types/tool/scope.d.ts +24 -0
- package/types/utils/Array.d.ts +480 -0
- package/types/utils/Cookie.d.ts +60 -0
- package/types/utils/Data.d.ts +91 -0
- package/types/utils/Dom.d.ts +138 -0
- package/types/utils/Event.d.ts +58 -0
- package/types/utils/Format.d.ts +37 -0
- package/types/utils/Hash.d.ts +81 -0
- package/types/utils/Locale.d.ts +115 -0
- package/types/utils/Mixed.d.ts +469 -0
- package/types/utils/Now.d.ts +125 -0
- package/types/utils/Number.d.ts +127 -0
- package/types/utils/Object.d.ts +255 -0
- package/types/utils/Route.d.ts +37 -0
- package/types/utils/Runner.d.ts +139 -0
- package/types/utils/String.d.ts +330 -0
- package/types/wip/Element.d.ts +119 -0
- package/types/wip/Map.d.ts +254 -0
- package/dist/.ignore.js +0 -0
- package/dist/pico-js.js +0 -2
- package/dist/pico-js.js.map +0 -1
- package/src/element/default.js +0 -46
- package/src/element/example.js +0 -58
- package/src/index.js +0 -90
- package/src/library/cookie.js +0 -123
- package/src/library/data.js +0 -111
- package/src/library/event.js +0 -91
- package/src/library/locale.js +0 -84
- package/src/library/queue.js +0 -64
- package/src/library/route.js +0 -28
- package/src/utility/any.js +0 -369
- package/src/utility/array.js +0 -410
- package/src/utility/dom.js +0 -1425
- package/src/utility/now.js +0 -544
- package/src/utility/number.js +0 -128
- package/src/utility/object.js +0 -429
- package/src/utility/string.js +0 -328
- package/types/index.d.ts +0 -77
- package/types/library/cookie.d.ts +0 -10
- package/types/library/data.d.ts +0 -15
- package/types/library/element.d.ts +0 -22
- package/types/library/event.d.ts +0 -13
- package/types/library/locale.d.ts +0 -14
- package/types/library/map.d.ts +0 -43
- package/types/library/queue.d.ts +0 -18
- package/types/library/route.d.ts +0 -11
- package/types/utility/any.d.ts +0 -35
- package/types/utility/array.d.ts +0 -46
- package/types/utility/dom.d.ts +0 -101
- package/types/utility/now.d.ts +0 -79
- package/types/utility/number.d.ts +0 -17
- package/types/utility/object.d.ts +0 -29
- package/types/utility/string.d.ts +0 -26
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Arr, For, Mix, Obj } from "../index.esm.js";
|
|
2
|
+
import { PicoFormat } from "../utils/Format.js";
|
|
3
|
+
|
|
4
|
+
export const OPTION_REGEX = {
|
|
5
|
+
entry: /(^|;)(\s*(?<key>.*?)\s*:\s*(?<val>".*?"|'.*?'|.*?)\s*)(?=;|$)/g
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @memberof PicoFormat
|
|
10
|
+
*/
|
|
11
|
+
export class PicoFormatOptionStatic
|
|
12
|
+
{
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Cast object to options string
|
|
16
|
+
*
|
|
17
|
+
* @example Format.castOptions({ a: 1 }) // => "a: 1;"
|
|
18
|
+
*
|
|
19
|
+
* @param {any} [options] Input options
|
|
20
|
+
* @param {boolean} [space] Add space
|
|
21
|
+
* @returns {string} Options string
|
|
22
|
+
*/
|
|
23
|
+
static castOptions(options = {}, space = true)
|
|
24
|
+
{
|
|
25
|
+
if ( Mix.isEmpty(options) ) {
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let result = Arr.each(options, (val, key) => {
|
|
30
|
+
return this.castOption(key, val, null, space);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return result.join(';') + ';';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Cast single option to string
|
|
38
|
+
*
|
|
39
|
+
* @example Format.castOption("a", 1) // => "a: 1"
|
|
40
|
+
*
|
|
41
|
+
* @param {string} key Option key
|
|
42
|
+
* @param {any} value Option value
|
|
43
|
+
* @param {string} [path] Key path
|
|
44
|
+
* @param {boolean} [space] Add space
|
|
45
|
+
* @returns {string} Option string
|
|
46
|
+
*/
|
|
47
|
+
static castOption(key, value, path = null, space = true)
|
|
48
|
+
{
|
|
49
|
+
if ( path != null ) {
|
|
50
|
+
key = path + '.' + key;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let div = space ? ': ' : ':';
|
|
54
|
+
|
|
55
|
+
if ( !Mix.isObj(value) ) {
|
|
56
|
+
return Mix.str(key) + div + For.casted(value, false);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let result = Arr.map(value, (v, k) => {
|
|
60
|
+
return this.castOption(k, v, key);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return result.join(';');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Parse options string
|
|
68
|
+
*
|
|
69
|
+
* @example Format.parseOptions("a: 1;") // => { a: 1 }
|
|
70
|
+
*
|
|
71
|
+
* @param {string} value Options string
|
|
72
|
+
* @returns {any} Options object
|
|
73
|
+
*/
|
|
74
|
+
static parseOptions(value)
|
|
75
|
+
{
|
|
76
|
+
if ( Mix.isEmpty(value) ) {
|
|
77
|
+
return {};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
let matches = value.matchAll(...[
|
|
81
|
+
OPTION_REGEX.entry
|
|
82
|
+
]);
|
|
83
|
+
|
|
84
|
+
if ( matches == null ) {
|
|
85
|
+
return {};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const [key, val] = [
|
|
89
|
+
For.keyed, For.parsed
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
return Arr.reduce(Array.from(matches), (result, { groups }) => {
|
|
93
|
+
return Obj.set(result, key(groups.key), val(groups.val));
|
|
94
|
+
}, {});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @param {typeof PicoFormat} self
|
|
101
|
+
* @returns {typeof PicoFormat}
|
|
102
|
+
*/
|
|
103
|
+
export const PicoFormatOptionPlugin = function (self) {
|
|
104
|
+
|
|
105
|
+
Obj.each(Mix.class(PicoFormatOptionStatic), (fn, id) => {
|
|
106
|
+
self[id] = fn;
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return self;
|
|
110
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Arr, Mix, Obj, For } from "../index.esm.js";
|
|
2
|
+
import { PicoFormat } from "../utils/Format.js";
|
|
3
|
+
|
|
4
|
+
export const PARAM_REGEX = {
|
|
5
|
+
entry: /(?<=^|&|\?)(\s*(?<key>.*?)\s*=\s*(?<val>".*?"|'.*?'|.*?)\s*)(?=&|$)/g
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @memberof PicoFormat
|
|
10
|
+
* @extends {PicoFormat}
|
|
11
|
+
*/
|
|
12
|
+
export class PicoFormatParamStatic
|
|
13
|
+
{
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Cast object to params string
|
|
17
|
+
*
|
|
18
|
+
* @example Format.castParams({ a: 1 }) // => "a=1"
|
|
19
|
+
*
|
|
20
|
+
* @param {any} [params] Input params
|
|
21
|
+
* @returns {string} Params string
|
|
22
|
+
*/
|
|
23
|
+
static castParams(params = {})
|
|
24
|
+
{
|
|
25
|
+
if ( Mix.isEmpty(params) ) {
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let result = Arr.each(params, (val, key) => {
|
|
30
|
+
return this.castParam(key, val);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return result.join('&');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Cast single param to string
|
|
38
|
+
*
|
|
39
|
+
* @example Format.castParam("a", 1) // => "a=1"
|
|
40
|
+
*
|
|
41
|
+
* @param {string} key Param key
|
|
42
|
+
* @param {any} value Param value
|
|
43
|
+
* @param {string} [path] Key path
|
|
44
|
+
* @returns {string} Param string
|
|
45
|
+
*/
|
|
46
|
+
static castParam(key, value, path = null)
|
|
47
|
+
{
|
|
48
|
+
if ( path != null ) {
|
|
49
|
+
key = path + '[' + key + ']';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if ( !Mix.isRef(value) ) {
|
|
53
|
+
return Mix.str(key) + '=' + For.casted(value, true);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let result = Arr.each(value, (v, k) => {
|
|
57
|
+
return this.castParam(Mix.isArr(value) ? '' : k, v, key);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return result.join('&');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Parse params string
|
|
65
|
+
*
|
|
66
|
+
* @example Format.parseParams("a=1") // => { a: 1 }
|
|
67
|
+
*
|
|
68
|
+
* @param {string} value Params string
|
|
69
|
+
* @returns {any} Params object
|
|
70
|
+
*/
|
|
71
|
+
static parseParams(value)
|
|
72
|
+
{
|
|
73
|
+
if ( Mix.isEmpty(value) ) {
|
|
74
|
+
return {};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
value = decodeURIComponent(value);
|
|
78
|
+
|
|
79
|
+
let matches = value.matchAll(...[
|
|
80
|
+
PARAM_REGEX.entry
|
|
81
|
+
]);
|
|
82
|
+
|
|
83
|
+
if ( matches == null ) {
|
|
84
|
+
return {};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const [key, val] = [
|
|
88
|
+
For.keyed, For.parsed
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
return Arr.reduce(Array.from(matches), (result, { groups }) => {
|
|
92
|
+
return Obj.set(result, key(groups.key), val(groups.val));
|
|
93
|
+
}, {});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @param {typeof PicoFormat} self
|
|
100
|
+
* @returns {typeof PicoFormat}
|
|
101
|
+
*/
|
|
102
|
+
export const PicoFormatParamPlugin = function (self) {
|
|
103
|
+
|
|
104
|
+
Obj.each(Mix.class(PicoFormatParamStatic), (fn, id) => {
|
|
105
|
+
self[id] = fn;
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return self;
|
|
109
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { Mix, Obj } from "../index.esm.js";
|
|
2
|
+
import { PicoFormat } from "../utils/Format.js";
|
|
3
|
+
|
|
4
|
+
export const TYPE_PARSERS = [
|
|
5
|
+
{ // null
|
|
6
|
+
match: (val) => {
|
|
7
|
+
return /^(null|undefined)$/i.test(val);
|
|
8
|
+
},
|
|
9
|
+
parse: (val) => {
|
|
10
|
+
return Mix.null(val);
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
{ // boolean
|
|
14
|
+
match: (val) => {
|
|
15
|
+
return /^(true|false|yes|no)$/i.test(val);
|
|
16
|
+
},
|
|
17
|
+
parse: (val) => {
|
|
18
|
+
return Mix.bool(val);
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
{ // integer
|
|
22
|
+
match: (val) => {
|
|
23
|
+
return /^-?[0-9]+$/.test(val);
|
|
24
|
+
},
|
|
25
|
+
parse: (val) => {
|
|
26
|
+
return Mix.int(val);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
{ // number
|
|
30
|
+
match: (val) => {
|
|
31
|
+
return /^-?[0-9]+\.[0-9]+$/.test(val);
|
|
32
|
+
},
|
|
33
|
+
parse: (val) => {
|
|
34
|
+
return Mix.num(val);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
{ // array
|
|
38
|
+
match: (val) => {
|
|
39
|
+
return /^[{\[].*?[}\]]$/.test(val);
|
|
40
|
+
},
|
|
41
|
+
parse: (val) => {
|
|
42
|
+
return JSON.parse(val);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
export const TYPE_CASTERS = [
|
|
48
|
+
{ // array
|
|
49
|
+
match: (val) => {
|
|
50
|
+
return Mix.isArr(val);
|
|
51
|
+
},
|
|
52
|
+
parse: (val) => {
|
|
53
|
+
return JSON.stringify(val);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @memberof PicoFormat
|
|
60
|
+
*/
|
|
61
|
+
export class PicoFormatParserStatic
|
|
62
|
+
{
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Convert key path format
|
|
66
|
+
*
|
|
67
|
+
* @example Format.keyed("a[b]") // => "a.b"
|
|
68
|
+
*
|
|
69
|
+
* @param {any} value Input key
|
|
70
|
+
* @param {any} [fallback] Fallback value
|
|
71
|
+
* @returns {string} Keyed string
|
|
72
|
+
*/
|
|
73
|
+
static keyed(value, fallback = null)
|
|
74
|
+
{
|
|
75
|
+
if ( ! Mix.isStr(value) ) {
|
|
76
|
+
return fallback;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if ( value.indexOf('[') === -1 ) {
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return value.replace(/\[([^\]]+)\]/g, '.$1');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Parse value by type
|
|
88
|
+
*
|
|
89
|
+
* @example Format.parsed("true") // => true
|
|
90
|
+
*
|
|
91
|
+
* @param {any} value Input value
|
|
92
|
+
* @param {any} [fallback] Fallback value
|
|
93
|
+
* @param {Array<any>} [parsers] Custom parsers
|
|
94
|
+
* @returns {any} Parsed value
|
|
95
|
+
*/
|
|
96
|
+
static parsed(value, fallback = null, parsers = [])
|
|
97
|
+
{
|
|
98
|
+
if ( ! Mix.isStr(value) ) {
|
|
99
|
+
return fallback;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
value = value.replace(/(^"|^'|'$|"$)/g, '');
|
|
103
|
+
|
|
104
|
+
for ( let type of parsers ) {
|
|
105
|
+
if ( type.match(value) ) return type.parse(value);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
for ( let type of TYPE_PARSERS ) {
|
|
109
|
+
if ( type.match(value) ) return type.parse(value);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return value;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Cast value to string
|
|
117
|
+
*
|
|
118
|
+
* @example Format.casted(true) // => "true"
|
|
119
|
+
*
|
|
120
|
+
* @param {any} value Input value
|
|
121
|
+
* @param {boolean} [encode] Encode value
|
|
122
|
+
* @param {Array<any>} [casters] Custom casters
|
|
123
|
+
* @returns {string} Casted string
|
|
124
|
+
*/
|
|
125
|
+
static casted(value, encode = false, casters = [])
|
|
126
|
+
{
|
|
127
|
+
if ( encode ) {
|
|
128
|
+
value = encodeURI(value);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if ( Mix.isStr(value) ) {
|
|
132
|
+
return value;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
for ( let type of casters ) {
|
|
136
|
+
if ( type.match(value) ) return type.parse(value);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
for ( let type of TYPE_CASTERS ) {
|
|
140
|
+
if ( type.match(value) ) return type.parse(value);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return Mix.str(value);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @param {typeof PicoFormat} self
|
|
149
|
+
* @returns {typeof PicoFormat}
|
|
150
|
+
*/
|
|
151
|
+
export const PicoFormatParserPlugin = function (self) {
|
|
152
|
+
|
|
153
|
+
Obj.each(Mix.class(PicoFormatParserStatic), (fn, id) => {
|
|
154
|
+
self[id] = fn;
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
return self;
|
|
158
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Arr, Mix, Obj } from "../index.esm.js";
|
|
2
|
+
import { PicoFormat } from "../utils/Format.js";
|
|
3
|
+
|
|
4
|
+
export const SLUG_CONVERT = [
|
|
5
|
+
['à', 'a'],
|
|
6
|
+
['á', 'a'],
|
|
7
|
+
['â', 'a'],
|
|
8
|
+
['è', 'e'],
|
|
9
|
+
['é', 'e'],
|
|
10
|
+
['ê', 'e'],
|
|
11
|
+
['ì', 'i'],
|
|
12
|
+
['í', 'i'],
|
|
13
|
+
['ï', 'i'],
|
|
14
|
+
['î', 'i'],
|
|
15
|
+
['ò', 'o'],
|
|
16
|
+
['ó', 'o'],
|
|
17
|
+
['ô', 'o'],
|
|
18
|
+
['ù', 'u'],
|
|
19
|
+
['ú', 'u'],
|
|
20
|
+
['û', 'u'],
|
|
21
|
+
['ñ', 'n'],
|
|
22
|
+
['ç', 'c'],
|
|
23
|
+
['.', '-'],
|
|
24
|
+
['·', '-'],
|
|
25
|
+
['/', '-'],
|
|
26
|
+
['_', '-'],
|
|
27
|
+
[',', '-'],
|
|
28
|
+
[':', '-'],
|
|
29
|
+
[';', '-'],
|
|
30
|
+
['ä', 'ae'],
|
|
31
|
+
['ö', 'oe'],
|
|
32
|
+
['ü', 'ue'],
|
|
33
|
+
['ß', 'ss'],
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @memberof PicoFormat
|
|
38
|
+
* @extends {PicoFormat}
|
|
39
|
+
*/
|
|
40
|
+
export class PicoFormatUrlStatic
|
|
41
|
+
{
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Create slug from string
|
|
45
|
+
*
|
|
46
|
+
* @example Format.slugify("Hello World") // => "hello-world"
|
|
47
|
+
*
|
|
48
|
+
* @param {any} value Input string
|
|
49
|
+
* @returns {string} Slug string
|
|
50
|
+
*/
|
|
51
|
+
static slugify(value)
|
|
52
|
+
{
|
|
53
|
+
value = String(value).replace(/(^\s+|\s+$)/g, '')
|
|
54
|
+
.toLowerCase();
|
|
55
|
+
|
|
56
|
+
Arr.each(SLUG_CONVERT, (v) => {
|
|
57
|
+
value = value.replaceAll(v[0], v[1]);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return value.replace(/[^a-z0-9-\s]+/g, '')
|
|
61
|
+
.replace(/\s+/g, '-').replace(/-+/g, '-');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @param {typeof PicoFormat} self
|
|
68
|
+
* @returns {typeof PicoFormat}
|
|
69
|
+
*/
|
|
70
|
+
export const PicoFormatUrlPlugin = function (self) {
|
|
71
|
+
|
|
72
|
+
Obj.each(Mix.class(PicoFormatUrlStatic), (fn, id) => {
|
|
73
|
+
self[id] = fn;
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return self;
|
|
77
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as pi from "./index.esm.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {Object} PicoLibrary
|
|
5
|
+
* @property {function(): *} [go]
|
|
6
|
+
* @property {function(): void} [browser]
|
|
7
|
+
* @property {function(): void} [device]
|
|
8
|
+
* @property {PicoMixed} [Any]
|
|
9
|
+
* @property {PicoArray} [Arr]
|
|
10
|
+
* @property {PicoDom} [Dom]
|
|
11
|
+
* @property {PicoFormat} [For]
|
|
12
|
+
* @property {PicoMap} [Map]
|
|
13
|
+
* @property {PicoMixed} [Mix]
|
|
14
|
+
* @property {PicoNow} [Now]
|
|
15
|
+
* @property {PicoNumber} [Num]
|
|
16
|
+
* @property {PicoObject} [Obj]
|
|
17
|
+
* @property {PicoRunner} [Run]
|
|
18
|
+
* @property {PicoString} [Str]
|
|
19
|
+
* @property {PicoHash} [Hash]
|
|
20
|
+
* @property {PicoEvent} [Event]
|
|
21
|
+
* @property {PicoLocale} [Locale]
|
|
22
|
+
* @property {PicoCookie} [Cookie]
|
|
23
|
+
* @property {PicoData} [Data]
|
|
24
|
+
* @property {PicoRoute} [Route]
|
|
25
|
+
* @property {PicoElement} [Element]
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @type {PicoLibrary}
|
|
30
|
+
*/
|
|
31
|
+
globalThis.pi = pi;
|
package/src/index.esm.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { default as PicoRunner } from "./utils/Runner.js";
|
|
2
|
+
import { default as PicoString } from "./utils/String.js";
|
|
3
|
+
import { default as PicoNumber } from "./utils/Number.js";
|
|
4
|
+
import { default as PicoArray } from "./utils/Array.js";
|
|
5
|
+
import { default as PicoObject } from "./utils/Object.js";
|
|
6
|
+
import { default as PicoMixed } from "./utils/Mixed.js";
|
|
7
|
+
import { default as PicoHash } from "./utils/Hash.js";
|
|
8
|
+
import { default as PicoEvent } from "./utils/Event.js";
|
|
9
|
+
import { default as PicoLocale } from "./utils/Locale.js";
|
|
10
|
+
import { default as PicoCookie } from "./utils/Cookie.js";
|
|
11
|
+
import { PicoDom, default as DomBuilder } from "./utils/Dom.js";
|
|
12
|
+
import { PicoNow, default as NowBuilder } from "./utils/Now.js";
|
|
13
|
+
import { PicoFormat, default as ForBuilder } from "./utils/Format.js";
|
|
14
|
+
|
|
15
|
+
import { go, browser, device } from "./tool/scope.js";
|
|
16
|
+
export { go, browser, device };
|
|
17
|
+
|
|
18
|
+
// You will be removed soon
|
|
19
|
+
import { default as Data } from "./utils/Data.js";
|
|
20
|
+
import { default as Route } from "./utils/Route.js";
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
Map, Data
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Work in progress (not started yet)
|
|
27
|
+
import { default as Map } from "./wip/Map.js";
|
|
28
|
+
import { default as Element } from "./wip/Element.js";
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
Route, Element
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @type {typeof PicoDom}
|
|
36
|
+
*/
|
|
37
|
+
export const Dom = DomBuilder();
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @type {typeof PicoNow}
|
|
41
|
+
*/
|
|
42
|
+
export const Now = NowBuilder();
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @type {typeof PicoFormat}
|
|
46
|
+
*/
|
|
47
|
+
export const For = ForBuilder();
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @type {typeof PicoRunner}
|
|
51
|
+
*/
|
|
52
|
+
export const Run = PicoRunner;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @type {typeof PicoString}
|
|
56
|
+
*/
|
|
57
|
+
export const Str = PicoString;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @type {typeof PicoNumber}
|
|
61
|
+
*/
|
|
62
|
+
export const Num = PicoNumber;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @type {typeof PicoArray}
|
|
66
|
+
*/
|
|
67
|
+
export const Arr = PicoArray;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @type {typeof PicoObject}
|
|
71
|
+
*/
|
|
72
|
+
export const Obj = PicoObject;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @type {typeof PicoMixed}
|
|
76
|
+
*/
|
|
77
|
+
export const Mix = PicoMixed;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @type {typeof PicoHash}
|
|
81
|
+
*/
|
|
82
|
+
export const Hash = PicoHash;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @type {typeof PicoEvent}
|
|
86
|
+
*/
|
|
87
|
+
export const Event = PicoEvent;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @type {typeof PicoLocale}
|
|
91
|
+
*/
|
|
92
|
+
export const Locale = PicoLocale;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @type {typeof PicoCookie}
|
|
96
|
+
*/
|
|
97
|
+
export const Cookie = PicoCookie;
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @type {typeof PicoMixed}
|
|
102
|
+
*/
|
|
103
|
+
export const Any = new Proxy({}, {
|
|
104
|
+
get: function (target, prop) {
|
|
105
|
+
console.warn(`Any.${prop} is deprecated, use Mix.${prop}() instead.`);
|
|
106
|
+
return (...args) => Mix[prop](...args);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @returns {string}
|
|
112
|
+
*/
|
|
113
|
+
export const UUID = function () {
|
|
114
|
+
console.warn('UUID() is deprecated, use Hash.make() instead.');
|
|
115
|
+
return PicoHash.make();
|
|
116
|
+
};
|