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

@sekiju/utilities

v1.0.2

Published

Common Node.js utilities library

Downloads

3

Readme

Table of Contents

Description

This is a library with common functions to help with programming. I got tired of moving utilities from one project to another, so I made this library.


Utilities

isClass

Verifies if the input is a class constructor.

class A {}

isClass(A) // true
isClass(function () {}) // false

isFunction

Verifies if the input is a function.

isFunction(function () {}) // true
isFunction('foo') // false

isUrl

Verifies if the input string is a valid url

isUrl('https://example.com') // true
isUrl('100PercentNotUrl') // false

isNumber

Verifies if a number is a finite number.

isNumber(10) // true
isNumber('10') // false

isObject

Verify if the input is an object literal (or class).

isObject({}) // true
isObject([]) // true
isObject('foo') // false

isNullOrUndefined

Checks whether a value is null or undefined.

isNullOrUndefined(null) // true
isNullOrUndefined(undefined) // true
isNullOrUndefined(1) // false

isNullOrUndefinedOrEmpty

Checks whether or not a value is null, undefined or '', []

isNullOrUndefinedOrEmpty('') // true
isNullishOrEmpty('') // true

isNullOrUndefinedOrZero

Checks whether or not a value is null, undefined or 0

isNullOrUndefinedOrZero(0) // true
isNullishOrZero(0) // true

fetchFiles

Fetches file paths from a directory

.
└── root/
    └── images/
        ├── jpeg/
        │   └── 01.jpeg
        └── 01.png
/**
 * @param dir Directory with files
 * @param includeSubdirectories Include subdirectories
 */

fetchFiles('/root/images') // ['/root/images/01.png']
isNullOrUndefined('/root/images', true) // ['/root/images/01.png', '/root/images/jpeg/01.jpeg']

clamp

Limiting number by min and max values

clamp(15, 1, 13) // 13
clamp(3, 5, 10) // 5
clamp(7, 0, 100) // 7

pickRandom

Picks a random element from an array

pickRandom([0, 1, 2, 3, 4, 5]) // 3
pickRandom([0, 1, 2, 3, 4, 5], 2) // [3, 0]

chunk

Splits an array into smaller arrays of a specified size

chunk([1000, 7, 993, 7], 2) // [[1000, 7], [993, 7]]

flatten

Flattens a nested array (i.e., an array of arrays) into a single-level array

flatten([[1, 2, 3], [9, 9, 3]]) // [1, 2, 3, 9, 9, 3]

generateString

Generates string from latin chars with numbers

generateString(8) // BbLzLcN3

cleanObject

Clean undefined and null values from object

cleanObject({ foo: 'bar', nullish: null }) // { foo: 'bar' }

sleep

await sleep(1000) // Sleep 1 second