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

@oticon/utilities

v1.6.10

Published

Helper utilities used in solutions developed in SMS.

Downloads

36

Readme

@oticon/utilities

Chunk

Use Array.from() to create a new array, that fits the number of chunks that will be produced. Use Array.slice() to map each element of the new array to a chunk the length of size. If the original array can't be split evenly, the final chunk will contain the remaining elements.

chunk([1, 2, 3, 4, 5], 2);
// [[1, 2], [3, 4], 5]

countOccurrences

Use Array.reduce() to increment a counter each time you encounter the specific value inside the array.

countOccurrences([1, 1, 2, 1, 2, 3], 1);
// 3

Difference

Create a Set from b, then use Array.filter() on a to only keep values not contained in b.

difference([1, 2, 3], [1, 2]);
// [3]

Flatten

Use Array.reduce() to get all values inside the array and concat() to flatten them.

flatten([1, [2], 3, 4]);
// [1, 2, 3, 4]

Intersection

Create a Set from b, then use Array.filter() on a to only keep values contained in b.

intersection([1, 2, 3], [4, 3, 2]);
// [2, 3]

Shuffle

Use Array.sort() to reorder elements, using Math.random() in the comparator.

shuffle([1, 2, 3]);
// [2, 3, 1]

Similarity

Use Array.filter() to remove values that are not part of values, determined using includes().

similarity([1, 2, 3], [1, 2, 4]);
// [1, 2]

Union

Create a Set with all values from a and b, then convert values to an array.

union([1, 2, 3], [4, 3, 2]);
// [1, 2, 3, 4]

Unique

Use Set and the ...rest operator to discard all duplicated values.

unique([1, 2, 2, 3, 4, 4, 5]);
// [1, 2, 3, 4, 5]

Parameters

Use match() with an appropriate regular expression to get all key-value pairs, Array.reduce() to map and combine them into a single object. Pass location.search as the argument to apply to the current url.

parameters('https://oticon.com/?firstname=Sadi&lastname=Kaya');
// { firstname: "Sadi", lastname: "Kaya" }

Redirect

Use window.location.href or window.location.replace() to redirect to url. Pass a second argument to simulate a link click (default is true) or an HTTP redirect.

redirect('https://oticon.com', true);

Asset

Use process.env.NODE_ENV to return a string from an object.

asset({obj}, "mediapath", "mediaurl");
// if (prod) { mediapath } else { mediaurl }

Log (Sentry.io)

If you're using React 16 or above, Error Boundaries are an important tool for defining the behavior of your application in the face of errors. Be sure to send errors they catch to Sentry using Raven.captureException.

log(ex, extra);

Parse

parse(xml);
// xml -> js

XMLParser

XMLParser(xml);
// xml -> js

Preload Images

preloadImages(arr);

UUID

Use the crypto API to generate a UUID, compliant with RFC4122 version 4.

uuid();
// "7982fcfe-5721-4632-bede-6000885be57d"