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 🙏

© 2026 – Pkg Stats / Ryan Hefner

punyutility

v1.0.1

Published

Small size JavaScript utilities library

Downloads

7

Readme

Puny Utility v1.0.1

A simple library to make coding life easy. It is light weight & do not make your project heavy.

Documentation

In the documentation we will go through the utilities available in the library.

sum

Find sum on n numbers.

import { sum } from "punyutility";

const s = sum(1, 2, 3, 4);      // 10

// or

const s = sum(...[1, 2, 3, 4]); // 10

multiply

Find multiplication on n numbers.

import { multiply } from "punyutility";

const s = multiply(2, 3, 4);      // 24

// or

const s = multiply(...[2, 3, 4]); // 24

capitalize

Capitalize the 1st letter of the argument.

import { capitalize } from "punyutility";

const s = capitalize("my name is coder"); // My name is coder

startCase

Capitalize the 1st letter of each word in the argument.

import { startCase } from "punyutility";
const s = startCase("my name is coder"); // My Name Is Coder

randomNumber

Generate a random number within a given range from min to max.

import { randomNumber } from "punyutility";

/**
 * @description pass the minimum & maximum.
 */
randomNumber(0, 10);  // 10

randomNumber(0, 10);  // 1

randomNumber(0, 10);  // 4

/**
 * @description if we pass a min value higher than max value. then the min value will be always the output.
 */
randomNumber(6, 0);   // 6

randomString

Generate a random string of length n.

import { randomString } from "punyutility";

randomString(10); // O1YrojMtjd

randomString(10); // wwJzClgolN

time

A simple native time object returns the date and time in 24 hours format. No extra 3rd party library.

time(new Date());

Sample ouput:

{
  day: 'Monday',
  month: 'September',
  date: 8,
  year: 2025,
  hours: 15,
  minutes: 4,
  seconds: 16
}

Allowed argument types,

time("7-18-2024");    // mm-dd-yyyy
time("07-18-2024");
time("7/18/2024");    // mm/dd/yyyy
time("07/18/2024");
time(1757324387458);  // milliseconds
time(new Date());     // date

The output will be:

{
  day: 'Thursday',
  month: 'July',
  date: 18,
  year: 2024,
  hours: 0,
  minutes: 0,
  seconds: 0
}

detectFileType

Understand the file type by the base64 string. Helps render the file icon when rendering on the UI.

import { detectFileType } from "punyutility";

/**
 * @description pass the base64 string as argument.
 */
detectFileType("iVBORw0KGgo..."); // png

hasAInB

Compares 2 objects and returns either true or false.

import { hasAInB } from "punyutility";

hasAInB({}, {}); // true

// or

hasAInB({ name: "Raju Das", age: 18 }, { name: "Raju Das" });         // false

// or

hasAInB({ name: "Raju Das", age: 18 }, { name: "Raju Das", age: 1 })  // false

// or

hasAInB({ name: "Raju Das", age: 18 }, { name: "Raju Das", age: 18 }) // true

cloneDeep

The lightest code block for creating deep copy of objects & arrays.

import { cloneDeep } from "punyutility";

const itemA = {
  name: "Raja",
  address: {
    city: "Kolkata",
    state: "West Bengal"
  },
  getAddress() {
    return `${this.address.city}, ${this.address.state}`;
  }
};

const itemB = cloneDeep(itemA);
itemB.address.city = "Mumbai";
itemB.address.state = "Maharashtra";

itemA.getAddress(); // Kolkata, West Bengal
itemB.getAddress(); // Mumbai, Maharashtra

filter

Filter an array of objects.

import { filter } from "punyutility";

interface Student {
  fName: string;
  lName: string;
  age: number;
  subjects: string[];
};

const students: Student[] = [
  { fName: "Raju", lName: "Biswas", age: 14, subjects: ["Math", "Physics"] },
  { fName: "Swapna", lName: "Halder", age: 15, subjects: ["Math"] },
  { fName: "Surojit", lName: "Sen", age: 14, subjects: ["Physics"] },
];

filter(students, { age: 14 });

Output will be:

[
  { fName: 'Surojit', lName: 'Sen', age: 14, subjects: [ 'Physics' ] }
]

