Skip to content

kodladev/uty

Repository files navigation

uty logo


This utility package provides helper functions for JavaScript tasks.

test  npm  shaking

Install

npm i uty

Overview

🔹 Type and Value Checks

Provides functions to assess variable types, compare values, and gather information about the system environment.

import { isArrayLike, isEqual } from 'uty/is';

isArrayLike('fruits'); //=> true

isEqual([1, 2, 3], [1, 2, 3, 4]); //=> false

more 'is' examples

🔹 Collection Interactions

Helpers for working with arrays and objects, providing functions for data extraction and manipulation.

import { pluck } from 'uty/collect';

pluck('name', 'detail.date', [
  { name: 'Albert', detail: { date: 1879 } },
  { name: 'Isaac', detail: { date: 1643 } },
]);

//=> {1879: 'Albert', 1643: 'Isaac'}

more 'collect' examples

🔹 Mathematical Operations

Efficient tools for a wide range of mathematical calculations designed to simplify number handling and analysis.

import { avg } from 'uty/math';

avg('pages', [
  { name: 'Les Miserables', pages: 176 },
  { name: 'My Left Foot', pages: 1096 },
]);
//=> 636

more 'math' examples

🔹 String Tools

Utility functions for easy and efficient string manipulation and formatting.

import { ucfirst, ucwords } from 'uty/string';

ucfirst('uty is simple'); //=> Uty is simple
ucwords('uty is simple'); //=> Uty Is Simple

🔹 Data Transformation

Converts data types and structures, making it easy to switch between arrays, objects, and other formats.

import { toArray } from 'uty/to';

toArray({ first: 'Lionel', middle: 'Andrés', last: 'Messi' });
//=> ['Lionel', 'Andrés', 'Messi']

more 'to' examples

🔹 Helpers

Commonly used utility functions that streamline coding patterns and reduce repetitive tasks.

import { pipe } from 'uty';
import { divisible, add, sum } from 'uty/math';

const total = pipe(divisible(2), add(10), sum);

total([1, 2, 3, 4, 5]);
//=> 26

await total(Promise.resolve([6, 7, 8, 9, 10]));
//=> 54

more helpers

🔹 Event Listeners

A simple, customizable event system for handling and emitting events.

import { event } from 'uty/event';

const bus = event();

bus.on('tick', number => {
  console.log(number);
});

bus.emit('tick', 1);
//=> 1

more 'event' examples

🔹 Define Hub

A set of consistent values used throughout the application to maintain clarity and reduce redundancy.

import { MAX_SAFE_INTEGER, RGX_WHITESPACE } from 'uty/define';

console.log(MAX_SAFE_INTEGER); //=> 9007199254740991
console.log(RGX_WHITESPACE); //=> /^\s*$/

🔹 Type Utilities

Advanced type-checking and utilities to ensure safe operations.

import type { Include } from 'uty/type';

function isArray<T>(value: T): value is Include<T, unknown[] | Readonly<unknown[]>> {
  return Array.isArray(value);
}

Documentation

Visit our documentation for detailed guides and references.


Release Notes

All notable changes to this project will be documented in the changelog.

License

MIT

About

🛠️ JS utils library

Topics

Resources

License

Stars

Watchers

Forks