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

spectrum-generator

Package Overview
Dependencies
Maintainers
6
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spectrum-generator - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

5

History.md

@@ -0,1 +1,6 @@

<a name="1.1.0"></a>
# [1.1.0](https://github.com/cheminfo/spectrum-generator/compare/v1.0.1...v1.1.0) (2018-03-12)
<a name="1.0.1"></a>

@@ -2,0 +7,0 @@ ## [1.0.1](https://github.com/cheminfo/spectrum-generator/compare/v1.0.0...v1.0.1) (2018-03-09)

15

lib/index.js

@@ -23,2 +23,3 @@ 'use strict';

const kSpectrum = Symbol('spectrum');
const kMaxSize = Symbol('maxSize');

@@ -33,2 +34,3 @@ class SpectrumGenerator {

* @param {number} [options.pointsPerUnit=5] - Number of values between each unit of the x axis
* @param {number} [options.maxSize=1e7] - maximal array size
* @param {function} [options.getWidth] - Returns the width of a peak for a given value. Defaults to (1 + 3 * value / 1000)

@@ -41,3 +43,4 @@ */

pointsPerUnit = 5,
getWidth = defaultGetWidth
getWidth = defaultGetWidth,
maxSize = 1e7
} = options;

@@ -48,2 +51,3 @@

assertInteger(pointsPerUnit, 'pointsPerUnit');
assertInteger(maxSize, 'maxSize');

@@ -62,6 +66,6 @@ if (end <= start) {

this[kGetWidth] = getWidth;
this[kMaxSize] = maxSize;
this[kSize] = (end - start) * pointsPerUnit + 1;
this.reset();
this.reset(maxSize);
}

@@ -139,2 +143,7 @@

reset() {
let finalSize = (this[kEnd] - this[kStart]) * this[kPointsPerUnit] + 1;
if (finalSize > this[kMaxSize]) {
throw new Error('Generated array has size ' + finalSize + ' larger than maxSize: ' + this[kMaxSize]);
}
const spectrum = this[kSpectrum] = {

@@ -141,0 +150,0 @@ x: [],

2

package.json
{
"name": "spectrum-generator",
"version": "1.0.1",
"version": "1.1.0",
"description": "generate a spectrum from discrete peaks",

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

@@ -29,6 +29,8 @@ import {generateSpectrum} from '..';

});
});
describe('generateSpectrum with one peak and small window', () => {
it('should work from zero', () => {
it('should work from 11', () => {
const spectrum = generateSpectrum([[12, 1]], {

@@ -44,3 +46,29 @@ start: 11,

describe('generateSpectrum check large size', () => {
let data = [];
for (let i = 0; i < 10000; i++) {
data.push([i, Math.random()]);
}
it('should throw error for huge array', () => {
expect(() => generateSpectrum(data, {
start: 0,
end: 10000,
pointsPerUnit: 1000,
getWidth: () => 0.1
})).toThrow('Generated array has size 10000001 larger than maxSize: 10000000');
});
it('should throw for simple array is maxSize=1', () => {
expect(() => generateSpectrum([[1, 1]], {
start: 0,
end: 2,
pointsPerUnit: 1,
maxSize: 1,
getWidth: () => 0.1
})).toThrow('Generated array has size 3 larger than maxSize: 1');
});
});
function assertSimple({start, end, peak}) {

@@ -64,1 +92,2 @@ const spectrum = generateSpectrum([[peak, 1]], {start, end, pointsPerUnit: 1, getWidth: simpleGetWidth});

}

@@ -19,2 +19,3 @@ const gaussianFactor = 5; // after 5 the value is nearly 0, nearly no artifacts

const kSpectrum = Symbol('spectrum');
const kMaxSize = Symbol('maxSize');

@@ -29,2 +30,3 @@ export class SpectrumGenerator {

* @param {number} [options.pointsPerUnit=5] - Number of values between each unit of the x axis
* @param {number} [options.maxSize=1e7] - maximal array size
* @param {function} [options.getWidth] - Returns the width of a peak for a given value. Defaults to (1 + 3 * value / 1000)

@@ -37,3 +39,4 @@ */

pointsPerUnit = 5,
getWidth = defaultGetWidth
getWidth = defaultGetWidth,
maxSize = 1e7
} = options;

@@ -44,2 +47,3 @@

assertInteger(pointsPerUnit, 'pointsPerUnit');
assertInteger(maxSize, 'maxSize');

@@ -58,6 +62,6 @@ if (end <= start) {

this[kGetWidth] = getWidth;
this[kMaxSize] = maxSize;
this[kSize] = (end - start) * pointsPerUnit + 1;
this.reset();
this.reset(maxSize);
}

@@ -135,2 +139,7 @@

reset() {
let finalSize = (this[kEnd] - this[kStart]) * this[kPointsPerUnit] + 1;
if (finalSize > this[kMaxSize]) {
throw new Error('Generated array has size ' + finalSize + ' larger than maxSize: ' + this[kMaxSize]);
}
const spectrum = this[kSpectrum] = {

@@ -137,0 +146,0 @@ x: [],

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