flatten

Flatten array elements. Supports multidimensional arrays.

import { flatten } from "punyutility";

type NumberMultiArray = (number | NumberMultiArray)[];

const itemsA: NumberMultiArray = [1, [2]]; // we can declare the items like this.
flatten(itemsA); // [1, 2]

const itemsB: NumberMultiArray = [1, [2], [[3], [4], [5, [6], [7], [8, 9, 10]], [10, 12]]];
flatten(itemsB);

/**
 * Output:
 * [
 *  1,  2, 3, 4,  5,
 *  6,  7, 8, 9, 10,
 *  10, 12
 * ]
 */

Let's make it more complex by passing objects.

interface Student {
  name: string;
  roll: number;
  class: number;
}

type StudentMultiArray = (Student | StudentMultiArray)[];

const students: StudentMultiArray = [
  { name: "Rahul", roll: 6, class: 9 },
  { name: "Ana", roll: 7, class: 9 },
  [
    { name: "Sujoy", roll: 8, class: 9 },
    { name: "Purohit", roll: 9, class: 9 },
    [
      { name: "Swapna", roll: 10, class: 9 },
      [
        { name: "Rishav", roll: 11, class: 9 },
        { name: "Kushal", roll: 12, class: 9 },
        { name: "Sanjeev", roll: 13, class: 9 }
      ]
    ]
  ]
];

const flattenStudents: Student[] = flatten<Student>(students);

The output will be,

[
  { name: 'Rahul', roll: 6, class: 9 },
  { name: 'Ana', roll: 7, class: 9 },
  { name: 'Sujoy', roll: 8, class: 9 },
  { name: 'Purohit', roll: 9, class: 9 },
  { name: 'Swapna', roll: 10, class: 9 },
  { name: 'Rishav', roll: 11, class: 9 },
  { name: 'Kushal', roll: 12, class: 9 },
  { name: 'Sanjeev', roll: 13, class: 9 }
]

groupBy

A very powerful operation to arrage data under a certain group. Let's say we have a list of students,

interface Student {
  fName: string;
  lName: string;
  roll: number;
  class: number;
  hasPickAndDrop: boolean;
}

const students: Student[] = [
  { fName: "Rahul", lName: "Mishra", roll: 6, class: 9, hasPickAndDrop: true },
  { fName: "Ana", lName: "Dutta", roll: 7, class: 9, hasPickAndDrop: true },
  { fName: "Sujoy", lName: "Mishra", roll: 8, class: 9, hasPickAndDrop: false },
  { fName: "Purohit", lName: "Saha", roll: 9, class: 10, hasPickAndDrop: true },
  { fName: "Swapna", lName: "Halder", roll: 10, class: 9, hasPickAndDrop: false },
  { fName: "Rishav", lName: "Sharma", roll: 11, class: 9, hasPickAndDrop: true },
  { fName: "Kushal", lName: "Paul", roll: 12, class: 10, hasPickAndDrop: true },
  { fName: "Sanjeev", lName: "Dutta", roll: 13, class: 10, hasPickAndDrop: true },
];

We want to group the students by the hasPickAndDrop attribute,

const { groups, groupCollection } = groupBy<Student, "hasPickAndDrop">(students, "hasPickAndDrop");

The groups will be a 2D array.

[
  [true, [
    { fName: "Rahul", lName: "Mishra", roll: 6, class: 9, hasPickAndDrop: true },
    { fName: "Ana", lName: "Dutta", roll: 7, class: 9, hasPickAndDrop: true },
    { fName: "Purohit", lName: "Saha", roll: 9, class: 10, hasPickAndDrop: true },
    { fName: "Rishav", lName: "Sharma", roll: 11, class: 9, hasPickAndDrop: true },
    { fName: "Kushal", lName: "Paul", roll: 12, class: 10, hasPickAndDrop: true },
    { fName: "Sanjeev", lName: "Dutta", roll: 13, class: 10, hasPickAndDrop: true },
  ]],
  [false, [
    { fName: "Sujoy", lName: "Mishra", roll: 8, class: 9, hasPickAndDrop: false },
    { fName: "Swapna", lName: "Halder", roll: 10, class: 9, hasPickAndDrop: false },
  ]]
]

And, groupCollection will be a HashMap of booleans.

const groupCollection = new Map([
  [true, [
    { fName: "Rahul", lName: "Mishra", roll: 6, class: 9, hasPickAndDrop: true },
    { fName: "Ana", lName: "Dutta", roll: 7, class: 9, hasPickAndDrop: true },
    { fName: "Purohit", lName: "Saha", roll: 9, class: 10, hasPickAndDrop: true },
    { fName: "Rishav", lName: "Sharma", roll: 11, class: 9, hasPickAndDrop: true },
    { fName: "Kushal", lName: "Paul", roll: 12, class: 10, hasPickAndDrop: true },
    { fName: "Sanjeev", lName: "Dutta", roll: 13, class: 10, hasPickAndDrop: true },
  ]],
  [false, [
    { fName: "Sujoy", lName: "Mishra", roll: 8, class: 9, hasPickAndDrop: false },
    { fName: "Swapna", lName: "Halder", roll: 10, class: 9, hasPickAndDrop: false },
  ]]
]);

const whoDoNotNeedPickAndDrop: Student[] | undefined = groupCollection.get(false);

List of students who do not need pick and drop.

[
  { fName: "Sujoy", lName: "Mishra", roll: 8, class: 9, hasPickAndDrop: false },
  { fName: "Swapna", lName: "Halder", roll: 10, class: 9, hasPickAndDrop: false },
]

sortBy

Simple JavaScript Array.sort() function. It sorts an array of objects as per its datatypes.

Let's consider we have a list of students,

import { DateType, FieldType, SortOrder, sortBy } from "punyutility";

interface Student {
  name: string;
  roll: number;
  marks: number;
  hasOptionalSubject: boolean;
  joiningDate: DateType;
}

const students: Student[] = [
  { name: "Ajay Sahu", roll: 10, marks: 86, hasOptionalSubject: true, joiningDate: "09/01/2025" },
  { name: "Suraj Verma", roll: 11, marks: 78, hasOptionalSubject: true, joiningDate: "09/02/2025" },
  { name: "Keya Sharma", roll: 12, marks: 91, hasOptionalSubject: true, joiningDate: new Date("08/30/2025") },
  { name: "Ankita Kundu", roll: 13, marks: 79, hasOptionalSubject: false, joiningDate: "08/27/2025" },
  { name: "Navin Reddy", roll: 14, marks: 82, hasOptionalSubject: false, joiningDate: "09-02-2025" },
  { name: "Lalith Choudhary", roll: 15, marks: 83, hasOptionalSubject: true, joiningDate: new Date("09-03-2025") }
];

We will sort them by their marks (number), name (string), hasOptionalSubject (boolean) and joiningDate (DateType).

import { DateType, FieldType, SortOrder, sortBy } from "punyutility";

sortBy<Student, "marks">(students, "marks", FieldType.number, SortOrder.desc);

// or

sortBy<Student, "name">(students, "name", FieldType.string);

// or

sortBy(students, "hasOptionalSubject", FieldType.boolean, SortOrder.desc);

// or

sortBy(students, "joiningDate", FieldType.date, SortOrder.desc);

Pay close attention to the arguments,

  • When using TypeScript we can pass the <Student, "joiningDate">. Which is optional.
  • 1st - The list (required).
  • 2nd - A field present in the list objects (required).
  • 3rd - The typeof the field. Presented using enum FieldType (required).
  • 4th - The sorting order. Presented using enum SortOrder. Default value is SortOrder.asc.

The output will look like Student[].

numericOrNull

A simple function that returns either numeric or null. To keep the consistency of the numeric datatype we can use numericOrNull.

import { numericOrNull } from "punyutility";

numericOrNull("abhisek"); // null

numericOrNull("10");      // 10

numericOrNull(9);         // 9

numericOrNull("8.07");    // 8.07

numericOrNull(undefined); // null

Publish

Let's generate the build file,

npm run rollup

Increase the version count,

You must be logged in on npm. Then run,

npm publish --access private

If publishing public plugins use,

npm publish --access public