@blazedpath/commons 0.0.10 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,169 +1,167 @@
1
1
  module.exports = {
2
- Dual: {
3
- _internal_: {
4
- htmlUnescapes: {
5
- '&': '&',
6
- '&lt;': '<',
7
- '&gt;': '>',
8
- '&quot;': '"',
9
- '&#39;': "'"
10
- },
11
- reEscapedHtml: /&(?:amp|lt|gt|quot|#(0+)?39);/g,
12
- reHasEscapedHtml: RegExp('&(?:amp|lt|gt|quot|#(0+)?39);'),
13
- htmlEscapes: {
14
- '&': '&amp;',
15
- '<': '&lt;',
16
- '>': '&gt;',
17
- '"': '&quot;',
18
- "'": '&#39;'
19
- },
20
- reUnescapedHtml: /[&<>"']/g,
21
- reHasUnescapedHtml: RegExp(`[&<>"']`),
22
- },
23
- concat: function () {
24
- let result = '';
25
- for (let i = 0; i < arguments.length; i++) {
26
- let argument = arguments[i];
27
- if (argument !== null)
28
- result += argument;
29
- }
30
- return result;
31
- },
32
- contains: function (target, value) {
33
- if (target === null || target === undefined)
34
- return false;
35
- if (value === null || value === undefined)
36
- return false;
37
- return target.indexOf(value) !== -1;
38
- },
39
- endsWith: function (target, value) {
40
- if (target === null || target === undefined)
41
- return false;
42
- if (value === null || value === undefined)
43
- return false;
44
- return target.substring(target.length - value.length, target.length) === value;
45
- },
46
- escapeHtml: function (value) {
47
- return (value && this._internal_.reHasUnescapedHtml.test(value))
48
- ? value.replace(this._internal_.reUnescapedHtml, (chr) => this._internal_.htmlEscapes[chr])
49
- : (value || '')
50
- },
51
- indexOf: function (target, value) {
52
- if (target === null || target === undefined)
53
- return -1;
54
- if (value === null || value === undefined)
55
- return -1;
56
- return target.indexOf(value);
57
- },
58
- isNullOrEmpty: function (target) {
59
- if (target === null || target === undefined)
60
- return true;
61
- return (target === '');
62
- },
63
- isNullOrWhiteSpace: function (target) {
64
- if (target === null || target === undefined)
65
- return true;
66
- return (target === '' || target.replace(/\s/g, '').length < 1);
67
- },
68
- join: function (target, delimiter) {
69
- if (target === null || target === undefined)
70
- return null;
71
- if (delimiter)
72
- return target.join(delimiter);
73
- else
74
- return target.join('');
75
- },
76
- lastIndexOf: function (target, value) {
77
- if (target === null || target === undefined)
78
- return -1;
79
- if (value === null || value === undefined)
80
- return -1;
81
- return target.lastIndexOf(value);
82
- },
83
- length: function (target) {
84
- if (target === null || target === undefined)
85
- return 0;
86
- return target.length;
87
- },
88
- padLeft: function (target, totalWidth, padding) {
89
- if (target === null || target === undefined)
90
- return null;
91
- if (totalWidth === null || totalWidth === undefined)
92
- return target;
93
- if (padding)
94
- return target.padStart(totalWidth, padding);
95
- else
96
- return target.padStart(totalWidth);
97
- },
98
- padRight: function (target, totalWidth, padding) {
99
- if (target === null || target === undefined)
100
- return null;
101
- if (totalWidth === null || totalWidth === undefined)
102
- return target;
103
- if (padding)
104
- return target.padEnd(totalWidth, padding);
105
- else
106
- return target.padEnd(totalWidth);
107
- },
108
- replace: function (target, oldValue, newValue) {
109
- if (target === null || target === undefined)
110
- return null;
111
- if (oldValue === null || oldValue === undefined)
112
- return target;
113
- if (newValue === null || newValue === undefined)
114
- return target;
115
- return target.replace(new RegExp(oldValue, 'g'), newValue);
116
- },
117
- split: function (target, delimiter) {
118
- if (target === null || target === undefined)
119
- return [];
120
- return target.split(delimiter);
121
- },
122
- startsWith: function (target, value) {
123
- if (target === null || target === undefined)
124
- return false;
125
- if (value === null || value === undefined)
126
- return false;
127
- return target.substring(0, value.length) === value;
128
- },
129
- substring: function (target, startIndex, length) {
130
- if (target === null || target === undefined)
131
- return null;
132
- if (startIndex === null || startIndex === undefined)
133
- return null;
134
- if (length === null || length === undefined)
135
- return null;
136
- return target.substring(startIndex, startIndex + length);
137
- },
138
- toLower: function (target) {
139
- if (target === null || target === undefined)
140
- return null;
141
- return target.toLowerCase();
142
- },
143
- toUpper: function (target) {
144
- if (target === null || target === undefined)
145
- return null;
146
- return target.toUpperCase();
147
- },
148
- trim: function (target) {
149
- if (target === null || target === undefined)
150
- return null;
151
- return target.trim();
152
- },
153
- trimEnd: function (target) {
154
- if (target === null || target === undefined)
155
- return null;
156
- return target.trimEnd();
157
- },
158
- trimStart: function (target) {
159
- if (target === null || target === undefined)
160
- return null;
161
- return target.trimStart();
162
- },
163
- unescapeHtml: function (value) {
164
- return (value && this._internal_.reHasEscapedHtml.test(value))
165
- ? value.replace(this._internal_.reEscapedHtml, (entity) => (this._internal_.htmlUnescapes[entity] || "'"))
166
- : (value || '')
167
- },
168
- }
2
+ _internal_: {
3
+ htmlUnescapes: {
4
+ '&amp;': '&',
5
+ '&lt;': '<',
6
+ '&gt;': '>',
7
+ '&quot;': '"',
8
+ '&#39;': "'"
9
+ },
10
+ reEscapedHtml: /&(?:amp|lt|gt|quot|#(0+)?39);/g,
11
+ reHasEscapedHtml: RegExp('&(?:amp|lt|gt|quot|#(0+)?39);'),
12
+ htmlEscapes: {
13
+ '&': '&amp;',
14
+ '<': '&lt;',
15
+ '>': '&gt;',
16
+ '"': '&quot;',
17
+ "'": '&#39;'
18
+ },
19
+ reUnescapedHtml: /[&<>"']/g,
20
+ reHasUnescapedHtml: RegExp(`[&<>"']`),
21
+ },
22
+ concat: function () {
23
+ let result = '';
24
+ for (let i = 0; i < arguments.length; i++) {
25
+ let argument = arguments[i];
26
+ if (argument !== null)
27
+ result += argument;
28
+ }
29
+ return result;
30
+ },
31
+ contains: function (target, value) {
32
+ if (target === null || target === undefined)
33
+ return false;
34
+ if (value === null || value === undefined)
35
+ return false;
36
+ return target.indexOf(value) !== -1;
37
+ },
38
+ endsWith: function (target, value) {
39
+ if (target === null || target === undefined)
40
+ return false;
41
+ if (value === null || value === undefined)
42
+ return false;
43
+ return target.substring(target.length - value.length, target.length) === value;
44
+ },
45
+ escapeHtml: function (value) {
46
+ return (value && this._internal_.reHasUnescapedHtml.test(value))
47
+ ? value.replace(this._internal_.reUnescapedHtml, (chr) => this._internal_.htmlEscapes[chr])
48
+ : (value || '')
49
+ },
50
+ indexOf: function (target, value) {
51
+ if (target === null || target === undefined)
52
+ return -1;
53
+ if (value === null || value === undefined)
54
+ return -1;
55
+ return target.indexOf(value);
56
+ },
57
+ isNullOrEmpty: function (target) {
58
+ if (target === null || target === undefined)
59
+ return true;
60
+ return (target === '');
61
+ },
62
+ isNullOrWhiteSpace: function (target) {
63
+ if (target === null || target === undefined)
64
+ return true;
65
+ return (target === '' || target.replace(/\s/g, '').length < 1);
66
+ },
67
+ join: function (target, delimiter) {
68
+ if (target === null || target === undefined)
69
+ return null;
70
+ if (delimiter)
71
+ return target.join(delimiter);
72
+ else
73
+ return target.join('');
74
+ },
75
+ lastIndexOf: function (target, value) {
76
+ if (target === null || target === undefined)
77
+ return -1;
78
+ if (value === null || value === undefined)
79
+ return -1;
80
+ return target.lastIndexOf(value);
81
+ },
82
+ length: function (target) {
83
+ if (target === null || target === undefined)
84
+ return 0;
85
+ return target.length;
86
+ },
87
+ padLeft: function (target, totalWidth, padding) {
88
+ if (target === null || target === undefined)
89
+ return null;
90
+ if (totalWidth === null || totalWidth === undefined)
91
+ return target;
92
+ if (padding)
93
+ return target.padStart(totalWidth, padding);
94
+ else
95
+ return target.padStart(totalWidth);
96
+ },
97
+ padRight: function (target, totalWidth, padding) {
98
+ if (target === null || target === undefined)
99
+ return null;
100
+ if (totalWidth === null || totalWidth === undefined)
101
+ return target;
102
+ if (padding)
103
+ return target.padEnd(totalWidth, padding);
104
+ else
105
+ return target.padEnd(totalWidth);
106
+ },
107
+ replace: function (target, oldValue, newValue) {
108
+ if (target === null || target === undefined)
109
+ return null;
110
+ if (oldValue === null || oldValue === undefined)
111
+ return target;
112
+ if (newValue === null || newValue === undefined)
113
+ return target;
114
+ return target.replace(new RegExp(oldValue, 'g'), newValue);
115
+ },
116
+ split: function (target, delimiter) {
117
+ if (target === null || target === undefined)
118
+ return [];
119
+ return target.split(delimiter);
120
+ },
121
+ startsWith: function (target, value) {
122
+ if (target === null || target === undefined)
123
+ return false;
124
+ if (value === null || value === undefined)
125
+ return false;
126
+ return target.substring(0, value.length) === value;
127
+ },
128
+ substring: function (target, startIndex, length) {
129
+ if (target === null || target === undefined)
130
+ return null;
131
+ if (startIndex === null || startIndex === undefined)
132
+ return null;
133
+ if (length === null || length === undefined)
134
+ return null;
135
+ return target.substring(startIndex, startIndex + length);
136
+ },
137
+ toLower: function (target) {
138
+ if (target === null || target === undefined)
139
+ return null;
140
+ return target.toLowerCase();
141
+ },
142
+ toUpper: function (target) {
143
+ if (target === null || target === undefined)
144
+ return null;
145
+ return target.toUpperCase();
146
+ },
147
+ trim: function (target) {
148
+ if (target === null || target === undefined)
149
+ return null;
150
+ return target.trim();
151
+ },
152
+ trimEnd: function (target) {
153
+ if (target === null || target === undefined)
154
+ return null;
155
+ return target.trimEnd();
156
+ },
157
+ trimStart: function (target) {
158
+ if (target === null || target === undefined)
159
+ return null;
160
+ return target.trimStart();
161
+ },
162
+ unescapeHtml: function (value) {
163
+ return (value && this._internal_.reHasEscapedHtml.test(value))
164
+ ? value.replace(this._internal_.reEscapedHtml, (entity) => (this._internal_.htmlUnescapes[entity] || "'"))
165
+ : (value || '')
166
+ },
169
167
  };
package/blz-uuid/index.js CHANGED
@@ -1,9 +1,7 @@
1
1
  const Uuid = require('uuid');
2
2
 
3
3
  module.exports = {
4
- Backend: {
5
- uuid: function () {
6
- return Uuid.v4();
7
- }
4
+ uuid: function () {
5
+ return Uuid.v4();
8
6
  }
9
7
  };
package/blz-yaml/index.js CHANGED
@@ -1,22 +1,19 @@
1
- const jsyaml = require('js-yaml');
2
- const { Backend } = require('../blz-rds');
1
+ const jsyaml = require('js-yaml')
3
2
 
4
3
  module.exports = {
5
- Backend: {
6
- yamlParse: function (value) {
7
- if (value === undefined)
8
- throw new Error('value undefined')
9
- if (value === null)
10
- return null
11
- return jsyaml.load(value)
12
- },
13
- yamlStringify: function (value) {
14
- if (value === undefined)
15
- throw new Error('value undefined')
16
- if (value === null)
17
- return null
18
- else
19
- return jsyaml.dump(value)
20
- }
21
- }
4
+ yamlParse: function (value) {
5
+ if (value === undefined)
6
+ throw new Error('value undefined')
7
+ if (value === null)
8
+ return null
9
+ return jsyaml.load(value)
10
+ },
11
+ yamlStringify: function (value) {
12
+ if (value === undefined)
13
+ throw new Error('value undefined')
14
+ if (value === null)
15
+ return null
16
+ else
17
+ return jsyaml.dump(value)
18
+ },
22
19
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blazedpath/commons",
3
- "version": "0.0.10",
3
+ "version": "0.1.0",
4
4
  "description": "commos library for blazedpath applications",
5
5
  "main": "index.js",
6
6
  "types": "dist/index.d.ts",