Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

input-number

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

input-number - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

33

index.js
/**
* @module num-input
* @module input-number
*/
const caret = require('caret-position2');
module.exports = Enhance;
const clamp = require('mumath/clamp');
const round = require('mumath/round');
const keys = {
38: 'up',
40: 'down'
}
};
const numRE = /[\.0-9]/;
function Enhance (input) {
module.exports = numerify;
function numerify (input, opts) {
opts = opts || {};
opts.step = opts.step || ((opts.min && opts.max) ? (opts.max - opts.min / 100) : 1);
opts.max = opts.max || Infinity;
opts.min = opts.min || -Infinity;
opts.precision = opts.precision || 0.00001;
input.addEventListener('keydown', e => {
var key = keys[e.which];
let key = keys[e.which];

@@ -25,3 +33,2 @@ if (!key) return;

let numRE = /[\.0-9]/;

@@ -45,4 +52,12 @@ //parse left side

let number = parseFloat(numStr);
number = key === 'up' ? number+1 : number-1;
if (key === 'up') {
number = clamp((number+opts.step), opts.min, opts.max);
}
else {
number = clamp((number-opts.step), opts.min, opts.max);
}
number = round(number, opts.precision);
let leftStr = str.slice(0, left);

@@ -49,0 +64,0 @@ let rightStr = str.slice(right);

{
"name": "input-number",
"version": "1.0.2",
"version": "1.0.3",
"description": "Make input recognize numbers",

@@ -27,7 +27,9 @@ "main": "index.js",

"dependencies": {
"caret-position2": "^1.0.2"
"caret-position2": "^1.0.2",
"mumath": "^2.3.0"
},
"devDependencies": {
"autosize-input": "^0.2.1",
"bubleify": "^0.5.0"
}
}

@@ -17,3 +17,7 @@ # input-number [![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)

num(input);
num(input, {
min: 0,
max: 255,
step: 1
});
```

@@ -20,0 +24,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc