Skip to content

K-M-Software/kmsoft-helpers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🛠️ ts-utils (KMSoft - helpers)

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.

📦 Installation

npm install kmsoft-helpers

🔧 Usage

import {
  addParametersToString,
  cloneDeep,
  generatePassword,
  isArrayNullOrEmpty,
  isDefined,
  isNumberNullOrZero,
  isStringNullOrEmpty,
  isStringNullOrEmptyOrUndefined,
  muteColor,
  noop,
  regexCheck,
  sort,
} from "kmsoft-helpers";

🧰 Function Examples

addParametersToString

addParametersToString("Hello, {0}! You have {1} new messages.", ["Alice", 5]);
// => "Hello, Alice! You have 5 new messages."

cloneDeep

const original = { a: 1, b: { c: 2 } };
const clone = cloneDeep(original);
clone.b.c = 99;
console.log(original.b.c); // => 2

generatePassword

generatePassword(8, 12);
// => "xF8!k9aV" (random output)

isArrayNullOrEmpty

isArrayNullOrEmpty([]); // => true
isArrayNullOrEmpty(null); // => true
isArrayNullOrEmpty([1, 2]); // => false

isDefined

isDefined(undefined); // => false
isDefined(null); // => false
isDefined(0); // => true

isNumberNullOrZero

isNumberNullOrZero(0); // => true
isNumberNullOrZero(null); // => true
isNumberNullOrZero(10); // => false

isStringNullOrEmpty

isStringNullOrEmpty(""); // => true
isStringNullOrEmpty("hello"); // => false

isStringNullOrEmptyOrUndefined

isStringNullOrEmptyOrUndefined(undefined); // => true
isStringNullOrEmptyOrUndefined(""); // => true
isStringNullOrEmptyOrUndefined("text"); // => false

muteColor

muteColor("#FF5733");
// => "#ff9e80" (result may vary depending on muting factors)

noop

noop(); // => undefined

regexCheck

regexCheck("Hello123", /^[A-Za-z0-9]+$/); // => true
regexCheck("Hello!", /^[A-Za-z0-9]+$/); // => false

sort

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

📄 License

ISC


Releases

No releases published

Packages

No packages published