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

quick-format

v2.1.0

Published

Solves a problem with util.format

Downloads

1,265

Readme

quick format

Solves a problem with util.format

usage

var format = require('quick-format')
var options = {lowres: false} // <--default
format(['hello %s %j %d', 'world', {obj: true}, 4, {another: 'obj'}], options)

options

lowres

Passing an options object with lowres: true will cause quick-format any object with a circular as a string with the value '"[Circular]"'. The default behaviour is to label circular references in an object, instead of abandoning the entire object. Naturally, lowres is a faster mode, and assumes you have made the decision to ensure the objects you're passing have no circular references.

caveats

We use JSON.stringify instead of util.inspect, this means object methods (functions) will not be serialized.

util.format

In util.format for Node 5.9, performance is significantly affected when we pass in more arguments than interpolation characters, e.g

util.format('hello %s %j %d', 'world', {obj: true}, 4, {another: 'obj'})

This is mostly due to the use of util.inspect. Use JSON.stringify (safely) instead which is significantly faster.

It also takes an array instead of arguments, which helps us avoid the use of apply in some cases.

Also - for speed purposes, we ignore symbol.

Benchmarks

Whilst exact matching of objects to interpolation characters is slower, the case of additional objects is 3x faster. Further, using lowres mode brings us closer to util.inspect speeds.

util*100000: 205.978ms
quickLowres*100000: 236.337ms
quick*100000: 292.018ms
utilWithTailObj*100000: 1054.592ms
quickWithTailObjLowres*100000: 267.992ms
quickWithTailObj*100000: 343.048ms
util*100000: 212.011ms
quickLowres*100000: 226.441ms
quick*100000: 296.600ms
utilWithTailObj*100000: 1020.195ms
quickWithTailObjLowres*100000: 267.331ms
quickWithTailObj*100000: 343.867ms

Acknowledgements

Sponsored by nearForm