@fullstackunicorn/initialize 1.0.7 → 1.0.9
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 +30 -5
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -72,6 +72,14 @@ globalThis.F3.promise = async (func, data) => {
|
|
|
72
72
|
})
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
globalThis.F3.promises = async (tasks = {}) => {
|
|
76
|
+
const entries = Object.entries(tasks)
|
|
77
|
+
const results = await Promise.all(entries.map(([key, fn]) => fn()))
|
|
78
|
+
const output = {}
|
|
79
|
+
entries.forEach(([key], i) => output[key] = results[i])
|
|
80
|
+
return output
|
|
81
|
+
}
|
|
82
|
+
|
|
75
83
|
globalThis.F3.res = {}
|
|
76
84
|
globalThis.F3.res.isGood = res => {
|
|
77
85
|
if (F3.isNil(res)) return false
|
|
@@ -105,10 +113,9 @@ globalThis.F3.throw = (...args) => { throw new F3Error(F3.service, ...args) }
|
|
|
105
113
|
globalThis.F3.err = {}
|
|
106
114
|
globalThis.F3.err.is500 = status => !!status && status >= 500
|
|
107
115
|
globalThis.F3.err.is400 = status => !!status && status >= 400 && status < 500
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
try { return Object.assign(base, Object.fromEntries(Object.entries(err)))}
|
|
116
|
+
globalThis.F3.err.toObj = err => {
|
|
117
|
+
const base = { name: err.name, message: err.message, stack: err.stack }
|
|
118
|
+
try { return Object.assign(base, Object.fromEntries(Object.entries(err))) }
|
|
112
119
|
catch { return base }
|
|
113
120
|
}
|
|
114
121
|
globalThis.F3.err.toStr = err => {
|
|
@@ -119,7 +126,25 @@ globalThis.F3.err.toStr = err => {
|
|
|
119
126
|
}
|
|
120
127
|
globalThis.F3.err.logs = err => {
|
|
121
128
|
if (err instanceof F3Error) console.error(F3.obj.toStr(err))
|
|
122
|
-
else console.error('non-F3-error',F3.obj.toStr(err))
|
|
129
|
+
else console.error('non-F3-error', F3.obj.toStr(err))
|
|
130
|
+
}
|
|
131
|
+
globalThis.F3.err.isOffline = (error) => {
|
|
132
|
+
if (!F3.obj.isGood(error)) return false
|
|
133
|
+
return (
|
|
134
|
+
error.code === 'ECONNABORTED' ||
|
|
135
|
+
error.code === 'ERR_NETWORK' ||
|
|
136
|
+
error.message.includes('Network Error') ||
|
|
137
|
+
error.message.includes('timeout')
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
globalThis.F3.err.cache = async (error, cached) => {
|
|
141
|
+
if (!F3.err.isOffline(error)) return { isError: true }
|
|
142
|
+
if (cached) return cached
|
|
143
|
+
return { isOffline: true }
|
|
144
|
+
}
|
|
145
|
+
globalThis.F3.err.handle = (error) => {
|
|
146
|
+
if (!F3.err.isOffline(error)) return { isError: true }
|
|
147
|
+
return { isOffline: true }
|
|
123
148
|
}
|
|
124
149
|
|
|
125
150
|
globalThis.F3.catch = {}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.
|
|
2
|
+
"version": "1.0.9",
|
|
3
3
|
"name": "@fullstackunicorn/initialize",
|
|
4
4
|
"author": "lucanigido (https://fullstackunicorn.dev/author/lucanigido)",
|
|
5
5
|
"description": "A collection of global utility functions for JavaScript/Node.js projects (type checks, string helpers, logging, etc.). Side-effect import extends globals.",
|