@fullstackunicorn/initialize 1.0.0 → 1.0.1
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/index.js +32 -27
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
String.prototype.cap = function () { return this[0].toUpperCase() + this.slice(1) }
|
|
2
2
|
String.prototype.up = function () { return this.toUpperCase() }
|
|
3
3
|
String.prototype.low = function () { return this.toLowerCase() }
|
|
4
|
-
String.prototype.cut = function (n=1) { return this.slice(0, -n) }
|
|
4
|
+
String.prototype.cut = function (n = 1) { return this.slice(0, -n) }
|
|
5
|
+
|
|
6
|
+
class F3Error extends Error {
|
|
7
|
+
constructor(service, message, params = {}) {
|
|
8
|
+
super(message)
|
|
9
|
+
this.service = service
|
|
10
|
+
this.params = params
|
|
11
|
+
}
|
|
12
|
+
}
|
|
5
13
|
|
|
6
14
|
globalThis.F3 = {}
|
|
15
|
+
|
|
16
|
+
globalThis.F3.service = ''
|
|
17
|
+
|
|
7
18
|
globalThis.F3.isArr = value => Array.isArray(value)
|
|
8
19
|
globalThis.F3.isNil = value => value === undefined || value === null
|
|
9
20
|
globalThis.F3.isFnc = value => typeof value === 'function'
|
|
@@ -36,20 +47,6 @@ globalThis.F3.obj.string = obj => {
|
|
|
36
47
|
try { return JSON.stringify(obj, null, 2) } catch { return String(obj) }
|
|
37
48
|
}
|
|
38
49
|
|
|
39
|
-
globalThis.F3.res = {}
|
|
40
|
-
globalThis.F3.res.isGood = res => {
|
|
41
|
-
if (F3.isNil(res)) return false
|
|
42
|
-
if (F3.isStr(res)) return F3.str.isGood(res)
|
|
43
|
-
if (F3.isArr(res)) return F3.arr.isGood(res)
|
|
44
|
-
if (F3.isObj(res)) {
|
|
45
|
-
if (!F3.obj.isGood(res)) return false
|
|
46
|
-
if (res.isError === true) return false
|
|
47
|
-
if (res.isOffline === true) return false
|
|
48
|
-
return true
|
|
49
|
-
}
|
|
50
|
-
return Boolean(res)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
50
|
globalThis.F3.fabUrl = (path = '', params = {}) => {
|
|
54
51
|
return path.replace(/:(\w+)/g, (_, key) => {
|
|
55
52
|
return params[key] !== undefined ? params[key] : `:${key}`
|
|
@@ -65,6 +62,20 @@ globalThis.F3.replacer = (string = '', values = {}) => {
|
|
|
65
62
|
return newString
|
|
66
63
|
}
|
|
67
64
|
|
|
65
|
+
globalThis.F3.res = {}
|
|
66
|
+
globalThis.F3.res.isGood = res => {
|
|
67
|
+
if (F3.isNil(res)) return false
|
|
68
|
+
if (F3.isStr(res)) return F3.str.isGood(res)
|
|
69
|
+
if (F3.isArr(res)) return F3.arr.isGood(res)
|
|
70
|
+
if (F3.isObj(res)) {
|
|
71
|
+
if (!F3.obj.isGood(res)) return false
|
|
72
|
+
if (res.isError === true) return false
|
|
73
|
+
if (res.isOffline === true) return false
|
|
74
|
+
return true
|
|
75
|
+
}
|
|
76
|
+
return Boolean(res)
|
|
77
|
+
}
|
|
78
|
+
|
|
68
79
|
globalThis.F3.logs = (...args) => console.log(...args)
|
|
69
80
|
|
|
70
81
|
globalThis.F3.log = {}
|
|
@@ -73,8 +84,8 @@ globalThis.F3.log.obj = (object = {}, ...rest) => {
|
|
|
73
84
|
const result = []
|
|
74
85
|
for (const item of rest) result.push(String(item))
|
|
75
86
|
for (const key of Object.keys(object)) {
|
|
76
|
-
try { result.push(`\n${key}:\n${F3.obj.string(object[key])}\n`)}
|
|
77
|
-
catch { result.push(`\n${key}: [Error serializing value]\n`)}
|
|
87
|
+
try { result.push(`\n${key}:\n${F3.obj.string(object[key])}\n`) }
|
|
88
|
+
catch { result.push(`\n${key}: [Error serializing value]\n`) }
|
|
78
89
|
}
|
|
79
90
|
console.log(result.join('\n'))
|
|
80
91
|
}
|
|
@@ -84,17 +95,11 @@ globalThis.F3.err.is500 = status => !!status && status >= 500
|
|
|
84
95
|
globalThis.F3.err.is400 = status => !!status && status >= 400 && status < 500
|
|
85
96
|
|
|
86
97
|
globalThis.F3.catch = {}
|
|
98
|
+
globalThis.F3.catch.throw = error => { throw error }
|
|
99
|
+
globalThis.F3.catch.log = (...args) => console.log(...args)
|
|
87
100
|
globalThis.F3.catch.res = (first, ...rest) => {
|
|
88
101
|
if (rest.length > 0) console.log(...rest)
|
|
89
102
|
return first
|
|
90
103
|
}
|
|
91
|
-
|
|
92
|
-
globalThis.F3.
|
|
93
|
-
const result = []
|
|
94
|
-
for (const item of rest) result.push(String(item))
|
|
95
|
-
for (const key of Object.keys(object)) {
|
|
96
|
-
try { result.push(`\n${key}:\n${F3.obj.string(object[key])}\n`)}
|
|
97
|
-
catch { result.push(`\n${key}: [Error serializing value]\n`)}
|
|
98
|
-
}
|
|
99
|
-
console.log(result.join('\n'))
|
|
100
|
-
}
|
|
104
|
+
|
|
105
|
+
globalThis.F3.throw = (message, params) => { throw new F3Error(F3.service, message, params) }
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fullstackunicorn/initialize",
|
|
3
3
|
"author": "lucanigido[](https://fullstackunicorn.dev/author/lucanigido)",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -30,4 +30,4 @@
|
|
|
30
30
|
"scripts": {
|
|
31
31
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
32
32
|
}
|
|
33
|
-
}
|
|
33
|
+
}
|