npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@corentinth/chisels

v1.1.0

Published

Collection of utilities for JavaScript and TypeScript, lightweight and tree-shakable.

Downloads

555

Readme

Chisels - JS/TS utilities and types

Opinionated collection of reusable JS/TS utilities and types.

  • Tree-shakable ES modules: Import only what you need
  • Fully tested: Rigorous unit tests with comprehensive coverage
  • TypeScript support: Written in TypeScript with full type definitions
  • Lightweight: Small bundle size
  • Modern: Written with modern JS/TS syntax
  • Named arguments: Functions with preferably named arguments

Installation

# Using npm
npm install @corentinth/chisels

# Using yarn
yarn add @corentinth/chisels

# Using pnpm
pnpm add @corentinth/chisels

Usage

// Using ES6 import
import { safely } from '@corentinth/chisels';

// Using CommonJS require
const { safely } = require('@corentinth/chisels');

const [result, error] = safely(mayThrowError);

console.log({ result, error });

API

safelySync

Function - See source

Safely executes a function and return a tuple with the result and an error if any.

const [result, error] = safelySync(myFunction);

if (error) {
 console.error(error);
}

console.log(result);

safely

Function - See source

Safely executes an async function or promise and return a tuple with the result and an error if any.

const [result, error] = await safely(myFunction);

if (error) {
 console.error(error);
}

console.log(result);

formatBytes

Function - See source

Formats a number of bytes into a human-readable string.

const formatted = formatBytes({ bytes: 4194304 });

console.log(formatted); // 4 MiB

castError

Function - See source

Casts an unknown value to an Error.

 try {
     // ...
 } catch (rawError) {
   const error = castError(rawError);

   // Do something with a proper Error instance
 }

joinUrlPaths

Function - See source

Join URL parts and trim slashes.

const url = joinUrlPaths('/part1/', '/part2/', 'part3', 'part4/');

console.log(url); // 'part1/part2/part3/part4'

buildUrl

Function - See source

Functional wrapper around URL constructor to build an URL string from a base URL and optional path, query params and hash.

const url = buildUrl({ baseUrl: 'https://example.com', path: 'foo', queryParams: { a: '1', b: '2' }, hash: 'hash' });

console.log(url); // 'https://example.com/foo?a=1&b=2#hash'

injectArguments

Function - See source

Injects arguments into a set of functions. Useful for DI of repositories, services, etc.

 const functions = {
  getUser: ({ userId, db }) => db.users.find({ id: userId }),
  removeUser: ({ userId, db }) => db.users.remove({ id: userId }),
 };

 const { getUser, removeUser } = injectArguments(functions, { db });

 getUser({ userId: 1 });
 removeUser({ userId: 1 });

PartialBy

Type alias - See source

Make some properties of T optional

type User = {
  id: number;
  name: string;
  email: string;
};

type PartialUser = PartialBy<User, 'email' | 'name'>;

const user: PartialUser = { id: 1 };

Expand

Type alias - See source

Flatten an object type for better IDE support

Dictionary

Type alias - See source

Record<string, T> alias

const dictionary: Dictionary<number> = {
  a: 1,
  b: 2,
};

DeepPartial

Type alias - See source

Make all properties of T optional recursively

Subtract

Type alias - See source

Exclude properties of T that are in U

type User = {
  id: number;
  name: string;
  email: string;
};

type WithId = {
  id: number;
}

type UserWithoutId = Subtract<User, WithId>;

License

This project is licensed under the MIT License. See the LICENSE file for more information.

Credits and Acknowledgements

This project is crafted with ❤️ by Corentin Thomasset.