Skip to content

Latest commit

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Typer

A small module that allows you to do simple type casting and detecting.

Installation

npm i --save typer

Usage

Usage is pretty simple. First, require typer and then use one of the documented methods.

.detect(value)

Detect the type of value.

vartyper=require('typer');console.log(typer.detect('12345.12'));// floatconsole.log(typer.detect('12345'));// integerconsole.log(typer.detect('false'));// booleanconsole.log(typer.detect('2016-02-22T18:00:00.000Z'));// datetime

You can find more examples in the tests.

.cast(value, type='smart')

Cast value to type.

vartyper=require('typer');console.log(typer.cast(23,'string'));// '23'console.log(typer.cast('23','integer'));// 23console.log(typer.cast('23','float'));// 23.00console.log(typer.cast('2016-02-22T18:00:00.000Z','date'));// Mon, 22 Feb 2016 18:00:00 GMT

About

Simple library helping you cast to types.

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages