dphelper 0.2.86 → 0.2.89

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 (112) hide show
  1. package/.editorconfig +13 -0
  2. package/.env +3 -0
  3. package/.eslintignore +13 -0
  4. package/.eslintrc.json +87 -0
  5. package/.eslintrc.legacy.json +91 -0
  6. package/.gitattributes +2 -0
  7. package/.hintrc +11 -0
  8. package/.jsbeautifyrc +25 -0
  9. package/.jshintrc +16 -0
  10. package/.prettierignore +2 -0
  11. package/.prettierrc.json +8 -0
  12. package/.stylelintignore +0 -0
  13. package/.stylelintrc.json +468 -0
  14. package/.vscode/launch.json +34 -0
  15. package/.vscode/settings.json +58 -0
  16. package/3party/shortcut.js +224 -0
  17. package/CHANGELOG.txt +4 -0
  18. package/SECURITY.md +3 -0
  19. package/__mocks__/fileMock.js +3 -0
  20. package/__mocks__/styleMock.js +3 -0
  21. package/babel.config.js +30 -0
  22. package/backup.bat +43 -0
  23. package/coverage/coverage-final.json +1 -0
  24. package/coverage/lcov-report/base.css +224 -0
  25. package/coverage/lcov-report/block-navigation.js +87 -0
  26. package/coverage/lcov-report/favicon.png +0 -0
  27. package/coverage/lcov-report/index.html +101 -0
  28. package/coverage/lcov-report/prettify.css +1 -0
  29. package/coverage/lcov-report/prettify.js +2 -0
  30. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  31. package/coverage/lcov-report/sorter.js +196 -0
  32. package/coverage/lcov.info +0 -0
  33. package/data/list.json +19 -0
  34. package/dist/LICENSE.txt +209 -0
  35. package/dist/README.md +79 -0
  36. package/elements/button/component.js +0 -0
  37. package/elements/code/component.js +0 -0
  38. package/elements/costants.tsx +13 -0
  39. package/elements/fieldset/component.js +0 -0
  40. package/elements/input/checkbox/component.js +0 -0
  41. package/elements/input/date/component.js +27 -0
  42. package/elements/input/number/component.js +0 -0
  43. package/elements/input/radio/component.js +0 -0
  44. package/elements/input/search/component.js +0 -0
  45. package/elements/input/select/component.js +0 -0
  46. package/elements/input/slider/component.js +0 -0
  47. package/elements/input/switch/component.js +0 -0
  48. package/elements/tab/component.js +0 -0
  49. package/elements/table/component.js +0 -0
  50. package/elements/tags.less +0 -0
  51. package/elements/textarea/component.js +0 -0
  52. package/elements/x-foo/define.js +33 -0
  53. package/elements/x-foo/namespace.d.ts +7 -0
  54. package/index.js +12 -2
  55. package/init.js +87 -0
  56. package/jest.config.js +81 -0
  57. package/node/createTag.js +7 -0
  58. package/node/gitDeploy.js +7 -0
  59. package/node/goLive.js +7 -0
  60. package/package.json +27 -20
  61. package/{assets → public/assets}/images/banner.png +0 -0
  62. package/{assets → public/assets}/logos/logo.svg +0 -0
  63. package/{documents → public/documents}/iDB/list.html +0 -0
  64. package/{documents → public/documents}/iDB/toState.html +0 -0
  65. package/scripts/.OLD/import.js +48 -0
  66. package/scripts/anchor.js +73 -0
  67. package/scripts/array.js +203 -0
  68. package/scripts/avoid.js +48 -0
  69. package/scripts/browser.js +100 -0
  70. package/scripts/color.js +121 -0
  71. package/scripts/console.js +97 -0
  72. package/scripts/console.mapped.js +160 -0
  73. package/scripts/coods.js +57 -0
  74. package/scripts/cookie.js +105 -0
  75. package/scripts/date.js +179 -0
  76. package/scripts/disable.js +91 -0
  77. package/scripts/errors.js +3 -0
  78. package/scripts/event.js +57 -0
  79. package/scripts/font.js +60 -0
  80. package/scripts/form.js +211 -0
  81. package/scripts/format.js +71 -0
  82. package/scripts/function.js +55 -0
  83. package/scripts/iDB.js +688 -0
  84. package/scripts/json.js +84 -0
  85. package/scripts/load.js +112 -0
  86. package/scripts/math.js +100 -0
  87. package/scripts/obj.js +118 -0
  88. package/scripts/path.js +101 -0
  89. package/scripts/promise.js +56 -0
  90. package/scripts/screen.js +82 -0
  91. package/scripts/scrollbar.js +293 -0
  92. package/scripts/shortcut.js +83 -0
  93. package/scripts/socket.js +184 -0
  94. package/scripts/state.js +87 -0
  95. package/scripts/storage.js +93 -0
  96. package/scripts/store.js +115 -0
  97. package/scripts/svg.js +380 -0
  98. package/scripts/text.js +116 -0
  99. package/scripts/time.js +43 -0
  100. package/scripts/timer.js +54 -0
  101. package/scripts/tool.js +73 -0
  102. package/scripts/trigger.js +57 -0
  103. package/scripts/type.js +76 -0
  104. package/scripts/ui.js +41 -0
  105. package/scripts/window.js +244 -0
  106. package/styles/console.less +95 -0
  107. package/tests/setupJest.tsx +4 -0
  108. package/typings/dphelper.d.ts +26 -0
  109. package/typings/image.d.ts +5 -0
  110. package/typings/styles.d.ts +23 -0
  111. package/webpack.config.js +249 -0
  112. package/index.js.LICENSE.txt +0 -31
