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

dynamic-typing

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dynamic-typing

Dynamically type a string

  • 0.1.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

dynamic-typing

NPM version build status Test coverage npm download

Dynamically types a string.

When parsing text files, like the ones coming out fromm scientific instruments, it is often useful to convert the obtained strings to their corresponding types.

Indeed when you parse the file while all the fields are text some of them represents in fact numbers or booleans.

This package will try to make the conversion for you using the following rules:

  • a string that has as lowercase value 'true' or 'false' will be converted to the corresponding boolean
  • a string that when converted to number (using Number(string)) does not yield to NaN will be converted to number
  • other strings will be kept as string

This package was optimized for speed and seems to work pretty well. Please don't hesitate to submit bug reports or contribute.

Installation

$ npm i dynamic-typing

Usage

import { parseString } from 'dynamic-typing';

const result = parseString('0x100');

// result is the number 256

More examples:

  • parseString('')''
  • parseString(' ')' '
  • parseString('.')'.'
  • parseString('0.')0
  • parseString('0.0')0
  • parseString('abc')'abc'
  • parseString('True')true
  • parseString('false')false
  • parseString('0')0
  • parseString('123')123
  • parseString('123.456')123.456
  • parseString('12e3')12000
  • parseString('0x10')16
  • parseString('0b10')2

API Documentation

License

MIT

FAQs

Package last updated on 07 Sep 2021

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