Skip to content

Commit 3e65130

Browse files
committed
6.0.0
1 parent 631a90d commit 3e65130

File tree

4 files changed

+29
-134
lines changed

4 files changed

+29
-134
lines changed

dist/linear-converter.js

Lines changed: 25 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* linear-converter - Copyright 2015 Javier Cejudo <javier@javiercejudo.com> (http://www.javiercejudo.com)
3-
* @version v5.0.1
3+
* @version v6.0.0
44
* @link https://github.com/javiercejudo/linear-converter#readme
55
* @license MIT
66
*/
@@ -9,73 +9,10 @@ require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof requ
99

1010
'use strict';
1111

12-
/**
13-
* Returns a two of a kind check
14-
*
15-
* @param {*} a
16-
* @param {*} b
17-
*
18-
* @return {Function} [description]
19-
*/
20-
module.exports = function olsen(a, b) {
21-
/**
22-
* Two of a kind check
23-
*
24-
* @param {Function} function to compare against
25-
*
26-
* @return {Boolean}
27-
*/
28-
return function check(kind) {
29-
return kind(a) === kind(b);
30-
};
31-
};
32-
33-
},{}],2:[function(require,module,exports){
34-
/**
35-
* lodash 3.0.1 (Custom Build) <https://lodash.com/>
36-
* Build: `lodash modern modularize exports="npm" -o ./`
37-
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
38-
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
39-
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
40-
* Available under MIT license <https://lodash.com/license>
41-
*/
42-
43-
/**
44-
* Checks if `value` is `undefined`.
45-
*
46-
* @static
47-
* @memberOf _
48-
* @category Lang
49-
* @param {*} value The value to check.
50-
* @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
51-
* @example
52-
*
53-
* _.isUndefined(void 0);
54-
* // => true
55-
*
56-
* _.isUndefined(null);
57-
* // => false
58-
*/
59-
function isUndefined(value) {
60-
return value === undefined;
61-
}
62-
63-
module.exports = isUndefined;
64-
65-
},{}],3:[function(require,module,exports){
66-
/*jshint node:true */
67-
68-
'use strict';
69-
70-
var isUndefined = require('lodash.isundefined');
71-
var unitScale = require('unit-scale');
72-
7312
module.exports = function factory(Decimal) {
7413
var api = {};
7514

76-
api.normalise = function normalise(x, scale) {
77-
scale = scale || unitScale;
78-
15+
api.normalise = function normalise(scale, x) {
7916
var scale0 = new Decimal(scale[0].toString());
8017

8118
return new Decimal(x.toString()).minus(scale0)
@@ -85,20 +22,15 @@ module.exports = function factory(Decimal) {
8522
return api;
8623
};
8724

88-
},{"lodash.isundefined":2,"unit-scale":7}],4:[function(require,module,exports){
25+
},{}],2:[function(require,module,exports){
8926
/*jshint node:true */
9027

9128
'use strict';
9229

93-
var isUndefined = require('lodash.isundefined');
94-
var unitScale = require('unit-scale');
95-
9630
module.exports = function factory(Decimal) {
9731
var api = {};
9832

99-
api.scale = function scaleNormalised(x, scale) {
100-
scale = scale || unitScale;
101-
33+
api.scale = function scaleNormalised(scale, x) {
10234
var scale0 = new Decimal(scale[0].toString());
10335

10436
return new Decimal(scale[1].toString()).minus(scale0)
@@ -108,12 +40,11 @@ module.exports = function factory(Decimal) {
10840
return api;
10941
};
11042

111-
},{"lodash.isundefined":2,"unit-scale":7}],5:[function(require,module,exports){
43+
},{}],3:[function(require,module,exports){
11244
/*jshint node:true */
11345

11446
'use strict';
11547

116-
var isUndefined = require('lodash.isundefined');
11748
var normaliseFactory = require('normalise');
11849
var scaleFactory = require('scale-normalised');
11950

@@ -122,43 +53,41 @@ module.exports = function factory(Decimal) {
12253
var scale = scaleFactory(Decimal).scale;
12354
var api = {};
12455

125-
api.rescale = function rescale(x, oldScale, newScale) {
126-
return scale(normalise(x, oldScale), newScale);
56+
api.rescale = function rescale(oldScale, newScale, x) {
57+
return scale(newScale, normalise(oldScale, x));
12758
};
12859

12960
return api;
13061
};
13162

132-
},{"lodash.isundefined":2,"normalise":3,"scale-normalised":4}],6:[function(require,module,exports){
63+
},{"normalise":1,"scale-normalised":2}],4:[function(require,module,exports){
13364
/* jshint node:true */
13465

13566
'use strict';
13667

137-
var unitScale = require('unit-scale');
138-
139-
module.exports = [unitScale, unitScale];
68+
module.exports = [0, 1];
14069

141-
},{"unit-scale":7}],7:[function(require,module,exports){
70+
},{}],5:[function(require,module,exports){
14271
/* jshint node:true */
14372

14473
'use strict';
14574

146-
module.exports = [0, 1];
75+
var unitScale = require('unit-scale');
14776

148-
},{}],"linear-converter":[function(require,module,exports){
77+
module.exports = [unitScale, unitScale];
78+
79+
},{"unit-scale":4}],"linear-converter":[function(require,module,exports){
14980
/*jshint node:true */
15081

15182
'use strict';
15283

15384
var rescaleFactory = require('rescale');
154-
var twoOfAKind = require('olsen');
15585
var unitPreset = require('unit-preset');
15686

15787
/**
15888
* Returns the linear converter api based on the given adapter
15989
*
16090
* @param {Object} Decimal instance of decimal library
161-
*
16291
* @return {Object} Linear converter API
16392
*/
16493
module.exports = function factory(Decimal) {
@@ -168,22 +97,18 @@ module.exports = function factory(Decimal) {
16897
/**
16998
* Linearly converts x as described by a preset
17099
*
171-
* @param {Number} x The number to be converted
172100
* @param {Array} preset The preset that describes the conversion
173-
*
101+
* @param {Number} x The number to be converted
174102
* @return {Number} The converted x
175103
*/
176-
api.convert = function convert(x, preset) {
177-
preset = preset || unitPreset;
178-
179-
return rescale.rescale(x, preset[0], preset[1]);
104+
api.convert = function convert(preset, x) {
105+
return rescale.rescale(preset[0], preset[1], x);
180106
};
181107

182108
/**
183109
* Inverts a preset to change the direction of the conversion
184110
*
185111
* @param {Array} preset The preset to invert
186-
*
187112
* @return {Array} The inverted preset
188113
*/
189114
api.invertPreset = function invertPreset(preset) {
@@ -195,17 +120,12 @@ module.exports = function factory(Decimal) {
195120
*
196121
* @param {Array} presetA The first preset to compose
197122
* @param {Array} presetB The second preset to compose
198-
*
199123
* @return {Array} The composed preset
200124
*/
201125
api.composePresets = function composePresets(presetA, presetB) {
202126
return [
203-
presetA[0].map(function(x) {
204-
return api.convert(x);
205-
}),
206-
presetA[1].map(function(x) {
207-
return api.convert(x, presetB);
208-
})
127+
[api.convert(unitPreset, presetA[0][0]), api.convert(unitPreset, presetA[0][1])],
128+
[api.convert(presetB, presetA[1][0]), api.convert(presetB, presetA[1][1])]
209129
];
210130
};
211131

@@ -214,62 +134,37 @@ module.exports = function factory(Decimal) {
214134
* the given preset.
215135
*
216136
* @param {Array} preset The preset for which to calculate its a coefficient
217-
*
218137
* @return {Number} The coefficient a
219138
*/
220139
api.getCoefficientA = function getCoefficientA(preset) {
221-
return new Decimal(preset[1][1].toString()).minus(new Decimal(preset[1][0].toString()))
222-
.div(new Decimal(preset[0][1].toString()).minus(new Decimal(preset[0][0].toString())));
140+
return api.convert(preset, 1).minus(api.getCoefficientB(preset));
223141
};
224142

225143
/**
226144
* Calculates the b coefficient in the f(x) = ax + b function that describes
227145
* the given preset.
228146
*
229147
* @param {Array} preset The preset for which to calculate its b coefficient
230-
*
231148
* @return {Number} The coefficient b
232149
*/
233150
api.getCoefficientB = function getCoefficientB(preset) {
234-
return api.convert(0, preset);
151+
return api.convert(preset, 0);
235152
};
236153

237-
var presetEquivalenceRequisites = [
238-
api.getCoefficientA,
239-
api.getCoefficientB
240-
];
241-
242-
var wrappedPresetEquivalenceRequisites = [
243-
api.getCoefficientA,
244-
api.getCoefficientB
245-
].map(wrapPresetEquivalenceRequisite);
246-
247154
/**
248155
* Check equivalence of two presets
249156
*
250157
* @param {Array} presetA The first preset to check for equivalence
251158
* @param {Array} presetB The second preset to check for equivalence
252-
*
253159
* @return {Boolean} whether the presets are equivalent or not
254160
*/
255161
api.equivalentPresets = function equivalentPresets(presetA, presetB) {
256-
return wrappedPresetEquivalenceRequisites.every(twoOfAKind(presetA, presetB));
162+
return [api.getCoefficientB, api.getCoefficientA].every(function(coefficient) {
163+
return coefficient(presetA).equals(coefficient(presetB));
164+
});
257165
};
258166

259-
/**
260-
* Wraps a preset equivalence requisite to return a stringified version
261-
*
262-
* @param {Function} presetEquivalenceRequisite [description]
263-
*
264-
* @return {Function}
265-
*/
266-
function wrapPresetEquivalenceRequisite(presetEquivalenceRequisite) {
267-
return function(preset) {
268-
return presetEquivalenceRequisite(preset).toString();
269-
};
270-
}
271-
272167
return api;
273168
};
274169

275-
},{"olsen":1,"rescale":5,"unit-preset":6}]},{},[]);
170+
},{"rescale":3,"unit-preset":5}]},{},[]);

dist/linear-converter.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)