UNPKG

snappy-utils

Version:

A lightweight and efficient JavaScript utility library packed with commonly used helper functions like capitalize, debounce, deepClone, flattenArray, isPrime, and more. Ideal for developers who want a simple yet powerful toolkit to streamline everyday cod

125 lines (88 loc) β€’ 2.36 kB
# 🧰 Snappy Utils A lightweight and efficient JavaScript utility library packed with commonly used helper functions like `capitalize`, `debounce`, `deepClone`, `flattenArray`, `isPrime`, and more. Designed to make everyday development easier and cleaner. --- ## πŸš€ Features - βœ… Capitalize strings - βœ… Debounce functions - βœ… Deep clone objects/arrays - βœ… Flatten nested arrays - βœ… Format dates - βœ… Check for prime numbers - βœ… Merge objects - βœ… Generate random numbers in a range - βœ… Truncate strings - βœ… Get unique values from arrays --- ## πŸ“¦ Installation ```bash npm install snappy-utils ``` or with yarn: ```bash yarn add snappy-utils ``` --- ## πŸ› οΈ Usage ```js import { capitalize, debounce, deepClone, flattenArray, formatDate, isPrime, mergeObjects, randomInRange, truncateString, uniqueArray } from 'snappy-utils'; console.log(capitalize("hello")); // "Hello" console.log(flattenArray([1, [2, [3]]])); // [1, 2, 3] console.log(isPrime(7)); // true ``` --- ## πŸ“‚ File Structure ``` β”œUtils/ β”œβ”€β”€ capitalize.js β”œβ”€β”€ debounce.js β”œβ”€β”€ deepClone.js β”œβ”€β”€ flattenArray.js β”œβ”€β”€ formatDate.js β”œβ”€β”€ isPrime.js β”œβ”€β”€ mergeObjects.js β”œβ”€β”€ randomInRange.js β”œβ”€β”€ truncateString.js β”œβ”€β”€ uniqueArray.js β”œ index.js # Exports all functions β”œ package.json β”” README.MD ``` --- ## πŸ“š Functions Reference ### `capitalize(string)` Capitalize the first letter of a string. ### `debounce(func, delay)` Limit how often a function is executed. ### `deepClone(obj)` Deeply clone an object or array. ### `flattenArray(arr)` Flatten deeply nested arrays into a single-level array. ### `formatDate(date)` Format a date object into a readable string. ### `isPrime(num)` Check whether a number is prime. ### `mergeObjects(obj1, obj2)` Merge two objects into one. ### `randomInRange(min, max)` Generate a random number within a given range. ### `truncateString(str, maxLength)` Truncate a string and add `...` if it exceeds the specified length. ### `uniqueArray(arr)` Return a new array with only unique values. --- ## πŸ“„ License ISC --- ## πŸ§‘β€πŸ’» Author Made with πŸ’™ by Prem Chavan