4.0.2 • Published 6 months ago

@lawlzer/utils v4.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

@lawlzer/utils

A collection of TypeScript utilities designed to streamline common programming tasks. This package provides over 50 well-tested utility functions covering everything from async operations to data manipulation. These utilities are focused on being useful for me, so I wouldn't necessarily recommend using them. Feel free to steal any of my utilities or use the package if you'd like, though! It is designed to be simple-to-use :)

npm version License: MIT

Features

  • 🚀 50+ Utility Functions - Comprehensive collection for common tasks
  • 📦 Tree-shakeable - Import only what you need
  • 🔧 TypeScript First - Full TypeScript support with proper types
  • 🎯 Zero Dependencies - Minimal footprint (only essential deps)
  • Well Tested - Extensive test coverage
  • 🏗️ ESM & CommonJS - Works everywhere

Installation

npm install @lawlzer/utils
yarn add @lawlzer/utils
pnpm add @lawlzer/utils

Quick Samples

import { sleep, retry, deepCompare, clamp, getRandomCharacters, shuffleArray, getUniques } from '@lawlzer/utils';

// Wait for 2 seconds
await sleep('2s'); // Also accepts numbers: sleep(2000)

// Retry an async operation with timeout
const result = await retry(5000, async () => {
	return await fetchSomeData();
});

// Deep compare objects
const isEqual = deepCompare({ a: 1, b: { c: 2 } }, { a: 1, b: { c: 2 } }); // true

// Clamp a number between min and max
const clamped = clamp(150, 0, 100); // 100

// Generate random string with letters and numbers
const randomStr = getRandomCharacters(10, { letters: true, numbers: true }); // e.g. "a7Bc9Ef2Gh"

// Shuffle an array
const shuffled = shuffleArray([1, 2, 3, 4, 5]); // e.g. [3, 1, 5, 2, 4]

// Get unique values from array
const unique = getUniques([1, 2, 2, 3, 3, 4]); // [1, 2, 3, 4]

Development

Building

# Build for production
npm run build

# Build with watch mode
npm run build:watch

The build process:

  • Generates both ESM (.js) and CommonJS (.cjs) outputs (so the code can be used in /any/ codebase?)
  • Creates TypeScript declarations (.d.ts) (TypeScript!!!)
  • Includes source maps for debugging (can read source code for easier debugging)
  • Tree-shakes unused code
  • Minifies in production mode

Testing

# Run unit tests
npm test

# Run integration tests
npm run test:integration:consumer

Linting

# Run all linters
npm run lint:all

# Run ESLint
npm run lint:eslint

# Run Prettier
npm run lint:prettier

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. Make sure to:

  1. Add tests for new utilities
  2. Update TypeScript types
  3. Add documentation for new functions

Repository

GitHub - Lawlzer/utils

Author

Lawlzer

License

MIT © Kevin Porter

4.0.1

7 months ago

4.0.0

7 months ago

4.0.2

6 months ago

3.4.14

2 years ago

3.4.15

2 years ago

3.4.13

2 years ago

3.4.12

2 years ago

3.4.11

2 years ago

3.4.9

2 years ago

3.4.0

2 years ago

3.4.4

2 years ago

3.4.3

2 years ago

3.4.2

2 years ago

3.4.1

2 years ago

3.4.8

2 years ago

3.4.7

2 years ago

3.4.6

2 years ago

3.4.5

2 years ago

3.3.1

2 years ago

3.2.24

3 years ago

3.3.0

3 years ago

3.2.23

3 years ago

3.2.22

3 years ago

3.2.21

3 years ago

3.2.19

3 years ago