dphelper 0.2.30 → 0.2.34
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/data/list.json +19 -39
- package/init.js +19 -5
- package/package.json +5 -7
- package/scripts/anchorToOnClick.js +15 -3
- package/scripts/array.js +29 -3
- package/scripts/console.js +86 -0
- package/scripts/cookie.js +97 -71
- package/scripts/currency.js +31 -11
- package/scripts/date.js +101 -0
- package/scripts/disable.js +90 -0
- package/scripts/event.js +39 -0
- package/scripts/font.js +52 -0
- package/scripts/form.js +113 -0
- package/scripts/indexedDB.js +47 -10
- package/scripts/json.js +42 -0
- package/scripts/load.js +70 -0
- package/scripts/noCache.js +26 -14
- package/scripts/number.js +42 -0
- package/scripts/obj.js +81 -0
- package/scripts/onBeforeUnLoad.js +120 -108
- package/scripts/parseBool.js +27 -15
- package/scripts/path.js +94 -0
- package/scripts/promise.js +35 -0
- package/scripts/purge.js +53 -41
- package/scripts/pushState.js +33 -14
- package/scripts/screen.js +64 -0
- package/scripts/scrollbar.js +226 -0
- package/scripts/{handleEvent.js → shortcut.js} +70 -59
- package/scripts/storage.js +29 -3
- package/scripts/svg.js +372 -0
- package/scripts/text.js +78 -0
- package/scripts/time.js +41 -0
- package/scripts/timer.js +35 -0
- package/scripts/trigger.js +37 -0
- package/scripts/uuid.js +33 -14
- package/scripts/window.js +50 -38
- package/#cmd.exe.lnk +0 -0
- package/.github/workflows/codeql-analysis.yml +0 -70
- package/scripts/.OLD/arrayDeleteItem.js +0 -35
- package/scripts/.OLD/arrayItemFinder.js +0 -22
- package/scripts/.OLD/arrayMerge.js +0 -20
- package/scripts/.OLD/arrayUnique.js +0 -15
- package/scripts/.OLD/loadAsset.js +0 -26
- package/scripts/addListenerMulti.js +0 -10
- package/scripts/camelCase.js +0 -29
- package/scripts/date2Iso.js +0 -20
- package/scripts/date2MMDDYYYY.js +0 -16
- package/scripts/dateConvert.js +0 -20
- package/scripts/dateIso2Epoch.js +0 -17
- package/scripts/dateLocal-ISOTime.js +0 -17
- package/scripts/dateUTC.js +0 -14
- package/scripts/disableSelect.js +0 -46
- package/scripts/disableSpellCheck.js +0 -21
- package/scripts/epoch.js +0 -14
- package/scripts/fontFit.js +0 -24
- package/scripts/fullScreen.js +0 -40
- package/scripts/isPromise.js +0 -14
- package/scripts/jsonCounter.js +0 -21
- package/scripts/loadFile.js +0 -17
- package/scripts/loadJson.js +0 -15
- package/scripts/loadJsonExternal.js +0 -32
- package/scripts/nl2br.js +0 -14
- package/scripts/object2array.js +0 -16
- package/scripts/parseDate.js +0 -19
- package/scripts/pathHash.js +0 -19
- package/scripts/pathQuery.js +0 -24
- package/scripts/pathRail.js +0 -25
- package/scripts/printInfo.js +0 -16
- package/scripts/randomNum.js +0 -14
- package/scripts/randomNumTmr.js +0 -14
- package/scripts/scrollCustom.js +0 -41
- package/scripts/scrollIndicator.js +0 -67
- package/scripts/scrollMemory.js +0 -26
- package/scripts/scrollSmooth.js +0 -74
- package/scripts/scrollToElement.js +0 -25
- package/scripts/serializeForm.js +0 -94
- package/scripts/serializeObj.js +0 -47
- package/scripts/sleep.js +0 -14
- package/scripts/stopConsole.js +0 -49
- package/scripts/svgSupport.js +0 -346
- package/scripts/textChanger.js +0 -24
- package/scripts/triggerClick.js +0 -16
package/data/list.json
CHANGED
|
@@ -1,39 +1,19 @@
|
|
|
1
|
-
{
|
|
2
|
-
"info" : {
|
|
3
|
-
"title" : "List",
|
|
4
|
-
"description" : "Complete list of tools"
|
|
5
|
-
},
|
|
6
|
-
"categories" : [
|
|
7
|
-
"3dparty",
|
|
8
|
-
"system",
|
|
9
|
-
"financial",
|
|
10
|
-
"memory",
|
|
11
|
-
"numbers",
|
|
12
|
-
"time",
|
|
13
|
-
"path",
|
|
14
|
-
"file",
|
|
15
|
-
"forms",
|
|
16
|
-
"ui",
|
|
17
|
-
"other"
|
|
18
|
-
]
|
|
19
|
-
|
|
20
|
-
{
|
|
21
|
-
"name" : "Anchors to onClick",
|
|
22
|
-
"description" : "Transform all anchor inside specific elements in to onClick (DOM)\r\n<br/>\r\n<br/>\r\n\r\nUsage: <br/>\r\n<br/>\r\n\r\n<code>\r\ndphelper.anchorToOnClick( \"your element(s)\" )\r\n</code>\r\n\r\n<br/>\r\n<br/>\r\nAutomatically all anchors became onClick. Use it at end off page or defer or after DOMs loaded \r\n\r\n",
|
|
23
|
-
"version" : "0.0.1",
|
|
24
|
-
"command" : "anchorToOnClick",
|
|
25
|
-
"example" : "dphelper.anchorToOnClick(\"nav\") --> now all nav anchor are onClick ( href is removed )",
|
|
26
|
-
"author" : "Dario Passariello",
|
|
27
|
-
"active" : true
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
"name" : "Arrays Tools",
|
|
31
|
-
"description" : "Useful way to andle array without efforts\r\n<br/>\r\n\r\n\r\n",
|
|
32
|
-
"version" : "0.0.1",
|
|
33
|
-
"command" : "array",
|
|
34
|
-
"example" : "// FIND\r\ndphelper.array.find( 12345 , YourArray ) --> search your data\r\n\r\n// UNIQUE\r\ndphelper.array.unique( YourArray ) --> remove duplicates\r\n\r\n// DELETE\r\ndphelper.array.delete( 12345 , YourArray ) --> remove a sub-data using id\r\n\r\n// MERGE\r\ndphelper.array.merge( YourArray1 , YourArray2 ) --> result is YourArray3 ",
|
|
35
|
-
"author" : "Dario Passariello",
|
|
36
|
-
"active" : true
|
|
37
|
-
}
|
|
38
|
-
]
|
|
39
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"info" : {
|
|
3
|
+
"title" : "List",
|
|
4
|
+
"description" : "Complete list of tools"
|
|
5
|
+
},
|
|
6
|
+
"categories" : [
|
|
7
|
+
"3dparty",
|
|
8
|
+
"system",
|
|
9
|
+
"financial",
|
|
10
|
+
"memory",
|
|
11
|
+
"numbers",
|
|
12
|
+
"time",
|
|
13
|
+
"path",
|
|
14
|
+
"file",
|
|
15
|
+
"forms",
|
|
16
|
+
"ui",
|
|
17
|
+
"other"
|
|
18
|
+
]
|
|
19
|
+
}
|
package/init.js
CHANGED
|
@@ -17,9 +17,23 @@
|
|
|
17
17
|
|
|
18
18
|
// CREATE ROOT STORE
|
|
19
19
|
const dphelper = window.dphelper = {};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
|
|
21
|
+
window.dphelper._list = require('./data/list.json');
|
|
22
|
+
window.dphelper._list.scripts = [];
|
|
23
|
+
window.dphelper._list.version = pjson.version;
|
|
24
|
+
|
|
25
|
+
const cache = {};
|
|
26
|
+
|
|
27
|
+
function importAll(r){
|
|
28
|
+
r.keys().forEach(
|
|
29
|
+
(key) => (
|
|
30
|
+
cache[key] = r(key)
|
|
31
|
+
)
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
importAll( require.context( __dirname + '/scripts/', false, /\.js$/) );
|
|
36
|
+
|
|
23
37
|
|
|
24
38
|
// FIRST MESSAGE
|
|
25
39
|
console.groupCollapsed( `%c${pjson.name} v${pjson.version}%c`,"color:orange","" );
|
|
@@ -35,8 +49,7 @@
|
|
|
35
49
|
console.debug( 'email: %c' + pjson.author.email,"color:orange","" );
|
|
36
50
|
console.groupEnd();
|
|
37
51
|
|
|
38
|
-
|
|
39
|
-
|
|
52
|
+
/*
|
|
40
53
|
// SYSTEM
|
|
41
54
|
require('./scripts/addListenerMulti.js');
|
|
42
55
|
|
|
@@ -118,5 +131,6 @@
|
|
|
118
131
|
require('./scripts/svgSupport.js');
|
|
119
132
|
require('./scripts/stopConsole.js');
|
|
120
133
|
require('./scripts/onBeforeUnLoad.js');
|
|
134
|
+
*/
|
|
121
135
|
|
|
122
136
|
})();
|
package/package.json
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dphelper",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.34",
|
|
4
4
|
"description": "Developer Tools",
|
|
5
|
-
|
|
6
5
|
"main": "index.js",
|
|
7
6
|
"publishConfig": {},
|
|
8
|
-
|
|
9
7
|
"targets": {
|
|
10
8
|
"main": {
|
|
11
9
|
"includeNodeModules": {
|
|
@@ -26,12 +24,12 @@
|
|
|
26
24
|
},
|
|
27
25
|
"funding": [
|
|
28
26
|
{
|
|
29
|
-
"type"
|
|
30
|
-
"url"
|
|
27
|
+
"type": "individual",
|
|
28
|
+
"url": "https://www.paypal.com/donate/?business=HC7LJ2ZXRRNDL&no_recurring=0&item_name=I+am+a+software+developer.+Just+a+donation+can+help+me+to+have+more+time+to+dedicate+on+this+project¤cy_code=CAD"
|
|
31
29
|
},
|
|
32
30
|
{
|
|
33
|
-
"type"
|
|
34
|
-
"url"
|
|
31
|
+
"type": "patreon",
|
|
32
|
+
"url": "https://www.patreon.com/passariello"
|
|
35
33
|
}
|
|
36
34
|
],
|
|
37
35
|
"eslintConfig": {
|
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* dpHelper <https://github.com/passariello/dpHelper>
|
|
3
|
-
*
|
|
4
|
-
* anchorToOnClick
|
|
5
|
-
*
|
|
6
3
|
* Copyright (c) 2021, Dario Passariello.
|
|
7
4
|
* Licensed under the Apache-2.0 License.
|
|
8
5
|
*/
|
|
9
6
|
|
|
7
|
+
/***********************************************************************/
|
|
8
|
+
|
|
9
|
+
var description = {
|
|
10
|
+
"name" : "Anchor To OnClick",
|
|
11
|
+
"description" : "test",
|
|
12
|
+
"version" : "0.0.1",
|
|
13
|
+
"command" : "anchorToOnClick",
|
|
14
|
+
"subCommand" : [],
|
|
15
|
+
"example" : "",
|
|
16
|
+
"author" : "Dario Passariello",
|
|
17
|
+
"active" : true
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
window.dphelper._list.scripts.push( description );
|
|
21
|
+
|
|
10
22
|
/***********************************************************************/
|
|
11
23
|
|
|
12
24
|
window.dphelper.anchorToOnClick = function( container ){
|
package/scripts/array.js
CHANGED
|
@@ -1,12 +1,38 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* dpHelper <https://github.com/passariello/dpHelper>
|
|
3
|
-
*
|
|
4
|
-
* arrayDeleteItem
|
|
5
|
-
*
|
|
6
3
|
* Copyright (c) 2021, Dario Passariello.
|
|
7
4
|
* Licensed under the Apache-2.0 License.
|
|
8
5
|
*/
|
|
9
6
|
|
|
7
|
+
/***********************************************************************/
|
|
8
|
+
|
|
9
|
+
var description = {
|
|
10
|
+
"name" : "Arrays",
|
|
11
|
+
"description" : "test",
|
|
12
|
+
"version" : "0.0.1",
|
|
13
|
+
"command" : "array",
|
|
14
|
+
"subCommand" : [
|
|
15
|
+
{
|
|
16
|
+
"name":"find",
|
|
17
|
+
"description":"test"
|
|
18
|
+
},{
|
|
19
|
+
"name":"unique",
|
|
20
|
+
"description":"test"
|
|
21
|
+
},{
|
|
22
|
+
"name":"delete",
|
|
23
|
+
"description":"test"
|
|
24
|
+
},{
|
|
25
|
+
"name":"merge",
|
|
26
|
+
"description":"test"
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"example" : "",
|
|
30
|
+
"author" : "Dario Passariello",
|
|
31
|
+
"active" : true
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
window.dphelper._list.scripts.push( description );
|
|
35
|
+
|
|
10
36
|
/***********************************************************************/
|
|
11
37
|
|
|
12
38
|
window.dphelper.array = {
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* dpHelper <https://github.com/passariello/dpHelper>
|
|
3
|
+
* Copyright (c) 2021, Dario Passariello.
|
|
4
|
+
* Licensed under the Apache-2.0 License.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/***********************************************************************/
|
|
8
|
+
|
|
9
|
+
var description = {
|
|
10
|
+
"name" : "Console",
|
|
11
|
+
"description" : "test",
|
|
12
|
+
"version" : "0.0.1",
|
|
13
|
+
"command" : "console",
|
|
14
|
+
"subCommand" : [
|
|
15
|
+
{
|
|
16
|
+
"name":"info",
|
|
17
|
+
"description":"test"
|
|
18
|
+
},{
|
|
19
|
+
"name":"stop",
|
|
20
|
+
"description":"test"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"example" : "",
|
|
24
|
+
"author" : "Dario Passariello",
|
|
25
|
+
"active" : true
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
window.dphelper._list.scripts.push( description );
|
|
29
|
+
|
|
30
|
+
/***********************************************************************/
|
|
31
|
+
|
|
32
|
+
window.dphelper.printInfo = () => {
|
|
33
|
+
console.debug( 'dpHelper: Please use "dphelper.path.rail()"' );
|
|
34
|
+
return window.dphelper.console.info();
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/***********************************************************************/
|
|
38
|
+
|
|
39
|
+
window.dphelper.console = {
|
|
40
|
+
|
|
41
|
+
info: () => {
|
|
42
|
+
console.groupCollapsed('%cApi:%c', "color:orange", "");
|
|
43
|
+
console.debug(dphelper.api);
|
|
44
|
+
console.groupEnd();
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
stop: () => {
|
|
48
|
+
|
|
49
|
+
let console = {};
|
|
50
|
+
console.log = function(){};
|
|
51
|
+
window.console = console;
|
|
52
|
+
if(!window.console) window.console = {};
|
|
53
|
+
|
|
54
|
+
const noop = () => {}
|
|
55
|
+
[
|
|
56
|
+
'assert',
|
|
57
|
+
'clear',
|
|
58
|
+
'count',
|
|
59
|
+
'debug',
|
|
60
|
+
'dir',
|
|
61
|
+
'dirxml',
|
|
62
|
+
'error',
|
|
63
|
+
'exception',
|
|
64
|
+
'group',
|
|
65
|
+
'groupCollapsed',
|
|
66
|
+
'groupEnd',
|
|
67
|
+
'info',
|
|
68
|
+
'log',
|
|
69
|
+
'markTimeline',
|
|
70
|
+
'profile',
|
|
71
|
+
'profileEnd',
|
|
72
|
+
'table',
|
|
73
|
+
'time',
|
|
74
|
+
'timeEnd',
|
|
75
|
+
'timeline',
|
|
76
|
+
'timelineEnd',
|
|
77
|
+
'timeStamp',
|
|
78
|
+
'trace',
|
|
79
|
+
'warn'
|
|
80
|
+
].forEach((method) => {
|
|
81
|
+
window.console[method] = noop;
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
};
|
package/scripts/cookie.js
CHANGED
|
@@ -1,71 +1,97 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* dpHelper <https://github.com/passariello/dpHelper>
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
1
|
+
/*!
|
|
2
|
+
* dpHelper <https://github.com/passariello/dpHelper>
|
|
3
|
+
* Copyright (c) 2021, Dario Passariello.
|
|
4
|
+
* Licensed under the Apache-2.0 License.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/***********************************************************************/
|
|
8
|
+
|
|
9
|
+
var description = {
|
|
10
|
+
"name" : "Cookie Manager",
|
|
11
|
+
"description" : "test",
|
|
12
|
+
"version" : "0.0.1",
|
|
13
|
+
"command" : "cookie",
|
|
14
|
+
"subCommand" : [
|
|
15
|
+
{
|
|
16
|
+
"name":"set",
|
|
17
|
+
"description":"test"
|
|
18
|
+
},{
|
|
19
|
+
"name":"get",
|
|
20
|
+
"description":"test"
|
|
21
|
+
},{
|
|
22
|
+
"name":"delete",
|
|
23
|
+
"description":"test"
|
|
24
|
+
},{
|
|
25
|
+
"name":"clearAll",
|
|
26
|
+
"description":"test"
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"example" : "",
|
|
30
|
+
"author" : "Dario Passariello",
|
|
31
|
+
"active" : true
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
window.dphelper._list.scripts.push( description );
|
|
35
|
+
|
|
36
|
+
/***********************************************************************/
|
|
37
|
+
|
|
38
|
+
var CookieType = "Lax";
|
|
39
|
+
var CookieSecure = "false";
|
|
40
|
+
var CookieSameSite = "false";
|
|
41
|
+
|
|
42
|
+
if (location.protocol === 'https:') {
|
|
43
|
+
CookieSecure = "Secure";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
window.dphelper.cookie = {
|
|
47
|
+
|
|
48
|
+
// CREATE THE COOKIE
|
|
49
|
+
|
|
50
|
+
set: function( cname , value , time , path = '/' ) {
|
|
51
|
+
var d = new Date();
|
|
52
|
+
d.setTime( d.getTime() + 3600 * 1000 * 24 * 365 );
|
|
53
|
+
|
|
54
|
+
if( !time ) time = d.toGMTString();
|
|
55
|
+
if( cname ){
|
|
56
|
+
document.cookie = cname + '=' + value + ';expires=' + time + ';path=' + path + ';SameSite=' + CookieSameSite + ';requireSSL='+ CookieSecure +';' + CookieSecure;
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
// GET THE COOKIE
|
|
61
|
+
|
|
62
|
+
get: function( cname ) {
|
|
63
|
+
var asCookies = document.cookie.split( "; " );
|
|
64
|
+
|
|
65
|
+
for ( var i = 0; i < asCookies.length; i++ ){
|
|
66
|
+
var asCookie = asCookies[ i ].split( "=" );
|
|
67
|
+
if ( cname === asCookie[0] ) return ( unescape( asCookie[1] ) );
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return null;
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
// DELETE THE COOKIE
|
|
74
|
+
|
|
75
|
+
delete: function( cname ) {
|
|
76
|
+
document.cookie = cname + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/;SameSite=' + CookieSameSite + ';requireSSL='+ CookieSecure +';' + CookieSecure;
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
// CLEAR ALL COOKIE
|
|
80
|
+
|
|
81
|
+
clearAll: function() {
|
|
82
|
+
var cookies = document.cookie.split(";");
|
|
83
|
+
|
|
84
|
+
for ( var i = 0; i < cookies.length; i++ ) {
|
|
85
|
+
|
|
86
|
+
var cookie = cookies[i];
|
|
87
|
+
var eqPos = cookie.indexOf("=");
|
|
88
|
+
var cname = eqPos > -1 ? cookie.slice( 0 , eqPos ) : cookie;
|
|
89
|
+
stpro.cookie.delete( cname );
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// START COOKIE DB
|
|
97
|
+
window.dphelper.cookie.set( "dpHelper", 'active' );
|
package/scripts/currency.js
CHANGED
|
@@ -1,21 +1,41 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* dpHelper <https://github.com/passariello/dpHelper>
|
|
3
|
-
*
|
|
4
|
-
* currency
|
|
5
|
-
*
|
|
6
3
|
* Copyright (c) 2021, Dario Passariello.
|
|
7
4
|
* Licensed under the Apache-2.0 License.
|
|
8
5
|
*/
|
|
9
6
|
|
|
10
7
|
/***********************************************************************/
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
var description = {
|
|
10
|
+
"name" : "Financial & Currency",
|
|
11
|
+
"description" : "test",
|
|
12
|
+
"version" : "0.0.1",
|
|
13
|
+
"command" : "currency",
|
|
14
|
+
"subCommand" : [
|
|
15
|
+
{
|
|
16
|
+
"name":"convert",
|
|
17
|
+
"description":"test"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"example" : "",
|
|
21
|
+
"author" : "Dario Passariello",
|
|
22
|
+
"active" : true
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
window.dphelper._list.scripts.push( description );
|
|
26
|
+
|
|
27
|
+
/***********************************************************************/
|
|
28
|
+
|
|
29
|
+
window.dphelper.currency = {
|
|
30
|
+
|
|
31
|
+
convert: ( val, int = 'en-US', cur = 'USD' ) => {
|
|
32
|
+
if( !val || isNaN( val ) ) val = 0;
|
|
33
|
+
var formatter = new Intl.NumberFormat( int , {
|
|
34
|
+
style: 'currency',
|
|
35
|
+
currency: cur,
|
|
36
|
+
});
|
|
37
|
+
// return ( val ).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')
|
|
38
|
+
return formatter.format( val );
|
|
39
|
+
}
|
|
18
40
|
|
|
19
|
-
// return ( val ).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')
|
|
20
|
-
return formatter.format( val );
|
|
21
41
|
};
|
package/scripts/date.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* dpHelper <https://github.com/passariello/dpHelper>
|
|
3
|
+
* Copyright (c) 2021, Dario Passariello.
|
|
4
|
+
* Licensed under the Apache-2.0 License.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/***********************************************************************/
|
|
8
|
+
|
|
9
|
+
var description = {
|
|
10
|
+
"name" : "Date",
|
|
11
|
+
"description" : "test",
|
|
12
|
+
"version" : "0.0.1",
|
|
13
|
+
"command" : "date",
|
|
14
|
+
"subCommand" : [
|
|
15
|
+
{
|
|
16
|
+
"name":"toIso",
|
|
17
|
+
"description":"test"
|
|
18
|
+
},{
|
|
19
|
+
"name":"toMMDDYYYY",
|
|
20
|
+
"description":"test"
|
|
21
|
+
},{
|
|
22
|
+
"name":"convert",
|
|
23
|
+
"description":"test"
|
|
24
|
+
},{
|
|
25
|
+
"name":"iso2Epoch",
|
|
26
|
+
"description":"test"
|
|
27
|
+
},{
|
|
28
|
+
"name":"localIsoTime",
|
|
29
|
+
"description":"test"
|
|
30
|
+
},{
|
|
31
|
+
"name":"utc",
|
|
32
|
+
"description":"test"
|
|
33
|
+
},{
|
|
34
|
+
"name":"parse",
|
|
35
|
+
"description":"test"
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
"example" : "",
|
|
39
|
+
"author" : "Dario Passariello",
|
|
40
|
+
"active" : true
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
window.dphelper._list.scripts.push( description );
|
|
44
|
+
|
|
45
|
+
/***********************************************************************/
|
|
46
|
+
|
|
47
|
+
window.dphelper.date = {
|
|
48
|
+
|
|
49
|
+
toIso: (value , int = 'en' ) => {
|
|
50
|
+
if (!value) value = '';
|
|
51
|
+
let date = new Date(value);
|
|
52
|
+
if (date == 'Invalid Date') return null; //date = new Date()
|
|
53
|
+
const dateTimeFormat = new Intl.DateTimeFormat( int , {
|
|
54
|
+
year: 'numeric', month: 'long', day: 'numeric',
|
|
55
|
+
});
|
|
56
|
+
return dateTimeFormat.format(date);
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
toMMDDYYYY: (value) => {
|
|
60
|
+
if (!value) value = '';
|
|
61
|
+
let date = new Date(value);
|
|
62
|
+
return ('0' + (date.getMonth() + 1)).slice(-2) + "" + ('0' + date.getDate()).slice(-2) + "" + date.getFullYear();
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
convert: (value , format ) => {
|
|
66
|
+
if( !format) format = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
67
|
+
if (!value) return null;
|
|
68
|
+
let monthNames = format;
|
|
69
|
+
let month = value.substring(0, 2).replace('0', '');
|
|
70
|
+
let day = value.substring(2, 4);
|
|
71
|
+
let year = value.substring(value.length - 4);
|
|
72
|
+
return day + ' ' + monthNames[Number(month) - 1] + ' ' + year;
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
iso2Epoch: (value) => {
|
|
76
|
+
if (!value) value = '';
|
|
77
|
+
let date = new Date(value);
|
|
78
|
+
let milliseconds = date.getTime();
|
|
79
|
+
return milliseconds;
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
localIsoTime: (value) => {
|
|
83
|
+
if (!value) value = '';
|
|
84
|
+
let tzoffset = (new Date(value)).getTimezoneOffset() * 60000;
|
|
85
|
+
let localISOTime = (new Date(Date.now() - tzoffset)).toISOString().slice(0, -1);
|
|
86
|
+
return localISOTime;
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
utc: () => {
|
|
90
|
+
return moment().toISOString();
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
parse: ( value , separator = '/' ) => {
|
|
94
|
+
if (!value) return null;
|
|
95
|
+
let month = value.substring(0, 2);
|
|
96
|
+
let day = value.substring(2, 4);
|
|
97
|
+
let year = value.substring(4, 8);
|
|
98
|
+
return month + separator + day + separator + year;
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
};
|