JSPM

purify-int

1.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q40442F
  • License MIT

Verify that an input value is a JavaScript integer and replace as needed

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

forthebadge

License: MIT github: version github: last-commit npm: version npm: downloads

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: 0

asIntIn()

  • 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 ms

asIntF()

  • 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: 0

asIntN()

  • Purify input to valid Integer with null as fallback:
let cleansed = Purify.asIntN('42')
console.log(cleansed) // output: 42
let cleansed = Purify.asIntN('words')
console.log(cleansed) // output: null

asArrayInt()

  • Flags are optional. Valid flags are:
    • R : Use random number as fallback
    • N : Use null as fallback
    • K : 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']