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-helpersimport {
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); // => 2generatePassword(8, 12);
// => "xF8!k9aV" (random output)isArrayNullOrEmpty([]); // => true
isArrayNullOrEmpty(null); // => true
isArrayNullOrEmpty([1, 2]); // => falseisDefined(undefined); // => false
isDefined(null); // => false
isDefined(0); // => trueisNumberNullOrZero(0); // => true
isNumberNullOrZero(null); // => true
isNumberNullOrZero(10); // => falseisStringNullOrEmpty(""); // => true
isStringNullOrEmpty("hello"); // => falseisStringNullOrEmptyOrUndefined(undefined); // => true
isStringNullOrEmptyOrUndefined(""); // => true
isStringNullOrEmptyOrUndefined("text"); // => falsemuteColor("#FF5733");
// => "#ff9e80" (result may vary depending on muting factors)noop(); // => undefinedregexCheck("Hello123", /^[A-Za-z0-9]+$/); // => true
regexCheck("Hello!", /^[A-Za-z0-9]+$/); // => falsesort([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