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

anysafe

v1.0.2

Published

Safely converts any JavaScript value into a string, integer, array, or JSON — namespace and fluent API

Readme

anysafe

npm version downloads license types build status

Safely converts any JavaScript value into a string, integer, array, or JSON string — never throws, always falls back to a sensible default.

This is a thin wrapper bundling to-safe-string, to-safe-integer, to-safe-array, and to-safe-json into a single install. Each of those packages also works completely standalone if you only need one conversion.

Installation

npm install anysafe

Usage

Two equivalent styles — pick whichever reads better in context.

Namespace style

const anysafe = require('anysafe');

anysafe.toSafeString(42);           // "42"
anysafe.toSafeInteger('42px');      // 42
anysafe.toSafeArray('[1,2,3]');     // [1, 2, 3]
anysafe.toSafeJson([1, 2, 3]);      // '[1,2,3]'

Fluent style

const safe = require('anysafe');

safe(42).toString();                 // "42"
safe('42px').toInteger();            // 42
safe('[1,2,3]').toArray();           // [1, 2, 3]
safe([1, 2, 3]).toJson();            // '[1,2,3]'

Useful when converting the same value multiple ways:

const raw = req.body.count;

safe(raw).toInteger();               // 42
safe(raw).toString();                // "42"

Fallback values

Both styles accept an optional fallback, passed straight through to the underlying package:

anysafe.toSafeInteger('abc', -1);   // -1
safe('abc').toInteger(-1);           // -1

Using a single conversion only?

If you only need one of these conversions, install the individual package instead — it has no dependencies and a smaller footprint:

npm install to-safe-integer

API

anysafe(value)

Returns an object with chainable methods: toString(fallback), toInteger(fallback), toArray(fallback), toJson(fallback).

anysafe.toSafeString(value, fallback)

anysafe.toSafeInteger(value, fallback)

anysafe.toSafeArray(value, fallback)

anysafe.toSafeJson(value, fallback)

Same functions as the standalone packages, attached directly to anysafe for namespace-style use.

License

MIT © Toby Maxham