Module: utils

Utilities module for YTMP3 project.

Since:
  • 1.0.0
Author:
  • Ryuu Mitsuki <https://github.com/mitsuki31>
License:
  • MIT
Source:

Classes

ProgressBar

Namespaces

Logger

Members

(package, inner, constant) LOGDIR :string

The log directory for error logs.

Basically, the log directory is set to:

  • POSIX: $HOME/.ytmp3-js/logs
  • Windows: %USERPROFILE%\.ytmp3-js\logs
Type:
  • string
Since:
  • 1.0.0
Source:

(package, inner, constant) OUTDIR :string

The output directory for the downloaded audio files.

Type:
  • string
Since:
  • 1.0.0
Source:

(package, inner, constant) ROOTDIR :string

The root directory of the project.

Type:
  • string
Since:
  • 1.0.0
Source:

(package, inner, constant) YTMP3_HOMEDIR :string

The home directory path for the YTMP3-JS configuration and data files.

This path is constructed by joining the user's home directory with the '.ytmp3-js' folder. On POSIX systems, this will typically be "/home/<USERNAME>/.ytmp3-js", while on Windows systems, it will be "C:\Users\<USERNAME>\.ytmp3-js". For Termux Android, it will be "/data/data/com.termux/files/home/.ytmp3-js".

Type:
  • string
Since:
  • 1.1.0
Source:

(inner, constant) logger :module:utils~Logger

A custom logger object for the YTMP3 project with ANSI color codes.

The logger is using the ANSI color codes to add color to the log messages, it might not support on every terminals.

Type:
Since:
  • 1.0.0
Source:
See:

Methods

(async, inner) createDirIfNotExist(dirpath) → {Promise.<void>}

Synchronously checks whether the specified directory path is exist, creates new if not exist with asynchronous operation.

Parameters:
Name Type Description
dirpath string

The directory path to be created if not exist.

Since:
  • 1.0.0
Source:
Returns:
Type
Promise.<void>

(inner) createDirIfNotExistSync()

Similar with createDirIfNotExist function, but it uses synchronous directory creation.

Since:
  • 1.0.1
Source:

(inner) dropNullAndUndefined(obj) → {Object}

Drops null and undefined values from the input object.

Parameters:
Name Type Description
obj Object

The input object to filter null and undefined values from.

Since:
  • 1.0.0
Source:
Returns:

The filtered object without null and undefined values.

Type
Object

(package, inner) getType(x) → {string}

Returns the type of the provided value as a string.

For null values, it returns 'null', and for objects, it returns a more detailed type such as '[object Object]'.

Parameters:
Name Type Description
x any

The value whose type is to be determined.

Since:
  • 1.1.0
Source:
Returns:

A string representing the type of the value.

Type
string

(inner) isNullOrUndefined(x) → {boolean}

Checks if a given value is null or undefined.

Parameters:
Name Type Description
x any

The value to check.

Since:
  • 1.0.0
Source:
Returns:
  • true if the value is null or undefined, otherwise false.
Type
boolean

(package, inner) isObject(x) → {boolean}

Determines whether the provided value is a non-null object.

This function returns true for any value that is of the object type and is not null, but it does not guarantee that the object is a plain object ({}).

Parameters:
Name Type Description
x any

The value to be checked.

Since:
  • 1.0.0
Source:
See:
Returns:

true if the value is a non-null object, otherwise false.

Type
boolean

(package, inner) isPlainObject(x) → {boolean}

Determines whether the provided value is a plain object ({}).

This function returns true only if the value is a non-null object with a prototype of Object.

Parameters:
Name Type Description
x any

The value to be checked.

Since:
  • 1.1.0
Source:
See:
Returns:

true if the value is a plain object, otherwise false.

Type
boolean

Type Definitions

LoggerFunc(msg) → {void}

Parameters:
Name Type Description
msg string

The message to be displayed.

Since:
  • 1.0.0
Source:
Returns:
Type
void

LoggerInterface

The interface of logger object.

Type:
  • Object
Properties:
Name Type Description
INFO_PREFIX string

The prefix for the info level message.

DONE_PREFIX string

The prefix for the done level message.

DEBUG_PREFIX string

The prefix for the debug level message.

WARNING_PREFIX string

The prefix for the warning level message.

ERROR_PREFIX string

The prefix for the error level message.

info LoggerFunc

The function to log the info level message to the console.

done LoggerFunc

The function to log the done level message to the console.

debug LoggerFunc

The function to log the debug level message to the console.

warn LoggerFunc

The function to log the warning level message to the console.

error LoggerFunc

The function to log the error level message to the console.

Since:
  • 1.0.0
Source:

ProgressBarOptions

Options object for configuring the progress bar.

Type:
  • Object
Properties:
Name Type Attributes Default Description
barWidth 'auto' | number <optional>
'auto'

The width of the progress bar. Can be 'auto' or a number representing the number of characters.

barCharElapsed string <optional>
'#'

The character used to represent the progress of the bar.

barCharTotal string <optional>
'-'

The character used to represent the total length of the bar.

bytesInfo boolean <optional>
true

Whether to display the bytes downloaded information in MB.

Since:
  • 1.0.0
Source:

ResolvedProgressBarOptions

The resolved ProgressBarOptions options.

Type:
  • ProgressBarOptions
Properties:
Name Type Description
barWidth 'auto' | number

The width of the progress bar. Can be 'auto' or a number representing the number of characters.

barCharElapsed string

The character used to represent the progress of the bar.

barCharTotal string

The character used to represent the total length of the bar.

bytesInfo boolean

Whether to display the bytes downloaded information in MB.

Since:
  • 1.0.0
Source: