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 🙏

© 2025 – Pkg Stats / Ryan Hefner

recurring-functions

v1.2.0

Published

Collection of recurring javascript / typescript functions.

Readme

Recurring functions

codecov

Recurring functions that are usually found and used on Stackoverflow or other code sharing websites. Exported function are not minified so please use a minifier/bundler if you use any.

  • No dependencies
  • Written in Typescript
  • Short aliases for all function names
npm i recurring-functions

Functions

Function names and there aliases are unique. They also documented for autocompletion with typedoc. More information or credits can be found in each function.

addToArrayIfNotExists

Add value to array if the value does not exists (no objects);

import { addToArrayIfNotExists } from 'recurring-functions';

addToArrayIfNotExists([1, 2, 3], 3);

// output: [1,2,3]

Aliases: addToArrIfNotExi ataine

capitalizeFirstLetter

Capitalize the first letter of a string / text

import { capitalizeFirstLetter } from 'recurring-functions';

capitalizeFirstLetter('some text');

// output: "Some text"

Aliases: capFirLet cfl

deepCopy

Deep copy of object or array

import { deepCopy } from 'recurring-functions';

deepCopy({});

// output: {}

Aliases: deeCop dc

distanceGeoPoints

This routine calculates the distance between two points (given the latitude/longitude of those points). It is being used to calculate the distance between two locations using GeoDataSource (TM) products

import { deepCopy } from 'recurring-functions';

distanceGeoPoints(59.3293371, 13.4877472, 59.3225525, 13.4619422, 'K');

// output: 1.6467140606313462

Aliases: disGeoPoi dgp

mergeArraysByKey

Merges two or more arrays of objects into a single array by merging objects with the same key

import { mergeArraysByKey } from 'recurring-functions';

const arr1 = [{ resourceId: '1' }, { resourceId: '2' }];
const arr2 = [{ resourceId: '2' }, { resourceId: '3' }];
mergeArraysByKey('resourceId', arr1, arr2);

// output: [{resourceId: "1"},{resourceId: "2"},{resourceId: "3"}]

Aliases: merArrByKey mabk

randomNumberBetween

Get a random number between 2 numbers

import { randomNumberBetween } from 'recurring-functions';

randomNumberBetween(1, 5);

// e.g. output: 4

Aliases: radNumBet rnb

removeElementsByClass

Removes items from dom by class name. Requires: document, works only in browsers.

import { removeElementsByClass } from 'recurring-functions';

removeElementsByClass('popup');

Aliases: remEleByCla rebc

shortenLargeNumber

Shorten large number similar to youtube views.

import { shortenLargeNumber } from 'recurring-functions';

shortenLargeNumber(300000);

// output: 300k

Aliases: shoLarNum sln

sleep

Function for testing e.g. loading time in a async function.

import { sleep } from 'recurring-functions';

async function test() {
  const date = new Date().getTime();
  await sleep(1000);
  return new Date().getTime() - date >= 1000 ? true : false;
}

test();

// output: true

Aliases: sle s

Test

If you want to test the functions run the test command

npm run test

Pull requests

Feel free to do one