@gaki/js-utils
v0.0.5
Published
JavaScript utility functions
Readme
@trdev20/js-utils
A comprehensive TypeScript/JavaScript utility library providing a collection of helper functions for arrays, strings, objects, and numbers.
Installation
pnpm add @trdev20/js-utilsyarn add @trdev20/js-utilsnpm install @trdev20/js-utilsFeatures
- 🔍 Validators - Type checking and validation utilities
- 🛠️ Operators - Common operations for arrays, strings, and objects
- 📊 Getters - Helper functions to retrieve specific data
- 📦 TypeScript Support - Full type definitions included
Usage
String Utilities
import { upperFirst, toCamelCase, toKebabCase, truncate, slugify } from "@trdev20/js-utils";
upperFirst("hello"); // => 'Hello'
toCamelCase("hello-world"); // => 'helloWorld'
toKebabCase("helloWorld"); // => 'hello-world'
truncate("hello world", 5); // => 'hello...'
slugify("Hello World!"); // => 'hello-world'Array Utilities
import { uniqueArr, chunkArr, intersection, difference } from "@trdev20/js-utils";
uniqueArr([1, 2, 2, 3]); // => [1, 2, 3]
chunkArr([1, 2, 3, 4, 5], 2); // => [[1, 2], [3, 4], [5]]
intersection([1, 2, 3], [2, 3, 4]); // => [2, 3]
difference([1, 2, 3], [2, 3, 4]); // => [1]Object Utilities
import { pick, omit } from "@trdev20/js-utils";
pick({ a: 1, b: 2, c: 3 }, ["a", "c"]); // => { a: 1, c: 3 }
omit({ a: 1, b: 2, c: 3 }, ["b"]); // => { a: 1, c: 3 }Validators
import { isString, isNumber, isArray, isObject, isPrime, isOdd, isEven } from "@trdev20/js-utils";
isString("hello"); // => true
isNumber(123); // => true
isArray([1, 2, 3]); // => true
isObject({}); // => true
isPrime(7); // => true
isOdd(3); // => true
isEven(4); // => trueAPI Documentation
String Operators
upperFirst(str: string): Capitalizes the first letter of a stringtoCamelCase(str: string): Converts a string to camelCasetoKebabCase(str: string): Converts a string to kebab-casetoTitleCase(str: string): Converts a string to Title Casetruncate(str: string, length: number): Truncates a string to specified lengthslugify(str: string): Converts a string to URL-friendly format
Array Operators
uniqueArr<T>(arr: T[]): Returns array with unique itemschunkArr<T>(arr: T[], size: number): Splits array into chunksintersection<T>(arr1: T[], arr2: T[]): Returns common elementsdifference<T>(arr1: T[], arr2: T[]): Returns elements in arr1 not in arr2
Object Operators
pick<T, K extends keyof T>(obj: T, keys: K[]): Creates object with selected propertiesomit<T, K extends keyof T>(obj: T, keys: K[]): Creates object without specified properties
Validators
isString(value: unknown): Checks if value is stringisNumber(value: unknown): Checks if value is numberisArray(value: unknown): Checks if value is arrayisObject(value: unknown): Checks if value is objectisPrime(value: number): Checks if number is primeisOdd(value: number): Checks if number is oddisEven(value: number): Checks if number is evenisEmptyString(value: string): Checks if string is emptyisEmptyArray(value: unknown[]): Checks if array is emptyisEmptyObject(value: object): Checks if object is empty
License
MIT © [Rabah Taib]
