Socket
Socket
Sign inDemoInstall

castit

Package Overview
Dependencies
0
Maintainers
3
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    castit

Opinionated Javascript variable casting with deep structures support


Version published
Weekly downloads
124
increased by37.78%
Maintainers
3
Install size
8.98 kB
Created
Weekly downloads
 

Readme

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

Last updated on 03 Nov 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc