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
Markdown
# π§° 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