Socket
Socket
Sign inDemoInstall

dynamic-typing

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    dynamic-typing

Dynamically type a string


Version published
Weekly downloads
2K
decreased by-3.34%
Maintainers
1
Install size
9.78 kB
Created
Weekly downloads
 

Changelog

Source

1.0.1 (2022-11-15)

Documentation

  • add link to Zenodo (c10aaa3)

Readme

Source

dynamic-typing

NPM version build status Test coverage npm download DOI

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

Last updated on 09 May 2024

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