npm package: @praveenupadhyay997/help-your-self
Description: A comprehensive collection of utility functions for JavaScript/TypeScript
Author: Praveen Upadhyay
Latest version: 1.0.0

# @praveenupadhyay997/help-your-self

[![npm version](https://badge.fury.io/js/%40praveenupadhyay997%2Fhelp-your-self.svg)](https://badge.fury.io/js/%40praveenupadhyay997%2Fhelp-your-self)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Build Status](https://github.com/praveenupadhyay997/help-your-self/actions/workflows/ci.yml/badge.svg)](https://github.com/praveenupadhyay997/help-your-self/actions)
[![codecov](https://codecov.io/gh/praveenupadhyay997/help-your-self/branch/main/graph/badge.svg)](https://codecov.io/gh/praveenupadhyay997/help-your-self)

A comprehensive collection of utility functions for JavaScript/TypeScript projects.

## Features

- 🛠 **Core Utilities**: Essential utility functions like `noop`, `identity`, `once`, etc.
- 📝 **String Manipulation**: String formatting, case conversion, and more.
- 🔢 **Array & Object Helpers**: Common operations on arrays and objects.
- ⏱ **Async Control**: `debounce`, `throttle`, `retry`, and other async patterns.
- 📅 **Date & Time**: Date manipulation and formatting utilities.
- 🔗 **URL & Query**: URL parsing and manipulation.
- 🔒 **Security**: Common security-related utilities.
- 🌐 **HTTP Helpers**: Common HTTP request utilities.
- 🗃 **Storage**: LocalStorage, SessionStorage, and cookie helpers.
- 🧪 **Validation**: Common validation functions.

## Installation

```bash
npm install @praveenupadhyay997/help-your-self
# or
yarn add @praveenupadhyay997/help-your-self
```

## Usage

```typescript
import { noop, identity, once, clamp, inRange } from '@praveenupadhyay997/help-your-self';

// Core utilities
const doNothing = noop();
const result = identity(42); // 42

const initialize = once(() => {
  console.log('Initialized!');
  return { initialized: true };
});

initialize(); // Logs: Initialized!
initialize(); // Does nothing on subsequent calls

// Number utilities
const value = clamp(10, 0, 5); // 5
const isInRange = inRange(3, 1, 5); // true
```

## Available Utilities

### Core
- `noop` - A function that does nothing
- `identity` - Returns the first argument it receives
- `once` - Creates a function that can only be called once
- `clamp` - Restricts a number between a min and max value
- `inRange` - Checks if a number is within a specified range

### Strings
- `capitalize` - Capitalizes the first letter of a string
- `camelCase` - Converts a string to camelCase
- `kebabCase` - Converts a string to kebab-case
- `snakeCase` - Converts a string to snake_case
- `truncate` - Truncates a string to a specified length
- `stripHtml` - Removes HTML tags from a string
- `randomString` - Generates a random string

### Arrays
- `chunk` - Splits an array into chunks of a given size
- `compact` - Removes falsy values from an array
- `unique` - Returns unique values from an array
- `flatten` - Flattens a nested array
- `groupBy` - Groups array elements by a key
- `partition` - Partitions an array based on a condition
- `zip` - Zips multiple arrays together
- `unzip` - Unzips an array of pairs
- `difference` - Returns the difference between two arrays
- `intersection` - Returns the intersection of two arrays

### Objects
- `deepClone` - Creates a deep clone of an object
- `deepMerge` - Deeply merges multiple objects
- `get` - Safely gets a nested property from an object
- `set` - Safely sets a nested property on an object
- `hasPath` - Checks if a path exists in an object
- `omit` - Omits specified properties from an object
- `pick` - Picks specified properties from an object
- `mapValues` - Maps over object values
- `invert` - Inverts object keys and values
- `freezeDeep` - Deeply freezes an object

### Async / Control
- `sleep` - Returns a promise that resolves after a delay
- `debounce` - Creates a debounced function
- `throttle` - Creates a throttled function
- `retry` - Retries a function a number of times
- `timeout` - Adds a timeout to a promise
- `memoizeAsync` - Memoizes an async function
- `limitConcurrency` - Limits the concurrency of async operations
- `poll` - Polls a function at a specified interval
- `withTimeoutSignal` - Adds a timeout signal to a function
- `raceAllSettled` - Waits for all promises to settle, then resolves with results

### Time & Date
- `nowIso` - Gets the current ISO date string
- `formatDate` - Formats a date according to a format string
- `parseDate` - Parses a date string into a Date object
- `addDays` - Adds days to a date
- `differenceInDays` - Gets the difference in days between two dates
- `toTimeZone` - Converts a date to a specific timezone
- `stopwatch` - A simple stopwatch utility
- `durationHumanize` - Humanizes a duration in milliseconds

### Numbers & Math
- `randomInt` - Generates a random integer in a range
- `roundTo` - Rounds a number to a specified precision
- `sum` - Calculates the sum of numbers
- `average` - Calculates the average of numbers
- `median` - Calculates the median of numbers

### URL & Query
- `parseQuery` - Parses a query string into an object
- `stringifyQuery` - Stringifies an object into a query string
- `getQueryParam` - Gets a query parameter from a URL
- `setQueryParam` - Sets a query parameter in a URL
- `normalizeUrl` - Normalizes a URL
- `joinUrl` - Joins URL parts

### Env / Platform
- `isBrowser` - Checks if the code is running in a browser
- `isNode` - Checks if the code is running in Node.js
- `isMobile` - Detects mobile devices
- `isTouchDevice` - Checks if the device supports touch
- `prefersDarkMode` - Checks if the user prefers dark mode
- `getEnvVar` - Gets an environment variable with a fallback

### DOM
- `qs` - Alias for `document.querySelector`
- `qsa` - Alias for `document.querySelectorAll`
- `on` - Adds an event listener
- `off` - Removes an event listener
- `onceEvent` - Adds an event listener that only fires once
- `scrollToElement` - Smooth scrolls to an element

### Storage & Clipboard
- `getLocal` - Gets an item from localStorage
- `setLocal` - Sets an item in localStorage
- `removeLocal` - Removes an item from localStorage
- `getSession` - Gets an item from sessionStorage
- `copyToClipboard` - Copies text to the clipboard

### Security
- `uuid` - Generates a UUID
- `hashSHA256` - Hashes a string with SHA-256
- `constantTimeEqual` - Constant time string comparison
- `sanitizeHtml` - Sanitizes HTML to prevent XSS

### HTTP / Network
- `fetchJson` - Fetches and parses JSON
- `getWithRetry` - Fetches with retry logic
- `postJson` - Sends a POST request with JSON body
- `uploadFormData` - Uploads a file using FormData
- `exponentialBackoff` - Implements exponential backoff

### Files (Node.js)
- `readJsonFile` - Reads and parses a JSON file
- `writeJsonFile` - Writes an object to a JSON file
- `ensureDir` - Ensures a directory exists
- `fileExists` - Checks if a file exists

### Validation
- `isEmail` - Validates an email address
- `isUrl` - Validates a URL
- `isUUID` - Validates a UUID
- `isEmpty` - Checks if a value is empty
- `isISODate` - Validates an ISO date string

### Formatting
- `bytesToHuman` - Formats bytes to a human-readable string

### Parsing
- `parseCookies` - Parses a cookie string into an object

## Contributing

Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details on how to contribute to this project.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.