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

pocketwrench

v0.0.2

Published

An eclectic collection of JavaScript utilities

Readme

pocketwrench

An eclectic collection of JavaScript utilities

Build Status Coverage Status

Module Overview

Pocketwrench is a collection of JavaScript utility functions that I've found useful over the years. The collection is pretty eclectic, and reflects the various problems I've needed to solve on a bunch of different projects. The functions are split into different namespaces dependent on what they cover. For example, there is an 'array' namespace containing all the functions that operate on arrays. I've not attached any new functions to the built in object prototypes because the functions are often only applicable in certain circumstances.

The namespaces are:

  • array - Utility functions that operate on arrays of objects.
  • browser - Functions to aid interaction with the browser.
  • math - Mathematical functions.
  • object - Utility functions that operate on objects.

Usage

array Namespace

findFirstByField(array, fieldName, valueToSearchFor)

Find the first occurrence of an object with key fieldName and value valueToSearchFor.

var pocketwrench = require('pocketwrench');

var testCollection = [
  {name: 'Fred', age: 25},
  {name: 'Bob', age: 40},
  {name: 'Sally', age: 42},
  {name: 'Alice', age: 34},
  {name: 'Jane', age: 25}
];

pocketwrench.array.findFirstByField(testCollection, 'name', 'Sally');

==> {name: 'Sally', age: 42}
findByField(array, fieldName, valueToSearchFor)

Find all the objects with a key fieldName that have a value valueToSearchFor.

pocketwrench.array.findFirstByField(testCollection, 'age', 25);

==> [{name: 'Fred', age: 25}, {name: 'Jane', age: 25}]
findFirstIndexByField(array, fieldName, valueToSearchFor)

Find the index of the first occurrence of an object with key fieldName and value valueToSearchFor.

pocketwrench.array.findFirstIndexByField(testCollection, 'name', 'Sally');

==> 2
sortByField(array, fieldName, desc)

Sort an array of objects by attribute fieldName. desc is a boolean indicating the sort direction, true sorts descending, false (or omitting the argument altogeter) sorts ascending.

pocketwrench.array.sortByField(testCollection, 'name', false);

==> [
    {name: 'Alice', age: 34},
    {name: 'Bob', age: 40},
    {name: 'Fred', age: 25},
    {name: 'Jane', age: 25},
    {name: 'Sally', age: 42}
  ];
mostFrequentElement(collection, fieldName)

Find the most frequency occurring value for fieldName.

pocketwrench.array.mostFrequentElement(testCollection, 'age')

==> 25
countOccurrences(collection, fieldName, value)

Count the number of times value occurrs in fieldName.

pocketwrench.array.countOccurrences(testCollection, 'age', 25)

==> 2
uniqueValuesByField(collection, fieldName)

Return a list of unique values in fieldName.

pocketwrench.array.uniqueValuesByField(testCollection, 'age')

==> [25, 40, 42, 34]
uniqueValues(collection)

Return a list of unique values in a simple array.

pocketwrench.array.uniqueValues([1, 2, 1, 3, 2, 4, 2, 5, 1])

==> [1, 2, 3, 4, 5]

browser Namespace

getQuerystringValues()

Gets the query string as an object.

pocketwrench.browser.getQuerystringValues()

==> {
  'key1' : 'value1',
  'key2' : 'value2',
  'key3' : 'value3'
}
getQuerystringValue(keyName)

Get the value from the query string that corresponds to keyName.

pocketwrench.browser.getQuerystringValue('key1')

==> 'value1'

math Namespace

logx(number, base)

Return the log of number to the base base.

pocketwrench.math.logx(8, 2)

==> 3

object Namespace

isDictionary(obj)

Returns true if obj is a dictionary, otherwise returns false.

pocketwrench.object.isDictionary([1,2,3])

==> false

pocketwrench.object.isDictionary({ 'a' : 1, 'b' : 2 })

==> true