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