dphelper 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/.editorconfig +12 -0
  2. package/3party/shortcut.js +224 -0
  3. package/init.js +71 -4
  4. package/package.json +6 -5
  5. package/scripts/anchorToOnClick.js +36 -0
  6. package/scripts/arrayItemFinder.js +22 -0
  7. package/scripts/arrayMerge.js +20 -0
  8. package/scripts/currency.js +21 -0
  9. package/scripts/date2Iso.js +20 -0
  10. package/scripts/date2MMDDYYYY.js +16 -0
  11. package/scripts/dateConvert.js +20 -0
  12. package/scripts/dateIso2Epoch.js +17 -0
  13. package/scripts/dateLocal-ISOTime.js +17 -0
  14. package/scripts/dateUTC.js +14 -0
  15. package/scripts/disableSelect.js +41 -0
  16. package/scripts/disableSpellCheck.js +21 -0
  17. package/scripts/epoch.js +14 -0
  18. package/scripts/fullScreen.js +40 -0
  19. package/scripts/handleEvent.js +59 -0
  20. package/scripts/isPromise.js +14 -0
  21. package/scripts/jsonCounter.js +21 -0
  22. package/scripts/loadAsset.js +26 -0
  23. package/scripts/loadFile.js +17 -0
  24. package/scripts/loadJson.js +15 -0
  25. package/scripts/loadJsonExternal.js +32 -0
  26. package/scripts/nl2br.js +14 -0
  27. package/scripts/noCache.js +14 -0
  28. package/scripts/object2array.js +18 -0
  29. package/scripts/onBeforeUnLoad.js +108 -0
  30. package/scripts/parseBool.js +15 -0
  31. package/scripts/parseDate.js +19 -0
  32. package/scripts/pathHash.js +20 -0
  33. package/scripts/pathQuery.js +24 -0
  34. package/scripts/pathRail.js +26 -0
  35. package/scripts/printInfo.js +16 -0
  36. package/scripts/purge.js +41 -0
  37. package/scripts/pushState.js +14 -0
  38. package/scripts/randomNum.js +14 -0
  39. package/scripts/randomNumTmr.js +14 -0
  40. package/scripts/scrollCustom.js +41 -0
  41. package/scripts/scrollIndicator.js +67 -0
  42. package/scripts/scrollMemory.js +26 -0
  43. package/scripts/scrollSmooth.js +74 -0
  44. package/scripts/scrollToElement.js +25 -0
  45. package/scripts/serializeForm.js +92 -0
  46. package/scripts/serializeObj.js +47 -0
  47. package/scripts/sleep.js +14 -0
  48. package/scripts/stopConsole.js +49 -0
  49. package/scripts/svgSupport.js +346 -0
  50. package/scripts/textChanger.js +24 -0
  51. package/scripts/triggerClick.js +16 -0
  52. package/scripts/uuid.js +14 -0
  53. package/scripts/window.js +38 -0
