Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

castit

Package Overview
Dependencies
Maintainers
3
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

castit

Opinionated Javascript variable casting with deep structures support

  • 1.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
32
decreased by-34.69%
Maintainers
3
Weekly downloads
 
Created
Source

castit Build Status via Travis CI NPM version

Opinionated Javascript variable casting with deep structures support for easily and automatically cast some common datatypes in JavaScript

Based on https://github.com/bahamas10/node-autocast but adapted for Fluid Configure existing JSON configurations. This version is meant to be used in CommonJS environments.

The main differences with autocast are:

  • hexadecimal and octals are not automatically casted, they remain as string values. Casing them is as simple as adding a plus sign in front of the string +"0xff".
  • "" and "-" are both casted to an empty string.
  • functions objects and array are not casted by default
  • supports deep casting by passing an optional deep flag.

Install

npm install castit --save

Usage

var cast = require("castit");

Example

> var cast = require("castit");
[Function: cast]
> cast("5")
5
> cast("5.8")
5.8
> cast("5.8.8")
"5.8.8"
> cast("null")
null
> cast("undefined")
undefined
> cast("NaN")
NaN
> cast("true")
true
> cast("false")
false
> cast("normal string")
"normal string"
> cast(fn)
fn
> cast({nested: ["false"]}, true)
{nested: [false]}

Tests

npm test

License

MIT Licensed

Keywords

FAQs

Package last updated on 03 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc