BajoExtra

BajoExtra class definition.

Constructor

new BajoExtra()

Constructor

Members

config

Properties
NameTypeDescription
configobject

Configuration object

Properties
NameTypeDescription
secretstring

Secret key for encryption/decryption

fetchobject

Fetch configuration

thumbnailobject

Thumbnail configuration

Methods

(async) countFileLines(file) → {Promise.<number>}

Count the number of lines in a file.

Parameters:
NameTypeDescription
filestring

The path to the file.

Returns:
  • The number of lines in the file.
Type: 
Promise.<number>

(async) createThumbnail(file, optionsopt) → {Promise.<void>}

Create a thumbnail for a given image file.

Parameters:
NameTypeAttributesDefaultDescription
filestring

The path to the image file.

optionsObject<optional>
{}

The options for creating the thumbnail.

Properties
NameTypeAttributesDefaultDescription
dirstring<optional>

The directory to save the thumbnail. Defaults to the same directory as the file.

silentboolean<optional>
true

Whether to silently ignore errors. Defaults to true.

sizestring | Array.<string><optional>

The size(s) of the thumbnail. Defaults to the configured sizes.

formatstring | Array.<string><optional>

The format(s) of the thumbnail. Defaults to the configured output formats.

optsObject<optional>
{}

Additional options for the sharp library.

Returns:
Type: 
Promise.<void>

(async) decrypt(cipher, optionsopt) → {Promise.<string>}

Decrypt a given cipher using the specified decryption type and options.

Parameters:
NameTypeAttributesDefaultDescription
cipherstring

The cipher to be decrypted.

optionsObject<optional>
{}

The decryption options.

Properties
NameTypeAttributesDefaultDescription
typestring<optional>
'short'

The decryption type. Defaults to 'short'.

subTypestring<optional>
'qr'

The decryption sub-type. Defaults to 'qr'.

Returns:
  • The decrypted text.
Type: 
Promise.<string>

(async) download(url, opts, extra) → {Promise.<string>}

Download a file from a URL.

Parameters:
NameTypeDescription
urlstring

The URL to download the file from.

optsobject

Fetch options.

extraobject

Extra options for downloading.

Returns:
  • The path to the downloaded file.
Type: 
Promise.<string>

(async) encrypt(text, optionsopt) → {Promise.<string>}

Encrypt a given text using the specified encryption type and options.

Parameters:
NameTypeAttributesDefaultDescription
textstring

The text to be encrypted.

optionsObject<optional>
{}

The encryption options.

Properties
NameTypeAttributesDefaultDescription
typestring<optional>
'short'

The encryption type. Defaults to 'short'.

subTypestring<optional>
'qr'

The encryption sub-type. Defaults to 'qr'.

Returns:
  • The encrypted text.
Type: 
Promise.<string>

(async) fetchAndSave(options)

Fetch data from a URL and save it using the specified options.

Parameters:
NameTypeDescription
optionsobject

The options for fetching and saving data.

Properties
NameTypeDescription
urlstring

The URL to fetch data from.

bulkobject

Bulk operation options.

saveobject

Save options.

optsobject

Fetch options.

(async) fetchBulk(url, bulk, opts)

Fetch data from a URL in bulk, processing it in steps and applying a handler function to each item.

Parameters:
NameTypeDescription
urlstring

The URL to fetch data from.

bulkobject

Bulk operation options.

optsobject

Fetch options.

(async) fetchUrl(url, optsopt, extraopt) → {Promise.<Object>}

Download a file/resource from a URL.

Parameters:
NameTypeAttributesDefaultDescription
urlstring

The URL to download the file from.

optsobject<optional>
{}

Fetch options. See Undici Client options for available options.

Properties
NameTypeAttributesDefaultDescription
methodobject<optional>
'GET'

HTTP method to use for the request. Defaults to 'GET'.

authobject<optional>

Basic authentication credentials.

Properties
NameTypeAttributesDescription
usernamestring<optional>

Username for basic authentication.

passwordstring<optional>

Password for basic authentication.

queryobject<optional>

Query parameters to append to the URL.

paramsobject<optional>

Alias for opts.query. Query parameters to append to the URL.

headersobject<optional>

HTTP headers to include in the request.

bodyobject<optional>

Request body to send with the request.

extra.formDataboolean<optional>
false

If true, sends the request body as multipart/form-data. Defaults to false.

extraobject<optional>
{}

Extra options for downloading.

Properties
NameTypeAttributesDefaultDescription
cacheBusterboolean<optional>
true

If true, appends a cache-busting query parameter to the URL. Defaults to true.

cacheBusterKeystring<optional>
'_'

