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

round10

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

round10 - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

5

package.json
{
"name": "round10",
"version": "1.0.2",
"version": "1.0.3",
"description": "Brings decimal adjustment to the Math object.",

@@ -9,4 +9,3 @@ "main": "round10.js",

},
"dependencies": {
},
"dependencies": {},
"devDependencies": {

@@ -13,0 +12,0 @@ "should": "^7.0.2"

@@ -22,2 +22,9 @@ Inspired by [Decimal rounding polyfill by MDN](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Math/round#Decimal_rounding).

```javascript
var round10 = require('round10').round10;
round10(55.55, -1); // 55.6
```
Optionally, you may use the polyfill which extends the global Math object:
```javascript
require('round10').polyfill();

@@ -24,0 +31,0 @@ Math.round10(55.55, -1); // 55.6

26

round10.js

@@ -28,21 +28,27 @@ /**

exports.polyfill = function() {
module.exports = {
round10: function(value, exp) {
return decimalAdjust('round', value, exp);
},
floor10: function(value, exp) {
return decimalAdjust('floor', value, exp);
},
ceil10: function(value, exp) {
return decimalAdjust('ceil', value, exp);
},
};
module.exports.polyfill = function() {
// Decimal round
if (!Math.round10) {
Math.round10 = function(value, exp) {
return decimalAdjust('round', value, exp);
};
Math.round10 = module.exports.round10;
}
// Decimal floor
if (!Math.floor10) {
Math.floor10 = function(value, exp) {
return decimalAdjust('floor', value, exp);
};
Math.floor10 = module.exports.floor10;
}
// Decimal ceil
if (!Math.ceil10) {
Math.ceil10 = function(value, exp) {
return decimalAdjust('ceil', value, exp);
};
Math.ceil10 = module.exports.ceil10;
}
};
var should = require('should');
require('../round10').polyfill();
var round10 = require('../round10');
describe('Math', function() {
describe('round10.polyfill', function() {
before(function() {
round10.polyfill()
});
it('should add #round10 to Math', function() {
// Round
Math.round10.should.be.a.Function();
});
it('should add #floor10 to Math', function() {
// Floor
Math.floor10.should.be.a.Function();
});
it('should add #ceil10 to Math', function() {
// Ceil
Math.ceil10.should.be.a.Function();
});
});
describe('round10', function() {
it('should have #round10', function() {
// Round
Math.round10(55.55, -1).should.equal(55.6);
Math.round10(55.549, -1).should.equal(55.5);
Math.round10(55, 1).should.equal(60);
Math.round10(54.9, 1).should.equal(50);
Math.round10(-55.55, -1).should.equal(-55.5);
Math.round10(-55.551, -1).should.equal(-55.6);
Math.round10(-55, 1).should.equal(-50);
Math.round10(-55.1, 1).should.equal(-60);
Math.round10(1.005, -2).should.equal(1.01);
round10.round10(55.55, -1).should.equal(55.6);
round10.round10(55.549, -1).should.equal(55.5);
round10.round10(55, 1).should.equal(60);
round10.round10(54.9, 1).should.equal(50);
round10.round10(-55.55, -1).should.equal(-55.5);
round10.round10(-55.551, -1).should.equal(-55.6);
round10.round10(-55, 1).should.equal(-50);
round10.round10(-55.1, 1).should.equal(-60);
round10.round10(1.005, -2).should.equal(1.01);
});
it('should have #floor10', function() {
// Floor
Math.floor10(55.59, -1).should.equal(55.5);
Math.floor10(59, 1).should.equal(50);
Math.floor10(-55.51, -1).should.equal(-55.6);
Math.floor10(-51, 1).should.equal(-60);
round10.floor10(55.59, -1).should.equal(55.5);
round10.floor10(59, 1).should.equal(50);
round10.floor10(-55.51, -1).should.equal(-55.6);
round10.floor10(-51, 1).should.equal(-60);
});
it('should have #ceil10', function() {
// Ceil
Math.ceil10(55.51, -1).should.equal(55.6);
Math.ceil10(51, 1).should.equal(60);
Math.ceil10(-55.59, -1).should.equal(-55.5);
Math.ceil10(-59, 1).should.equal(-50);
round10.ceil10(55.51, -1).should.equal(55.6);
round10.ceil10(51, 1).should.equal(60);
round10.ceil10(-55.59, -1).should.equal(-55.5);
round10.ceil10(-59, 1).should.equal(-50);
});
});
});
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