Code Monkey home page Code Monkey logo

yaspar's Introduction

Yaspar

Yaspar stands for Yet Another String Parser. It's a tine utility with no other dependencies that converts string to numeric values.

  • toMilliseconds(param) converts string to milliseconds. param must be number or string. Converts param to milliseconds. The following time units are supported: ms, s/sec/second/seconds, m/min/minute/minutes, h/hour/hours. It also supports time format as m:ss, h:mm:ss.
  • toBoolean(param) converts string to milliseconds. param must be boolean, number or string. Converts param to boolean. Supports the following strings true/false, yes/no, on/off (case insensitive).

Installation

npm install yaspar

or

yarn add yaspar

Usage

Examples:

Converting strings to milliseconds:

const { toMilliseconds } = require('yaspar');

console.log(toMilliseconds('3000')); // => 3000
console.log(toMilliseconds('300 ms')); // => 300
console.log(toMilliseconds('30 sec')); // => 30000
console.log(toMilliseconds('10 s')); // => 10000
console.log(toMilliseconds('5 min')); // => 300000
console.log(toMilliseconds('1 hour')); // => 3600000
console.log(toMilliseconds('1:20')); // => 80000
console.log(toMilliseconds('1:00:20')); // => 3620000

Converting strings to boolean:

const { toBoolean } = require('yaspar');

console.log(toBoolean('True')); // => true
console.log(toBoolean('no')); // => false
console.log(toBoolean('yes')); // => true
console.log(toBoolean('off')); // => false
console.log(toBoolean('on')); // => true
console.log(toBoolean('1')); // => true

License

MIT

yaspar's People

Contributors

bladerunner2020 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.