shixm-js-utils-toolkit
v1.0.0
Published
A collection of common JavaScript utility functions
Downloads
1
Readme
JS Utils Toolkit
A collection of common JavaScript utility functions for everyday development.
Installation
npm install shixm-js-utils-toolkitUsage
const {
isObject,
isArray,
hasValue,
isNumber,
isString,
isNumberOrNumString,
percentToDecimal,
decimalToPercent,
} = require("shixm-js-utils-toolkit");
// Example usage
console.log(isObject({})); // true
console.log(isArray([1, 2, 3])); // true
console.log(hasValue(null)); // false
console.log(isNumber(123)); // true
console.log(isString("hello")); // true
console.log(isNumberOrNumString("456")); // true
console.log(percentToDecimal("50%")); // 0.5
console.log(decimalToPercent(0.75)); // '75.00%'API
isObject(value)
Check if a value is an object.
- value: The value to check
- returns: Boolean
isArray(value)
Check if a value is an array.
- value: The value to check
- returns: Boolean
hasValue(value)
Check if a value is not null or undefined.
- value: The value to check
- returns: Boolean
isNumber(value)
Check if a value is a valid number.
- value: The value to check
- returns: Boolean
isString(value)
Check if a value is a valid non-empty string.
- value: The value to check
- returns: Boolean
isNumberOrNumString(value)
Check if a value is a number or a numeric string.
- value: The value to check
- returns: Boolean
percentToDecimal(percent)
Convert a percentage value to a decimal.
- percent: The percentage value (number or string with %)
- returns: Number
decimalToPercent(decimal, precision = 2)
Convert a decimal to a percentage string.
- decimal: The decimal value
- precision: The number of decimal places (default: 2)
- returns: String
Running Tests
npm testLicense
MIT
