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

node-opcua-numeric-range

Package Overview
Dependencies
Maintainers
1
Versions
187
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-opcua-numeric-range - npm Package Compare versions

Comparing version 0.2.3 to 0.3.0

20

package.json
{
"name": "node-opcua-numeric-range",
"version": "0.2.3",
"version": "0.3.0",
"description": "pure nodejs OPCUA SDK - module -numeric-range",

@@ -12,14 +12,14 @@ "main": "src/numeric_range.js",

"dependencies": {
"node-opcua-assert": "^0.2.0",
"node-opcua-basic-types": "^0.2.3",
"node-opcua-enum": "^0.2.3",
"node-opcua-factory": "^0.2.3",
"node-opcua-status-code": "^0.2.3",
"node-opcua-assert": "^0.3.0",
"node-opcua-basic-types": "^0.3.0",
"node-opcua-enum": "^0.3.0",
"node-opcua-factory": "^0.3.0",
"node-opcua-status-code": "^0.3.0",
"underscore": "^1.8.3"
},
"devDependencies": {
"node-opcua-generator": "^0.2.3",
"node-opcua-nodeid": "^0.2.3",
"node-opcua-packet-analyzer": "^0.2.3",
"node-opcua-test-helpers": "^0.2.0",
"node-opcua-generator": "^0.3.0",
"node-opcua-nodeid": "^0.3.0",
"node-opcua-packet-analyzer": "^0.3.0",
"node-opcua-test-helpers": "^0.3.0",
"should": "13.2.1"

@@ -26,0 +26,0 @@ },

@@ -6,11 +6,11 @@ /* global NumericRange*/

*/
var assert = require("node-opcua-assert");
var _ = require("underscore");
const assert = require("node-opcua-assert").assert;
const _ = require("underscore");
var StatusCodes = require("node-opcua-status-code").StatusCodes;
var Enum = require("node-opcua-enum");
const StatusCodes = require("node-opcua-status-code").StatusCodes;
const Enum = require("node-opcua-enum");
var ec = require("node-opcua-basic-types");
const ec = require("node-opcua-basic-types");

@@ -39,3 +39,3 @@

var NumericRangeEmpty_str = "NumericRange:<Empty>";
const NumericRangeEmpty_str = "NumericRange:<Empty>";

@@ -49,3 +49,3 @@ // BNF of NumericRange

//
var NumericRange_Schema = {
const NumericRange_Schema = {
name: "NumericRange",

@@ -64,3 +64,3 @@ subtype: "UAString",

decode: function (stream) {
var str = ec.decodeString(stream);
const str = ec.decodeString(stream);
return new NumericRange(str);

@@ -90,4 +90,4 @@ },

var start = r();
var end = start + r();
const start = r();
const end = start + r();
return new NumericRange(start, end);

@@ -98,9 +98,9 @@ }

var factories = require("node-opcua-factory");
const factories = require("node-opcua-factory");
factories.registerBasicType(NumericRange_Schema);
var NumericRangeType = new Enum(["Empty", "SingleValue", "ArrayRange", "MatrixRange", "InvalidRange"]);
const NumericRangeType = new Enum(["Empty", "SingleValue", "ArrayRange", "MatrixRange", "InvalidRange"]);
var regexNumericRange = /^[0-9:,]*$/;
const regexNumericRange = /^[0-9:,]*$/;

@@ -113,3 +113,3 @@ function _valid_range(low, high) {

var values = str.split(":");
const values = str.split(":");

@@ -123,3 +123,3 @@ if (values.length === 1) {

var array = values.map(function (a) {
const array = values.map(function (a) {
return parseInt(a, 10);

@@ -156,3 +156,3 @@ });

/* detect multi dim range*/
var values = str.split(",");
const values = str.split(",");

@@ -164,4 +164,4 @@ if (values.length === 1) {

var rowRange, colRange;
var elements = values.map(construct_numeric_range_bit_from_string);
let rowRange, colRange;
const elements = values.map(construct_numeric_range_bit_from_string);
rowRange = elements[0];

@@ -186,3 +186,3 @@ colRange = elements[1];

function _construct_from_string(self, value) {
var nr = construct_numeric_range_from_string(value);
const nr = construct_numeric_range_from_string(value);
self.type = nr.type;

@@ -223,3 +223,3 @@ self.value = nr.value;

var self = this;
const self = this;

@@ -366,3 +366,3 @@ assert(!value || !(value instanceof NumericRange), "use coerce to create a NumericRange");

var res;
let res;
//xx console.log("arr",arr.constructor.name,arr.length,start,end);

@@ -440,5 +440,5 @@ if (arr.buffer instanceof ArrayBuffer) {

// like extracting data from a one dimensionnal array of strings or byteStrings...
var result = extract_array_range(array, rowRange[0], rowRange[1]);
for (var i = 0; i < result.array.length; i++) {
var e = result.array[i];
const result = extract_array_range(array, rowRange[0], rowRange[1]);
for (let i = 0; i < result.array.length; i++) {
const e = result.array[i];
result.array[i] = extract_array_range(e, colRange[0], colRange[1]).array;

@@ -458,12 +458,12 @@ }

//
var rowLow = rowRange[0];
var rowHigh = rowRange[1];
var colLow = colRange[0];
var colHigh = colRange[1];
const rowLow = rowRange[0];
const rowHigh = rowRange[1];
const colLow = colRange[0];
const colHigh = colRange[1];
var nbRow = dimension[0];
var nbCol = dimension[1];
const nbRow = dimension[0];
const nbCol = dimension[1];
var nbRowDest = rowHigh - rowLow + 1;
var nbColDest = colHigh - colLow + 1;
const nbRowDest = rowHigh - rowLow + 1;
const nbColDest = colHigh - colLow + 1;

@@ -473,5 +473,5 @@

// store the extracted matrix.
var tmp = new array.constructor(nbColDest * nbRowDest);
const tmp = new array.constructor(nbColDest * nbRowDest);
var row, col, r, c;
let row, col, r, c;
r = 0;

@@ -481,4 +481,4 @@ for (row = rowLow; row <= rowHigh; row++) {

for (col = colLow; col <= colHigh; col++) {
var srcIndex = row * nbCol + col;
var destIndex = r * nbColDest + c;
const srcIndex = row * nbCol + col;
const destIndex = r * nbColDest + c;
tmp[destIndex] = array[srcIndex];

@@ -511,2 +511,4 @@ c++;

}
let index,low_index,high_index,rowRange,colRange;
switch (this.type) {

@@ -517,13 +519,13 @@ case NumericRangeType.Empty:

case NumericRangeType.SingleValue:
var index = this.value;
index = this.value;
return extract_single_value(array, index);
case NumericRangeType.ArrayRange:
var low_index = this.value[0];
var high_index = this.value[1];
low_index = this.value[0];
high_index = this.value[1];
return extract_array_range(array, low_index, high_index);
case NumericRangeType.MatrixRange:
var rowRange = this.value[0];
var colRange = this.value[1];
rowRange = this.value[0];
colRange = this.value[1];
return extract_matrix_range(array, rowRange, colRange, dimensions);

@@ -541,3 +543,3 @@

function insertInPlaceStandardArray(arrayToAlter, low, high, newValues) {
var args = [low, high - low + 1].concat(newValues);
const args = [low, high - low + 1].concat(newValues);
arrayToAlter.splice.apply(arrayToAlter, args);

@@ -562,3 +564,3 @@ return arrayToAlter;

assert(newValues.length === high - low + 1);
for (var i = 0; i < newValues.length; i++) {
for (let i = 0; i < newValues.length; i++) {
bufferToAlter[i + low] = newValues[i];

@@ -575,3 +577,3 @@ }

var low_index, high_index;
let low_index, high_index;

@@ -606,3 +608,3 @@ switch (this.type) {

var insertInPlace = (_.isArray(arrayToAlter) ? insertInPlaceStandardArray : (arrayToAlter instanceof Buffer ? insertInPlaceBuffer : insertInPlaceTypedArray));
const insertInPlace = (_.isArray(arrayToAlter) ? insertInPlaceStandardArray : (arrayToAlter instanceof Buffer ? insertInPlaceBuffer : insertInPlaceTypedArray));
return {

@@ -619,3 +621,3 @@ array: insertInPlace(arrayToAlter, low_index, high_index, newValues),

var empty = new NumericRange();
const empty = new NumericRange();
NumericRange.overlap = function (nr1, nr2) {

@@ -636,6 +638,6 @@ nr1 = nr1 || empty;

// +----+ +---+ +--------+ +---+
var l1 = nr1.value[0];
var h1 = nr1.value[1];
var l2 = nr2.value[0];
var h2 = nr2.value[1];
const l1 = nr1.value[0];
const h1 = nr1.value[1];
const l2 = nr2.value[0];
const h2 = nr2.value[1];
return _overlap(l1, h1, l2, h2);

@@ -642,0 +644,0 @@ }

"use strict";
var should = require("should");
const should = require("should");
var NumericRange = require("..").NumericRange;
const NumericRange = require("..").NumericRange;
var factories = require("node-opcua-factory");
var generator = require("node-opcua-generator");
const factories = require("node-opcua-factory");
const generator = require("node-opcua-generator");
var encode_decode_round_trip_test = require("node-opcua-packet-analyzer/test_helpers/encode_decode_round_trip_test").encode_decode_round_trip_test;
var json_encode_decode_round_trip_test = require("node-opcua-packet-analyzer/test_helpers/encode_decode_round_trip_test").json_encode_decode_round_trip_test;
const encode_decode_round_trip_test = require("node-opcua-packet-analyzer/test_helpers/encode_decode_round_trip_test").encode_decode_round_trip_test;
const json_encode_decode_round_trip_test = require("node-opcua-packet-analyzer/test_helpers/encode_decode_round_trip_test").json_encode_decode_round_trip_test;
var path = require("path");
var temporary_folder = path.join(__dirname,"..","_test_generated");
const path = require("path");
const temporary_folder = path.join(__dirname,"..","_test_generated");
var ObjWithNumericRange_Schema = {
const ObjWithNumericRange_Schema = {

@@ -31,7 +31,7 @@ id: factories.next_available_id(),

describe(" encoding / decoding", function () {
var ObjWithNumericRange;
let ObjWithNumericRange;
function _encode_decode_test(prefix, encode_decode_round_trip_test) {
it(prefix + "should persist an object with a numeric range - empty", function () {
var o = new ObjWithNumericRange({});
const o = new ObjWithNumericRange({});
o.numericRange.type.should.equal(NumericRange.NumericRangeType.Empty);

@@ -43,3 +43,3 @@ should(o.numericRange.isValid()).eql(true);

it(prefix + "should persist an object with a numeric range - value pair", function () {
var o = new ObjWithNumericRange({
const o = new ObjWithNumericRange({
numericRange: "2:3"

@@ -53,3 +53,3 @@ });

it(prefix + "should persist an object with a numeric range - single value", function () {
var o = new ObjWithNumericRange({
const o = new ObjWithNumericRange({
numericRange: "100"

@@ -63,3 +63,3 @@ });

it(prefix + "should persist an object with a numeric range - Invalid", function () {
var o = new ObjWithNumericRange({
const o = new ObjWithNumericRange({
numericRange: "-4,-8"

@@ -73,3 +73,3 @@ });

it(prefix + "should persist an object with a numeric range - MatrixRange - type 1", function () {
var o = new ObjWithNumericRange({
const o = new ObjWithNumericRange({
numericRange: "1:2,3:4"

@@ -83,3 +83,3 @@ });

it(prefix + "should persist an object with a numeric range - MatrixRange - type 2", function () {
var o = new ObjWithNumericRange({
const o = new ObjWithNumericRange({
numericRange: "1,3"

@@ -86,0 +86,0 @@ });

/*global describe,require,it */
var should = require("should");
const should = require("should");
var NumericRange = require("..").NumericRange;
var NumericRangeType = NumericRange.NumericRangeType;
var StatusCodes = require("node-opcua-status-code").StatusCodes;
var assert_arrays_are_equal = require("node-opcua-test-helpers/src/typedarray_helpers").assert_arrays_are_equal;
const NumericRange = require("..").NumericRange;
const NumericRangeType = NumericRange.NumericRangeType;
const StatusCodes = require("node-opcua-status-code").StatusCodes;
const assert_arrays_are_equal = require("node-opcua-test-helpers/src/typedarray_helpers").assert_arrays_are_equal;

@@ -13,3 +13,3 @@ describe("Testing numerical range", function () {

it("should construct an empty NumericRange", function () {
var nr = new NumericRange();
const nr = new NumericRange();
nr.type.should.eql(NumericRangeType.Empty);

@@ -20,3 +20,3 @@ should(nr.toEncodeableString()).eql(null);

it("should construct a NumericRange from a integer", function () {
var nr = new NumericRange(12);
const nr = new NumericRange(12);
nr.type.should.eql(NumericRangeType.SingleValue);

@@ -28,3 +28,3 @@ nr.toString().should.eql("12");

it("should construct a NumericRange from a integer (InvalidRange)", function () {
var nr = new NumericRange("-12");
const nr = new NumericRange("-12");
nr.type.should.eql(NumericRangeType.InvalidRange);

@@ -35,3 +35,3 @@ nr.isValid().should.equal(false);

it("should construct a NumericRange with low and high bound", function () {
var nr = new NumericRange(12, 15);
const nr = new NumericRange(12, 15);
nr.type.should.eql(NumericRangeType.ArrayRange);

@@ -43,3 +43,3 @@ nr.toString().should.eql("12:15");

it("should be an InvalidRange if low bound is greater than high bound", function () {
var nr = new NumericRange([15, 12]);
const nr = new NumericRange([15, 12]);
nr.type.should.equal(NumericRange.NumericRangeType.InvalidRange);

@@ -50,3 +50,3 @@ nr.isValid().should.equal(false);

xit("should be an ArrayRange if low bound === high bound", function () {
var nr = new NumericRange(15, 15);
const nr = new NumericRange(15, 15);
nr.type.should.equal(NumericRange.NumericRangeType.ArrayRange);

@@ -59,3 +59,3 @@ nr.isValid().should.equal(true);

should(function () {
var a = new NumericRange(15, "crappy stuff");
const a = new NumericRange(15, "crappy stuff");
}).throwError();

@@ -65,3 +65,3 @@ });

it("should construct a NumericRange with a array containing low and high bound", function () {
var nr = new NumericRange([12, 15]);
const nr = new NumericRange([12, 15]);
nr.type.should.eql(NumericRangeType.ArrayRange);

@@ -72,3 +72,3 @@ nr.toString().should.eql("12:15");

it("should construct a NumericRange from a string containing an integer", function () {
var nr = new NumericRange("12");
const nr = new NumericRange("12");
nr.type.should.eql(NumericRangeType.SingleValue);

@@ -79,3 +79,3 @@ nr.toString().should.eql("12");

it("should construct a NumericRange from a string containing a simple range", function () {
var nr = new NumericRange("12:15");
const nr = new NumericRange("12:15");
nr.type.should.eql(NumericRangeType.ArrayRange);

@@ -86,3 +86,3 @@ nr.toString().should.eql("12:15");

it("should be an InvalidRange when constructed with a string with invalid range", function () {
var nr = new NumericRange("12:ABC");
const nr = new NumericRange("12:ABC");
nr.type.should.equal(NumericRange.NumericRangeType.InvalidRange);

@@ -93,3 +93,3 @@ nr.isValid().should.equal(false);

it("should be an InvalidRange when constructed with a string with 3 values separated with :", function () {
var nr = new NumericRange("12:13:14");
const nr = new NumericRange("12:13:14");
nr.type.should.equal(NumericRange.NumericRangeType.InvalidRange);

@@ -100,3 +100,3 @@ nr.isValid().should.equal(false);

it("should be an InvalidRange when constructed with two values ( high ,low)", function () {
var nr = new NumericRange(15, 12);
const nr = new NumericRange(15, 12);
nr.type.should.equal(NumericRange.NumericRangeType.InvalidRange);

@@ -107,3 +107,3 @@ nr.isValid().should.equal(false);

it("should be an InvalidRange when constructed with two values ( negative ,negative)", function () {
var nr = new NumericRange(-15, -12);
const nr = new NumericRange(-15, -12);
nr.type.should.equal(NumericRange.NumericRangeType.InvalidRange);

@@ -114,3 +114,3 @@ nr.isValid().should.equal(false);

it("should be an InvalidRange when constructed with a single negative numb", function () {
var nr = new NumericRange("-11000");
const nr = new NumericRange("-11000");
nr.type.should.equal(NumericRange.NumericRangeType.InvalidRange);

@@ -121,3 +121,3 @@ nr.isValid().should.equal(false);

it("should be an InvalidRange when constructed with a string with invalid array range (low==high) ", function () {
var nr = new NumericRange("12:12");
const nr = new NumericRange("12:12");
nr.type.should.equal(NumericRange.NumericRangeType.InvalidRange);

@@ -128,3 +128,3 @@ nr.isValid().should.equal(false);

it("should be an InvalidRange when constructed with a string with invalid array range (low==high) ", function () {
var nr = new NumericRange([12,12]);
const nr = new NumericRange([12,12]);
nr.type.should.equal(NumericRange.NumericRangeType.InvalidRange);

@@ -135,3 +135,3 @@ nr.isValid().should.equal(false);

it("should be an InvalidRange when constructed with a string with invalid array range ( low > high )", function () {
var nr = new NumericRange("15:12");
const nr = new NumericRange("15:12");
nr.type.should.equal(NumericRange.NumericRangeType.InvalidRange);

@@ -142,3 +142,3 @@ nr.isValid().should.equal(false);

it("should be an InvalidRange when constructed with a badly formed string '2-4' ", function () {
var nr = new NumericRange("2-4");
const nr = new NumericRange("2-4");
nr.type.should.equal(NumericRange.NumericRangeType.InvalidRange);

@@ -149,3 +149,3 @@ nr.isValid().should.equal(false);

it("should be an InvalidRange when constructed with a badly formed string : '-2:0' ", function () {
var nr = new NumericRange("-2:0");
const nr = new NumericRange("-2:0");
nr.type.should.equal(NumericRange.NumericRangeType.InvalidRange);

@@ -158,3 +158,3 @@ nr.isValid().should.equal(false);

it("should be an MatrixRange when constructed with a string : '1:3,4:5' ", function () {
var nr = new NumericRange("1:3,4:5");
const nr = new NumericRange("1:3,4:5");
nr.type.should.equal(NumericRange.NumericRangeType.MatrixRange);

@@ -165,3 +165,3 @@ nr.isValid().should.equal(true);

it("should be an InvalidRange when constructed with a matrix form string : '1:1,2:2'",function() {
var nr = new NumericRange("1:1,2:2");
const nr = new NumericRange("1:1,2:2");
nr.type.should.equal(NumericRange.NumericRangeType.InvalidRange);

@@ -172,3 +172,3 @@ nr.isValid().should.equal(false);

it("should be an InvalidRange when constructed with a matrix form string : '1,2:2'",function() {
var nr = new NumericRange("1,2:2");
const nr = new NumericRange("1,2:2");
nr.type.should.equal(NumericRange.NumericRangeType.InvalidRange);

@@ -179,3 +179,3 @@ nr.isValid().should.equal(false);

it("should be an InvalidRange when constructed with a matrix form string : '1:1,2'",function() {
var nr = new NumericRange("1:1,2");
const nr = new NumericRange("1:1,2");
nr.type.should.equal(NumericRange.NumericRangeType.InvalidRange);

@@ -186,3 +186,3 @@ nr.isValid().should.equal(false);

it("should be an MatrixRange when constructed with a matrix form string : '1,2' ", function () {
var nr = new NumericRange("1,2");
const nr = new NumericRange("1,2");
nr.type.should.equal(NumericRange.NumericRangeType.MatrixRange);

@@ -194,3 +194,3 @@ nr.isValid().should.equal(true);

it("should be an Matrix when constructed with string : '1,2:3' ", function () {
var nr = new NumericRange("1,2:3");
const nr = new NumericRange("1,2:3");
nr.type.should.equal(NumericRange.NumericRangeType.MatrixRange);

@@ -203,3 +203,3 @@ nr.isValid().should.equal(true);

it("should be an MatrixRange when constructed with string : '1:2,2' ", function () {
var nr = new NumericRange("1:2,3");
const nr = new NumericRange("1:2,3");
nr.type.should.equal(NumericRange.NumericRangeType.MatrixRange);

@@ -215,8 +215,8 @@ nr.isValid().should.equal(true);

var referenceString = "Lorem Ipsum";
const referenceString = "Lorem Ipsum";
it("it should extract a single element with a single value range", function () {
referenceString.length.should.eql(11);
var nr = new NumericRange(2);
var r = nr.extract_values(referenceString);
const nr = new NumericRange(2);
const r = nr.extract_values(referenceString);
r.array.should.eql("r");

@@ -228,5 +228,5 @@ r.statusCode.should.eql(StatusCodes.Good);

it("it should extract a sub array with the requested element with a simple array range", function () {
var nr = new NumericRange(2, 4);
const nr = new NumericRange(2, 4);
referenceString.length.should.eql(11);
var r = nr.extract_values(referenceString);
const r = nr.extract_values(referenceString);
r.array.should.eql("rem");

@@ -239,3 +239,3 @@ r.statusCode.should.eql(StatusCodes.Good);

var matrixString = [
const matrixString = [
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam ",

@@ -248,5 +248,5 @@ "nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat ",

var nr = new NumericRange("1:2,3:5");
const nr = new NumericRange("1:2,3:5");
var result = nr.extract_values(matrixString);
const result = nr.extract_values(matrixString);
result.array.should.be.instanceOf(Array);

@@ -257,4 +257,4 @@ result.array.length.should.eql(2);

var nr2 = new NumericRange("1,3");
var result2 = nr2.extract_values(matrixString);
const nr2 = new NumericRange("1,3");
const result2 = nr2.extract_values(matrixString);
result2.array.should.be.instanceOf(Array);

@@ -269,8 +269,8 @@ result2.array.length.should.eql(1);

var referenceByteString = new Buffer("Lorem Ipsum", "ascii");
const referenceByteString = new Buffer("Lorem Ipsum", "ascii");
it("it should extract a single element with a range defined with a individual integer", function () {
referenceByteString.length.should.eql(11);
var nr = new NumericRange(2);
var r = nr.extract_values(referenceByteString);
const nr = new NumericRange(2);
const r = nr.extract_values(referenceByteString);
r.array.should.be.instanceOf(Buffer);

@@ -283,5 +283,5 @@ r.array.toString().should.eql("r");

it("it should extract a sub array with the requested element with a simple array range", function () {
var nr = new NumericRange(2, 4);
const nr = new NumericRange(2, 4);
referenceByteString.length.should.eql(11);
var r = nr.extract_values(referenceByteString);
const r = nr.extract_values(referenceByteString);
r.array.should.be.instanceOf(Buffer);

@@ -302,6 +302,6 @@ r.array.toString().should.eql("rem");

var nr = new NumericRange("0:16777215"); // very large range outside the bound
const nr = new NumericRange("0:16777215"); // very large range outside the bound
referenceByteString.length.should.eql(11);
var r = nr.extract_values(referenceByteString);
const r = nr.extract_values(referenceByteString);

@@ -317,6 +317,6 @@ r.statusCode.should.eql(StatusCodes.Good);

var nr = new NumericRange("16777000:16777215"); // very large range outside the bound
const nr = new NumericRange("16777000:16777215"); // very large range outside the bound
referenceByteString.length.should.eql(11);
var r = nr.extract_values(referenceByteString);
const r = nr.extract_values(referenceByteString);

@@ -332,8 +332,8 @@ r.statusCode.should.eql(StatusCodes.BadIndexRangeNoData);

var array = [0, 1, 2, 3, 4, 5];
const array = [0, 1, 2, 3, 4, 5];
it("it should extract a single element with a range defined with a individual integer", function () {
array.length.should.eql(6);
var nr = new NumericRange(2);
var r = nr.extract_values(array);
const nr = new NumericRange(2);
const r = nr.extract_values(array);
r.array.should.eql([2]);

@@ -345,5 +345,5 @@ array.length.should.eql(6);

var nr = new NumericRange(2, 4);
const nr = new NumericRange(2, 4);
array.length.should.eql(6);
var r = nr.extract_values(array);
const r = nr.extract_values(array);
r.array.should.eql([2, 3, 4]);

@@ -356,3 +356,3 @@ r.statusCode.should.eql(StatusCodes.Good);

it("it should extract a sub array with the requested element with a empty NumericRange", function () {
var nr = new NumericRange();
const nr = new NumericRange();
nr.extract_values(array).array.should.eql([0, 1, 2, 3, 4, 5]);

@@ -362,4 +362,4 @@ });

it("it should extract the last 3 elements of an array", function () {
var nr = new NumericRange("3:5");
var r = nr.extract_values(array);
const nr = new NumericRange("3:5");
const r = nr.extract_values(array);
r.statusCode.should.eql(StatusCodes.Good);

@@ -370,4 +370,4 @@ assert_arrays_are_equal(r.array, [3, 4, 5]);

it("it should return BadIndexRangeNoData if single value Range is outside array boundary", function () {
var nr = new NumericRange("1000");
var r = nr.extract_values(array);
const nr = new NumericRange("1000");
const r = nr.extract_values(array);
r.statusCode.should.eql(StatusCodes.BadIndexRangeNoData);

@@ -377,4 +377,4 @@ });

it("should handle null array", function () {
var nr = new NumericRange("1000");
var r = nr.extract_values(null);
const nr = new NumericRange("1000");
const r = nr.extract_values(null);
r.statusCode.should.eql(StatusCodes.BadIndexRangeNoData);

@@ -384,4 +384,4 @@ });

it("should handle null array", function () {
var nr = new NumericRange();
var r = nr.extract_values(null);
const nr = new NumericRange();
const r = nr.extract_values(null);
r.array = array;

@@ -400,4 +400,4 @@ r.statusCode.should.eql(StatusCodes.Good);

var array = [];
for (var i=0;i<row;i++) {
const array = [];
for (let i=0;i<row;i++) {
array[i] = flatarray.slice(i*col,i*col+col);

@@ -408,4 +408,4 @@ }

var matrix = createMatrix(3,3,[11, 12, 13, 21, 22, 23, 31, 32, 33]);
var dimensions = [3,3];
const matrix = createMatrix(3,3,[11, 12, 13, 21, 22, 23, 31, 32, 33]);
const dimensions = [3,3];

@@ -422,4 +422,4 @@ beforeEach(function () {

it("should extract sub matrix at 0,0", function () {
var nr = new NumericRange("0,0");
var r = nr.extract_values(matrix,dimensions);
const nr = new NumericRange("0,0");
const r = nr.extract_values(matrix,dimensions);
r.statusCode.should.eql(StatusCodes.Good);

@@ -431,4 +431,4 @@ r.dimensions.should.eql([1,1]);

it("should extract sub matrix at 1,0", function () {
var nr = new NumericRange("1,0");
var r = nr.extract_values(matrix,dimensions);
const nr = new NumericRange("1,0");
const r = nr.extract_values(matrix,dimensions);
r.statusCode.should.eql(StatusCodes.Good);

@@ -440,4 +440,4 @@ r.dimensions.should.eql([1,1]);

it("should extract sub matrix at 0,1", function () {
var nr = new NumericRange("0,1");
var r = nr.extract_values(matrix,dimensions);
const nr = new NumericRange("0,1");
const r = nr.extract_values(matrix,dimensions);
r.statusCode.should.eql(StatusCodes.Good);

@@ -449,4 +449,4 @@ r.dimensions.should.eql([1,1]);

it("should extract sub matrix column at 0:2,1 ( a column)", function () {
var nr = new NumericRange("0:2,0");
var r = nr.extract_values(matrix,dimensions);
const nr = new NumericRange("0:2,0");
const r = nr.extract_values(matrix,dimensions);
r.statusCode.should.eql(StatusCodes.Good);

@@ -461,4 +461,4 @@ r.array.length.should.eql(3);

it("should extract sub matrix row at 0:2,1 ( a row)", function () {
var nr = new NumericRange("0,0:2");
var r = nr.extract_values(matrix,dimensions);
const nr = new NumericRange("0,0:2");
const r = nr.extract_values(matrix,dimensions);
r.statusCode.should.eql(StatusCodes.Good);

@@ -474,4 +474,4 @@ r.dimensions.should.eql([1,3]);

function makeBuffer(values) {
var buff = new Buffer(values.length);
for (var i = 0; i < values.length; i++) {
const buff = new Buffer(values.length);
for (let i = 0; i < values.length; i++) {
buff[i] = values[i];

@@ -487,3 +487,3 @@ }

var array = createArray([0, 1, 2, 3, 4, 5]);
const array = createArray([0, 1, 2, 3, 4, 5]);

@@ -499,4 +499,4 @@ beforeEach(function () {

var nr = new NumericRange(2);
var r = nr.extract_values(array);
const nr = new NumericRange(2);
const r = nr.extract_values(array);

@@ -510,10 +510,10 @@ assert_arrays_are_equal(r.array, createArray([2]));

var nr = new NumericRange(2, 4);
const nr = new NumericRange(2, 4);
var r = nr.extract_values(array);
const r = nr.extract_values(array);
assert_arrays_are_equal(r.array, createArray([2, 3, 4]));
});
it(name + " Z3 - it should extract a sub array with the requested element with a empty NumericRange", function () {
var nr = new NumericRange();
var r = nr.extract_values(array);
const nr = new NumericRange();
const r = nr.extract_values(array);
assert_arrays_are_equal(r.array, createArray([0, 1, 2, 3, 4, 5]));

@@ -523,4 +523,4 @@ });

it(name + " Z4 - it should extract the last 3 elements of an array", function () {
var nr = new NumericRange("3:5");
var r = nr.extract_values(array);
const nr = new NumericRange("3:5");
const r = nr.extract_values(array);
r.statusCode.should.eql(StatusCodes.Good);

@@ -531,9 +531,9 @@ assert_arrays_are_equal(r.array, createArray([3, 4, 5]));

it(name + " Z5 - it should return BadIndexRangeNoData if range is outside array boundary", function () {
var nr = new NumericRange("300000:100000000");
var r = nr.extract_values(array);
const nr = new NumericRange("300000:100000000");
const r = nr.extract_values(array);
r.statusCode.should.eql(StatusCodes.BadIndexRangeNoData);
});
it(name + " Z6 - it should return BadIndexRangeInvalid if range is invalid", function () {
var nr = new NumericRange("-3:100000000");
var r = nr.extract_values(array);
const nr = new NumericRange("-3:100000000");
const r = nr.extract_values(array);
r.statusCode.should.eql(StatusCodes.BadIndexRangeInvalid);

@@ -543,5 +543,5 @@ });

it(name + " Z7 - it should return BadIndexRangeNoData if range is a MatrixRange and value is an array that contains no ArrayLike Elements", function () {
var nr = new NumericRange("1,1");
const nr = new NumericRange("1,1");
nr.type.should.eql(NumericRange.NumericRangeType.MatrixRange);
var r = nr.extract_values(array);
const r = nr.extract_values(array);
r.statusCode.should.eql(StatusCodes.BadIndexRangeNoData);

@@ -585,3 +585,3 @@ });

describe("setting range of an array", function () {
var array;
let array;
beforeEach(function () {

@@ -591,3 +591,3 @@ array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

it("S1 - should replace the old array with the provided array when numeric range is empty", function () {
var nr = new NumericRange();
const nr = new NumericRange();
nr.set_values(array, [20, 30, 40]).array.should.eql([20, 30, 40]);

@@ -598,3 +598,3 @@ array.should.eql([20, 30, 40]);

it("S2 - should replace a single element when numeric range is a single value", function () {
var nr = new NumericRange("4");
const nr = new NumericRange("4");
nr.set_values(array, [40]).array.should.eql([0, 1, 2, 3, 40, 5, 6, 7, 8, 9, 10]);

@@ -606,3 +606,3 @@

it("S3 - should replace a single element when numeric range is a simple range", function () {
var nr = new NumericRange("4:6");
const nr = new NumericRange("4:6");
nr.set_values(array, [40, 50, 60]).array.should.eql([0, 1, 2, 3, 40, 50, 60, 7, 8, 9, 10]);

@@ -613,3 +613,3 @@ array.should.eql([0, 1, 2, 3, 40, 50, 60, 7, 8, 9, 10]);

it("S4 - should replace a single element when numeric range is a pair of values matching the first two elements", function () {
var nr = new NumericRange("0:2");
const nr = new NumericRange("0:2");
nr.set_values(array, [-3, -2, -1]).array.should.eql([-3, -2, -1, 3, 4, 5, 6, 7, 8, 9, 10]);

@@ -619,3 +619,3 @@ array.should.eql([-3, -2, -1, 3, 4, 5, 6, 7, 8, 9, 10]);

it("S5 - should replace a single element when numeric range is a single value matching the last element", function () {
var nr = new NumericRange("10");
const nr = new NumericRange("10");
nr.set_values(array, [-100]).array.should.eql([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -100]);

@@ -625,3 +625,3 @@ array.should.eql([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -100]);

it("S6 - should replace a single element when numeric range is a pair of values matching the last two elements", function () {
var nr = new NumericRange("9:10");
const nr = new NumericRange("9:10");
nr.set_values(array, [-90, -100]).array.should.eql([0, 1, 2, 3, 4, 5, 6, 7, 8, -90, -100]);

@@ -631,3 +631,3 @@ array.should.eql([0, 1, 2, 3, 4, 5, 6, 7, 8, -90, -100]);

it("S7 - should replace a single element when numeric range is a pair of values matching the whole array", function () {
var nr = new NumericRange("0:10");
const nr = new NumericRange("0:10");
nr.set_values(array, [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11]).array.should.eql([-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11]);

@@ -637,4 +637,4 @@ array.should.eql([-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11]);

it("S8 - should write the last 3 elements of an array", function () {
var nr = new NumericRange("8:10");
var r = nr.set_values(array, [80, 90, 100]);
const nr = new NumericRange("8:10");
const r = nr.set_values(array, [80, 90, 100]);
r.statusCode.should.eql(StatusCodes.Good);

@@ -644,14 +644,14 @@ assert_arrays_are_equal(r.array, [0, 1, 2, 3, 4, 5, 6, 7, 80, 90, 100]);

it("S9 - should return BadIndexRangeNoData if range is outside array boundary", function () {
var nr = new NumericRange("1000:1010");
var r = nr.set_values(array, [80, 90, 100]);
const nr = new NumericRange("1000:1010");
const r = nr.set_values(array, [80, 90, 100]);
r.statusCode.should.eql(StatusCodes.BadIndexRangeNoData);
});
it("S10 - should return BadIndexRangeInvalid if range is invalid", function () {
var nr = new NumericRange("-1000:1010");
var r = nr.set_values(array, [80, 90, 100]);
const nr = new NumericRange("-1000:1010");
const r = nr.set_values(array, [80, 90, 100]);
r.statusCode.should.eql(StatusCodes.BadIndexRangeInvalid);
});
it("S11 - should return BadIndexRangeInvalid if range does'nt match new array size", function () {
var nr = new NumericRange("2:2");
var r = nr.set_values(array, [80, 90, 100]);
const nr = new NumericRange("2:2");
const r = nr.set_values(array, [80, 90, 100]);
r.statusCode.should.eql(StatusCodes.BadIndexRangeInvalid);

@@ -665,3 +665,3 @@ });

function test(name, createArray) {
var array;
let array;
beforeEach(function () {

@@ -672,4 +672,4 @@ array = createArray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);

it(name + "-S1 - should replace the old array with the provided array when numeric range is empty", function () {
var nr = new NumericRange();
var r = nr.set_values(array, createArray([20, 30, 40]));
const nr = new NumericRange();
const r = nr.set_values(array, createArray([20, 30, 40]));
assert_arrays_are_equal(r.array, createArray([20, 30, 40]));

@@ -680,3 +680,3 @@ should(r.array instanceof array.constructor).be.eql(true);

it(name + "-S2 - should replace a single element when numeric range is a single value", function () {
var nr = new NumericRange("4");
const nr = new NumericRange("4");
nr.set_values(array, createArray([40])).array.should.eql(createArray([0, 1, 2, 3, 40, 5, 6, 7, 8, 9, 10]));

@@ -686,3 +686,3 @@ });

it(name + "-S3 - should replace a single element when numeric range is a simple range", function () {
var nr = new NumericRange("4:6");
const nr = new NumericRange("4:6");
nr.set_values(array, createArray([40, 50, 60])).array.should.eql(createArray([0, 1, 2, 3, 40, 50, 60, 7, 8, 9, 10]));

@@ -692,21 +692,21 @@ });

it(name + "-S4 - should replace a single element when numeric range is a pair of values matching the first two elements", function () {
var nr = new NumericRange("0:2");
const nr = new NumericRange("0:2");
nr.set_values(array, createArray([-3, -2, -1])).array.should.eql(createArray([-3, -2, -1, 3, 4, 5, 6, 7, 8, 9, 10]));
});
it(name + "-S5 - should replace a single element when numeric range is a single value matching the last element", function () {
var nr = new NumericRange("10");
const nr = new NumericRange("10");
nr.set_values(array, createArray([-100])).array.should.eql(createArray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -100]));
});
it(name + "-S6 - should replace a single element when numeric range is a pair of values matching the last two elements", function () {
var nr = new NumericRange("9:10");
const nr = new NumericRange("9:10");
nr.set_values(array, createArray([-90, -100])).array.should.eql(createArray([0, 1, 2, 3, 4, 5, 6, 7, 8, -90, -100]));
});
it(name + "-S7 - should replace a single element when numeric range is a pair of values matching the whole array", function () {
var nr = new NumericRange("0:10");
var r = nr.set_values(array, createArray([-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11]));
const nr = new NumericRange("0:10");
const r = nr.set_values(array, createArray([-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11]));
assert_arrays_are_equal(r.array, createArray([-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11]));
});
it(name + "-S8 - should write the last 3 elements of an array", function () {
var nr = new NumericRange("8:10");
var r = nr.set_values(array, createArray([80, 90, 100]));
const nr = new NumericRange("8:10");
const r = nr.set_values(array, createArray([80, 90, 100]));
r.statusCode.should.eql(StatusCodes.Good);

@@ -717,4 +717,4 @@ assert_arrays_are_equal(r.array, createArray([0, 1, 2, 3, 4, 5, 6, 7, 80, 90, 100]));

it(name + "-S9 - should return BadIndexRangeNoData if range is a matrix range and value is an array", function () {
var nr = new NumericRange("1,1"); // Matrix Range
var r = nr.set_values(array, createArray([80, 90, 100]));
const nr = new NumericRange("1,1"); // Matrix Range
const r = nr.set_values(array, createArray([80, 90, 100]));
r.statusCode.should.eql(StatusCodes.BadIndexRangeNoData);

@@ -721,0 +721,0 @@ assert_arrays_are_equal(r.array, createArray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));

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