1.4.1 • Published 4 years ago

multitool-js v1.4.1

Weekly downloads
56
License
-
Repository
-
Last release
4 years ago

Multitool JS

A collection of useful methods.

Each tool or group of tools can be required/imported on its own like this:

// Full require
const multitool = require('multitool-js');
const getProp = multitool.objects.getProp;
// *tool-group* or *single-tool*
const objectTools = require('multitool-js/tools/objects');
const getProp = objectTools.getProp;
// *tool* from *tool-group*
const getProp = require('multitool-js/tools/objects/getProp');

Objects (tool group)

const objects = require('multitool-js/tools/objects');
tooldescription
getPropRetrives a property from an object
hasPropChecks if an object contains a property
setPropSets a property in an object
replacePropReplaces a property in an object

Promises (tool group)

const promises = require('multitool-js/tools/promises');
tooldescription
promiseAnyHandles a group of promises, extendin the capabilities of Promise.all()
timerReturns a promise that is resolved/rejected after a timeout

Process (tool group)

const process = require('multitool-js/tools/process');
tooldescription
processArgsHandles a group of promises, extendin the capabilities of Promise.all()
TimerCreates a timer, either with standard resolution (millisecond) or high resolution (nanoseconds)

Strings (tool group)

const strings = require('multitool-js/tools/strings');
tooldescription
ellipsisTrims a string to a given length and applies ellipsis
quotesOffers some methods to add and check quotations on strings

ConfigManager (tool)

ConfigManager allows to easily manage application configurations. The configManager tool reads the following configuration files (in the given order) and merges the configurations:

  • default.json - Default configurations.
  • production.json - Production configurations, enabled only with NODE_ENV = production.
  • development.json - Development configurations, enabled only with NODE_ENV != production.
  • local.json - Local configurations.
  • custom-environment-variables.json - Env variables overrides, loads the value of the environment variable as the config value.
    E.g. { "varaible": "ENV_VARIABLE_NAME" }.
    Additionally the env variable name can be prefixed with the following terms to forcefully cast/parse the value:

    • JSON: parses the value, if the value is not parsable the whole string is applied: { "varaible": "JSON:ENV_VARIABLE_NAME" }: | "ENV_VARIABLE_NAME" value | "varaible" value | |--------|-------------| | 'some_string' | "some_string" | | '{"some":"json"}' | { some: "json" } |

    • JSON_ONLY: parses the value, if the value is not parsable is ignored: { "varaible": "JSON_ONLY:ENV_VARIABLE_NAME" }: | "ENV_VARIABLE_NAME" value | "varaible" value | |--------|-------------| | 'some_string' | | | '{"some":"json"}' | { some: "json" } |

    • MERGE: like JSON but merges the value with current value (if present).

    • BOOL: reads the strings 'true' and 'false' and sets the corresponding boolean value.

    • NUMBER: casts the value as number. If the value is not a valid number the string is kept instead.

    • NUMBER_NAN: casts the value as number. If the value is not a valid number the property is set to NaN.

    • NUMBER_ONLY: casts the value as number. If the value is not a valid number is ignored.

const configManager = require('multitool-js/tools/configManager');
methoddescription
getRetrives a property from the configuration.
hasChecks if a property is defined in the configuration.
setSets a property value in the configuration.
reloadReloads all the configuration values (loses unsaved values).
saveSaves the configuration file (includes values set during runtime).
saveSyncSynchronously saves the configuration file (includes values set during runtime).
deleteDeletes the currently saved configuration.
deleteSyncSynchronously deletes the currently saved configuration.

The ConfigManager tool also comes with a small CLI utility npx multitool-config to help you handle the config files: | command | description | |--------|-------------| | init | creates "config" folder and files | | enable \ | creates/enables \ file | | disable \ | disables \ file | | remove \ | removes \ file | | add-property (ap) \ | adds a new property to the config files. Asks the value for each enabled config file. | | remove-property (rp) \ \ | removes a property from the config files. |


1.4.1

4 years ago

1.4.0

4 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0-beta1

5 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago