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

pan-lib

v1.7.2

Published

A lightweight library featuring a collection of small, versatile functions designed to streamline your development experience and enhance productivity.

Downloads

25

Readme

pan-lib

 pnpm install pan-lib

Documentation

Clamp

The clamp function takes in three parameters:

  • min (required): The minimum value that the number parameter can take.
  • max (required): The maximum value that the number parameter can take.
  • value (required): The number to be clamped.
  • return: The clamped number.
import { clamp } from 'pan-lib';

clamp(1, 1, 2); // returns 1
clamp(0, 1, 2); // returns 1
clamp(3, 1, 2); // returns 2

clamp(5, 1, 1) // Error : min must be less than or equal to max

Throw

If min is greater than max, an error is thrown with the message "min must be less than or equal to max".

Capitalize

Function: Capitalize the first letter of a string The capitalize function takes in one parameter:

  • string (required): The string to be capitalized.
  • return: The capitalized string.
import { capitalize } from 'pan-lib';

capitalize('hello world'); // returns 'Hello world'
capitalize('Hello'); // returns 'Hello'

Throw

if srting is empty, an error is thrown with the message "string must not be empty".

Truncate

The truncate function takes in two parameters:

  • string (required): The string to be truncated.
  • length (required): The length of the truncated string.
  • suffix (optional): The suffix to be added to the truncated string.
  • return: The truncated string.
import { truncate } from 'pan-lib';

truncate('hello world', 5); // returns 'hello...'
truncate('hello world', 5, '!!!'); // returns 'hello!!!'

Throw

If string is empty, an error is thrown with the message "str cannot be null or undefined".

Chunk

The chunk function takes in two parameters:

  • array (required): The array to be chunked.
  • size (required): The size of the chunked array.
  • return: The chunked array.
import { chunk } from 'pan-lib';

chunk([1, 2, 3, 4, 5], 2); // returns [[1, 2], [3, 4], [5]]
chunk([1, 2, 3, 4, 5], 3); // returns [[1, 2, 3], [4, 5]]

Throw

If size is less than or equal to 0, an error is thrown with the message "size must be greater than 0".

Lerp

lerp is a critical function for animations, allowing smooth transitions between two states or values of properties.

The lerp function takes in three parameters:

  • start (required): The start value.
  • end (required): The end value.
  • amount (required): The amount to be lerped.
  • return: The lerped value.
import { lerp } from 'pan-lib';

lerp(0, 10, 0.5); // returns 5
lerp(0, 10, 0.2); // returns 2

Throw

If amount is less than 0 or greater than 1, an error is thrown with the message "amount must be between 0 and 1".

Random color

The randomColor function takes in no parameters:

  • return: A random color to hex or rgb.
import { generateRandomColor } from 'pan-lib';

generateRandomColor().toHex(); // returns '#f2f2f2'
generateRandomColor().toRgb(); // returns 'rgb(242, 242, 242)'