Skip to content

Commit

Permalink
feat(api): freeze API object
Browse files Browse the repository at this point in the history
  • Loading branch information
javiercejudo committed Feb 1, 2016
1 parent b78e3ab commit 31ad634
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/normalise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ var toDecimalFactory = require('to-decimal-arbitrary-precision');

module.exports = function factory(Decimal) {
var toDecimal = toDecimalFactory(Decimal);
var api = {};

api.normalise = function normalise(scale, x) {
var scale0 = toDecimal(scale[0]);
return Object.freeze({
normalise: function normalise(scale, x) {
var scale0 = toDecimal(scale[0]);

return toDecimal(x).minus(scale0)
.div(toDecimal(scale[1]).minus(scale0));
};

return api;
return toDecimal(x).minus(scale0)
.div(toDecimal(scale[1]).minus(scale0));
}
});
};
11 changes: 11 additions & 0 deletions test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ var floatingAdapter = require('floating-adapter');
var normaliseFactory = require('../src/normalise');

describe('normalising', function() {
describe('api', function() {
it('should be frozen', function() {
var Decimal = arbitraryPrecision(floatingAdapter);
var normalise = normaliseFactory(Decimal);

(function() {
normalise.normalise = function() {};
}).should.throw();
});
});

describe('with valid scales', function() {
describe('should support', function() {
var Decimal = arbitraryPrecision(floatingAdapter);
Expand Down

0 comments on commit 31ad634

Please sign in to comment.