Package Exports
- purify-int
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (purify-int) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Purify Int
How To Use
- Run
npm i purify-int - Include
const Purify = require('purify-int')
Function Guide
asInt()
- Purify input to valid Integer:
let cleansed = Purify.asInt('42')
console.log(cleansed) // output: 42
let cleansed = Purify.asInt('words')
console.log(cleansed) // output: 0asIntIn()
- Purify input to valid Integer with input non-Integer as fallback:
let cleansed = Purify.asIntIn('42')
console.log(cleansed) // output: 42
let cleansed = Purify.asIntIn('words')
console.log(cleansed) // output: 'words'asIntR()
- Purify input to valid Integer with randomized fallback:
let cleansed = Purify.asIntR('42')
console.log(cleansed) // output: 42
let cleansed = Purify.asIntR('words')
console.log(cleansed) // output: random integer between 1 and current unix time in msasIntF()
- Purify input to valid Integer with optional second Integer-like arg as fallback:
let cleansed = Purify.asIntF('42', 5)
console.log(cleansed) // output: 42
let cleansed = Purify.asIntF('words', 5)
console.log(cleansed) // output: 5
let cleansed = Purify.asIntF('words', '5')
console.log(cleansed) // output: 5
let cleansed = Purify.asIntF('words', 'more words')
console.log(cleansed) // output: 0asIntN()
- Purify input to valid Integer with
nullas fallback:
let cleansed = Purify.asIntN('42')
console.log(cleansed) // output: 42
let cleansed = Purify.asIntN('words')
console.log(cleansed) // output: nullasArrayInt()
- Flags are optional. Valid flags are:
R: Use random number as fallbackN: Usenullas fallbackK: Use input non-Integer as fallback
- Purify input to valid array of Integers:
let cleansed = Purify.asArrayInt(['42', 'words']) // flag is optional
console.log(cleansed) // output: [42, 0]
let cleansed = Purify.asArrayInt(['42', 'words'], 'R')
console.log(cleansed) // output: [42, random integer as above]
let cleansed = Purify.asArrayInt(['42', 'words'], 'N')
console.log(cleansed) // output: [42, null]
let cleansed = Purify.asArrayInt(['42', 'words'], 'K')
console.log(cleansed) // output: [42, 'words']