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

ml-array-rescale

Package Overview
Dependencies
Maintainers
5
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ml-array-rescale - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

21

lib/index.js

@@ -11,3 +11,6 @@ 'use strict';

throw new TypeError('input must be an array');
} else if (input.length === 0) {
throw new TypeError('input must not be empty');
}
let output;

@@ -23,5 +26,12 @@ if (options.output !== undefined) {

const currentMin = min(input);
const currentMax = max(input);
if (currentMin === currentMax) {
throw new RangeError('minimum and maximum input values are equal. Cannot rescale a constant array');
}
const {
min: minValue = 0,
max: maxValue = 1
min: minValue = options.autoMinMax ? currentMin : 0,
max: maxValue = options.autoMinMax ? currentMax : 1
} = options;

@@ -33,9 +43,2 @@

const currentMin = min(input);
const currentMax = max(input);
if (currentMin === currentMax) {
throw new RangeError('minimum and maximum input values are equal. Cannot rescale a constant array');
}
const factor = (maxValue - minValue) / (currentMax - currentMin);

@@ -42,0 +45,0 @@ for (var i = 0; i < input.length; i++) {

{
"name": "ml-array-rescale",
"version": "1.0.2",
"version": "1.1.0",
"description": "Rescale an array into a range",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -38,8 +38,14 @@ import rescale from '../index';

expect(() => rescale()).toThrow(/input must be an array/);
expect(() => rescale([], {output: false})).toThrow(/output option must be an array if specified/);
expect(() => rescale([], {min: 2})).toThrow(/min option must be smaller than max option/);
expect(() => rescale([], {max: -1})).toThrow(/min option must be smaller than max option/);
expect(() => rescale([], {min: 2, max: 0})).toThrow(/min option must be smaller than max option/);
expect(() => rescale([], {min: 1, max: 1})).toThrow(/min option must be smaller than max option/);
expect(() => rescale([0, 1, 2], {output: false})).toThrow(/output option must be an array if specified/);
expect(() => rescale([0, 1, 2], {min: 2})).toThrow(/min option must be smaller than max option/);
expect(() => rescale([0, 1, 2], {max: -1})).toThrow(/min option must be smaller than max option/);
expect(() => rescale([0, 1, 2], {min: 2, max: 0})).toThrow(/min option must be smaller than max option/);
expect(() => rescale([0, 1, 2], {min: 1, max: 1})).toThrow(/min option must be smaller than max option/);
expect(() => rescale([], {min: 0, max: 1})).toThrow(/input must not be empty/);
});
it('should work with current min/max', () => {
expect(rescale([0, 1, 2], {min: 1, autoMinMax: true})).toEqual([1, 1.5, 2]);
expect(rescale([0, 1, 2], {max: 3, autoMinMax: true})).toEqual([0, 1.5, 3]);
});
});

@@ -7,3 +7,6 @@ import max from 'ml-array-max';

throw new TypeError('input must be an array');
} else if (input.length === 0) {
throw new TypeError('input must not be empty');
}
let output;

@@ -19,5 +22,12 @@ if (options.output !== undefined) {

const currentMin = min(input);
const currentMax = max(input);
if (currentMin === currentMax) {
throw new RangeError('minimum and maximum input values are equal. Cannot rescale a constant array');
}
const {
min: minValue = 0,
max: maxValue = 1
min: minValue = options.autoMinMax ? currentMin : 0,
max: maxValue = options.autoMinMax ? currentMax : 1
} = options;

@@ -29,9 +39,2 @@

const currentMin = min(input);
const currentMax = max(input);
if (currentMin === currentMax) {
throw new RangeError('minimum and maximum input values are equal. Cannot rescale a constant array');
}
const factor = (maxValue - minValue) / (currentMax - currentMin);

@@ -38,0 +41,0 @@ for (var i = 0; i < input.length; i++) {

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