1.0.6 • Published 6 years ago

@itemsjs/string-to v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

ItemsJS string-to

Convert string values to other value types

NPM version NPM downloads

Installation

npm i @itemsjs/string-to --save

Usage

const strTo = require('@itemsjs/string-to');

// Array

const array = strTo.array('1,2,%203,4'); // you can pass options here. See the code

console.log(array); // ['1', '2', '3', '4']


// Boolean

// trueValues: ['true', 't', 'y', 'yes', '1'],
// falseValues: ['false', 'f', 'n', 'no', '0'],

const trueValue = strTo.bool('t'); // returns true
const falseValue = strTo.bool('n'); // returns false

console.log(typeof trueValue); // boolean


// Date

// 'Wednesday, Nov 14, 2018',
// '11/14/2018',
// '11-14-2018 08:36',
// 'Nov 14, 8:36 AM',
// 'November 2018',
// 'Nov 14, 2018',
// 'Wed, 14 Nov 2018 08:36:04 +0000',
// '2018-11-14T08:36:04+0000'

const dt = strTo.date('2019-01-01');

console.log(typeof dt); // object


// Float

const floatNumber = strTo.float('.12345');

console.log(typeof floatNumber); // number


// int

const intNumber = strTo.float('12345.678');

console.log(intNumber); // 12345
console.log(typeof intNumber); // number


// number

const anyNumber = strTo.number('.12345');

console.log(typeof anyNumber); // number

And you're good to go!

License

MIT

1.0.6

6 years ago

1.0.5

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago