input-number
Advanced tools
Comparing version 1.0.5 to 1.1.0
21
index.js
/** | ||
* @module input-number | ||
*/ | ||
'use strict' | ||
@@ -14,5 +15,5 @@ const caret = require('caret-position2'); | ||
module.exports = numerify; | ||
module.exports = inputNumber; | ||
function numerify (input, opts) { | ||
function inputNumber (input, opts) { | ||
opts = opts || {}; | ||
@@ -26,3 +27,6 @@ opts.step = opts.step || ((opts.min && opts.max) ? (opts.max - opts.min / 100) : 1); | ||
input.addEventListener('keydown', e => { | ||
input.removeEventListener('keydown', input._inputNumber) | ||
input.addEventListener('keydown', keydown) | ||
function keydown(e) { | ||
let key = keys[e.which]; | ||
@@ -54,4 +58,4 @@ | ||
let number = parseFloat(numStr); | ||
let fract = /\.([0-9]+)/.exec(numStr); | ||
if (key === 'up') { | ||
@@ -65,2 +69,5 @@ number = clamp((number+opts.step), opts.min, opts.max); | ||
// ensure number format | ||
if (fract) number = number.toFixed(fract[1].length) | ||
let leftStr = str.slice(0, left); | ||
@@ -89,5 +96,7 @@ let rightStr = str.slice(right); | ||
} | ||
}); | ||
} | ||
input._inputNumber = keydown | ||
return input; | ||
} | ||
} |
{ | ||
"name": "input-number", | ||
"version": "1.0.5", | ||
"version": "1.1.0", | ||
"description": "Make input recognize numbers", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5124
116