镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
This repository was archived by the owner on Dec 11, 2024. It is now read-only.
cli-kitPublic archive

About

Native type conversion functions

Resources

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

Native

Utility functions for converting strings to native types and vice versa.

Install

npm install cli-native

Test

npm test

API

var native = require('cli-native');
native.to('1,2,3', ',');                    // => [1, 2, 3]
native.to('true');                          // => true
native.to('false');                         // => false
native.to('null');                          // => null
native.to('undefined');                     // => undefined
native.to('value');                         // => 'value'
native.to('{"arr":[1,2,3]}', null, true);   // => {arr: [1, 2 ,3]}

to(str, [delimiter], [json])

Convert a string to a native type.

  • str: The string to convert.
  • delimiter: A delimiter to use to convert to arrays.
  • json: A boolean indicating that strings that appear to be JSON should be parsed.

from(val, [delimiter], [json])

Convert a native type to a string.

  • val: The value to convert to a string.
  • delimiter: A delimiter to used to join arrays.
  • json: A boolean indicating that complex objects should be serialized to JSON.

License

Everything is MIT. Read the license if you feel inclined.

About

Native type conversion functions

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages