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

js-util-methods

v1.0.8

Published

Javascript usefull utility functions

Downloads

3

Readme

What is this ?

Lightweight, usefull, tiny size(<4kb), javascript package for commenly used utility functions.

Installation

npm i js-util-methods

How to use ?

import { findAvg } from 'js-util-methods'

findAvg([12, 13, 14, 15, 16, 17]);
  • For static server to serve your static build folder use package with (< kb) size. ind-js-server.

  • For use in typescript projects follow the steps below.

  • Create file with name .d.ts copy and paste below code in created file.

  • declare module 'js-util-methods';

What all utility functions there ?

  • findAvg(List of numbers) => number
  • isEmpty(object | array | null | undefined) => boolean
    isEmpty({}) => true
    isEmpty([]) => true
    isEmpty({ name: 'Pujari', age: 20 }) => false
    isEmpty([1, 2, 3]) => false
  • sortBy(array, compareType, sortType) => sorted array (orderBy also can be done)
    const arr = [
        { name: 'Raj', age: 21 },
        { name: 'Tiwari', age: 20 },
        { name: 'Pujari', age: 20 },
        { name: 'Avi', age: 30 }
    ]
    sortBy(arr, 'name', 'asc') =>
        [
            { name: 'Avi', age: 30 },
            { name: 'Pujari', age: 20 },
            { name: 'Raj', age: 21 },
            { name: 'Tiwari', age: 20 }
        ]
  • uniqBy(arr, predicate) => arr
    const arr = [
        { name: 'Raj', age: 21 },
        { name: 'Tiwari', age: 20 },
        { name: 'Pujari', age: 20 }
    ]
    uniqBy(arr, 'age') =>
    [
        { name: 'Raj', age: 21 }
        { name: 'Tiwari', age: 20 }
    ]
  • groupBy(arr, property) => grouped obj
    const arr = [
        { name: 'Raj', age: 21 },
        { name: 'Tiwari', age: 20 },
        { name: 'Pujari', age: 20 }
    ]
    groupBy(arr, 'age') =>
    {
      20: [
        { name: 'Tiwari', age: 20 },
        { name: 'Pujari', age: 20 }
      ],
      21: [{ name: 'Raj', age: 21 }]
    }
  • deepCopy(obj) => deepcopied Object (Works better than JSON.parse(JSON.stringify(obj)))
    const a = {
        string: 'string',
        number: 123,
        bool: false,
        nul: null,
        date: new Date(),
        undef: undefined,
        inf: Infinity,
        re: /.*/,
    }

    const b = deepCopy(a);
    b => {
        string: 'string',
        number: 123,
        bool: false,
        nul: null,
        date: new Date(),
        undef: undefined,
        inf: Infinity,
        re: /.*/,
    }
  • deleteObjProperty(obj, property) => obj
  • isValidObjProperty(obj, property) => boolean
  • isArrHasElement(arr, element) => boolean
    isArrHasElement([12, 34, 'pujari'], 'pujari') => true
    isArrHasElement([12, 34, 'pujari'], 50) => false
  • isArrHasObject(arr, obj, predicate) => boolean
    isArrHasObject(arr, { name: 'Tiwari', age: 20 }, age) => true
    isArrHasObject(arr, { name: 'Tiwari', age: 30 }, age) => false
  • toCamelCase(string) => string
  • getPercentage(totalValue, value) => number
  • formatPriceINR(price, isDecimalRequired = true, isRSRequried = true) => string
  • getMobileFormat(valid mobile number(123 4567 890)) => string in format (+91 123 4567 890)
  • getFirstElement(list of elements) => single object
  • calculateDiscountPercentage(price, discountedPrice) => number
  • calculatePriceFromDiscount(price, discountPercent) => number
  • getDobFromAge(age in number) => DOB in Date format
  • getAgeFromDob(DOB in Date format) => age in number
  • capitalizeFirstLetter(string) => string