dphelper 0.2.0 → 0.2.22
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 +112 -13
- package/README.md.bak +70 -0
- package/init.js +114 -112
- package/package.json +17 -2
- package/scripts/{arrayDeleteItem.js → .OLD/arrayDeleteItem.js} +0 -0
- package/scripts/{arrayItemFinder.js → .OLD/arrayItemFinder.js} +0 -0
- package/scripts/{arrayMerge.js → .OLD/arrayMerge.js} +0 -0
- package/scripts/.OLD/arrayUnique.js +15 -0
- package/scripts/anchorToOnClick.js +36 -36
- package/scripts/array.js +69 -0
- package/scripts/currency.js +21 -21
- package/scripts/indexedDB.js +131 -126
- package/scripts/object2array.js +16 -18
- package/scripts/randomNum.js +14 -14
- package/scripts/serializeForm.js +94 -92
package/README.md
CHANGED
|
@@ -1,13 +1,112 @@
|
|
|
1
|
-
# dpHelper
|
|
2
|
-
|
|
3
|
-
Many utils for your projects
|
|
4
|
-
|
|
5
|
-
Use "npm i dphelper" to install
|
|
6
|
-
|
|
7
|
-
in the index:
|
|
8
|
-
|
|
9
|
-
```js
|
|
10
|
-
import "dphelper"
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
type 'dphelper' in your console to have a look about all available functions that you can use globaly!
|
|
1
|
+
# dpHelper
|
|
2
|
+
|
|
3
|
+
Many utils for your projects
|
|
4
|
+
|
|
5
|
+
Use "npm i dphelper" to install
|
|
6
|
+
|
|
7
|
+
in the index:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import "dphelper"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
type 'dphelper' in your console to have a look about all available functions that you can use globaly!
|
|
14
|
+
|
|
15
|
+
You can call these from everywhere without import
|
|
16
|
+
|
|
17
|
+
## OPTIONS
|
|
18
|
+
|
|
19
|
+
### CURRENCY
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
dphelper.currency( val, int = 'en-US', cur = 'USD' )
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### MEMORY / STORAGE
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
dphelper.storage.get( name )
|
|
29
|
+
dphelper.storage.set( name , value )
|
|
30
|
+
dphelper.storage.delete( name )
|
|
31
|
+
dphelper.storage.clearAll()
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### MEMORY / COOKIE
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
dphelper.cookie.set( name , value , time , path = '/' )
|
|
38
|
+
dphelper.cookie.get( name )
|
|
39
|
+
dphelper.cookie.delete( name )
|
|
40
|
+
dphelper.cookie.clearAll()
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### MEMORY / INDEXED-DB
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
dphelper.indexedDB.create( storeName, table, name )
|
|
47
|
+
dphelper.indexedDB.open( storeName )
|
|
48
|
+
dphelper.indexedDB.store( storeName, table )
|
|
49
|
+
dphelper.indexedDB.insert( storeName, table, key, value )
|
|
50
|
+
dphelper.indexedDB.update( storeName, table, key, value )
|
|
51
|
+
dphelper.indexedDB.get( storeName, table, key )
|
|
52
|
+
|
|
53
|
+
window.dphelper.dbExist() -> know databases
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### NUMBERS
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
dphelper.rnd() // generate long random number
|
|
60
|
+
dphelper.tmr() // generate number by timer
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### DATE / TIME
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
dphelper.epoch() // return epoch time
|
|
67
|
+
dphelper.parseDate( value ) // epoch to human date
|
|
68
|
+
dphelper.dateUTC() // generate UTC date format
|
|
69
|
+
dphelper.dateIso2Epoch( value ) // transform human date to epoch
|
|
70
|
+
dphelper.dateConvert( value , format ) // format like 23 Dec, 2021
|
|
71
|
+
dphelper.date2MMDDYYYY( value ) // format like 12312021
|
|
72
|
+
dphelper.date2Iso( value , int = 'en' ) // format in bese of internationalization
|
|
73
|
+
dphelper.localISOTime( value ) // format Thu, 31 May 2012 08:33:41 +0000
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### PATH RAILS
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
dphelper.pathRail() // Generate array start from subFolders
|
|
80
|
+
dphelper.pathQuery() // Generate array start from querystring
|
|
81
|
+
dphelper.pathHash() // Generate array start from hash path
|
|
82
|
+
dphelper.pushState(state, title, url) // Create a new spushState and avoid page reload
|
|
83
|
+
dphelper.anchorToOnClick( container ) // Transform all a href to onclick (use . for class or # for div )
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### FILE
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
dphelper.loadFile(element, path) // text to element
|
|
90
|
+
dphelper.loadJson( file ) // load json data to a variable
|
|
91
|
+
dphelper.loadJsonExternal( path, method='GET', type='application/json' ) // load json from remote to variable
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### FORM
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
dphelper.serializeForm( form ) // serialize a form (input array) to json
|
|
98
|
+
dphelper.objSerialize(value) // serialize object to json
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### ARRAY
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
dphelper.array.find( id, array ) // find value by ID into array
|
|
105
|
+
dphelper.array.delete( id, array ) // delete value by ID from array
|
|
106
|
+
dphelper.array.merge( arrayA , arrayB ) // merge two array
|
|
107
|
+
dphelper.array.unique( array ) // remove all duplicates
|
|
108
|
+
|
|
109
|
+
dphelper.obj2array( object ) // transform obj to array
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
... TO BE CONTINUE
|
package/README.md.bak
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# dpHelper
|
|
2
|
+
|
|
3
|
+
Many utils for your projects
|
|
4
|
+
|
|
5
|
+
Use "npm i dphelper" to install
|
|
6
|
+
|
|
7
|
+
in the index:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import "dphelper"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
type 'dphelper' in your console to have a look about all available functions that you can use globaly!
|
|
14
|
+
|
|
15
|
+
You can call these from everywhere without import
|
|
16
|
+
|
|
17
|
+
## CURRENCY
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
dphelper.currency( val, int = 'en-US', cur = 'USD' )
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## MEMORY
|
|
24
|
+
|
|
25
|
+
### STORAGE
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
dphelper.storage.get( name )
|
|
29
|
+
dphelper.storage.set( name , value )
|
|
30
|
+
dphelper.storage.delete( name )
|
|
31
|
+
dphelper.storage.clearAll()
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### COOKIE
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
dphelper.cookie.set( name , value , time , path = '/' )
|
|
38
|
+
dphelper.cookie.get( name )
|
|
39
|
+
dphelper.cookie.delete( name )
|
|
40
|
+
dphelper.cookie.clearAll()
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### INDEXED-DB
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
dphelper.indexedDB.create( storeName, table, name )
|
|
47
|
+
dphelper.indexedDB.open( storeName )
|
|
48
|
+
dphelper.indexedDB.store( storeName, table )
|
|
49
|
+
dphelper.indexedDB.insert( storeName, table, key, value )
|
|
50
|
+
dphelper.indexedDB.update( storeName, table, key, value )
|
|
51
|
+
dphelper.indexedDB.get( storeName, table, key )
|
|
52
|
+
|
|
53
|
+
window.dphelper.dbExist() -> know databases
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### NUMBERS
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
dphelper.rnd() // generate long random number
|
|
60
|
+
dphelper.tmr() // generate number by timer
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### TIME
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
dphelper.epoch() // return epoch time
|
|
67
|
+
dphelper.parseDate(value) // epoch to human date
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### 3Party
|
package/init.js
CHANGED
|
@@ -1,112 +1,114 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* dpHelper <https://github.com/passariello/dpHelper>
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2021, Dario Passariello.
|
|
5
|
-
* Licensed under the Apache-2.0 License.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/***********************************************************************/
|
|
9
|
-
|
|
10
|
-
(function () {
|
|
11
|
-
|
|
12
|
-
if (typeof window === 'undefined') {
|
|
13
|
-
global.window = {};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const pjson = require('./package.json');
|
|
17
|
-
|
|
18
|
-
// CREATE ROOT STORE
|
|
19
|
-
const dphelper = window.dphelper = {};
|
|
20
|
-
|
|
21
|
-
// FIRST MESSAGE
|
|
22
|
-
console.groupCollapsed( `%c${pjson.name} v${pjson.version}%c`,"color:orange","" );
|
|
23
|
-
console.debug( `%c${pjson.name} v${pjson.version}%c by Dario Passariello started`,"color:orange","" );
|
|
24
|
-
console.debug( `%cType ${pjson.name} in this console to see it`, "color:gray","" );
|
|
25
|
-
console.debug( "%cFor help visit: " + pjson.repository.help, "color:gray","" );
|
|
26
|
-
console.debug( 'name: %c' + pjson.name,"color:orange","" );
|
|
27
|
-
console.debug( 'version: %c' + pjson.version,"color:orange","" );
|
|
28
|
-
console.debug( 'description: %c' + pjson.description,"color:orange","" );
|
|
29
|
-
console.debug( 'license: %c' + pjson.license,"color:orange","" );
|
|
30
|
-
console.debug( 'repository: %c' + pjson.repository.url,"color:orange","" );
|
|
31
|
-
console.debug( 'author: %c' + pjson.author.name,"color:orange","" );
|
|
32
|
-
console.debug( 'email: %c' + pjson.author.email,"color:orange","" );
|
|
33
|
-
console.groupEnd();
|
|
34
|
-
|
|
35
|
-
const $ = require("jquery");
|
|
36
|
-
|
|
37
|
-
// 3party
|
|
38
|
-
require('./3party/shortcut.js');
|
|
39
|
-
|
|
40
|
-
// CURRENCY
|
|
41
|
-
require('./scripts/currency.js');
|
|
42
|
-
|
|
43
|
-
// MEMORY
|
|
44
|
-
require('./scripts/storage.js');
|
|
45
|
-
require('./scripts/cookie.js');
|
|
46
|
-
require('./scripts/indexedDB.js');
|
|
47
|
-
|
|
48
|
-
// NUMBERS
|
|
49
|
-
require('./scripts/randomNum.js');
|
|
50
|
-
require('./scripts/randomNumTmr.js');
|
|
51
|
-
|
|
52
|
-
// TIME
|
|
53
|
-
require('./scripts/epoch.js');
|
|
54
|
-
require('./scripts/parseDate.js');
|
|
55
|
-
require('./scripts/dateUTC.js');
|
|
56
|
-
require('./scripts/dateIso2Epoch.js');
|
|
57
|
-
require('./scripts/dateConvert.js');
|
|
58
|
-
require('./scripts/date2MMDDYYYY.js');
|
|
59
|
-
require('./scripts/date2Iso.js');
|
|
60
|
-
require('./scripts/dateLocal-ISOTime.js');
|
|
61
|
-
|
|
62
|
-
// PATH
|
|
63
|
-
require('./scripts/pathRail.js');
|
|
64
|
-
require('./scripts/pathQuery.js');
|
|
65
|
-
require('./scripts/pathHash.js');
|
|
66
|
-
require('./scripts/pushState.js');
|
|
67
|
-
require('./scripts/anchorToOnClick.js');
|
|
68
|
-
|
|
69
|
-
// FILE
|
|
70
|
-
require('./scripts/loadFile.js');
|
|
71
|
-
//require('./scripts/loadAsset.js');
|
|
72
|
-
require('./scripts/loadJson.js');
|
|
73
|
-
require('./scripts/loadJsonExternal.js');
|
|
74
|
-
|
|
75
|
-
// FORMS
|
|
76
|
-
require('./scripts/serializeForm.js');
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
require('./scripts/
|
|
81
|
-
require('./scripts/
|
|
82
|
-
require('./scripts/
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
require('./scripts/
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
require('./scripts/
|
|
89
|
-
require('./scripts/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
require('./scripts/
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
require('./scripts/
|
|
96
|
-
require('./scripts/
|
|
97
|
-
require('./scripts/
|
|
98
|
-
require('./scripts/
|
|
99
|
-
require('./scripts/
|
|
100
|
-
require('./scripts/
|
|
101
|
-
require('./scripts/
|
|
102
|
-
require('./scripts/
|
|
103
|
-
require('./scripts/
|
|
104
|
-
require('./scripts/
|
|
105
|
-
require('./scripts/
|
|
106
|
-
require('./scripts/
|
|
107
|
-
require('./scripts/
|
|
108
|
-
require('./scripts/
|
|
109
|
-
require('./scripts/
|
|
110
|
-
require('./scripts/
|
|
111
|
-
|
|
112
|
-
|
|
1
|
+
/*!
|
|
2
|
+
* dpHelper <https://github.com/passariello/dpHelper>
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2021, Dario Passariello.
|
|
5
|
+
* Licensed under the Apache-2.0 License.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/***********************************************************************/
|
|
9
|
+
|
|
10
|
+
(function () {
|
|
11
|
+
|
|
12
|
+
if (typeof window === 'undefined') {
|
|
13
|
+
global.window = {};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const pjson = require('./package.json');
|
|
17
|
+
|
|
18
|
+
// CREATE ROOT STORE
|
|
19
|
+
const dphelper = window.dphelper = {};
|
|
20
|
+
|
|
21
|
+
// FIRST MESSAGE
|
|
22
|
+
console.groupCollapsed( `%c${pjson.name} v${pjson.version}%c`,"color:orange","" );
|
|
23
|
+
console.debug( `%c${pjson.name} v${pjson.version}%c by Dario Passariello started`,"color:orange","" );
|
|
24
|
+
console.debug( `%cType ${pjson.name} in this console to see it`, "color:gray","" );
|
|
25
|
+
console.debug( "%cFor help visit: " + pjson.repository.help, "color:gray","" );
|
|
26
|
+
console.debug( 'name: %c' + pjson.name,"color:orange","" );
|
|
27
|
+
console.debug( 'version: %c' + pjson.version,"color:orange","" );
|
|
28
|
+
console.debug( 'description: %c' + pjson.description,"color:orange","" );
|
|
29
|
+
console.debug( 'license: %c' + pjson.license,"color:orange","" );
|
|
30
|
+
console.debug( 'repository: %c' + pjson.repository.url,"color:orange","" );
|
|
31
|
+
console.debug( 'author: %c' + pjson.author.name,"color:orange","" );
|
|
32
|
+
console.debug( 'email: %c' + pjson.author.email,"color:orange","" );
|
|
33
|
+
console.groupEnd();
|
|
34
|
+
|
|
35
|
+
const $ = require("jquery");
|
|
36
|
+
|
|
37
|
+
// 3party
|
|
38
|
+
require('./3party/shortcut.js');
|
|
39
|
+
|
|
40
|
+
// CURRENCY
|
|
41
|
+
require('./scripts/currency.js');
|
|
42
|
+
|
|
43
|
+
// MEMORY
|
|
44
|
+
require('./scripts/storage.js');
|
|
45
|
+
require('./scripts/cookie.js');
|
|
46
|
+
require('./scripts/indexedDB.js');
|
|
47
|
+
|
|
48
|
+
// NUMBERS
|
|
49
|
+
require('./scripts/randomNum.js');
|
|
50
|
+
require('./scripts/randomNumTmr.js');
|
|
51
|
+
|
|
52
|
+
// TIME
|
|
53
|
+
require('./scripts/epoch.js');
|
|
54
|
+
require('./scripts/parseDate.js');
|
|
55
|
+
require('./scripts/dateUTC.js');
|
|
56
|
+
require('./scripts/dateIso2Epoch.js');
|
|
57
|
+
require('./scripts/dateConvert.js');
|
|
58
|
+
require('./scripts/date2MMDDYYYY.js');
|
|
59
|
+
require('./scripts/date2Iso.js');
|
|
60
|
+
require('./scripts/dateLocal-ISOTime.js');
|
|
61
|
+
|
|
62
|
+
// PATH
|
|
63
|
+
require('./scripts/pathRail.js');
|
|
64
|
+
require('./scripts/pathQuery.js');
|
|
65
|
+
require('./scripts/pathHash.js');
|
|
66
|
+
require('./scripts/pushState.js');
|
|
67
|
+
require('./scripts/anchorToOnClick.js');
|
|
68
|
+
|
|
69
|
+
// FILE
|
|
70
|
+
require('./scripts/loadFile.js');
|
|
71
|
+
//require('./scripts/loadAsset.js');
|
|
72
|
+
require('./scripts/loadJson.js');
|
|
73
|
+
require('./scripts/loadJsonExternal.js');
|
|
74
|
+
|
|
75
|
+
// FORMS
|
|
76
|
+
require('./scripts/serializeForm.js');
|
|
77
|
+
require('./scripts/serializeObj.js');
|
|
78
|
+
|
|
79
|
+
// ARRAY
|
|
80
|
+
// require('./scripts/arrayItemFinder.js');
|
|
81
|
+
// require('./scripts/arrayDeleteItem.js');
|
|
82
|
+
// require('./scripts/arrayMerge.js');
|
|
83
|
+
// require('./scripts/arrayUnique.js');
|
|
84
|
+
require('./scripts/array.js');
|
|
85
|
+
require('./scripts/object2array.js');
|
|
86
|
+
|
|
87
|
+
// SCROLL
|
|
88
|
+
require('./scripts/scrollToElement.js');
|
|
89
|
+
require('./scripts/scrollSmooth.js');
|
|
90
|
+
require('./scripts/scrollIndicator.js');
|
|
91
|
+
require('./scripts/scrollMemory.js');
|
|
92
|
+
require('./scripts/scrollCustom.js');
|
|
93
|
+
|
|
94
|
+
// OTHER
|
|
95
|
+
require('./scripts/uuid.js');
|
|
96
|
+
require('./scripts/noCache.js');
|
|
97
|
+
require('./scripts/parseBool.js');
|
|
98
|
+
require('./scripts/isPromise.js');
|
|
99
|
+
require('./scripts/textChanger.js');
|
|
100
|
+
require('./scripts/nl2br.js');
|
|
101
|
+
require('./scripts/sleep.js');
|
|
102
|
+
require('./scripts/printInfo.js');
|
|
103
|
+
require('./scripts/disableSelect.js');
|
|
104
|
+
require('./scripts/fullScreen.js');
|
|
105
|
+
require('./scripts/disableSpellCheck.js');
|
|
106
|
+
require('./scripts/triggerClick.js');
|
|
107
|
+
require('./scripts/handleEvent.js');
|
|
108
|
+
require('./scripts/window.js');
|
|
109
|
+
require('./scripts/purge.js');
|
|
110
|
+
require('./scripts/svgSupport.js');
|
|
111
|
+
require('./scripts/stopConsole.js');
|
|
112
|
+
require('./scripts/onBeforeUnLoad.js');
|
|
113
|
+
|
|
114
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dphelper",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.22",
|
|
4
4
|
"description": "Many utils for your projects",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {},
|
|
7
|
+
|
|
7
8
|
"scripts": {
|
|
8
|
-
"
|
|
9
|
+
"test1": "echo \"Error: no test specified\" && exit 1",
|
|
10
|
+
"test": "jest --silent --detectOpenHandles",
|
|
11
|
+
"test-coverage": "jest --coverage --silent"
|
|
9
12
|
},
|
|
13
|
+
|
|
10
14
|
"targets": {
|
|
11
15
|
"main": {
|
|
12
16
|
"includeNodeModules": {
|
|
@@ -17,23 +21,29 @@
|
|
|
17
21
|
}
|
|
18
22
|
},
|
|
19
23
|
"deprecated": false,
|
|
24
|
+
|
|
20
25
|
"engines": {
|
|
21
26
|
"node": ">=0.10.0"
|
|
22
27
|
},
|
|
28
|
+
|
|
23
29
|
"repository": {
|
|
24
30
|
"type": "git",
|
|
25
31
|
"url": "https://github.com/passariello/dpHelper",
|
|
26
32
|
"help": "https://github.com/passariello/dpHelper#readme"
|
|
27
33
|
},
|
|
34
|
+
|
|
28
35
|
"eslintConfig": {
|
|
29
36
|
"globals": {
|
|
30
37
|
"window": true
|
|
31
38
|
}
|
|
32
39
|
},
|
|
40
|
+
|
|
33
41
|
"bugs": {
|
|
34
42
|
"url": "https://github.com/passariello/dpHelper/issues"
|
|
35
43
|
},
|
|
44
|
+
|
|
36
45
|
"homepage": "https://github.com/passariello/dpHelper",
|
|
46
|
+
|
|
37
47
|
"keywords": [
|
|
38
48
|
"utils",
|
|
39
49
|
"tools",
|
|
@@ -46,17 +56,21 @@
|
|
|
46
56
|
"powerful",
|
|
47
57
|
"passariello"
|
|
48
58
|
],
|
|
59
|
+
|
|
49
60
|
"author": {
|
|
50
61
|
"name": "Dario Passariello",
|
|
51
62
|
"website": "https://dario.passariello.ca",
|
|
52
63
|
"email": "dariopassariello@gmail.com"
|
|
53
64
|
},
|
|
65
|
+
|
|
54
66
|
"license": "Apache-2.0",
|
|
67
|
+
|
|
55
68
|
"dependencies": {
|
|
56
69
|
"jquery": "^3.6.0",
|
|
57
70
|
"jshint": "^2.13.1",
|
|
58
71
|
"require": "^0.4.4"
|
|
59
72
|
},
|
|
73
|
+
|
|
60
74
|
"contributors": [
|
|
61
75
|
{
|
|
62
76
|
"name": "Dario Passariello",
|
|
@@ -67,4 +81,5 @@
|
|
|
67
81
|
"email": "valeriacalascaglitta@gmail.com"
|
|
68
82
|
}
|
|
69
83
|
]
|
|
84
|
+
|
|
70
85
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* dpHelper <https://github.com/passariello/dpHelper>
|
|
3
|
+
*
|
|
4
|
+
* arrayUnique
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2021, Dario Passariello.
|
|
7
|
+
* Licensed under the Apache-2.0 License.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/***********************************************************************/
|
|
11
|
+
|
|
12
|
+
window.dphelper.arrayUnique = ( array ) => {
|
|
13
|
+
let unique = [...new Set( array )];
|
|
14
|
+
return unique;
|
|
15
|
+
};
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* dpHelper <https://github.com/passariello/dpHelper>
|
|
3
|
-
*
|
|
4
|
-
* anchorToOnClick
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) 2021, Dario Passariello.
|
|
7
|
-
* Licensed under the Apache-2.0 License.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/***********************************************************************/
|
|
11
|
-
|
|
12
|
-
window.dphelper.anchorToOnClick = function(){
|
|
13
|
-
// const $ = require("jquery");
|
|
14
|
-
|
|
15
|
-
$('a').each( function( index ) {
|
|
16
|
-
|
|
17
|
-
let elem = $( this );
|
|
18
|
-
let href = elem.attr( 'href' );
|
|
19
|
-
|
|
20
|
-
if( href ){
|
|
21
|
-
elem
|
|
22
|
-
.on( 'mouseup', function(){
|
|
23
|
-
Loader( 'body' , null );
|
|
24
|
-
})
|
|
25
|
-
.css('cursor','pointer')
|
|
26
|
-
.addClass( dphelper.pathRail()[3].replace(/\//g, '') )
|
|
27
|
-
.removeAttr( 'href' )
|
|
28
|
-
.on( 'click', function(){
|
|
29
|
-
window.location.href = href;
|
|
30
|
-
window.history.pushState('', '', href);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
};
|
|
1
|
+
/*!
|
|
2
|
+
* dpHelper <https://github.com/passariello/dpHelper>
|
|
3
|
+
*
|
|
4
|
+
* anchorToOnClick
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2021, Dario Passariello.
|
|
7
|
+
* Licensed under the Apache-2.0 License.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/***********************************************************************/
|
|
11
|
+
|
|
12
|
+
window.dphelper.anchorToOnClick = function( container ){
|
|
13
|
+
// const $ = require("jquery");
|
|
14
|
+
|
|
15
|
+
$( container + ' a' ).each( function( index ) {
|
|
16
|
+
|
|
17
|
+
let elem = $( this );
|
|
18
|
+
let href = elem.attr( 'href' );
|
|
19
|
+
|
|
20
|
+
if( href ){
|
|
21
|
+
elem
|
|
22
|
+
.on( 'mouseup', function(){
|
|
23
|
+
Loader( 'body' , null );
|
|
24
|
+
})
|
|
25
|
+
.css('cursor','pointer')
|
|
26
|
+
.addClass( dphelper.pathRail()[3].replace(/\//g, '') )
|
|
27
|
+
.removeAttr( 'href' )
|
|
28
|
+
.on( 'click', function(){
|
|
29
|
+
window.location.href = href;
|
|
30
|
+
window.history.pushState('', '', href);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
};
|
package/scripts/array.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* dpHelper <https://github.com/passariello/dpHelper>
|
|
3
|
+
*
|
|
4
|
+
* arrayDeleteItem
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2021, Dario Passariello.
|
|
7
|
+
* Licensed under the Apache-2.0 License.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/***********************************************************************/
|
|
11
|
+
|
|
12
|
+
window.dphelper.array = {
|
|
13
|
+
|
|
14
|
+
// FIND
|
|
15
|
+
find: ( id, array )=>{
|
|
16
|
+
for (let node of array) {
|
|
17
|
+
if (node.id === id) return node;
|
|
18
|
+
|
|
19
|
+
if (node.children) {
|
|
20
|
+
let finalNode = window.dphelper.arrayFindItem(id, node.children);
|
|
21
|
+
if (finalNode) return finalNode;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
// UNIQUE
|
|
28
|
+
unique: ( array ) => {
|
|
29
|
+
let unique = [...new Set( array )];
|
|
30
|
+
return unique;
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
// DELETE
|
|
34
|
+
delete: ( id, array ) => {
|
|
35
|
+
array.some(function iter (o,i,a) {
|
|
36
|
+
|
|
37
|
+
if (o.Id === id) {
|
|
38
|
+
a.splice(i, 1);
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var key = Object.keys(o);
|
|
43
|
+
|
|
44
|
+
for (let key of Object.keys(o)) {
|
|
45
|
+
let value = o[key];
|
|
46
|
+
if(value.length && typeof value === 'object') return value && value.map(iter);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// OLD SCHOOL WAY
|
|
50
|
+
// for (var p=0; p < key.length; ++p){
|
|
51
|
+
// if( o[key[p]]?.length && typeof o[key[p]] === 'object') return o[key[p]] && o[key[p]].some(iter);
|
|
52
|
+
// }
|
|
53
|
+
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
// MERGE
|
|
59
|
+
merge: ( arrayA, arrayB ) => {
|
|
60
|
+
for (const key of Object.keys(source)) {
|
|
61
|
+
if (source[key] instanceof Object && target[key]) Object.assign(source[key], window.dphelper.mergeArrays(target[key], source[key]));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Object.assign(target || {}, source);
|
|
65
|
+
return target;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
};
|
|
69
|
+
|
package/scripts/currency.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* dpHelper <https://github.com/passariello/dpHelper>
|
|
3
|
-
*
|
|
4
|
-
* currency
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) 2021, Dario Passariello.
|
|
7
|
-
* Licensed under the Apache-2.0 License.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/***********************************************************************/
|
|
11
|
-
|
|
12
|
-
window.dphelper.currency = ( val, int = 'en-US',
|
|
13
|
-
if( !val || isNaN( val ) ) val = 0;
|
|
14
|
-
var formatter = new Intl.NumberFormat( int , {
|
|
15
|
-
style: 'currency',
|
|
16
|
-
currency: cur,
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
// return ( val ).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')
|
|
20
|
-
return formatter.format( val );
|
|
21
|
-
};
|
|
1
|
+
/*!
|
|
2
|
+
* dpHelper <https://github.com/passariello/dpHelper>
|
|
3
|
+
*
|
|
4
|
+
* currency
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2021, Dario Passariello.
|
|
7
|
+
* Licensed under the Apache-2.0 License.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/***********************************************************************/
|
|
11
|
+
|
|
12
|
+
window.dphelper.currency = ( val, int = 'en-US', cur = 'USD' ) => {
|
|
13
|
+
if( !val || isNaN( val ) ) val = 0;
|
|
14
|
+
var formatter = new Intl.NumberFormat( int , {
|
|
15
|
+
style: 'currency',
|
|
16
|
+
currency: cur,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// return ( val ).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')
|
|
20
|
+
return formatter.format( val );
|
|
21
|
+
};
|
package/scripts/indexedDB.js
CHANGED
|
@@ -9,172 +9,177 @@
|
|
|
9
9
|
|
|
10
10
|
/***********************************************************************/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
window.dphelper.indexedDB = {
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
//CREATE: dphelper.indexedDB.create('database','table','id')
|
|
15
|
+
create: ( storeName, table, name ) => {
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
var request = window.indexedDB.open( storeName, 1 );
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
request.onerror = ( e ) => {
|
|
20
|
+
console.debug(e, "Database create error: " + e.target.errorCode);
|
|
21
|
+
return;
|
|
22
|
+
};
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
request.onupgradeneeded = ( e ) => {
|
|
25
|
+
var db = e.target.result;
|
|
26
|
+
var objectStore = db.createObjectStore( table, { keyPath: 'id', autoIncrement:true } );
|
|
27
|
+
objectStore.createIndex( 'id', 'id', { unique: true });
|
|
28
|
+
// objectStore.createIndex( 'id', 'id', { unique: true });
|
|
29
|
+
// objectStore.createIndex( 'json', 'json', { unique: false });
|
|
30
|
+
// objectStore.createIndex( 'active', 'active', { unique: false });
|
|
31
|
+
// console.debug( db );
|
|
32
|
+
// db.close();
|
|
33
|
+
};
|
|
24
34
|
|
|
25
|
-
|
|
26
|
-
console.debug( 'indexedDB "' + storeName + '" open' );
|
|
27
|
-
return e.target.result;
|
|
28
|
-
//request.close();
|
|
29
|
-
};
|
|
30
|
-
request.onerror = ( e ) => {
|
|
31
|
-
console.debug( "Database open error: " + e.target.errorCode );
|
|
32
|
-
return;
|
|
33
|
-
};
|
|
34
|
-
return request;
|
|
35
|
+
},
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
/************************************************************************/
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
open: ( storeName ) => {
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
create: ( storeName, table ) => {
|
|
41
|
+
const indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
if (!indexedDB) {
|
|
44
|
+
console.debug( e );
|
|
45
|
+
console.debug( "Your browser doesn't support a skey version of IndexedDB. Such and such feature will not be available.");
|
|
46
|
+
console.debug( "Something went badly wrong with your indexedDB!" );
|
|
47
|
+
}
|
|
44
48
|
|
|
45
|
-
|
|
46
|
-
console.debug(e, "Database create error: " + e.target.errorCode);
|
|
47
|
-
return;
|
|
48
|
-
};
|
|
49
|
+
var request = window.indexedDB.open( storeName , 1 );
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
request.onsuccess = ( e ) => {
|
|
52
|
+
// console.debug( 'indexedDB "' + storeName + '" open' );
|
|
53
|
+
// return e.target.result;
|
|
54
|
+
// request.close();
|
|
55
|
+
};
|
|
56
|
+
request.onerror = ( e ) => {
|
|
57
|
+
console.debug( "Database open error: " + e.target.errorCode );
|
|
58
|
+
return;
|
|
59
|
+
};
|
|
60
|
+
return request;
|
|
58
61
|
|
|
59
|
-
|
|
62
|
+
},
|
|
60
63
|
|
|
61
|
-
|
|
64
|
+
/************************************************************************/
|
|
62
65
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
//STORE: indexedDB.store('myDB','MyTable')
|
|
67
|
+
store: ( storeName, table ) => {
|
|
68
|
+
var request = indexedDB.open( storeName );
|
|
66
69
|
|
|
67
|
-
|
|
70
|
+
request.onsuccess = function (e){
|
|
68
71
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
var database = e.target.result;
|
|
73
|
+
var version = parseInt(database.version);
|
|
74
|
+
database.close();
|
|
72
75
|
|
|
73
|
-
|
|
76
|
+
//var secondRequest = indexedDB.open( storeName , version + 1 );
|
|
77
|
+
var secondRequest = indexedDB.open( storeName , 1 );
|
|
74
78
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
secondRequest.onsuccess = function (e) {
|
|
83
|
-
e.target.result.close();
|
|
84
|
-
};
|
|
85
|
-
};
|
|
79
|
+
secondRequest.onupgradeneeded = function (e) {
|
|
80
|
+
// var database = e.target.result;
|
|
81
|
+
// database.createObjectStore( table, { keyPath: 'id' });
|
|
82
|
+
var db = e.target.result;
|
|
83
|
+
var objectStore = db.createObjectStore( table, { keyPath: 'id', autoIncrement:true } );
|
|
84
|
+
objectStore.createIndex( 'id', 'id', { unique: true });
|
|
85
|
+
};
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
secondRequest.onsuccess = function (e) {
|
|
88
|
+
e.target.result.close();
|
|
89
|
+
};
|
|
90
|
+
};
|
|
88
91
|
|
|
89
|
-
|
|
90
|
-
//INSERT: indexedDB.insert('myDB','Mytable','Mykey','MyValue')
|
|
91
|
-
insert: ( storeName, table, key, value ) => {
|
|
92
|
+
},
|
|
92
93
|
|
|
93
|
-
|
|
94
|
+
/************************************************************************/
|
|
95
|
+
//INSERT: indexedDB.insert('myDB','Mytable','Mykey','MyValue')
|
|
96
|
+
insert: ( storeName, table, key, value ) => {
|
|
94
97
|
|
|
95
|
-
|
|
98
|
+
console.log( storeName, table, key, value );
|
|
96
99
|
|
|
97
|
-
|
|
98
|
-
console.debug(e, "Database insert error: " + e.target.errorCode);
|
|
99
|
-
return;
|
|
100
|
-
};
|
|
100
|
+
var request = window.indexedDB.open( storeName, 1 );
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
var StoreObjInsert = StoreObj.add( value, key, value );
|
|
107
|
-
db.close();
|
|
108
|
-
}catch( e ){
|
|
109
|
-
console.debug( e, "IndexDB insert not work" );
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
},
|
|
102
|
+
request.onerror = ( e ) => {
|
|
103
|
+
console.debug(e, "Database insert error: " + e.target.errorCode);
|
|
104
|
+
return;
|
|
105
|
+
};
|
|
113
106
|
|
|
114
|
-
|
|
107
|
+
request.onsuccess = ( e ) => {
|
|
108
|
+
try{
|
|
109
|
+
var db = e.target.result;
|
|
110
|
+
var StoreObj = db.transaction( storeName , "readwrite").objectStore( storeName );
|
|
111
|
+
StoreObj.add( value, key, value );
|
|
112
|
+
db.close();
|
|
113
|
+
}catch( e ){
|
|
114
|
+
console.debug( e, "IndexDB insert not work" );
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
},
|
|
115
118
|
|
|
116
|
-
|
|
117
|
-
update: ( storeName, table, key, value ) => {
|
|
119
|
+
/************************************************************************/
|
|
118
120
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
console.debug(e, "Database update error: " + e.target.errorCode);
|
|
122
|
-
return;
|
|
123
|
-
};
|
|
124
|
-
request.onsuccess = ( e ) => {
|
|
125
|
-
try{
|
|
126
|
-
var db = e.target.result;
|
|
127
|
-
var StoreObj = db.transaction( storeName , "readwrite").objectStore( storeName );
|
|
128
|
-
var StoreObjUpdate = StoreObj.put( value, key, value );
|
|
129
|
-
db.close();
|
|
130
|
-
}catch( e ){
|
|
131
|
-
console.debug( e, "IndexDB update not work" );
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
},
|
|
121
|
+
//UPDATE: indexedDB.update('myDB','Mykey','MyValue')
|
|
122
|
+
update: ( storeName, table, key, value ) => {
|
|
135
123
|
|
|
136
|
-
|
|
124
|
+
var request = window.indexedDB.open( storeName, 1 );
|
|
125
|
+
request.onerror = ( e ) => {
|
|
126
|
+
console.debug(e, "Database update error: " + e.target.errorCode);
|
|
127
|
+
return;
|
|
128
|
+
};
|
|
129
|
+
request.onsuccess = ( e ) => {
|
|
130
|
+
try{
|
|
131
|
+
var db = e.target.result;
|
|
132
|
+
var StoreObj = db.transaction( storeName , "readwrite").objectStore( storeName );
|
|
133
|
+
StoreObj.put( value, key, value );
|
|
134
|
+
db.close();
|
|
135
|
+
}catch( e ){
|
|
136
|
+
console.debug( e, "IndexDB update not work" );
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
},
|
|
137
140
|
|
|
138
|
-
|
|
139
|
-
get: ( storeName, table, key ) => {
|
|
141
|
+
/************************************************************************/
|
|
140
142
|
|
|
141
|
-
|
|
143
|
+
//GET: indexedDB.get('value')
|
|
144
|
+
get: ( storeName, table, key ) => {
|
|
142
145
|
|
|
143
|
-
|
|
144
|
-
console.debug( e , "Database get error: " + e.target.errorCode );
|
|
145
|
-
return;
|
|
146
|
-
};
|
|
146
|
+
var request = window.indexedDB.open( storeName, 1 );
|
|
147
147
|
|
|
148
|
-
|
|
148
|
+
request.onerror = ( e ) => {
|
|
149
|
+
console.debug( e , "Database get error: " + e.target.errorCode );
|
|
150
|
+
return;
|
|
151
|
+
};
|
|
149
152
|
|
|
150
|
-
|
|
151
|
-
var Store = db.transaction( [storeName] , "readwrite" );
|
|
152
|
-
var obj = Store.objectStore( storeName );
|
|
153
|
-
var req = obj.get( key );
|
|
153
|
+
request.onsuccess = ( e ) => {
|
|
154
154
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
155
|
+
var db = e.target.result;
|
|
156
|
+
var Store = db.transaction( [storeName] , "readwrite" );
|
|
157
|
+
var obj = Store.objectStore( storeName );
|
|
158
|
+
var req = obj.get( key );
|
|
158
159
|
|
|
160
|
+
req.onsuccess = function( e ){
|
|
161
|
+
//console.log( e.target.result )
|
|
159
162
|
};
|
|
160
163
|
|
|
161
|
-
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
},
|
|
162
167
|
|
|
163
|
-
|
|
168
|
+
};
|
|
164
169
|
|
|
165
|
-
|
|
166
|
-
|
|
170
|
+
// CHECK IF INDEXEDDB EXIST
|
|
171
|
+
// ***************************************************************************************************/
|
|
167
172
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
173
|
+
window.dphelper.dbExist = () => {
|
|
174
|
+
const promise = indexedDB.databases();
|
|
175
|
+
promise.then(databases => {
|
|
176
|
+
console.log(databases);
|
|
177
|
+
});
|
|
178
|
+
};
|
|
172
179
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
window.dphelper.indexedDB.insert( "dpHelper" , 'active' , 'test[0]' , [] );
|
|
178
|
-
*/
|
|
180
|
+
// START DEFAULT DB
|
|
181
|
+
// window.dphelper.indexedDB.open( "dpHelper" );
|
|
182
|
+
// window.dphelper.indexedDB.store( "dpHelper" );
|
|
183
|
+
// window.dphelper.indexedDB.insert( "dpHelper" , 'active' , 'test[0]' , [] );
|
|
179
184
|
|
|
180
185
|
|
package/scripts/object2array.js
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
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
|
-
window.dphelper.
|
|
13
|
-
return Object
|
|
14
|
-
.entries(object)
|
|
15
|
-
.map(([key, value]) => Object.assign({key}, value && typeof value === 'object' ? {forms: ObjToArray(value)}
|
|
16
|
-
|
|
17
|
-
));
|
|
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
|
+
window.dphelper.obj2array = ( object ) => {
|
|
13
|
+
return Object
|
|
14
|
+
.entries( object )
|
|
15
|
+
.map( ( [ key, value ] ) => Object.assign( { key } , value && typeof value === 'object' ? { forms: ObjToArray( value ) } : { value, forms: [] } ) );
|
|
16
|
+
};
|
package/scripts/randomNum.js
CHANGED
|
@@ -1,14 +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
|
-
window.dphelper.rnd = () => {
|
|
13
|
-
return Math.floor(100000 + Math.random() * dphelper.tmr());
|
|
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
|
+
window.dphelper.rnd = () => {
|
|
13
|
+
return Math.floor( 100000 + Math.random() * dphelper.tmr() );
|
|
14
|
+
};
|
package/scripts/serializeForm.js
CHANGED
|
@@ -1,92 +1,94 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* dpHelper <https://github.com/passariello/dpHelper>
|
|
3
|
-
*
|
|
4
|
-
* serializeForm
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) 2021, Dario Passariello.
|
|
7
|
-
* Licensed under the Apache-2.0 License.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/***********************************************************************/
|
|
11
|
-
|
|
12
|
-
window.dphelper.serializeForm = function( form ) {
|
|
13
|
-
|
|
14
|
-
const $ = require("jquery");
|
|
15
|
-
const el = this;
|
|
16
|
-
//const el = $( form );
|
|
17
|
-
|
|
18
|
-
var self = el,
|
|
19
|
-
|
|
20
|
-
json = {},
|
|
21
|
-
push_counters = {},
|
|
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
|
-
if( merge === '
|
|
59
|
-
if( merge === '
|
|
60
|
-
if( merge === '
|
|
61
|
-
if( merge === '
|
|
62
|
-
if( merge === '
|
|
63
|
-
if( merge === '
|
|
64
|
-
if( merge === '' ) merge =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
1
|
+
/*!
|
|
2
|
+
* dpHelper <https://github.com/passariello/dpHelper>
|
|
3
|
+
*
|
|
4
|
+
* serializeForm
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2021, Dario Passariello.
|
|
7
|
+
* Licensed under the Apache-2.0 License.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/***********************************************************************/
|
|
11
|
+
|
|
12
|
+
window.dphelper.serializeForm = function( form ) {
|
|
13
|
+
|
|
14
|
+
const $ = require("jquery");
|
|
15
|
+
const el = this;
|
|
16
|
+
//const el = $( form );
|
|
17
|
+
|
|
18
|
+
var self = el,
|
|
19
|
+
|
|
20
|
+
json = {},
|
|
21
|
+
push_counters = {},
|
|
22
|
+
|
|
23
|
+
patterns = {
|
|
24
|
+
//"validate": /^[a-zA-Z][a-zA-Z0-9_]*(?:\[(?:\d*|[a-zA-Z0-9_]+)\])*$/,
|
|
25
|
+
"validate": /[a-zA-Z][a-zA-Z0-9-_.]/, //{1,200}
|
|
26
|
+
"key": /[a-zA-Z0-9_]+|(?=\[\])/g,
|
|
27
|
+
"push": /^$/,
|
|
28
|
+
"fixed": /^\d+$/,
|
|
29
|
+
"named": /^[a-zA-Z0-9_]+$/
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//console.log( el )
|
|
33
|
+
|
|
34
|
+
el.build = function(base, key, value) {
|
|
35
|
+
base[key] = isNaN(value) || Array.isArray(value) ? value : Number(value);
|
|
36
|
+
return base;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
el.push_counter = function(key) {
|
|
40
|
+
if (push_counters[key] === undefined) {
|
|
41
|
+
push_counters[key] = 0;
|
|
42
|
+
}
|
|
43
|
+
return push_counters[key]++;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
$.each( $(el).serializeArray(), function() {
|
|
47
|
+
|
|
48
|
+
// skip invalid keys
|
|
49
|
+
if (!patterns.validate.test(el.name)) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
var k,
|
|
54
|
+
keys = el.name.match(patterns.key),
|
|
55
|
+
merge = el.value,
|
|
56
|
+
reverse_key = el.name;
|
|
57
|
+
|
|
58
|
+
if( merge === 'false' ) merge = Boolean(false);
|
|
59
|
+
if( merge === 'true' ) merge = Boolean(true);
|
|
60
|
+
if( merge === 'off' ) merge = Boolean(false);
|
|
61
|
+
if( merge === 'on' ) merge = Boolean(true);
|
|
62
|
+
if( merge === '[]' ) merge = [];
|
|
63
|
+
if( merge === '{}' ) merge = {};
|
|
64
|
+
if( merge === 'undefined' ) merge = undefined;
|
|
65
|
+
if( merge === 'null' ) merge = null;
|
|
66
|
+
if( merge === '' ) merge = '';
|
|
67
|
+
|
|
68
|
+
while ((k = keys.pop()) !== undefined) {
|
|
69
|
+
|
|
70
|
+
// adjust reverse_key
|
|
71
|
+
reverse_key = reverse_key.replace(new RegExp("\\[" + k + "\\]$"), '');
|
|
72
|
+
|
|
73
|
+
// push
|
|
74
|
+
if (k.match(patterns.push)) {
|
|
75
|
+
merge = self.build([], self.push_counter(reverse_key), merge);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// fixed
|
|
79
|
+
else if (k.match(patterns.fixed)) {
|
|
80
|
+
merge = self.build([], k, merge);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// named
|
|
84
|
+
else if (k.match(patterns.named)) {
|
|
85
|
+
merge = self.build({}, k, merge);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
json = $.extend(true, json, merge);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return json;
|
|
94
|
+
};
|