Constructor
new Bajo(app)
Constructor.
| Name | Type | Description |
|---|---|---|
app | App | App instance. Usefull to call app method inside a plugin. |
- Source
Members
alias :string
Alias
- string
- Source
config :Bajo.TObject
Config object.
- Bajo.
TObject
- Source
- See
- config
hooks :Array.<Bajo.THook>
Hooks container.
- Array.<Bajo.THook>
- Source
whiteSpace :Array.<string>
White space characters
- Array.<string>
- Source
Methods
breakNsPath(name, checkNsopt) → {TNsPathResult}
Break name to its namespace & path infos
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
name | TNsPathPairs | | Name to break | ||
checkNs | boolean | <optional> | true | If |
- Source
- Type:
- TNsPathResult
breakNsPathFromFile(options) → {Object}
Break file path to its namespace & path infos.
| Name | Type | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | Object | Options object Properties
|
- Source
Namespace and path information
- Type:
- Object
(async) buildCollections(options) → {Array.<Object>}
Method to transform config's array or object into an array of collection.
| Name | Type | Description | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | Object | Options. Properties
|
- Source
- bajo:beforeBuildCollection
- bajo:afterBuildCollection
The collection
- Type:
- Array.<Object>
buildNsPath(optionsopt) → {TNsPathPairs}
Build ns/path pairs.
| Name | Type | Attributes | Default | Description | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | object | <optional> | {} | Options object Properties
|
- Source
Ns/path pairs
- Type:
- TNsPathPairs
(async) callHandler(name, …argsopt) → {any}
Calling any plugin's method by its name:
- If name is a string, the corresponding plugin's method will be called with passed args as its parameters
- If name is a plugin instance, this will be used as the scope instead. The first args is now the handler name and the rest are its parameters
- If name is a function, this function will be run under scope with the remaining args
- If name is an object and has
handlerkey in it, this function handler will be instead
| Name | Type | Attributes | Description |
|---|---|---|---|
name | TNsPathPairs | | Method's name, function handler, plain object or plugin instance. | |
args | any | <optional> <repeatable> | One or more arguments passed as parameter to the handler. |
- Source
Returned value.
- Type:
- any
(async) eachPlugins(handler, optionsopt) → {any}
This function iterates through all loaded plugins and call the provided handler scoped as the running plugin. And an object with the following key serves as its parameter:
file: file matched the glob patterndir: plugin's base directory
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
handler | function | Function handler. Can be an async function. Scoped to the running plugin. | ||||||||||||||||||||||||||||||||
options | string | | <optional> | {} | Options. If a string is provided, it serves as the glob pattern, otherwise: Properties
|
- Source
- Type:
- any
format(value, typeopt, optionsopt) → {string}
Format value.
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
value | any | Value to format. | ||||||||||||||||||||||||||||||||
type | string | <optional> | Data type to use. See TBajoDataType for acceptable values. If not provided, return the untouched value. | |||||||||||||||||||||||||||||||
options | Object | <optional> | {} | Options. Properties
|
- Source
Formatted value.
- Type:
- string
formatByType(type, value, dataTypeopt, optionsopt) → {Array|string}
Format value by type.
| Name | Type | Attributes | Default | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
type | string | Format type. See TBajoFormatType for acceptable values. | |||||||||||||||||
value | any | Value to format. | |||||||||||||||||
dataType | string | <optional> | Value's data type. See TBajoDataType for acceptable values. | ||||||||||||||||
options | Object | <optional> | {} | Options. Properties
|
- Source
Return string if withUnit is true. Otherwise is an array of [value, unit, separator].
- Type:
- Array |
string
(async) fromJs(file, optionsopt) → {Object}
Read and parse JavaScript file.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
file | string | File to read and parse. | ||
options | Object | <optional> | {} | Options. |
- Source
Parsed JavaScript object.
- Type:
- Object
fromJson(data, optionsopt) → {Object}
Read and parse JSON string or object.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
data | string | Filename to load from or JSON string to parse. | ||
options | Object | <optional> | {} | Options. |
- Source
Parsed JSON object.
- Type:
- Object
fromYaml(text, options) → {object}
Parse YAML text
| Name | Type | Description |
|---|---|---|
text | string | Text to be parsed |
options | object | Options object |
- Source
Parsed object
- Type:
- object
fromYml(text, options) → {object}
Parse YML text. Alias for fromYaml.
| Name | Type | Description |
|---|---|---|
text | string | Text to be parsed |
options | object | Options object |
- Source
Parsed object
- Type:
- object
getMethod(name, thrownopt) → {function}
Get class method by name.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
name | string | Name in format | ||
thrown | boolean | <optional> | true | If |
- Source
Class method.
- Type:
- function
getModuleDir(pkgName, withGlobalDiropt) → {string}
Get module directory.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pkgName | string | Package name to find. | ||
withGlobalDir | boolean | <optional> | true | Whether to include the global module directory. |
- Source
Return absolute package directory.
- Type:
- string
getUnitFormat(optionsopt) → {TBajoFormatResult}
Get unit format.
| Name | Type | Attributes | Default | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | Object | <optional> | {} | Options. Properties
|
- Source
Returned value.
- Type:
- TBajoFormatResult
(async) importModule()
Import file/module from any loaded plugins.
Method proxy from module:Helper.importModule
- Source
(async) importPkg(…pkgs) → {Object|Array}
Import one or more packages belongs to a plugin.
If the last arguments passed is an object, this object serves as options object:
returnDefault: should return package's default export. Defaults totruethrowNotFound: should throw if package is not found. Defaults tofalsenoCache: always use fresh import. Defaults tofalseasObject: see below. Defaults tofalse
Return value:
- if
options.asObjectistrue(defaultfalse), return as object with package's names as it's keys - Otherwise depends on how many parameters are provided, it should return the named package or an array of packages
Example: you want to import delay and chalk from bajo plugin because you want to use it in your code `javascript const { importPkg } from this.app.bajo const [delay, chalk] = await importPkg('bajo:delay', 'bajo:chalk')
await delay(1000) ... `
| Name | Type | Attributes | Description |
|---|---|---|---|
pkgs | TNsPathPairs | <repeatable> | One or more packages in format |
- Source
See above.
- Type:
- Object |
Array
(async) init()
Initialization:
- Building base config
- Building plugins
- Collect all config handler
- Building extra config
- Setup boot order
- Boot loaded plugins
- Attach exit handlers
- Source
isLogInRange(level) → {boolean}
Check whether log level is within log's app current level.
| Name | Type | Description |
|---|---|---|
level | string | Level to check. See TLogLevels for more. |
- Source
- Type:
- boolean
isValidApp(dir, returnPkgopt) → {boolean|Object}
Check whether directory is a valid Bajo app.
| Name | Type | Attributes | Description |
|---|---|---|---|
dir | string | Directory to check. | |
returnPkg | boolean | <optional> | Set |
- Source
- Type:
- boolean |
Object
isValidPlugin(dir, returnPkgopt) → {boolean|Object}
Check whether directory is a valid Bajo plugin.
| Name | Type | Attributes | Description |
|---|---|---|---|
dir | string | Directory to check. | |
returnPkg | boolean | <optional> | Set |
- Source
- Type:
- boolean |
Object
join(array, options) → {string}
Human friendly join array of items.
| Name | Type | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
array | Array.<any> | Array to join | |||||||||||||||
options | string | | If provided and is a string, it will be used as separator. Properties
|
- Source
- Type:
- string
numUnit(valueopt, defUnitopt) → {string}
Return its numeric portion of a value.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
value | string | <optional> | '' | Value to get its numeric portion. |
defUnit | string | <optional> | '' | Default unit if value doesn't have one. |
- Source
- Type:
- string
(async) readAllConfigs(path, optionsopt) → {Object}
Read all config files from path.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
path | string | Base path to start looking config files. | ||
options | Object | <optional> | {} | Options. |
- Source
Merged configuration object.
- Type:
- Object
readAsConfig(input, extsopt, optionsopt) → {Object|Array|null}
Read config using all registered config handlers. The first handler that returns a valid object or array will be used.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
input | string | The input string to be processed by the config handlers. | ||
exts | Array.<string> | <optional> | Optional array of extensions to filter the config handlers. If provided, only handlers with matching extensions will be used. | |
options | object | <optional> | {} | Options to be passed to the config handlers. |
- Source
The result from the first successful config handler, or null if none succeed.
- Type:
- Object |
Array | null
(async) readConfig(file, optionsopt) → {Object}
Read and parse file as config object. Supported types: .js, .json and .yml/.yaml. More supports can be added using plugin. bajo-config gives you additional supports for .yml, .yaml and .toml file.
If file extension is .*, it will be auto detected and parsed accordingly
| Name | Type | Attributes | Default | Description | |||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
file | string | File to read and parse. | |||||||||||||||||||||||||||||||||||||
options | Object | <optional> | {} | Options. Properties
|
- Source
- Type:
- Object
readJson(file, thrownNotFoundopt) → {Object}
Read and parse json file.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
file | string | File to read. | ||
thrownNotFound | boolean | <optional> | false | If |
- Source
- Type:
- Object
(async) runHook(hookName, …argsopt) → {Array}
Run named hook/event.
| Name | Type | Attributes | Description |
|---|---|---|---|
hookName | TNsPathPairs | Name of the hook to run. | |
args | any | <optional> <repeatable> | Argument passed to the hook function. |
- Source
Array of hook execution results.
- Type:
- Array
(async) saveAsDownload(file, item, printSavedopt) → {string}
Save item as file in Bajo's download directory. That is a directory inside your Bajo plugin's data directory.
If file exists already, file will automatically be renamed incrementally.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
file | string | File name. | ||
item | Object | Item to save. | ||
printSaved | boolean | <optional> | true | Print info on screen. |
- Source
Full file path.
- Type:
- string
toJson(data, optionsopt) → {string}
Convert data to JSON string.
| Name | Type | Attributes | Default | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data | Object | Data to convert to JSON string. | |||||||||||||||||
options | Object | <optional> | {} | Options. Properties
|
- Source
JSON string
- Type:
- string
toYaml(object, options) → {string}
Convert object to YAML string
| Name | Type | Description |
|---|---|---|
object | object | Object to be converted |
options | object | Options object |
- Source
YAML string
- Type:
- string
toYml(object, options) → {string}
Convert object to YML string. Alias for toYaml.
| Name | Type | Description |
|---|---|---|
object | object | Object to be converted |
options | object | Options object |
- Source
YML string
- Type:
- string
Type Definitions
TDataType
Supported data types.
- Object
| Name | Type | Description |
|---|---|---|
0 | string | string |
1 | string | float |
2 | string | double |
3 | string | integer |
4 | string | smallint |
5 | string | date |
6 | string | time |
7 | string | datetime |
8 | string | array |
9 | string | object |
10 | string | auto |
- Source
TFormatResult
Object returned by bajo:getUnitFormat.
- Object
| Name | Type | Description |
|---|---|---|
unitSys | string | Unit system. |
format | Object | Format object. |
- Source
TFormatType
General format types,
- Object
| Name | Type | Description |
|---|---|---|
0 | string | speed |
1 | string | distance |
2 | string | area |
3 | string | degree |
- Source
TNsPathPairs
Name based {ns}:{path} format.
- string
- Source
- See
- TNsPathResult
- Bajo#buildNsPath
- Bajo#breakNsPath
TNsPathResult
Object returned by bajo:breakNsPath.
- Object
| Name | Type | Attributes | Description |
|---|---|---|---|
ns | string | Namespace | |
subNs | string | <optional> | Sub namespace |
subSubNs | string | <optional> | Sub of sub namespace |
path | string | Path without query string or hash | |
fullPath | string | Full path, including query string and hash |
- Source
- See
- TNsPathPairs
- Bajo#buildNsPath
- Bajo#breakNsPath