@@ -0,0 +1,179 @@
1
+ /*!
2
+ dpHelper
3
+ Copyright (c) 2021 Dario Passariello <dariopassariello@gmail.com>
4
+ Licensed under the Apache-2.0, see
5
+ https://dario.passariello.ca
6
+ */
7
+
8
+ /***********************************************************************/
9
+
10
+ var description = {
11
+ "name" : "Date",
12
+ "description" : "",
13
+ "version" : "0.0.1",
14
+ "command" : "date",
15
+ "subCommand" : [
16
+ {
17
+ "name":"toIso",
18
+ "description":"test"
19
+ },{
20
+ "name":"toMMDDYYYY",
21
+ "description":"test"
22
+ },{
23
+ "name":"convert",
24
+ "description":"test"
25
+ },{
26
+ "name":"iso2Epoch",
27
+ "description":"test"
28
+ },{
29
+ "name":"localIsoTime",
30
+ "description":"test"
31
+ },{
32
+ "name":"utc",
33
+ "description":"test"
34
+ },{
35
+ "name":"parse",
36
+ "description":"test"
37
+ },{
38
+ "name":"year",
39
+ "description":"actual year"
40
+ },{
41
+ "name":"addDays",
42
+ "description":"actual year"
43
+ },{
44
+ "name":"dateTimeToString",
45
+ "description":"actual year"
46
+ },{
47
+ "name":"datePickerFormat",
48
+ "description":"actual year"
49
+ },{
50
+ "name":"isoToHuman",
51
+ "description":"actual year"
52
+ },
53
+ ],
54
+ "example" : "",
55
+ "author" : "Dario Passariello",
56
+ "active" : true
57
+ };
58
+
59
+ dphelper._list.scripts.push( description );
60
+
61
+ /***********************************************************************/
62
+
63
+ dphelper.date = {
64
+
65
+ toIso: (value , int = 'en' ) => {
66
+ if (!value) value = '';
67
+ let date = new Date(value);
68
+ if (date == 'Invalid Date') return null; //date = new Date()
69
+ const dateTimeFormat = new Intl.DateTimeFormat( int , {
70
+ year: 'numeric', month: 'long', day: 'numeric',
71
+ });
72
+ return dateTimeFormat.format(date);
73
+ },
74
+
75
+ toMMDDYYYY: (value) => {
76
+ if (!value) value = '';
77
+ let date = new Date(value);
78
+ return ('0' + (date.getMonth() + 1)).slice(-2) + "" + ('0' + date.getDate()).slice(-2) + "" + date.getFullYear();
79
+ },
80
+
81
+ convert: (value , format ) => {
82
+ if (!value) return null;
83
+ if( !format) format = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
84
+ let month = value.substring(0, 2).replace('0', '');
85
+ let day = value.substring(2, 4);
86
+ let year = value.substring(value.length - 4);
87
+ return day + ' ' + format[Number(month) - 1] + ' ' + year;
88
+ },
89
+
90
+ iso2Epoch: (value) => {
91
+ if (!value) value = '';
92
+ let date = new Date(value);
93
+ let milliseconds = date.getTime();
94
+ return milliseconds;
95
+ },
96
+
97
+ localIsoTime: (value) => {
98
+ if (!value) value = '';
99
+ let tzoffset = (new Date(value)).getTimezoneOffset() * 60000;
100
+ let localISOTime = (new Date(Date.now() - tzoffset)).toISOString().slice(0, -1);
101
+ return localISOTime;
102
+ },
103
+
104
+ utc: () => {
105
+ return moment().toISOString();
106
+ },
107
+
108
+ parse: ( value , separator = '/' ) => {
109
+ if (!value) return null;
110
+ let month = value.substring(0, 2);
111
+ let day = value.substring(2, 4);
112
+ let year = value.substring(4, 8);
113
+ return month + separator + day + separator + year;
114
+ },
115
+
116
+ year: () => {
117
+ return /\d{4}/.exec(Date())[0];
118
+ },
119
+
120
+ addDays: (date, days) => {
121
+ const copy = new Date(Number(date))
122
+ copy.setDate(date.getDate() + days)
123
+ return copy
124
+ },
125
+
126
+ dateTimeToString: ( dateObject ) => {
127
+ try {
128
+ return `${dateObject.getFullYear()}${
129
+ dateObject.getMonth().toString().length > 1
130
+ ? dateObject.getMonth() + 1
131
+ : `0${dateObject.getMonth() + 1}`
132
+ }${
133
+ dateObject.getDate().toString().length > 1 ? dateObject.getDate() : `0${dateObject.getDate()}`
134
+ }_${dateObject.getHours()}${dateObject.getMinutes()}${dateObject.getSeconds()}`
135
+ } catch (err) {
136
+ // todo: log errors
137
+ return dateObject
138
+ }
139
+ },
140
+
141
+ datePickerFormat: ( dateObject ) => {
142
+ try {
143
+ return `${dateObject.getFullYear()}-${
144
+ dateObject.getMonth().toString().length > 1
145
+ ? dateObject.getMonth() + 1
146
+ : `0${dateObject.getMonth() + 1}`
147
+ }-${
148
+ dateObject.getDate().toString().length > 1 ? dateObject.getDate() : `0${dateObject.getDate()}`
149
+ }`
150
+ } catch (err) {
151
+ // todo: log errors
152
+ return dateObject
153
+ }
154
+ },
155
+
156
+ isoToHuman: ( value , symbol="@" ) => {
157
+ if(!value) return null;
158
+ var format = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
159
+ var date = new Date( value );
160
+ var year = date.getFullYear();
161
+ var month = (date.getMonth()+1).toString();
162
+ var dt = date.getDate().toString();
163
+ var t = value.split("T")[1].split(":").slice(0, 2).join(':');
164
+
165
+
166
+ if (dt.length < 2 ) dt = '0' + dt;
167
+ if (month.length < 2) month = '0' + month;
168
+
169
+ return (dt +' ' + format[ Number(month)-1 ] + ' ' + year + " " + symbol + " " + t );
170
+ }
171
+
172
+ };
173
+
174
+ Object.defineProperty( dphelper, 'date', {
175
+ writable: false,
176
+ configurable: false
177
+ });
178
+
179
+ //console.log( Object.getOwnPropertyDescriptor( dphelper, 'socket' ) )
@@ -0,0 +1,91 @@
1
+ /*!
2
+ dpHelper
3
+ Copyright (c) 2021 Dario Passariello <dariopassariello@gmail.com>
4
+ Licensed under the Apache-2.0, see
5
+ https://dario.passariello.ca
6
+ */
7
+
8
+ /***********************************************************************/
9
+
10
+ var description = {
11
+ "name" : "Disable",
12
+ "description" : "",
13
+ "version" : "0.0.1",
14
+ "command" : "disable",
15
+ "subCommand" : [
16
+ {
17
+ "name":"select",
18
+ "description":"test"
19
+ },{
20
+ "name":"spellCheck",
21
+ "description":"test"
22
+ }
23
+ ],
24
+ "example" : "",
25
+ "author" : "Dario Passariello",
26
+ "active" : true
27
+ };
28
+
29
+ dphelper._list.scripts.push( description );
30
+
31
+ /***********************************************************************/
32
+
33
+ // // ALIAS
34
+ // dphelper.disableSelect = ( el = 'body' ) => {
35
+ // console.debug( "Please, use 'dphelper.disable.select' instead dphelper.disableSelect" );
36
+ // dphelper.disable.select( el = 'body' );
37
+ // };
38
+
39
+ /***********************************************************************/
40
+
41
+ dphelper.disable = {
42
+
43
+ select: function( el = 'body' ){
44
+
45
+ const disabling = ( el , e ) => {
46
+
47
+ var target = $( e.target );
48
+
49
+ if( target.is( "input, button, select, textarea, .selectable *") ){
50
+ //console.log( 'ok' )
51
+ }else{
52
+ $('*').trigger('blur')
53
+ e.preventDefault();
54
+ return false
55
+ }
56
+
57
+ $( 'img, a, input, button' )
58
+ .on( 'dragstart' , function( e ) {
59
+ e.preventDefault();
60
+ return false;
61
+ });
62
+
63
+ };
64
+
65
+ $( el ).on( "mousedown", function( e ){ disabling( el , e ); });
66
+
67
+ console.debug( '%cSelection Disabled: %c' + true,"color:orange","" );
68
+
69
+ },
70
+
71
+ spellCheck: ( tmr = 5000 ) => {
72
+
73
+ setInterval( () => {
74
+ let inputs = document.querySelectorAll("input[type=text], textarea, code");
75
+ for(let i = 0; i < inputs.length; i++){
76
+ if( !inputs[i].getAttribute("spellcheck") ){
77
+ inputs[i].setAttribute("spellcheck", "false");
78
+ }
79
+ }
80
+ }, tmr );
81
+
82
+ }
83
+
84
+ };
85
+
86
+ Object.defineProperty( dphelper, 'disable', {
87
+ writable: false,
88
+ configurable: false
89
+ });
90
+
91
+ //console.log( Object.getOwnPropertyDescriptor( dphelper, 'socket' ) )
@@ -0,0 +1,3 @@
1
+ // function FatalError(){ Error.apply(this, arguments); }
2
+ // FatalError.prototype = Object.create(Error.prototype);
3
+ // throw new FatalError("Something went badly wrong!");
@@ -0,0 +1,57 @@
1
+ /*!
2
+ dpHelper
3
+ Copyright (c) 2021 Dario Passariello <dariopassariello@gmail.com>
4
+ Licensed under the Apache-2.0, see
5
+ https://dario.passariello.ca
6
+ */
7
+
8
+ /***********************************************************************/
9
+
10
+ var description = {
11
+ "name" : "Event",
12
+ "description" : "",
13
+ "version" : "0.0.1",
14
+ "command" : "event",
15
+ "subCommand" : [
16
+ {
17
+ "name":"multi",
18
+ "description":"test",
19
+ }
20
+ ],
21
+ "example" : "",
22
+ "author" : "Dario Passariello",
23
+ "active" : true
24
+ };
25
+
26
+ dphelper._list.scripts.push( description );
27
+
28
+ /***********************************************************************/
29
+
30
+ dphelper.event ={
31
+
32
+ multi: ( element, eventNames, listener ) => {
33
+ var events = eventNames.split(' ');
34
+ for (var i=0, iLen = events.length; i < iLen; ++i ) {
35
+ element.addEventListener( events[i], listener, false );
36
+ }
37
+
38
+ },
39
+
40
+ dispatch: ( name , value ) => {
41
+ document.dispatchEvent( new CustomEvent( name,value ) )
42
+ }
43
+
44
+ };
45
+
46
+ Object.defineProperty( dphelper, 'event', {
47
+ writable: false,
48
+ configurable: false
49
+ });
50
+
51
+ Object.defineProperty( dphelper.event, 'dispatch', {
52
+ isTrusted: true,
53
+ writable: false,
54
+ configurable: false
55
+ });
56
+
57
+ //console.log( Object.getOwnPropertyDescriptor( dphelper, 'socket' ) )
@@ -0,0 +1,60 @@
1
+ /*!
2
+ dpHelper
3
+ Copyright (c) 2021 Dario Passariello <dariopassariello@gmail.com>
4
+ Licensed under the Apache-2.0, see
5
+ https://dario.passariello.ca
6
+ */
7
+
8
+ /***********************************************************************/
9
+
10
+ var description = {
11
+ "name" : "Font",
12
+ "description" : "",
13
+ "version" : "0.0.1",
14
+ "command" : "font",
15
+ "subCommand" : [
16
+ {
17
+ "name":"fitContainer",
18
+ "description":""
19
+ }
20
+ ],
21
+ "example" : "",
22
+ "author" : "Dario Passariello",
23
+ "active" : true
24
+ };
25
+
26
+ dphelper._list.scripts.push( description );
27
+
28
+ /***********************************************************************/
29
+
30
+ dphelper.font = {
31
+
32
+ fitContainer: ( name ) => {
33
+ if( !name ) return;
34
+
35
+ function fitStart(){
36
+ var divs = document.querySelectorAll( name );
37
+ if( divs.length <= 0 ) return;
38
+ for(var i = 0; i < divs.length; i++) {
39
+ var fontSize = divs[i].offsetWidth * 0.05;
40
+ divs[i].style.fontSize = fontSize+'px';
41
+ }
42
+ }
43
+
44
+ dphelper.addListenerMulti( window , 'load resize', () => {
45
+ fitStart( name );
46
+ });
47
+
48
+ }
49
+
50
+ };
51
+
52
+ Object.defineProperty( dphelper, 'font', {
53
+ writable: false,
54
+ configurable: false
55
+ });
56
+
57
+ //console.log( Object.getOwnPropertyDescriptor( dphelper, 'socket' ) )
58
+
59
+
60
+
@@ -0,0 +1,211 @@
1
+ /*!
2
+ dpHelper
3
+ Copyright (c) 2021 Dario Passariello <dariopassariello@gmail.com>
4
+ Licensed under the Apache-2.0, see
5
+ https://dario.passariello.ca
6
+ */
7
+
8
+ /***********************************************************************/
9
+
10
+ var description = {
11
+ "name" : "Form",
12
+ "description" : "",
13
+ "version" : "0.0.1",
14
+ "command" : "form",
15
+ "subCommand" : [
16
+ {
17
+ "name":"serialize",
18
+ "description":"test"
19
+ },{
20
+ "name":"confirmType",
21
+ "description":"test"
22
+ },{
23
+ "name":"required",
24
+ "description":"test"
25
+ },{
26
+ "name":"minLength",
27
+ "description":"test"
28
+ },{
29
+ "name":"maxLength",
30
+ "description":"test"
31
+ },{
32
+ "name":"maxPhoneNumber",
33
+ "description":"test"
34
+ },{
35
+ "name":"isNumeric",
36
+ "description":"test"
37
+ },{
38
+ "name":"isEmail",
39
+ "description":"test"
40
+ }
41
+ ],
42
+ "example" : "",
43
+ "author" : "Dario Passariello",
44
+ "active" : true
45
+ };
46
+
47
+ dphelper._list.scripts.push( description );
48
+
49
+ /***********************************************************************/
50
+
51
+ dphelper.form = {
52
+
53
+ serialize: ( form ) => {
54
+
55
+ const $ = require("jquery");
56
+ const el = this;
57
+ //const el = $( form );
58
+
59
+ var self = el,
60
+
61
+ json = {},
62
+ push_counters = {},
63
+
64
+ patterns = {
65
+ //"validate": /^[a-zA-Z][a-zA-Z0-9_]*(?:\[(?:\d*|[a-zA-Z0-9_]+)\])*$/,
66
+ "validate": /[a-zA-Z][a-zA-Z0-9-_.]/, //{1,200}
67
+ "key": /[a-zA-Z0-9_]+|(?=\[\])/g,
68
+ "push": /^$/,
69
+ "fixed": /^\d+$/,
70
+ "named": /^[a-zA-Z0-9_]+$/
71
+ };
72
+
73
+ el.build = function(base, key, value) {
74
+ base[key] = isNaN(value) || Array.isArray(value) ? value : Number(value);
75
+ return base;
76
+ };
77
+
78
+ el.push_counter = function(key) {
79
+ if (push_counters[key] === undefined) {
80
+ push_counters[key] = 0;
81
+ }
82
+ return push_counters[key]++;
83
+ };
84
+
85
+ $.each( $(el).serializeArray(), function() {
86
+
87
+ // skip invalid keys
88
+ if (!patterns.validate.test(el.name)) {
89
+ return;
90
+ }
91
+
92
+ var k,
93
+ keys = el.name.match(patterns.key),
94
+ merge = el.value,
95
+ reverse_key = el.name;
96
+
97
+ if( merge === 'false' ) merge = Boolean(false);
98
+ if( merge === 'true' ) merge = Boolean(true);
99
+ if( merge === 'off' ) merge = Boolean(false);
100
+ if( merge === 'on' ) merge = Boolean(true);
101
+ if( merge === '[]' ) merge = [];
102
+ if( merge === '{}' ) merge = {};
103
+ if( merge === 'undefined' ) merge = undefined;
104
+ if( merge === 'null' ) merge = null;
105
+ if( merge === '' ) merge = '';
106
+
107
+ while ((k = keys.pop()) !== undefined) {
108
+
109
+ // adjust reverse_key
110
+ reverse_key = reverse_key.replace(new RegExp("\\[" + k + "\\]$"), '');
111
+
112
+ // push
113
+ if (k.match(patterns.push)) {
114
+ merge = self.build([], self.push_counter(reverse_key), merge);
115
+ }
116
+
117
+ // fixed
118
+ else if (k.match(patterns.fixed)) {
119
+ merge = self.build([], k, merge);
120
+ }
121
+
122
+ // named
123
+ else if (k.match(patterns.named)) {
124
+ merge = self.build({}, k, merge);
125
+ }
126
+
127
+ }
128
+
129
+ json = $.extend(true, json, merge);
130
+ });
131
+
132
+ return json;
133
+ },
134
+
135
+ confirmType: ( type, value ) => {
136
+
137
+ // FIX NUMBERS
138
+ if ( type === 'number' ) {
139
+ const containsNum = new RegExp(/^\d+$/);
140
+ // console.log(type, value, containsNum.test(value.toString()));
141
+ return containsNum.test(value.toString());
142
+ }
143
+
144
+ // FIX EMAIL FORMAT
145
+ if ( type === 'email' ) {
146
+ const isEmail = new RegExp(
147
+ /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
148
+ )
149
+ // console.log( type, value, isEmail.test(value.toString()) );
150
+ return isEmail.test(value.toString().toLowerCase());
151
+ }
152
+
153
+ return true;
154
+ },
155
+
156
+ required: (value) => {
157
+ if (value === null || value === undefined) {
158
+ return "Required";
159
+ } else {
160
+ return undefined;
161
+ }
162
+ },
163
+
164
+ minLength: ( value , num = 1 ) => {
165
+ if (!value || value?.length < num ) {
166
+ return "Must Enter a Value";
167
+ } else {
168
+ return undefined;
169
+ }
170
+ },
171
+
172
+ maxLength: ( value , num = 10 ) => {
173
+ if (value?.length > num ) {
174
+ return "Exceeds Max Length";
175
+ } else {
176
+ return undefined;
177
+ }
178
+ },
179
+
180
+ maxPhoneNumber: ( value , num = 10 ) => {
181
+ if (value?.toString()?.length > num ) {
182
+ return "Exceeds Max Length";
183
+ } else {
184
+ return undefined;
185
+ }
186
+ },
187
+
188
+ isNumeric: ( value ) => {
189
+ if ( isNaN(value) ) {
190
+ return false;
191
+ } else {
192
+ return value;
193
+ }
194
+ },
195
+
196
+ isEmail: ( value ) => {
197
+ const isEmail = new RegExp(
198
+ /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
199
+ )
200
+ return isEmail.test( value.toString().toLowerCase() );
201
+ }
202
+
203
+
204
+ };
205
+
206
+ Object.defineProperty( dphelper, 'form', {
207
+ writable: false,
208
+ configurable: false
209
+ });
210
+
211
+ //console.log( Object.getOwnPropertyDescriptor( dphelper, 'socket' ) )
@@ -0,0 +1,71 @@
1
+ /*!
2
+ dpHelper
3
+ Copyright (c) 2021 Dario Passariello <dariopassariello@gmail.com>
4
+ Licensed under the Apache-2.0, see
5
+ https://dario.passariello.ca
6
+ */
7
+
8
+ /***********************************************************************/
9
+
10
+ var description = {
11
+ "name" : "Format",
12
+ "description" : "",
13
+ "version" : "0.0.1",
14
+ "command" : "cormat",
15
+ "subCommand" : [
16
+ {
17
+ "name":"currency",
18
+ "description":"test"
19
+ },{
20
+ "name":"phoneNumber",
21
+ "description":"test"
22
+ }
23
+ ],
24
+ "example" : "",
25
+ "author" : "Dario Passariello",
26
+ "active" : true
27
+ };
28
+
29
+ dphelper._list.scripts.push( description );
30
+
31
+ /***********************************************************************/
32
+
33
+ dphelper.format = {
34
+
35
+ currency: ( val, int = 'en-US', cur = 'USD' ) => {
36
+ if( !val || isNaN( val ) ) val = 0;
37
+ var formatter = new Intl.NumberFormat( int , {
38
+ style: 'currency',
39
+ currency: cur,
40
+ });
41
+ // return ( val ).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')
42
+ return formatter.format( val );
43
+ },
44
+
45
+ ////////////////////////////////////////////////////////////////////////////
46
+
47
+ phoneNumber: (str) => {
48
+ //Filter only numbers from the input
49
+ let cleaned = ('' + str).replace(/\D/g, '');
50
+
51
+ //Check if the input is of correct
52
+ let match = cleaned.match(/^(1|)?(\d{3})(\d{3})(\d{4})$/);
53
+
54
+ if (match) {
55
+ //Remove the matched extension code
56
+ //Change this to format for any country code.
57
+ let intlCode = (match[1] ? '+1 ' : '')
58
+ return [intlCode, '(', match[2], ') ', match[3], '-', match[4]].join('')
59
+ }
60
+
61
+ return null;
62
+ }
63
+
64
+ };
65
+
66
+ Object.defineProperty( dphelper, 'format', {
67
+ writable: false,
68
+ configurable: false
69
+ });
70
+
71
+ //console.log( Object.getOwnPropertyDescriptor( dphelper, 'socket' ) )