@vulkano/core 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.
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Filter ltrim
3
+ *
4
+ * Filter.get('custom string', 'ltrim', 'cus');
5
+ * return 'tom string'
6
+ *
7
+ */
8
+ module.exports = {
9
+
10
+ exec: (_str, opt) => {
11
+ let str = _str || '';
12
+ if (opt) {
13
+ while (str.charAt(str.length - 1) === opt) {
14
+ str = str.substr(0, str.length - 1);
15
+ }
16
+ } else {
17
+ while (str.charAt(str.length - 1) === ' ') {
18
+ str = str.substr(0, str.length - 1);
19
+ }
20
+ }
21
+ return str;
22
+ }
23
+
24
+ };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Filter Save Integer
3
+ *
4
+ * Filter.get('580937985977360003193018', 'saveinteger');
5
+ * return true or false
6
+ *
7
+ */
8
+ module.exports = {
9
+
10
+ exec: (str) => {
11
+
12
+ const tmpFn = Number.isSafeInteger || ((value) => {
13
+ const isValid = Number.isInteger(value) && Math.abs(value) <= Number.MAX_SAFE_INTEGER;
14
+ return isValid;
15
+ });
16
+
17
+ return tmpFn(str);
18
+
19
+ }
20
+
21
+ };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Filter suffix
3
+ *
4
+ * Filter.get('custom string', 'suffix', '/');
5
+ * return 'custom string/'
6
+ *
7
+ */
8
+ module.exports = {
9
+
10
+ exec: (str, opt) => {
11
+
12
+ if (str.endsWith(opt)) {
13
+ return str;
14
+ }
15
+ return str + opt;
16
+
17
+ }
18
+
19
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Filter ltrim
3
+ *
4
+ * Filter.get('custom string', 'ltrim', 'cus');
5
+ * return 'tom string'
6
+ *
7
+ */
8
+ module.exports = {
9
+
10
+ exec: (_str, opt) => {
11
+ const str = Filter.get(_str, ['rtrim', 'ltrim'], opt);
12
+ return str;
13
+ }
14
+
15
+ };
package/libs/i18n.js ADDED
@@ -0,0 +1,51 @@
1
+ const i18next = require('i18next');
2
+ const moment = require('moment');
3
+
4
+ require('moment/min/locales.min');
5
+
6
+ moment.locale('en');
7
+
8
+ module.exports = (() => {
9
+
10
+ const {
11
+ config
12
+ } = app || {};
13
+
14
+ let {
15
+ locales: configLocales
16
+ } = config || {};
17
+
18
+ if (!configLocales) {
19
+ configLocales = {
20
+ en: {}
21
+ };
22
+ }
23
+
24
+ const locales = Object.keys(configLocales);
25
+ const resources = new Map();
26
+
27
+ locales.forEach( (locale) => {
28
+ resources.set(locale, { translation: configLocales[locale] });
29
+ });
30
+
31
+ // Change translations
32
+ i18next.init({
33
+ lng: 'en',
34
+ fallbackLng: 'en',
35
+ resources: Object.fromEntries(resources)
36
+ });
37
+
38
+ // catch the event and make changes accordingly
39
+ i18next.on('languageChanged', (lng) => {
40
+
41
+ try {
42
+ moment.locale(lng);
43
+ } catch (err) {
44
+ console.log(err);
45
+ }
46
+
47
+ });
48
+
49
+ return i18next;
50
+
51
+ })();
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@vulkano/core",
3
+ "version": "0.1.0",
4
+ "description": "A MVC framework using Express 4",
5
+ "license": "MIT",
6
+ "author": "Vulkano Team",
7
+ "engines": {
8
+ "node": "^20"
9
+ },
10
+ "main": "init.js",
11
+ "scripts": {
12
+ "test": "echo \"Error: no test specified\" && exit 1"
13
+ },
14
+ "preferGlobal": true,
15
+ "homepage": "https://github.com/vulkanojs/vulkano-core",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/vulkanojs/vulkano-core"
19
+ },
20
+ "keywords": [
21
+ "vulkano",
22
+ "vulkano-core",
23
+ "express",
24
+ "mongo",
25
+ "mongoose"
26
+ ],
27
+ "bugs": {
28
+ "url": "https://github.com/vulkanojs/vulkano-core/issues"
29
+ },
30
+ "dependencies": {
31
+ "@socket.io/redis-adapter": "^8.3.0",
32
+ "bluebird": "^3.7.2",
33
+ "body-parser": "^1.20.2",
34
+ "compression": "^1.7.4",
35
+ "connect-timeout": "^1.9.0",
36
+ "cookie-parser": "^1.4.6",
37
+ "cron": "^3.1.6",
38
+ "deepmerge": "^4.3.1",
39
+ "dotenv": "^16.4.5",
40
+ "express": "^4.19.2",
41
+ "express-jwt": "^8.4.1",
42
+ "express-useragent": "^1.0.15",
43
+ "frameguard": "^4.0.0",
44
+ "fs": "^0.0.1-security",
45
+ "fs-extra": "^11.2.0",
46
+ "helmet": "^7.1.0",
47
+ "i18next": "^23.10.1",
48
+ "include-all": "^4.0.3",
49
+ "jwt-simple": "^0.5.6",
50
+ "moment": "^2.30.1",
51
+ "moment-timezone": "^0.5.45",
52
+ "mongoose": "^8.2.4",
53
+ "mongoose-paginate": "^5.0.3",
54
+ "morgan": "^1.10.0",
55
+ "multer": "^1.4.5-lts.1",
56
+ "nodemon": "^3.1.0",
57
+ "nunjucks": "^3.2.4",
58
+ "path": "^0.12.7",
59
+ "promise.prototype.finally": "^3.1.8",
60
+ "redis": "^4.6.13",
61
+ "socket.io": "^4.7.5",
62
+ "socket.io-client": "4.7.5",
63
+ "underscore": "^1.13.6",
64
+ "webp-middleware": "^0.4.0",
65
+ "yargs": "^17.7.2"
66
+ }
67
+ }
@@ -0,0 +1,87 @@
1
+ /**
2
+ * VULKANO STANDARD RESPONSE (VSR)
3
+ */
4
+
5
+ const Promise = require('bluebird');
6
+
7
+ module.exports = function VSRPromise(promiseToRun, httpStatusCode) {
8
+
9
+ const {
10
+ req
11
+ } = this;
12
+
13
+ const {
14
+ res,
15
+ path
16
+ } = req;
17
+
18
+ let code = httpStatusCode || 200;
19
+ let output = {
20
+ success: true,
21
+ statusCode: code
22
+ };
23
+
24
+ if (!promiseToRun || !promiseToRun.then) {
25
+
26
+ // Log error to console
27
+ console.log('The response is not a promise');
28
+ return res.status(500).jsonp({
29
+ success: false,
30
+ error: {
31
+ detail: 'The response is not a promise.'
32
+ }
33
+ });
34
+
35
+ }
36
+
37
+ // Executing promise
38
+ promiseToRun
39
+ .then( (r) => {
40
+
41
+ if ( (r.statusCode && r.statusCode >= 400) || output.statusCode >= 400) {
42
+
43
+ if (r.statusCode && r.statusCode !== 402) {
44
+ return Promise.reject(r);
45
+ }
46
+
47
+ if ( output.statusCode >= 400 && output.statusCode !== 402 ) {
48
+ return Promise.reject(r);
49
+ }
50
+
51
+ output.statusCode = r.statusCode;
52
+ code = r.statusCode;
53
+
54
+ }
55
+
56
+ output.data = r;
57
+
58
+ return true;
59
+
60
+ })
61
+ .catch( (e) => {
62
+
63
+ if (path) {
64
+ console.log('ERROR PATH', path);
65
+ }
66
+
67
+ if (!app.PRODUCTION) {
68
+ console.log(e);
69
+ }
70
+
71
+ const message = e.message !== undefined && typeof e.message === 'object' ? e.message : e;
72
+ code = message.statusCode || e.statusCode || 400;
73
+
74
+ // Output
75
+ output.success = false;
76
+ output.statusCode = code;
77
+ output.error = {
78
+ errorCode: message.code || '001',
79
+ errorName: message.name || 'BadRequest',
80
+ detail: message.message || message.error || message.invalidAttributes || message.toString(),
81
+ output: message
82
+ };
83
+
84
+ })
85
+ .finally( () => res.status(code).jsonp(output) );
86
+
87
+ };