Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shnhrrsn/as-type
Javascript type casting
https://github.com/shnhrrsn/as-type
casting javascript nodejs typecast types
Last synced: 26 days ago
JSON representation
Javascript type casting
- Host: GitHub
- URL: https://github.com/shnhrrsn/as-type
- Owner: shnhrrsn
- License: mit
- Created: 2016-07-09T21:11:19.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-10-21T02:37:59.000Z (about 4 years ago)
- Last Synced: 2024-08-09T06:53:19.844Z (3 months ago)
- Topics: casting, javascript, nodejs, typecast, types
- Language: TypeScript
- Size: 7.81 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
- Changelog: CHANGELOG.markdown
- License: LICENSE
Awesome Lists containing this project
README
# as-type
Convert undetermined data types to the type you want.
### Installation
```sh
npm install --save as-type
```## Usage
```js
const as = require('as-type')console.log(as.boolean('true')) // true
console.log(as.boolean('t')) // true
console.log(as.boolean('T')) // true
console.log(as.boolean('yes')) // true
console.log(as.boolean('y')) // true
console.log(as.boolean('Y')) // true
console.log(as.boolean(1)) // true
console.log(as.boolean('asdf')) // false
console.log(as.boolean(5)) // falseconsole.log(as.integer('5')) // 5
console.log(as.integer('5.5')) // 5
console.log(as.integer('five')) // 0console.log(as.float('5')) // 5
console.log(as.float('5.5')) // 5.5
console.log(as.float('five')) // 0
```