@radiantabyss/neutralino 1.0.2 → 1.0.3
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/package.json +1 -1
- package/src/Bootstrap.js +4 -3
- package/src/Routing/Route.js +4 -5
- package/src/Routing/RouteCrud.js +2 -0
- package/src/Routing/Router.js +10 -8
- package/src/Support/Config.js +14 -14
- package/src/Support/Str.js +209 -0
- /package/src/{Invoke.js → InvokeData.js} +0 -0
package/package.json
CHANGED
package/src/Bootstrap.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Response from './Response.js';
|
|
2
|
-
import
|
|
2
|
+
import Invoked from './Invoked.js';
|
|
3
3
|
import Validator from './Validator.js';
|
|
4
4
|
import IPC from './IPC.js';
|
|
5
5
|
|
|
@@ -7,18 +7,19 @@ import Config from './Support/Config.js';
|
|
|
7
7
|
import Env from './Support/Env.js';
|
|
8
8
|
import Helpers from './Support/Helpers.js';
|
|
9
9
|
|
|
10
|
+
window.RA.Neu = {};
|
|
11
|
+
|
|
10
12
|
export default () => {
|
|
11
13
|
//helpers
|
|
12
14
|
for ( let key in Helpers ) {
|
|
13
15
|
window[key] = Helpers[key];
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
window.RA = {};
|
|
17
18
|
window.Config = Config;
|
|
18
19
|
window.Env = Env;
|
|
19
20
|
|
|
20
21
|
window.Response = Response;
|
|
21
|
-
window.
|
|
22
|
+
window.Invoked = Invoked;
|
|
22
23
|
window.Validator = Validator;
|
|
23
24
|
window.IPC = IPC;
|
|
24
25
|
};
|
package/src/Routing/Route.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import Str from './../Support/Str';
|
|
2
|
+
|
|
1
3
|
let group_middleware = null;
|
|
2
4
|
|
|
3
5
|
function addRoute(method, path, action, middleware, name, throw_error) {
|
|
@@ -5,9 +7,6 @@ function addRoute(method, path, action, middleware, name, throw_error) {
|
|
|
5
7
|
throw `Action missing for ${path}`;
|
|
6
8
|
}
|
|
7
9
|
|
|
8
|
-
//format path
|
|
9
|
-
path = path.replace(/\{([\s\S]+?)\}/g, ':$1');
|
|
10
|
-
|
|
11
10
|
//get action
|
|
12
11
|
action = action.replace(/\\/g, '.').replace(/\//g, '.');
|
|
13
12
|
let split = action.split('.');
|
|
@@ -21,7 +20,7 @@ function addRoute(method, path, action, middleware, name, throw_error) {
|
|
|
21
20
|
|
|
22
21
|
let component;
|
|
23
22
|
try {
|
|
24
|
-
component = getAction(Actions, split[split.length - 1], namespace, action_name);
|
|
23
|
+
component = getAction(window.RA.Neu.Actions, split[split.length - 1], namespace, action_name);
|
|
25
24
|
}
|
|
26
25
|
catch(e) {
|
|
27
26
|
if ( throw_error ) {
|
|
@@ -30,7 +29,7 @@ function addRoute(method, path, action, middleware, name, throw_error) {
|
|
|
30
29
|
return;
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
window.RA.RouteFiles[__neutralino_route_file].push({
|
|
32
|
+
window.RA.Neu.RouteFiles[window.RA.Neu.__neutralino_route_file].push({
|
|
34
33
|
name: action_name,
|
|
35
34
|
component,
|
|
36
35
|
path,
|
package/src/Routing/RouteCrud.js
CHANGED
package/src/Routing/Router.js
CHANGED
|
@@ -4,9 +4,9 @@ import RouteFiles from './RouteFiles.js';
|
|
|
4
4
|
import Route from './Route.js';
|
|
5
5
|
import RouteCrud from './RouteCrud.js';
|
|
6
6
|
|
|
7
|
-
window.RA.RouteFiles = RouteFiles;
|
|
8
|
-
window.RA.Route = Route;
|
|
9
|
-
window.RA.RouteCrud = RouteCrud;
|
|
7
|
+
window.RA.Neu.RouteFiles = RouteFiles;
|
|
8
|
+
window.RA.Neu.Route = Route;
|
|
9
|
+
window.RA.Neu.RouteCrud = RouteCrud;
|
|
10
10
|
|
|
11
11
|
let Routes = [];
|
|
12
12
|
|
|
@@ -14,15 +14,15 @@ let Routes = [];
|
|
|
14
14
|
let context = import.meta.glob('/app/Routes/**/*.js');
|
|
15
15
|
|
|
16
16
|
const loadModules = async () => {
|
|
17
|
-
window.RA.Actions = await Actions();
|
|
17
|
+
window.RA.Neu.Actions = await Actions();
|
|
18
18
|
const files = Object.keys(context);
|
|
19
19
|
|
|
20
20
|
for ( let i = 0; i < files.length; i++ ) {
|
|
21
21
|
let file = files[i].replace('/app/Routes/', '').replace(/\.js$/, '');
|
|
22
|
-
window.RA.__neutralino_route_file = file;
|
|
22
|
+
window.RA.Neu.__neutralino_route_file = file;
|
|
23
23
|
|
|
24
|
-
if ( !RouteFiles[window.RA.__neutralino_route_file] ) {
|
|
25
|
-
RouteFiles[window.RA.__neutralino_route_file] = [];
|
|
24
|
+
if ( !window.RA.Neu.RouteFiles[window.RA.Neu.__neutralino_route_file] ) {
|
|
25
|
+
window.RA.Neu.RouteFiles[window.RA.Neu.__neutralino_route_file] = [];
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
await context[files[i]]();
|
|
@@ -69,10 +69,12 @@ const match = async(args, event) => {
|
|
|
69
69
|
for (let i = 1; i < match.length; i++) {
|
|
70
70
|
params.push(match[i]);
|
|
71
71
|
}
|
|
72
|
+
|
|
73
|
+
break;
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
|
|
77
|
+
Invoked.data = args.payload;
|
|
76
78
|
params.push(event);
|
|
77
79
|
|
|
78
80
|
return {
|
package/src/Support/Config.js
CHANGED
|
@@ -7,33 +7,33 @@ const self = {
|
|
|
7
7
|
await Neutralino.filesystem.writeFile(`${APP_PATH}/configs/${config}.json`, JSON.stringify(data, null, 4));
|
|
8
8
|
},
|
|
9
9
|
|
|
10
|
-
get(config) {
|
|
11
|
-
return self.read(config);
|
|
10
|
+
async get(config) {
|
|
11
|
+
return await self.read(config);
|
|
12
12
|
},
|
|
13
13
|
|
|
14
|
-
getKey(config, key) {
|
|
15
|
-
let data = self.read(config);
|
|
14
|
+
async getKey(config, key) {
|
|
15
|
+
let data = await self.read(config);
|
|
16
16
|
return data[key];
|
|
17
17
|
},
|
|
18
18
|
|
|
19
|
-
set(config, data) {
|
|
20
|
-
self.write(config, data);
|
|
19
|
+
async set(config, data) {
|
|
20
|
+
await self.write(config, data);
|
|
21
21
|
},
|
|
22
22
|
|
|
23
|
-
setKey(config, key, value) {
|
|
24
|
-
let data = self.read(config);
|
|
23
|
+
async setKey(config, key, value) {
|
|
24
|
+
let data = await self.read(config);
|
|
25
25
|
data[key] = value;
|
|
26
|
-
self.write(config, data);
|
|
26
|
+
await self.write(config, data);
|
|
27
27
|
},
|
|
28
28
|
|
|
29
|
-
deleteKey(config, key) {
|
|
30
|
-
let data = self.read(config);
|
|
29
|
+
async deleteKey(config, key) {
|
|
30
|
+
let data = await self.read(config);
|
|
31
31
|
delete data[key];
|
|
32
|
-
self.write(config, data);
|
|
32
|
+
await self.write(config, data);
|
|
33
33
|
},
|
|
34
34
|
|
|
35
|
-
clear(config) {
|
|
36
|
-
self.write(config, {});
|
|
35
|
+
async clear(config) {
|
|
36
|
+
await self.write(config, {});
|
|
37
37
|
},
|
|
38
38
|
};
|
|
39
39
|
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
let self = {
|
|
2
|
+
/*helpers from https://github.com/validatorjs/validator.js*/
|
|
3
|
+
ltrim(str, chars) {
|
|
4
|
+
const pattern = chars ? new RegExp(`^[${chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}]+`, 'g') : /^\s+/g;
|
|
5
|
+
return `${str}`.replace(pattern, '');
|
|
6
|
+
},
|
|
7
|
+
|
|
8
|
+
rtrim(str, chars) {
|
|
9
|
+
const pattern = chars ? new RegExp(`[${chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}]+$`, 'g') : /(\s)+$/g;
|
|
10
|
+
return `${str}`.replace(pattern, '');
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
trim(str, chars) {
|
|
14
|
+
return self.rtrim(self.ltrim(`${str}`, chars), chars);
|
|
15
|
+
},
|
|
16
|
+
/*end helpers from https://github.com/validatorjs/validator.js*/
|
|
17
|
+
|
|
18
|
+
urlencode(str) {
|
|
19
|
+
return encodeURIComponent(str);
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
slug(str) {
|
|
23
|
+
str = str.replace(/^\s+|\s+$/g, ''); // trim
|
|
24
|
+
str = str.toLowerCase();
|
|
25
|
+
|
|
26
|
+
// remove accents, swap ñ for n, etc
|
|
27
|
+
var from = "àáãäâèéëêìíïîòóöôùúüûñç·/_,:;";
|
|
28
|
+
var to = "aaaaaeeeeiiiioooouuuunc------";
|
|
29
|
+
|
|
30
|
+
for (var i=0, l=from.length ; i<l ; i++) {
|
|
31
|
+
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
|
|
35
|
+
.replace(/\s+/g, '-') // collapse whitespace and replace by -
|
|
36
|
+
.replace(/-+/g, '-'); // collapse dashes
|
|
37
|
+
|
|
38
|
+
return str;
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
dash(str) {
|
|
42
|
+
return str.split('').map((letter, idx) => {
|
|
43
|
+
return letter.toUpperCase() === letter
|
|
44
|
+
? `${idx !== 0 ? '-' : ''}${letter.toLowerCase()}`
|
|
45
|
+
: letter;
|
|
46
|
+
}).join('');
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
snake(string) {
|
|
50
|
+
return string
|
|
51
|
+
.replace(/\s+(?=\d)/g, '')
|
|
52
|
+
.replace(/\s+/g, '_')
|
|
53
|
+
.replace(/([a-z])([A-Z])/g, '$1_$2')
|
|
54
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
|
|
55
|
+
.toLowerCase();
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
camel(str) {
|
|
59
|
+
return str.replace(/-/g, ' ').replace(/_/g, ' ').replace(/(^([a-zA-Z\p{M}]))|([ -][a-zA-Z\p{M}])/g,function(s) {
|
|
60
|
+
return s.toUpperCase();
|
|
61
|
+
}).replace(/\s+/g, '');
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
pascal(str) {
|
|
65
|
+
return `${str}`
|
|
66
|
+
.toLowerCase()
|
|
67
|
+
.replace(new RegExp(/[-_]+/, 'g'), ' ')
|
|
68
|
+
.replace(new RegExp(/[^\w\s]/, 'g'), '')
|
|
69
|
+
.replace(new RegExp(/\s+(.)(\w*)/, 'g'), ($1, $2, $3) => `${$2.toUpperCase() + $3}`)
|
|
70
|
+
.replace(new RegExp(/\w/), s => s.toUpperCase());
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
kebab(str) {
|
|
74
|
+
return `${str}`.replace(/([a-z])([A-Z])/g, "$1-$2")
|
|
75
|
+
.replace(/[\s_]+/g, '-')
|
|
76
|
+
.toLowerCase();
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
camel2space(str) {
|
|
80
|
+
if ( !str ) {
|
|
81
|
+
return '';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return str.split('').map((letter, idx) => {
|
|
85
|
+
return letter.toUpperCase() === letter
|
|
86
|
+
? `${idx !== 0 ? ' ' : ''}${letter}`
|
|
87
|
+
: letter;
|
|
88
|
+
}).join('');
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
ucfirst(string) {
|
|
92
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
ucwords(str) {
|
|
96
|
+
if ( !str ) {
|
|
97
|
+
str = '';
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//ensure string
|
|
101
|
+
str = str + '';
|
|
102
|
+
|
|
103
|
+
return str.replace(/-/g, ' ').replace(/_/g, ' ').replace(/(^([a-zA-Z\p{M}]))|([ -][a-zA-Z\p{M}])/g,function(s) {
|
|
104
|
+
return s.toUpperCase();
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
ordinal_suffix(i) {
|
|
109
|
+
var j = i % 10,
|
|
110
|
+
k = i % 100;
|
|
111
|
+
if (j == 1 && k != 11) {
|
|
112
|
+
return i + "st";
|
|
113
|
+
}
|
|
114
|
+
if (j == 2 && k != 12) {
|
|
115
|
+
return i + "nd";
|
|
116
|
+
}
|
|
117
|
+
if (j == 3 && k != 13) {
|
|
118
|
+
return i + "rd";
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return i + "th";
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
number_to_month(number) {
|
|
125
|
+
let months = {
|
|
126
|
+
1: 'January',
|
|
127
|
+
2: 'February',
|
|
128
|
+
3: 'March',
|
|
129
|
+
4: 'April',
|
|
130
|
+
5: 'May',
|
|
131
|
+
6: 'June',
|
|
132
|
+
7: 'July',
|
|
133
|
+
8: 'August',
|
|
134
|
+
9: 'September',
|
|
135
|
+
10: 'October',
|
|
136
|
+
11: 'November',
|
|
137
|
+
12: 'December',
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
return months[`${number}`.replace(/^0/, '')];
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
nl2br(str) {
|
|
144
|
+
if ( !str || !str.length ) {
|
|
145
|
+
return '';
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return str.replace(/(\r\n|\n\r|\r|\n)/g, '<br/>' + '$1');
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
strip_tags(str) {
|
|
152
|
+
var div = document.createElement("div");
|
|
153
|
+
div.innerHTML = str;
|
|
154
|
+
var text = div.textContent || div.innerText || "";
|
|
155
|
+
return text;
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
ensure_https(string) {
|
|
159
|
+
if (!string.match(/^[a-zA-Z]+:\/\//)) {
|
|
160
|
+
string = 'https://' + string;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return string;
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
add_commas(number) {
|
|
167
|
+
if ( number === undefined || number === null ) {
|
|
168
|
+
return '';
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
number = parseFloat(number).toFixed(2).toLocaleString('en-US');
|
|
172
|
+
|
|
173
|
+
return number;
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
leading_zero(number) {
|
|
177
|
+
return number < 10 ? `0${number}` : number;
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
to_percetange(number) {
|
|
181
|
+
if ( number === undefined || !number ) {
|
|
182
|
+
return '0%';
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return (number / 10)+'%';
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
plural(str) {
|
|
189
|
+
if ( str.match(/y$/) ) {
|
|
190
|
+
return str.replace(/y$/, 'ies');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if ( str.match(/s$/) ) {
|
|
194
|
+
return `${str}es`;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return `${str}s`;
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
truncate(str, length) {
|
|
201
|
+
if (str.length > length) {
|
|
202
|
+
return str.slice(0, length) + '...';
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return str;
|
|
206
|
+
},
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export default self;
|
|
File without changes
|