@fullstackunicorn/initialize 1.0.0 → 1.0.2

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.
Files changed (2) hide show
  1. package/index.js +41 -27
  2. package/package.json +18 -15
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,26 @@ globalThis.F3.replacer = (string = '', values = {}) => {
65
62
  return newString
66
63
  }
67
64
 
65
+ globalThis.F3.promise = async (func, data) => {
66
+ return new Promise((resolve, reject) => {
67
+ func(data, (error, output) => { if (error) reject(error); else resolve(output) })
68
+ })
69
+ }
70
+
71
+ globalThis.F3.res = {}
72
+ globalThis.F3.res.isGood = res => {
73
+ if (F3.isNil(res)) return false
74
+ if (F3.isStr(res)) return F3.str.isGood(res)
75
+ if (F3.isArr(res)) return F3.arr.isGood(res)
76
+ if (F3.isObj(res)) {
77
+ if (!F3.obj.isGood(res)) return false
78
+ if (res.isError === true) return false
79
+ if (res.isOffline === true) return false
80
+ return true
81
+ }
82
+ return Boolean(res)
83
+ }
84
+
68
85
  globalThis.F3.logs = (...args) => console.log(...args)
69
86
 
70
87
  globalThis.F3.log = {}
@@ -73,8 +90,8 @@ globalThis.F3.log.obj = (object = {}, ...rest) => {
73
90
  const result = []
74
91
  for (const item of rest) result.push(String(item))
75
92
  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`)}
93
+ try { result.push(`\n${key}:\n${F3.obj.string(object[key])}\n`) }
94
+ catch { result.push(`\n${key}: [Error serializing value]\n`) }
78
95
  }
79
96
  console.log(result.join('\n'))
80
97
  }
@@ -84,17 +101,14 @@ globalThis.F3.err.is500 = status => !!status && status >= 500
84
101
  globalThis.F3.err.is400 = status => !!status && status >= 400 && status < 500
85
102
 
86
103
  globalThis.F3.catch = {}
104
+ globalThis.F3.catch.throw = (error, ...rest) => {
105
+ if (rest.length > 0) console.log(...rest)
106
+ throw error
107
+ }
108
+ globalThis.F3.catch.log = (...args) => console.log(...args)
87
109
  globalThis.F3.catch.res = (first, ...rest) => {
88
110
  if (rest.length > 0) console.log(...rest)
89
111
  return first
90
112
  }
91
- globalThis.F3.catch.arr = (...args) => console.log(...args)
92
- globalThis.F3.catch.obj = (object = {}, ...rest) => {
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
- }
113
+
114
+ globalThis.F3.throw = (message, params) => { throw new F3Error(F3.service, message, params) }
package/package.json CHANGED
@@ -1,22 +1,12 @@
1
1
  {
2
+ "version": "1.0.2",
2
3
  "name": "@fullstackunicorn/initialize",
3
- "author": "lucanigido[](https://fullstackunicorn.dev/author/lucanigido)",
4
- "version": "1.0.0",
4
+ "author": "lucanigido (https://fullstackunicorn.dev/author/lucanigido)",
5
+ "description": "A collection of global utility functions for JavaScript/Node.js projects (type checks, string helpers, logging, etc.). Side-effect import extends globals.",
6
+ "readme": "README.md",
5
7
  "main": "index.js",
6
8
  "type": "module",
7
9
  "license": "MIT",
8
- "private": false,
9
- "description": "A collection of global utility functions for JavaScript/Node.js projects (type checks, string helpers, logging, etc.). Side-effect import extends globals.",
10
- "readme": "README.md",
11
- "keywords": [
12
- "utilities",
13
- "helpers",
14
- "global",
15
- "javascript",
16
- "node",
17
- "type-checks",
18
- "logging"
19
- ],
20
10
  "repository": {
21
11
  "type": "git",
22
12
  "url": "https://gitlab.com/fullstackunicorn/initialize.git"
@@ -27,7 +17,20 @@
27
17
  "sideEffects": [
28
18
  "index.js"
29
19
  ],
20
+ "keywords": [
21
+ "utilities",
22
+ "helpers",
23
+ "global",
24
+ "javascript",
25
+ "node",
26
+ "type-checks",
27
+ "logging"
28
+ ],
29
+ "imports": {
30
+ "#@": "./",
31
+ "#@/*": "./*"
32
+ },
30
33
  "scripts": {
31
34
  "test": "echo \"Error: no test specified\" && exit 1"
32
35
  }
33
- }
36
+ }