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

sanicast

v2.0.0

Published

A bulletproof, zero-dependency data parser and caster. The ultimate solution for the developer's daily data tax.

Readme

sanicast

npm version License: MIT PRs Welcome

The ultimate solution for the developer's daily data tax.
A lightweight, zero-dependency, bulletproof data parser and caster that automatically detects and standardizes messy inputs.

Are you tired of handling inconsistent API responses, parsing chaotic date formats, or extracting numbers from messy strings? sanicast does the heavy lifting for you in a single function call, without ever crashing your app.

Why sanicast?

  • Zero Dependencies: Extremely lightweight. Won't bloat your node_modules.
  • Bulletproof: Gracefully handles bad data without throwing unhandled exceptions.
  • Strict Mode (New in v2.0.0!): Automatically strips out unknown properties to secure your data pipeline.
  • Default Fallbacks (New in v2.0.0!): Provide fallback values when data is missing or completely unparseable.
  • Array Power: Seamlessly cast arrays of primitives and arrays of objects.
  • Deeply Recursive: Supports deeply nested object schemas out of the box.
  • TypeScript First: Written in TS with full type inference and support.

Installation

npm install sanicast
yarn add sanicast
pnpm add sanicast

Usage

Here is how you can use sanicast to clean up chaotic data, apply defaults, and strip unknown properties:

import { sanicast } from 'sanicast';

// 1. Messy, unpredictable data (Notice the missing 'role' and the extra 'hacker_code')
const messyData = {
  user: {
    name: '   Sabtain Ali   ', 
    age: 'unknown_string', // Bad data, cannot be converted to number
  },
  role: null,              // Missing data
  hacker_code: "drop_me!", // Malicious/Unknown extra property
  transactions: ["$10.50", "20"]
};

// 2. Define your schema (with default values!)
const schema = {
  user: {
    name: 'string',
    age: { type: 'number', default: 18 } // Provide a fallback if parsing fails
  },
  role: { type: 'string', default: 'guest' },
  transactions: ['number']
};

// 3. Clean and cast it! (Strict mode is ON by default)
const cleanData = sanicast(messyData, schema);

/*
Output:
{
  user: { 
    name: 'Sabtain Ali', 
    age: 18               // Fell back to default!
  },
  role: 'guest',          // Fell back to default!
  transactions: [10.5, 20]
  // 'hacker_code' is safely dropped because of Strict Mode!
}
*/

Configuration (Strict Mode)

By default, sanicast runs in Strict Mode. It automatically deletes any keys from your input data that are not defined in your schema. This is highly recommended for security.

If you want to retain unknown properties, you can disable strict mode by passing an options object as the third argument:

const looseData = sanicast(messyData, schema, { strict: false });
// This will keep 'hacker_code' in the output.

Supported Types

In your schema, you can use the following definitions to cast your data:

| Schema Type | How it works | Example Input | Parsed Output | | --- | --- | --- | --- | | 'string' | Converts to string and .trim()s white spaces. | 123 or ' hello ' | '123', 'hello' | | 'number' | Strips currency signs, commas, spaces and parses to float. | "$1,200.50" | 1200.5 | | 'boolean' | Checks for truthy strings ('yes', '1', 'true', 'on'). | 'yes', 1 | true | | 'date' | Parses timestamps and strings into ISO 8601 strings. | '2026/04/12' | '2026-04-12T00:00:00.000Z' | | ['type'] | Parses an array of values based on the provided type. | ["$10", 20] | [10, 20] | | { type, default } | Falls back to default if input is missing/invalid. | null | Your default value |

Documentation & Community

  • Changelog: See what's new in the latest versions.
  • Contributing: Learn how to contribute to the project.
  • Code of Conduct: Please read before participating in our community.
  • Security Policy: Information about reporting vulnerabilities safely.

License

This project is licensed under the MIT License.