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

numbrify

v2.0.0

Published

A utility to convert number-like strings in objects/arrays into numbers.

Downloads

4

Readme

Numbrify

Numbrify is a small utility to convert number-like strings in objects and arrays into actual numbers. For example If you've ever parsed a csv file and gotten a bunch of numbers-as-strings in your object, this can help with converting those back to numbers. It will leave things that don't look like numbers alone.

NOTE: By default, Numbrify will do a deep traversal of properties/elements in the collection, however non primitive values that are not Arrays or Objects (e.g. dates) are copied by reference. So if you want a completely separate result and have lots of non primitive values you should deep clone your object first.

Download

You can download a copy of the whole thing from the releases page. Or if you just want the built script there is here. Or if you are using npm, npm install numbrify.

Usage

Include the script into your page. Possibly like so <script src="dist/numbrify.js" charset="utf-8"></script>. The src attribute should point to wherever you downloaded the dist/numbrify.js file to.

Then call Numbrify(data, deepTraversal=true) with your collection. Here are some quick examples

var data;
var result;

// Numbrify an array
data = ["123", "456", "789.2342", "foo"];
result = Numbrify(data);
// Result should equal: [123, 456, 789.2342, "foo"];

data = [
  {"name": "foo", "age": "42"},
  {"name": "bar", "age": "32"},
  {"name": "baz", "age": "22"}
]

// Numbrify an array of objects
result = Numbrify(data)
// Result should equal:
// [
//   {"name": "foo", "age": 42},
//   {"name": "foo", "age": 32},
//   {"name": "foo", "age": 22}
// ]

// You can also do
result = data.map(Numbrify);

// If you want to only do a shallow traversal of your object, then pass in
// a second parameter set to false. e.g.
data = [
  {"name": "foo", "age": "42"},
  {"name": "bar", "age": "32"},
  {"name": "baz", "age": "22"}
]
result = Numbrify(data, false)

// Result should equal:
// [
//   {"name": "foo", "age": "42"},
//   {"name": "foo", "age": "32"},
//   {"name": "foo", "age": "22"}
// ]
// Note this has not done anything since the age property is in
// a nested object.

Development

To build this locally, check out the repository, run npm install and then run npm build. There is also an npm watch task that rebuilds on changes to the src file.

The source is written in ES6/ES2015 primarily to take advantage of ES6 modules and the convenient UMD build provided by babel.