External helpers you can use by importing its file directly

Methods

(static) currentLoc(metaImport) → {Object}

Get current directory & file. An attempt to brings back the old __dirname and __filename to the ES6 era.

Returns object with the following keys:

  • __dirname (aliases to dir) - current directory name
  • __filename (aliases to file) - current file path

Example:

const { importModule } = this.app.bajo
const currentLoc = await importModule('bajo:/lib/current-loc.js')

const { __dirname, __filename } = currentLoc(import.meta)
console.log(__dirname, __filename)
Parameters:
NameTypeDescription
metaImportObject

import.meta object

Returns:
Type: 
Object

(async, static) importModule(file, optionsopt) → {any}

Import file/module from any loaded plugins

Example: your plugin structure looks like this

|- src
|  |- lib
|  |  |- my-module.js
|- index.js
|- package.json

And now this is how to import my-module.js:

const { importModule } = this.app.bajo
const myModule = await importModule('myPlugin:/src/lib/my-module.js')
Parameters:
NameTypeAttributesDefaultDescription
fileTNsPathPairs

File to import

optionsObject<optional>
{}

Options

Properties
NameTypeAttributesDefaultDescription
asDefaultImportboolean<optional>
true

If true (default), return default imported module

asHandlerboolean<optional>

If true, return as a handler

noCacheboolean<optional>

If true, always import as a fresh copy

Returns:
Type: 
any

(async, static) parseArgsArgv(useParseropt) → {Object}

Parse program arguments (args) & options (argv). See args & argv for examples

Parameters:
NameTypeAttributesDescription
useParserboolean<optional>

If true, skip yargs

Returns:

An object containing args and argv

Type: 
Object

(static) parseEnv() → {Object}

Parse environment variables. See envVars for examples

Returns:
Type: 
Object

(static) resolvePath(file, asFileUrlopt) → {string}

Resolve file name to filesystem's path. Windows path separator \ is normalized to Unix's /

Parameters:
NameTypeAttributesDefaultDescription
filestring

File to resolve

asFileUrlboolean<optional>
false

Return as file URL format file:///<name>

Returns:
Type: 
string

(static) shim()

Function to attach some of the methods needed but probably not provided by your node installation:

  • String.prototype.replaceAll
  • String.prototype.splice