A collection of lightweight, typed, and well-documented utility functions for everyday TypeScript/JavaScript development.
Library is under development, stay tuned for updates! Example code in the README is updated for the current version content.
npm install kmsoft-helpers
import {
addParametersToString,
cloneDeep,
generatePassword,
isArrayNullOrEmpty,
isDefined,
isNumberNullOrZero,
isStringNullOrEmpty,
isStringNullOrEmptyOrUndefined,
muteColor,
noop,
regexCheck,
sort,
} from "kmsoft-helpers";
addParametersToString("Hello, {0}! You have {1} new messages.", ["Alice", 5]);
// => "Hello, Alice! You have 5 new messages."
const original = { a: 1, b: { c: 2 } };
const clone = cloneDeep(original);
clone.b.c = 99;
console.log(original.b.c); // => 2
generatePassword(8, 12);
// => "xF8!k9aV" (random output)
isArrayNullOrEmpty([]); // => true
isArrayNullOrEmpty(null); // => true
isArrayNullOrEmpty([1, 2]); // => false
isDefined(undefined); // => false
isDefined(null); // => false
isDefined(0); // => true
isNumberNullOrZero(0); // => true
isNumberNullOrZero(null); // => true
isNumberNullOrZero(10); // => false
isStringNullOrEmpty(""); // => true
isStringNullOrEmpty("hello"); // => false
isStringNullOrEmptyOrUndefined(undefined); // => true
isStringNullOrEmptyOrUndefined(""); // => true
isStringNullOrEmptyOrUndefined("text"); // => false
muteColor("#FF5733");
// => "#ff9e80" (result may vary depending on muting factors)
noop(); // => undefined
regexCheck("Hello123", /^[A-Za-z0-9]+$/); // => true
regexCheck("Hello!", /^[A-Za-z0-9]+$/); // => false
sort([3, 1, 4, 2], "asc"); // => [1, 2, 3, 4]
sort(["b", "a", "c"], "desc"); // => ["c", "b", "a"]
sort([new Date(2020, 5), new Date(2019, 1)]); // => sorted by date