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 - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

4

lib/index.js

@@ -7,4 +7,4 @@ 'use strict';

* Dynamically type a string
* {string} [value]
* @return {boolean|string|number}
* @param {string} value String to dynamically type
* @returns {boolean|string|number}
*/

@@ -11,0 +11,0 @@ function parseString(value) {

{
"name": "dynamic-typing",
"version": "0.1.1",
"version": "0.1.2",
"description": "Dynamically type a string",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -8,8 +8,17 @@ # dynamic-typing

Dynamically type a string.
## Dynamically types a string.
Becomes a boolean if the value to lowercase is 'true' or 'false'
Becomes a number if (! isNaN). This will also convert hexadecimal numbers
Stays a string otherwise
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

@@ -29,2 +38,19 @@

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](https://cheminfo.github.io/dynamic-typing/)

@@ -31,0 +57,0 @@

/**
* Dynamically type a string
* {string} [value]
* @return {boolean|string|number}
* @param {string} value String to dynamically type
* @returns {boolean|string|number}
*/

@@ -6,0 +6,0 @@ export function parseString(value) {

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