@creatrix/helper
v0.0.1
Published
A lightweight TypeScript utility library with helper functions for strings, arrays, numbers, objects, and more.
Maintainers
Readme
@creatrix/helper
A lightweight TypeScript utility library providing common helper functions for strings, arrays, numbers, objects, and more. Includes functions for HTML entity decoding, type-safe checks, conversions, reading time estimation, and more.
Features
- Type-safe checks for strings and arrays (
isNotEmptyString,isArrayCount) - HTML entity decoding and replacements (
entity,entityReplace) - String manipulation (capitalize, clean strings, get first letters, remove duplicates)
- Array operations (sum numbers, split by separator, add keys to object)
- Number conversions (
parseToNumber,bytesToMegaBytes,megaBytesToBytes) - Boolean parsing (
parseToBoolean) - Color formatting (
HexColorOrString) - Reading time estimation (
estimateReadingTime)
Installation
# Using npm
npm install @creatrix/helper
# Using yarn
yarn add @creatrix/helper
import {
isNotEmptyString,
entity,
entityReplace,
capitalize,
isArrayCount,
startsWith,
parseToNumber,
parseToBoolean,
sumFromArrayOfNumbers,
cleanString,
SplitByComma,
AddKeytoExistingObject,
getFirstCharOfString,
getFirstLetters,
bytesToMegaBytes,
megaBytesToBytes,
removeDuplicateWords,
HexColorOrString,
estimateReadingTime
} from '@creatrix/helper';
isNotEmptyString('Hello'); // true
entity('&'); // '&'
entityReplace('', 'Default'); // 'Default'
capitalize('hello world'); // 'Hello world'
getFirstLetters('Hello World'); // 'HW'
removeDuplicateWords('hello hello world'); // 'hello world'
cleanString(' Extra spaces '); // 'Extra spaces'
isArrayCount([1, 2, 3]); // true
sumFromArrayOfNumbers([1, '2', undefined]); // 3
SplitByComma('a,b,c').then(console.log); // ['a','b','c']
const obj = { name: 'John' };
AddKeytoExistingObject(obj, [{ key: 'age', value: 30 }]).then(console.log);
// { name: 'John', age: 30 }
parseToNumber('42'); // 42
parseToBoolean('1'); // true
bytesToMegaBytes(1048576, 2); // '1.00'
megaBytesToBytes(1.5); // 1572864
HexColorOrString('#FF0000'); // '[#FF0000]'
estimateReadingTime('This is a test'); // 1
startsWith('Hello World', 'He'); // true
getFirstCharOfString('Hello'); // 'e'