@@ -0,0 +1,59 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * handleEvent
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.handleEvent = ( e, trigger ) => {
13
+ const code = e.which ? e.which : e.keyCode;
14
+
15
+ if( !trigger ) trigger = {
16
+ // EXAMPLES:
17
+ "data" : [
18
+ {
19
+ "key" : "83",
20
+ "ctrl" : true,
21
+ "active" : true,
22
+ "description" : "CTRL+S",
23
+ //"element" : "#formSave",
24
+ "function" : ""
25
+ },
26
+ {
27
+ "key" : "27",
28
+ "ctrl" : false,
29
+ "active" : true,
30
+ "description" : "ESC",
31
+ "element" : "",
32
+ "function" : ""
33
+ },
34
+ {
35
+ "key" : "80",
36
+ "ctrl" : true,
37
+ "active" : true,
38
+ "description" : "CTRL+P",
39
+ "element" : "",
40
+ //"function" : "function(){ Print }"
41
+ }
42
+ ]
43
+ };
44
+
45
+ trigger.map( list => {
46
+
47
+ // IF CTRL COMMAND
48
+ if ( e.ctrlKey || e.metaKey && list.ctrl === true ) {
49
+ if( code === parseInt(list.key) && list.active === true ){
50
+ if( list.element > '' ) simulateClick( list.element );
51
+ if( list.function > '' ) list.function;
52
+ e.preventDefault();
53
+ return;
54
+ }
55
+ }
56
+
57
+ });
58
+
59
+ };
@@ -0,0 +1,14 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * isPromise
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.isPromise = (p) => {
13
+ return p && Object.prototype.toString.call(p) === "[object Promise]";
14
+ };
@@ -0,0 +1,21 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * jsonCounter
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.jsonCounter = (json, key, val) => {
13
+ if (!json) return null;
14
+ let keyCount;
15
+ if (key && val) {
16
+ keyCount = Object.keys(jsonObject).length;
17
+ } else {
18
+ keyCount = json.items.filter(value => value.key === val).lengt;
19
+ }
20
+ return keyCount;
21
+ };
@@ -0,0 +1,26 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * loadAsset
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.loadAsset = function( folder, img, path = '/assets/images/'){
13
+
14
+ const check = /\.(ttf|eot|svg|gif|png)(\?v=[0-9]\.[0-9]\.[0-9])?$/;
15
+
16
+ const asset = require.context( path , true, /\.(ttf|eot|svg|gif|png)(\?v=[0-9]\.[0-9]\.[0-9])?$/ );
17
+ let dynamicLoad = null;
18
+ dynamicLoad = asset(`./${img}`);
19
+
20
+ if( dynamicLoad !== null ){
21
+ return dynamicLoad.default;
22
+ }else{
23
+ console.error(e, folder +" "+ img + ' error' );
24
+ }
25
+
26
+ };
@@ -0,0 +1,17 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * loadFile
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.loadFile = (element, path) => {
13
+ fetch(path).then(async function (response) {
14
+ const text = await response.text();
15
+ document.querySelector( element ).innerHTML = dphelper.nl2br( String(text) );
16
+ });
17
+ };
@@ -0,0 +1,15 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * loadJson
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.loadJson = function( file ){
13
+ if ( file.match(/.(json)$/i ) ) return require( '' + file + '' );
14
+ };
15
+
@@ -0,0 +1,32 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * loadJsonExternal
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.loadJsonExternal = ( path, method='GET', type='application/json' ) => {
13
+
14
+ fetch( path ,{
15
+ method: method,
16
+ headers : {
17
+ 'Content-Type': type
18
+ }
19
+ })
20
+ .then(
21
+ function(response) {
22
+ //return response.json();
23
+ return response;
24
+ }
25
+ )
26
+ .then(
27
+ function( myFile ) {
28
+ return myFile;
29
+ }
30
+ );
31
+
32
+ };
@@ -0,0 +1,14 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * nl2br
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.nl2br = (str) => {
13
+ return str.replace(/(?:\r\n|\r|\n)/g, '<br>');
14
+ };
@@ -0,0 +1,14 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * no cache
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.noCache = (uri) => {
13
+ return uri.concat( /\?/.test(uri) ? '&' : '?', 't=', dphelper.rnd() );
14
+ };
@@ -0,0 +1,18 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * object2array
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.object2array = (object) => {
13
+ return Object
14
+ .entries(object)
15
+ .map(([key, value]) => Object.assign({key}, value && typeof value === 'object' ? {forms: ObjToArray(value)}
16
+ : {value, forms: []}
17
+ ));
18
+ };
@@ -0,0 +1,108 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * onBeforeUnLoad
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.onBeforeUnLoad = () => {
13
+
14
+ let is_dirty = false;
15
+ let answer = null;
16
+ let mex = "You have made some changes which you might want to save.";
17
+ let loadOnce = false;
18
+ let save_button = document.querySelector("#save_button");
19
+
20
+ const beforeUnloadListener = ( event ) => {
21
+ event.preventDefault();
22
+ return mex;
23
+ };
24
+
25
+ const nameInput = document.querySelector("#name");
26
+
27
+ if( nameInput ){
28
+ nameInput.addEventListener( "input" , (event) => {
29
+ if (event.target.value !== "") {
30
+ addEventListener("beforeunload", beforeUnloadListener, { capture: true });
31
+ } else {
32
+ removeEventListener("beforeunload", beforeUnloadListener, { capture: true });
33
+ }
34
+ });
35
+ }
36
+
37
+ /****************************************************************************** */
38
+
39
+ let handleEvent = function( event ){
40
+
41
+ if( event.target.type === 'textarea' || event.target.type === 'input' ){
42
+ if( is_dirty === false ){
43
+ return is_dirty = true;
44
+ }
45
+ }
46
+
47
+ };
48
+
49
+ /****************************************************************************** */
50
+
51
+ let TEST = function (){
52
+ // CHANGE ON KEY
53
+ document.body.addEventListener( "keyup" , handleEvent );
54
+ }();
55
+
56
+ /****************************************************************************** */
57
+
58
+ // CHANGE ON ASIDE CLICK
59
+ if( loadOnce === false ){
60
+ document.body.addEventListener( "click" , function( event ){
61
+
62
+ if( event.target.tagName === 'IMG'){
63
+
64
+ if( is_dirty === true ) {
65
+
66
+ // if the user navigates away from this page via an anchor link,
67
+ // popup a new boxy confirmation.
68
+ answer = confirm( mex );
69
+ if ( answer === true ) {
70
+ return is_dirty = false;
71
+ }else{
72
+ event.preventDefault();
73
+ }
74
+ }
75
+ }
76
+
77
+ });
78
+ loadOnce = true;
79
+ }
80
+
81
+ /****************************************************************************** */
82
+
83
+ addEventListener('popstate', function(event) {
84
+
85
+ if( is_dirty === true ){
86
+ answer = confirm( mex );
87
+ if ( answer === true ) {
88
+ return is_dirty = false;
89
+ } else {
90
+ event.stopImmediatePropagation();
91
+ event.preventDefault();
92
+ return mex;
93
+ }
94
+ }
95
+
96
+ });
97
+
98
+ /****************************************************************************** */
99
+
100
+ window.onbeforeunload = function( event ) {
101
+ if( ( is_dirty === true ) && ( answer === null ) ){
102
+ event.preventDefault();
103
+ return event.returnValue = mex;
104
+ //return mex
105
+ }
106
+ };
107
+
108
+ };
@@ -0,0 +1,15 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * parse Bool
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.parseBool = (val) => {
13
+ if (!val || val.length == null) return true;
14
+ return val == '1' ? true : false;
15
+ };
@@ -0,0 +1,19 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * parse date
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.parseDate = (value) => {
13
+ if (!value) return null;
14
+ let separator = '/';
15
+ let month = value.substring(0, 2);
16
+ let day = value.substring(2, 4);
17
+ let year = value.substring(4, 8);
18
+ return month + separator + day + separator + year;
19
+ };
@@ -0,0 +1,20 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * path Hash
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.pathHash = () => {
13
+ const array = location.hash
14
+ .replace('#', '').split('/');
15
+ if (array.length) {
16
+ return array.filter(item => item);
17
+ } else {
18
+ return ["empty"];
19
+ }
20
+ };
@@ -0,0 +1,24 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * path Query
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.pathQuery = () => {
13
+ let x, y, array = [], search = location.search;
14
+ if (search) {
15
+ search.replace("?", '').split('&')
16
+ .map(x => {
17
+ y = x.split('=');
18
+ array[y[0]] = y[1];
19
+ });
20
+ return array;
21
+ } else {
22
+ return ["empty"];
23
+ }
24
+ };
@@ -0,0 +1,26 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * path Rails
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.pathRail = () => {
13
+ const removeFistFolder = 1;
14
+ const array = location.href
15
+ .split("?")[0]
16
+ .replace(location.protocol, '')
17
+ .replace(location.host, '')
18
+ .replace(location.hash, '')
19
+ .split('/');
20
+ if (array.length) {
21
+ const arrayFinal = array.filter(item => item);
22
+ return arrayFinal.slice(removeFistFolder);
23
+ } else {
24
+ return;
25
+ }
26
+ };
@@ -0,0 +1,16 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * printInfo
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.printInfo = () => {
13
+ console.groupCollapsed('%cApi:%c', "color:orange", "");
14
+ console.debug(wng.api);
15
+ console.groupEnd();
16
+ };
@@ -0,0 +1,41 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * purge
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.purge = ( d = body, time = 10000 ) => {
13
+
14
+ setTimeout(() => {
15
+ if( d === undefined ) return null;
16
+
17
+ let a = d.attributes, i, l, n;
18
+
19
+ if (a) {
20
+ l = a.length;
21
+ for( i = 0; i < l; i += 1 ) {
22
+ n = a[i].name;
23
+ if( typeof d[n] === 'function' ) { d[n] = null; }
24
+ if( typeof d[n] === 'undefined' ) { d[n] = null; }
25
+ }
26
+
27
+ }
28
+
29
+ a = d.childNodes;
30
+
31
+ if (a) {
32
+ l = a.length;
33
+ for( i = 0; i < l; i += 1 ) {
34
+ Purge( d.childNodes[i] );
35
+ }
36
+ }
37
+ }, time );
38
+
39
+ };
40
+
41
+ // purge()
@@ -0,0 +1,14 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * pushState
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.pushState = (state, title, url) => {
13
+ return history.pushState( state, title, url );
14
+ };
@@ -0,0 +1,14 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * random number
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.rnd = () => {
13
+ return Math.floor(100000 + Math.random() * wng.tmr());
14
+ };
@@ -0,0 +1,14 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * random number tmr
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.tmr = () => {
13
+ return Math.round(wng.epoch() / 1000);
14
+ };
@@ -0,0 +1,41 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * scrollCustom
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.scrollCustom = ( el, colors, size ) => {
13
+
14
+ if(!colors) colors =[ "black", "transparent" ];
15
+ if(!size) size =[ "6px", "6px" ];
16
+
17
+ const $style = `${el}{
18
+ scrollbar-width:auto;
19
+ scrollbar-color:${colors[0]} ${colors[1]};
20
+ scrollbar-width: thin;
21
+ -ms-overflow-style: -ms-autohiding-scrollbar;
22
+ }
23
+ ${el}::-webkit-scrollbar {
24
+ width: ${size[0]};
25
+ height: ${size[0]};
26
+ }
27
+ ${el}::-webkit-scrollbar-track {
28
+ background: ${colors[1]};
29
+ }
30
+ ${el}::-webkit-scrollbar-thumb {
31
+ background: ${colors[0]};
32
+ }
33
+ `;
34
+
35
+ let styleToHead = document.createElement( "style" );
36
+ document.head.appendChild( styleToHead );
37
+ styleToHead.innerHTML = $style;
38
+
39
+ };
40
+
41
+ //example: dphelper.scrollCustom('*')
@@ -0,0 +1,67 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * scrollIndicator
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.scrollIndicator = ( props ) => {
13
+
14
+ /**
15
+ /* This timeout it's to be suse that whole UI is loaded
16
+ /* Just smaller trick!
17
+ */
18
+
19
+ let cont = document.querySelector( props.el );
20
+ let sc = document.querySelector('.scrollindicator');
21
+
22
+ if( !sc ){
23
+
24
+ const createEl = document.createElement('div');
25
+ createEl.classList.add("scrollindicator");
26
+ document.querySelector('header').appendChild(createEl);
27
+
28
+ createEl.style.cssText = `
29
+ height:5px;
30
+ background:#65c45c;
31
+ position:absolute;
32
+ bottom:0;
33
+ left:0;
34
+ z-index:2
35
+ `;
36
+ }
37
+
38
+ if( !props.el && sc) {
39
+ sc.style.width = 0 + '%';
40
+ return null;
41
+ }
42
+
43
+ try{
44
+ let sc = document.querySelector('.scrollindicator');
45
+ cont.addEventListener( 'scroll' , function ( e ) {
46
+
47
+ sc.style.width = 0 + '%';
48
+ let winScroll = this.scrollTop || this.scrollTop;
49
+ let height = this.scrollHeight - this.clientHeight;
50
+ let scrolled = Math.min(Math.max(parseInt( (winScroll / height) * 100 ), 0), 100);
51
+ sc.style.width = scrolled + '%';
52
+
53
+ sc.click();
54
+
55
+ });
56
+
57
+ window.addEventListener('popstate', function ( e ) {
58
+ sc.style.width = 0;
59
+ });
60
+
61
+ }catch( e ){
62
+ return;
63
+ }
64
+
65
+ return null;
66
+
67
+ };