The query parameter key to use for cache-busting. Defaults to '_'.

agentobject<optional>

Custom agent options for the fetch request. If provided, overrides the default agent configuration.

rawResponseboolean<optional>
false

If true, returns the raw response object instead of parsing it as JSON. Defaults to false.

Returns:
  • The response object.
Type: 
Promise.<Object>

formatByte(value, opts) → {string}

Format a value as bytes.

Parameters:
NameTypeDescription
valuenumber

The value to format.

optsobject

Formatting options.

Returns:
  • Formatted byte string.
Type: 
string

formatFloat(value, opts) → {string}

Format a value as a floating-point number.

Parameters:
NameTypeDescription
valuenumber

The value to format.

optsobject

Formatting options.

Returns:
  • Formatted floating-point string.
Type: 
string

formatInteger(value, opts) → {string}

Format a value as an integer.

Parameters:
NameTypeDescription
valuenumber

The value to format.

optsobject

Formatting options.

Returns:
  • Formatted integer string.
Type: 
string

formatPercentage(value, opts) → {string}

Format a value as a percentage.

Parameters:
NameTypeDescription
valuenumber

The value to format.

optsobject

Formatting options.

Returns:
  • Formatted percentage string.
Type: 
string

(async) gunzip(file, deleteOldopt) → {Promise.<void>}

Gunzip a file, optionally deleting the original file after extraction.

Parameters:
NameTypeAttributesDefaultDescription
filestring

The path to the file to be gunzipped.

deleteOldboolean<optional>
false

If true, deletes the original file after extraction. Defaults to false.

Returns:
  • Resolves when the gunzip operation is complete.
Type: 
Promise.<void>

(async) gzip(file, deleteOldopt, expandopt) → {Promise.<void>}

Gzip or gunzip a file, optionally deleting the original file after the operation.

Parameters:
NameTypeAttributesDefaultDescription
filestring

The path to the file to be gzipped or gunzipped.

deleteOldboolean<optional>
false

If true, deletes the original file after the operation. Defaults to false.

expandboolean<optional>
false

If true, gunzips the file. If false, gzips the file. Defaults to false.

Returns:
  • Resolves when the gzip or gunzip operation is complete.
Type: 
Promise.<void>

(async) hash(input, typeopt, optionsopt) → {Promise.<string>}

Hash a given text or object using the specified algorithm and options.

Parameters:
NameTypeAttributesDefaultDescription
inputstring | object

The text or object to be hashed.

typestring<optional>
'md5'

The hashing algorithm to use. Defaults to 'md5'. Set to 'bcrypt' for bcrypt hashing or 'short' for a short hash.

optionsobject<optional>
{}

Additional options for the hashing algorithm.

Properties
NameTypeAttributesDefaultDescription
digeststring<optional>
'hex'

The output encoding for the hash. Defaults to 'hex'.

saltnumber<optional>
10

The salt rounds for bcrypt hashing. Defaults to 10.

Returns:
  • The resulting hash.
Type: 
Promise.<string>

isBcrypt(text) → {boolean}

Check if a given text is a bcrypt hash.

Parameters:
NameTypeDescription
textstring

The text to be checked.

Returns:
  • True if the text is a bcrypt hash, false otherwise.
Type: 
boolean

Check if a given text is an HTML link.

Parameters:
NameTypeDescription
textstring

The text to be checked.

Returns:
  • True if the text is an HTML link, false otherwise.
Type: 
boolean

isMd5(text) → {boolean}

Check if a given text is an MD5 hash.

Parameters:
NameTypeDescription
textstring

The text to be checked.

Returns:
  • True if the text is an MD5 hash, false otherwise.
Type: 
boolean

isSha256(text) → {boolean}

Check if a given text is a SHA-256 hash.

Parameters:
NameTypeDescription
textstring

The text to be checked.

Returns:
  • True if the text is a SHA-256 hash, false otherwise.
Type: 
boolean

randomRange(min, max, alphaopt) → {number|string}

Generate a random number or letter within a specified range.

Parameters:
NameTypeAttributesDefaultDescription
minnumber

The minimum value of the range.

maxnumber

The maximum value of the range.

alphaboolean<optional>
false

Whether to return a letter instead of a number.

Returns:
  • The generated random number or letter.
Type: 
number | string

thumbnailSizes(name) → {Array.<number>}

Get the dimensions for a given thumbnail size name.

Parameters:
NameTypeDescription
namestring

The name of the thumbnail size (e.g., 's', 'm', 'l', or 'x').

Returns:
  • The width and height of the thumbnail.
Type: 
Array.<number>