bajo 0.1.0 → 0.2.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/bajoBook/book/doc/.metadata.json +28 -0
- package/bajoBook/book/doc/How-to-Make-a-Paper-Boat-564x400@2x.jpg +0 -0
- package/bajoBook/book/doc/pages/guides/definition.md +7 -0
- package/bajoBook/book/doc/pages/guides/intro.md +3 -0
- package/bajoBook/book/doc/pages/guides/setup.md +22 -0
- package/bajoBook/book/reference/.metadata.json +152 -0
- package/bajoBook/book/reference/concept-leadership-business-with-paper-boats.jpg +0 -0
- package/bajoBook/book/reference/pages/configuration/configuration-file.md +52 -0
- package/bajoBook/book/reference/pages/helper/break-ns-path.md +24 -0
- package/bajoBook/book/reference/pages/helper/build-collections.md +19 -0
- package/bajoBook/book/reference/pages/helper/call-helper-or-handler.md +35 -0
- package/bajoBook/book/reference/pages/helper/current-loc.md +28 -0
- package/bajoBook/book/reference/pages/helper/dayjs.md +13 -0
- package/bajoBook/book/reference/pages/helper/defaults-deep.md +29 -0
- package/bajoBook/book/reference/pages/helper/dump.md +32 -0
- package/bajoBook/book/reference/pages/helper/each-plugins.md +24 -0
- package/bajoBook/book/reference/pages/helper/envs.md +11 -0
- package/bajoBook/book/reference/pages/helper/error.md +29 -0
- package/bajoBook/book/reference/pages/helper/fatal.md +18 -0
- package/bajoBook/book/reference/pages/helper/freeze.md +13 -0
- package/bajoBook/book/reference/pages/helper/generate-id.md +36 -0
- package/bajoBook/book/reference/pages/helper/get-config.md +27 -0
- package/bajoBook/book/reference/pages/helper/get-global-module-dir.md +13 -0
- package/bajoBook/book/reference/pages/helper/get-helper.md +13 -0
- package/bajoBook/book/reference/pages/helper/get-item-by-name.md +13 -0
- package/bajoBook/book/reference/pages/helper/get-key-by-value.md +13 -0
- package/bajoBook/book/reference/pages/helper/get-module-dir.md +13 -0
- package/bajoBook/book/reference/pages/helper/get-plugin-data-dir.md +13 -0
- package/bajoBook/book/reference/pages/helper/get-plugin-name.md +13 -0
- package/bajoBook/book/reference/pages/helper/get-plugin.md +13 -0
- package/bajoBook/book/reference/pages/helper/import-module.md +13 -0
- package/bajoBook/book/reference/pages/helper/import-pkg.md +13 -0
- package/bajoBook/book/reference/pages/helper/is-empty-dir.md +13 -0
- package/bajoBook/book/reference/pages/helper/is-log-in-range.md +13 -0
- package/bajoBook/book/reference/pages/helper/is-set.md +13 -0
- package/bajoBook/book/reference/pages/helper/is-valid-app.md +13 -0
- package/bajoBook/book/reference/pages/helper/is-valid-plugin.md +13 -0
- package/bajoBook/book/reference/pages/helper/log-levels.md +13 -0
- package/bajoBook/book/reference/pages/helper/log.md +13 -0
- package/bajoBook/book/reference/pages/helper/paginate.md +13 -0
- package/bajoBook/book/reference/pages/helper/pascal-case.md +13 -0
- package/bajoBook/book/reference/pages/helper/print.md +13 -0
- package/bajoBook/book/reference/pages/helper/read-config.md +13 -0
- package/bajoBook/book/reference/pages/helper/read-json.md +13 -0
- package/bajoBook/book/reference/pages/helper/resolve-path.md +13 -0
- package/bajoBook/book/reference/pages/helper/resolve-tpl-path.md +13 -0
- package/bajoBook/book/reference/pages/helper/run-hook.md +13 -0
- package/bajoBook/book/reference/pages/helper/save-as-download.md +13 -0
- package/bajoBook/book/reference/pages/helper/titleize.md +13 -0
- package/bajoBook/book/reference/pages/helper/white-space.md +13 -0
- package/boot/attach-helper.js +8 -0
- package/boot/build-config.js +8 -3
- package/boot/exit-handler.js +3 -1
- package/boot/helper/break-ns-path.js +17 -0
- package/boot/helper/build-collections.js +17 -23
- package/boot/helper/each-plugins.js +59 -49
- package/boot/helper/error.js +22 -2
- package/boot/helper/generate-id.js +4 -3
- package/boot/helper/get-config.js +3 -2
- package/boot/helper/get-global-module-dir.js +2 -2
- package/boot/helper/get-helper.js +2 -1
- package/boot/helper/get-module-dir.js +23 -11
- package/boot/helper/get-module-dir.js__ +50 -0
- package/boot/helper/get-plugin-data-dir.js +12 -0
- package/boot/helper/get-plugin.js +9 -2
- package/boot/helper/paginate.js +26 -0
- package/boot/helper/print.js +12 -2
- package/boot/helper/resolve-tpl-path.js +5 -11
- package/boot/helper/save-as-download.js +2 -3
- package/boot/helper/titleize.js +14 -0
- package/boot/lib/build-helper.js +1 -2
- package/boot/plugins/build-config.js +11 -4
- package/boot/plugins/collect-hooks.js +10 -9
- package/package.json +1 -1
- package/boot/helper/index.js +0 -36
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"book": {
|
|
3
|
+
"title": "Bajo Framework - User Guides",
|
|
4
|
+
"description": "Getting started for new user, the basics and advanced topics",
|
|
5
|
+
"author": "Ardhi Lukianto <ardhi@lukianto.com>",
|
|
6
|
+
"meta": {
|
|
7
|
+
"externalLink": {
|
|
8
|
+
"Github": "https://github.com/ardhi/bajo",
|
|
9
|
+
"NPM": "https://www.npmjs.com/package/bajo"
|
|
10
|
+
},
|
|
11
|
+
"coverImage": "How-to-Make-a-Paper-Boat-564x400@2x.jpg"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"pages": {
|
|
15
|
+
"guides": {
|
|
16
|
+
"level": "1"
|
|
17
|
+
},
|
|
18
|
+
"guides/definition": {
|
|
19
|
+
"level": "1.1"
|
|
20
|
+
},
|
|
21
|
+
"guides/intro": {
|
|
22
|
+
"level": "1.2"
|
|
23
|
+
},
|
|
24
|
+
"guides/setup": {
|
|
25
|
+
"level": "1.3"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Instalation & Setup
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Installation is quite straight forward; in your app project directory, enter following command:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
$ npm install bajo-book
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Then in your data directory, find ```config``` folder and add the package in ```bajo.json``` file:
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"log": {
|
|
16
|
+
"level": "debug"
|
|
17
|
+
},
|
|
18
|
+
"plugins": ["bajo-db", "bajo-web", "bajo-web-mpa", "bajo-web-static", "bajo-book"]
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
After app restart, all books found in plugins will be rebuilt and displayed as web pages in ```/book``` mountpoint (or any prefix you've put in ```bajoBook.json```)
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
{
|
|
2
|
+
"book": {
|
|
3
|
+
"title": "Bajo Framework - Reference",
|
|
4
|
+
"description": "Framework reference, API and developer related documentation",
|
|
5
|
+
"author": "Ardhi Lukianto <ardhi@lukianto.com>",
|
|
6
|
+
"meta": {
|
|
7
|
+
"externalLink": {
|
|
8
|
+
"Github": "https://github.com/ardhi/bajo",
|
|
9
|
+
"NPM": "https://www.npmjs.com/package/bajo"
|
|
10
|
+
},
|
|
11
|
+
"coverImage": "concept-leadership-business-with-paper-boats.jpg",
|
|
12
|
+
"coverImageAttr": "<a href=\"https://www.freepik.com/free-photo/concept-leadership-business-with-paper-boats_40312961.htm#page=2&query=paper%20boat&position=45&from_view=search&track=ais\">Image by atlascompany</a> on Freepik"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"pages": {
|
|
16
|
+
"configuration": {
|
|
17
|
+
"level": "1"
|
|
18
|
+
},
|
|
19
|
+
"configuration/configuration-file": {
|
|
20
|
+
"level": "1.1"
|
|
21
|
+
},
|
|
22
|
+
"helper": {
|
|
23
|
+
"level": "2"
|
|
24
|
+
},
|
|
25
|
+
"helper/break-ns-path": {
|
|
26
|
+
"level": "2.1"
|
|
27
|
+
},
|
|
28
|
+
"helper/build-collections": {
|
|
29
|
+
"level": "2.2"
|
|
30
|
+
},
|
|
31
|
+
"helper/call-helper-or-handler": {
|
|
32
|
+
"level": "2.3"
|
|
33
|
+
},
|
|
34
|
+
"helper/current-loc": {
|
|
35
|
+
"level": "2.4"
|
|
36
|
+
},
|
|
37
|
+
"helper/dayjs": {
|
|
38
|
+
"level": "2.5"
|
|
39
|
+
},
|
|
40
|
+
"helper/defaults-deep": {
|
|
41
|
+
"level": "2.6"
|
|
42
|
+
},
|
|
43
|
+
"helper/dump": {
|
|
44
|
+
"level": "2.7"
|
|
45
|
+
},
|
|
46
|
+
"helper/each-plugins": {
|
|
47
|
+
"level": "2.8"
|
|
48
|
+
},
|
|
49
|
+
"helper/envs": {
|
|
50
|
+
"level": "2.9"
|
|
51
|
+
},
|
|
52
|
+
"helper/error": {
|
|
53
|
+
"level": "2.10"
|
|
54
|
+
},
|
|
55
|
+
"helper/fatal": {
|
|
56
|
+
"level": "2.11"
|
|
57
|
+
},
|
|
58
|
+
"helper/freeze": {
|
|
59
|
+
"level": "2.12"
|
|
60
|
+
},
|
|
61
|
+
"helper/generate-id": {
|
|
62
|
+
"level": "2.13"
|
|
63
|
+
},
|
|
64
|
+
"helper/get-config": {
|
|
65
|
+
"level": "2.14"
|
|
66
|
+
},
|
|
67
|
+
"helper/get-global-module-dir": {
|
|
68
|
+
"level": "2.15"
|
|
69
|
+
},
|
|
70
|
+
"helper/get-helper": {
|
|
71
|
+
"level": "2.16"
|
|
72
|
+
},
|
|
73
|
+
"helper/get-item-by-name": {
|
|
74
|
+
"level": "2.17"
|
|
75
|
+
},
|
|
76
|
+
"helper/get-key-by-value": {
|
|
77
|
+
"level": "2.18"
|
|
78
|
+
},
|
|
79
|
+
"helper/get-module-dir": {
|
|
80
|
+
"level": "2.19"
|
|
81
|
+
},
|
|
82
|
+
"helper/get-plugin": {
|
|
83
|
+
"level": "2.20"
|
|
84
|
+
},
|
|
85
|
+
"helper/get-plugin-data-dir": {
|
|
86
|
+
"level": "2.21"
|
|
87
|
+
},
|
|
88
|
+
"helper/get-plugin-name": {
|
|
89
|
+
"level": "2.22"
|
|
90
|
+
},
|
|
91
|
+
"helper/import-module": {
|
|
92
|
+
"level": "2.23"
|
|
93
|
+
},
|
|
94
|
+
"helper/import-pkg": {
|
|
95
|
+
"level": "2.24"
|
|
96
|
+
},
|
|
97
|
+
"helper/is-empty-dir": {
|
|
98
|
+
"level": "2.25"
|
|
99
|
+
},
|
|
100
|
+
"helper/is-log-in-range": {
|
|
101
|
+
"level": "2.26"
|
|
102
|
+
},
|
|
103
|
+
"helper/is-set": {
|
|
104
|
+
"level": "2.27"
|
|
105
|
+
},
|
|
106
|
+
"helper/is-valid-app": {
|
|
107
|
+
"level": "2.28"
|
|
108
|
+
},
|
|
109
|
+
"helper/is-valid-plugin": {
|
|
110
|
+
"level": "2.29"
|
|
111
|
+
},
|
|
112
|
+
"helper/log": {
|
|
113
|
+
"level": "2.30"
|
|
114
|
+
},
|
|
115
|
+
"helper/log-levels": {
|
|
116
|
+
"level": "2.31"
|
|
117
|
+
},
|
|
118
|
+
"helper/paginate": {
|
|
119
|
+
"level": "2.32"
|
|
120
|
+
},
|
|
121
|
+
"helper/pascal-case": {
|
|
122
|
+
"level": "2.33"
|
|
123
|
+
},
|
|
124
|
+
"helper/print": {
|
|
125
|
+
"level": "2.34"
|
|
126
|
+
},
|
|
127
|
+
"helper/read-config": {
|
|
128
|
+
"level": "2.35"
|
|
129
|
+
},
|
|
130
|
+
"helper/read-json": {
|
|
131
|
+
"level": "2.36"
|
|
132
|
+
},
|
|
133
|
+
"helper/resolve-path": {
|
|
134
|
+
"level": "2.37"
|
|
135
|
+
},
|
|
136
|
+
"helper/resolve-tpl-path": {
|
|
137
|
+
"level": "2.38"
|
|
138
|
+
},
|
|
139
|
+
"helper/run-hook": {
|
|
140
|
+
"level": "2.39"
|
|
141
|
+
},
|
|
142
|
+
"helper/save-as-download": {
|
|
143
|
+
"level": "2.40"
|
|
144
|
+
},
|
|
145
|
+
"helper/titleize": {
|
|
146
|
+
"level": "2.41"
|
|
147
|
+
},
|
|
148
|
+
"helper/white-space": {
|
|
149
|
+
"level": "2.42"
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Configuration file should be placed inside app data directory: ```<data dir>/config/bajo.json```. Supported format: **.json** and **.js** file. If you use ```bajo-config```, you can also write config
|
|
2
|
+
file in YAML or TOML format. But we recommend to stick with good old JSON file.
|
|
3
|
+
|
|
4
|
+
The following table lists all keys used to control running app:
|
|
5
|
+
|
|
6
|
+
| Key | Type | Default | Description |
|
|
7
|
+
| --- | ---- | ------- | ----------- |
|
|
8
|
+
| ```dir``` | object |||
|
|
9
|
+
| ```base``` | string | _Autodetect_ | Your app base directory. _Readonly_ |
|
|
10
|
+
| ```pkg``` | string | _Autodetect_ | **bajo** package directory. _Readonly_ |
|
|
11
|
+
| ```data``` | string | ```data``` sub directory under ```dir.base``` | Your data directory. Can be anywhere in your file system |
|
|
12
|
+
| ```tmp``` | string | Sub directory ```bajo``` in your default OS temp directory | Temp directory. Can be anywhere in your file system |
|
|
13
|
+
| ```log``` | object |||
|
|
14
|
+
| ```level``` | string | ```debug``` | Log level. Choices: **trace**, **debug**, **info**, **warn**, **error**, **fatal**, **silent** |
|
|
15
|
+
| ```dateFormat``` | string | ```YYYY-MM-DDTHH:MM:ss.SSS[Z]``` | Using Pino format |
|
|
16
|
+
| ```tool``` | boolean | ```false``` | If _true_ log will still be shown even when app is running in **sidetool** mode |
|
|
17
|
+
| ```lang``` | string | ```en-US``` | Language used |
|
|
18
|
+
| ```env``` | string | ```dev``` | Running environment: **prod** for production, **dev** for development |
|
|
19
|
+
| ```plugins``` | array | ```['app']``` | List of plugins used by your app |
|
|
20
|
+
| ```exitHandler``` | boolean | ```true``` | If _true_, error will be handled automatically |
|
|
21
|
+
|
|
22
|
+
#### Example
|
|
23
|
+
|
|
24
|
+
Using JSON file:
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"dir": {
|
|
29
|
+
"data": "/home/me/app/data"
|
|
30
|
+
},
|
|
31
|
+
"log": {
|
|
32
|
+
"level": "trace"
|
|
33
|
+
},
|
|
34
|
+
"lang": "id"
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Using JS file:
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
async function () {
|
|
42
|
+
return {
|
|
43
|
+
dir: {
|
|
44
|
+
data: '/home/me/app/data'
|
|
45
|
+
},
|
|
46
|
+
log: {
|
|
47
|
+
level: 'trace'
|
|
48
|
+
},
|
|
49
|
+
lang: 'id'
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: function breakNsPath()
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Bajo uses this common format ```<ns>:<path>``` everywhere to describe a path (variable, function name, etc) belongs to what namespace/plugin. This function helps you to get the right **ns** and **path** pair by validating named namespace.
|
|
6
|
+
|
|
7
|
+
###### Parameters:
|
|
8
|
+
|
|
9
|
+
| Name | Type | Default Value | Description |
|
|
10
|
+
| ---- | ---- | ------------- | ----------- |
|
|
11
|
+
| ```item``` | string | ```''``` | ```<ns>:<path>``` pair |
|
|
12
|
+
|
|
13
|
+
###### Returns:
|
|
14
|
+
|
|
15
|
+
```array``` of **ns** and **path**
|
|
16
|
+
|
|
17
|
+
#### Example
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
...
|
|
21
|
+
const { breakNsPath } = this.bajo.helper
|
|
22
|
+
console.log(breakNsPath('bajoWeb:/my/path'))
|
|
23
|
+
// ['bajoWeb', '/my/path']
|
|
24
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: async function buildCollections()
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
A function helper to collect and format data from a plugin's config entries.
|
|
6
|
+
|
|
7
|
+
###### Parameters:
|
|
8
|
+
|
|
9
|
+
| Name | Type | Default Value | Description |
|
|
10
|
+
| ---- | ---- | ------------- | ----------- |
|
|
11
|
+
| ```options``` | object | ```{}``` ||
|
|
12
|
+
| ```plugin``` | string | _Autodetect_ | Plugin name from which collections are gathered |
|
|
13
|
+
| ```handler``` | function || Extraction function handler. _Required_ |
|
|
14
|
+
| ```dupChecks``` | array | ```[]``` | Array of keys to check for duplications. If none is provided, ignore duplication checks |
|
|
15
|
+
| ```container``` | string | ```connections``` | Plugin's config key used as container |
|
|
16
|
+
|
|
17
|
+
###### Returns:
|
|
18
|
+
|
|
19
|
+
```array```
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: async function callHelperOrHandler()
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Helper that call a function based on 1st parameter supplied:
|
|
6
|
+
|
|
7
|
+
- if it a function (handler), than it will be call it right away.
|
|
8
|
+
- if it a string and a valid helper name, it will call its underlaying function.
|
|
9
|
+
|
|
10
|
+
Any other parameters will be passed through as its arguments
|
|
11
|
+
|
|
12
|
+
###### Parameters:
|
|
13
|
+
|
|
14
|
+
| Name | Type | Default Value | Description |
|
|
15
|
+
| ---- | ---- | ------------- | ----------- |
|
|
16
|
+
| ```nameOrFn``` | string or function || see above |
|
|
17
|
+
| ```...args``` | ```any``` || rest parameter |
|
|
18
|
+
|
|
19
|
+
###### Returns:
|
|
20
|
+
|
|
21
|
+
```any```
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
#### Example
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
...
|
|
28
|
+
const { callHelperOrHandler } = this.bajo.helper
|
|
29
|
+
|
|
30
|
+
const add = (a, b) => a + b
|
|
31
|
+
const newId = 'bajo:generateId'
|
|
32
|
+
|
|
33
|
+
console.log(await callHelperOrHandler(add, 5, 6)) // returns: 11
|
|
34
|
+
console.log(await callHelperOrHandler(newId)) // returns: '<generated id>'
|
|
35
|
+
```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: function currentLoc()
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
In ES 6, there is no *__dirname* nor *__filename*. This helper simply provides a simple way to get what you want
|
|
6
|
+
|
|
7
|
+
###### Parameters:
|
|
8
|
+
|
|
9
|
+
| Name | Type | Default Value | Description |
|
|
10
|
+
| ---- | ---- | ------------- | ----------- |
|
|
11
|
+
| ```meta``` ||| imported meta |
|
|
12
|
+
|
|
13
|
+
###### Returns:
|
|
14
|
+
|
|
15
|
+
```object``` of
|
|
16
|
+
- ```dir```: current script directory
|
|
17
|
+
- ```file```: current script file
|
|
18
|
+
- ```__dirname```: alias of ```dir```
|
|
19
|
+
- ```__filename```: alias of ```file```
|
|
20
|
+
|
|
21
|
+
#### Example
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
...
|
|
25
|
+
const { currentLoc } = this.bajo.helper
|
|
26
|
+
const { dir, file } = currentLoc(import.meta)
|
|
27
|
+
console.log(dir) // prints: '/home/me/apps/current/dir'
|
|
28
|
+
```
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: function defaultsDeep()
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Similar to lodash's [defaultsDeep](https://lodash.com/docs/4.17.15#defaultsDeep), but without mutating the source object, and no merging of arrays.
|
|
6
|
+
|
|
7
|
+
Based on [@nodeutils/defaults-deep](https://github.com/nodeutils/defaults-deep), customized to work
|
|
8
|
+
in Bajo environment
|
|
9
|
+
|
|
10
|
+
###### Parameters:
|
|
11
|
+
|
|
12
|
+
| Name | Type | Default Value | Description |
|
|
13
|
+
| ---- | ---- | ------------- | ----------- |
|
|
14
|
+
| ```...args``` | ...object || rest parameter of objects |
|
|
15
|
+
|
|
16
|
+
###### Returns:
|
|
17
|
+
|
|
18
|
+
```object``` of merged argument's objects
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
#### Example
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
...
|
|
25
|
+
const { defaultsDeep } = this.bajo.helper
|
|
26
|
+
const a = { one: 1, two: 2 }
|
|
27
|
+
const b = { one: 'one', three: 'three' }
|
|
28
|
+
console.log(defaultsDeep(b, a)) // returns: { one: 'one', two: 2, three: 'three' }
|
|
29
|
+
```
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: function dump()
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
A ```console.log``` with untruncated, deep objects. Doesn't return anything, instead prints arguments as nested, deep object.
|
|
6
|
+
|
|
7
|
+
###### Parameters:
|
|
8
|
+
|
|
9
|
+
| Name | Type | Default Value | Description |
|
|
10
|
+
| ---- | ---- | ------------- | ----------- |
|
|
11
|
+
| ```...args``` | ...object || rest parameter of objects |
|
|
12
|
+
|
|
13
|
+
###### Returns:
|
|
14
|
+
|
|
15
|
+
```void```
|
|
16
|
+
|
|
17
|
+
#### Example
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
...
|
|
21
|
+
const { dump } = this.bajo.helper
|
|
22
|
+
const value = {
|
|
23
|
+
level1: {
|
|
24
|
+
level2: {
|
|
25
|
+
level3: {
|
|
26
|
+
level4: 'this is a test'
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
dump(value)
|
|
32
|
+
```
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: async function eachPlugins()
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Walk through all loaded plugins and execute the callback handler.
|
|
6
|
+
|
|
7
|
+
###### Parameters:
|
|
8
|
+
|
|
9
|
+
| Name | Type | Default Value | Description |
|
|
10
|
+
| ---- | ---- | ------------- | ----------- |
|
|
11
|
+
| ```handler``` | async function || callback handler. _Required_ |
|
|
12
|
+
| ```options``` | object |||
|
|
13
|
+
| ```key``` | string | ```name``` | Key of Bajo's config object that will be used as the key of returned object |
|
|
14
|
+
| ```glob``` | string/object || see above |
|
|
15
|
+
| ```ns``` | string | _Autodetect_ | If not set, it defaults to calling plugin |
|
|
16
|
+
| ```extend``` | string || see above |
|
|
17
|
+
| ```extendHandler``` | function | ```handler``` | see above |
|
|
18
|
+
| ```useBajo``` | boolean | ```false``` | weather to scan **bajo** package dir too |
|
|
19
|
+
|
|
20
|
+
###### Returns:
|
|
21
|
+
|
|
22
|
+
```object```
|
|
23
|
+
|
|
24
|
+
#### Example
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: function error()
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
A shortcut to create an instance of Error with message and optionally rest parameter within a single line.
|
|
6
|
+
|
|
7
|
+
Message can hold ```sprintf``` token. If it does, use rest parameter to replace its token.
|
|
8
|
+
|
|
9
|
+
If last parameter is a plain object, it will be used as error payload.
|
|
10
|
+
|
|
11
|
+
###### Parameters:
|
|
12
|
+
|
|
13
|
+
| Name | Type | Default Value | Description |
|
|
14
|
+
| ---- | ---- | ------------- | ----------- |
|
|
15
|
+
| ```message``` | string || Error message. _Required_ |
|
|
16
|
+
| ```...args``` | ...any || see above |
|
|
17
|
+
|
|
18
|
+
###### Returns:
|
|
19
|
+
|
|
20
|
+
```object``` new instance of node's Error
|
|
21
|
+
|
|
22
|
+
#### Example
|
|
23
|
+
|
|
24
|
+
```javascript
|
|
25
|
+
...
|
|
26
|
+
const { error } = this.bajo.helper
|
|
27
|
+
const payload = { statusCode: 500, details: [{ field: 'username', error: 'Required' }] }
|
|
28
|
+
throw error('This is a %s error, it should also hold some payloads', 'fatal', payload)
|
|
29
|
+
```
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: function fatal()
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Basically the same as [error()](2.9-error.md), with two extras:
|
|
6
|
+
|
|
7
|
+
- prints error on screen
|
|
8
|
+
- terminate running program with exit code 1
|
|
9
|
+
|
|
10
|
+
###### Parameters:
|
|
11
|
+
|
|
12
|
+
| Name | Type | Default Value | Description |
|
|
13
|
+
| ---- | ---- | ------------- | ----------- |
|
|
14
|
+
| ```...args``` | ...any || any arguments provided here will be passed through **error()** |
|
|
15
|
+
|
|
16
|
+
###### Returns:
|
|
17
|
+
|
|
18
|
+
```void```
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: function generateId()
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
ID generator based on [nanoid](https://github.com/ai/nanoid).
|
|
6
|
+
|
|
7
|
+
By default, ```options.pattern``` is set to ```abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789``` so that resulted ID will be a full alphanumeric characters with the length of ```options.length``` (default: ```21```)
|
|
8
|
+
|
|
9
|
+
If ```options.pattern``` is an object:
|
|
10
|
+
|
|
11
|
+
- ```pattern```: characters to use
|
|
12
|
+
- ```lowerCase```: if ```true```, only use lowercase
|
|
13
|
+
- ```upperCase```: if ```true```, only use uppercase
|
|
14
|
+
|
|
15
|
+
```lowerCase``` and ```upperCase``` is mutually exclusive, first one win.
|
|
16
|
+
|
|
17
|
+
###### Parameters:
|
|
18
|
+
|
|
19
|
+
| Name | Type | Default Value | Description |
|
|
20
|
+
| ---- | ---- | ------------- | ----------- |
|
|
21
|
+
| ```options``` | object |||
|
|
22
|
+
| ```pattern``` | string or object | all alphanumeric characters | see above |
|
|
23
|
+
| ```length``` | integer | ```21``` | length of generated ID |
|
|
24
|
+
| ```returnInstance``` | boolean | ```false``` | Set ```true``` to return a nanoid instance |
|
|
25
|
+
|
|
26
|
+
###### Returns:
|
|
27
|
+
|
|
28
|
+
```string``` or ```object```
|
|
29
|
+
|
|
30
|
+
#### Example
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
...
|
|
34
|
+
const { generateId } = this.bajo.helper
|
|
35
|
+
console.log(generateId()) // returns: <randomly generated characters>
|
|
36
|
+
```
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: function getConfig()
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Get configuration object of **bajo** or its **plugin**
|
|
6
|
+
|
|
7
|
+
###### Parameters:
|
|
8
|
+
|
|
9
|
+
| Name | Type | Default Value | Description |
|
|
10
|
+
| ---- | ---- | ------------- | ----------- |
|
|
11
|
+
| ```name``` | string | ```bajo``` | A valid plugin name |
|
|
12
|
+
| ```options``` | object |||
|
|
13
|
+
| ```full``` | boolean | ```false``` | If ```true```, returns ALL config objects belonging to named plugin. Otherwise, returns only subset of objects that can be changed through configuration file |
|
|
14
|
+
| ```clone``` | boolean | ```false``` | If ```true```, returns cloned object |
|
|
15
|
+
|
|
16
|
+
###### Returns:
|
|
17
|
+
|
|
18
|
+
```object```
|
|
19
|
+
|
|
20
|
+
#### Example
|
|
21
|
+
|
|
22
|
+
```javascript
|
|
23
|
+
...
|
|
24
|
+
const { getConfig } = this.bajo.helper
|
|
25
|
+
const cfg = getConfig('bajoLogger')
|
|
26
|
+
console.log(cfg)
|
|
27
|
+
```
|