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

xy-parser

Package Overview
Dependencies
Maintainers
4
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xy-parser - npm Package Compare versions

Comparing version 5.0.4 to 5.0.5

2

lib-esm/index.d.ts

@@ -6,3 +6,2 @@ import type { TextData } from 'cheminfo-types';

* Parse a text-file and convert it to an object {x:[], y:[]}
*
* @param text - Csv or tsv strings.

@@ -15,3 +14,2 @@ * @param options - Parsing options

* Parse a text-file and returns the parsed data and information about the columns
*
* @param text - Csv or tsv strings.

@@ -18,0 +16,0 @@ * @param options - Parsing options

@@ -5,3 +5,2 @@ import { parse } from './parse';

* Parse a text-file and convert it to an object {x:[], y:[]}
*
* @param text - Csv or tsv strings.

@@ -16,3 +15,2 @@ * @param options - Parsing options

* Parse a text-file and returns the parsed data and information about the columns
*
* @param text - Csv or tsv strings.

@@ -19,0 +17,0 @@ * @param options - Parsing options

5

lib-esm/parse.d.ts

@@ -5,3 +5,2 @@ import { DataXY, TextData } from 'cheminfo-types';

* General internal parsing function
*
* @param text - Csv or tsv strings.

@@ -12,8 +11,8 @@ * @param options - Parsing options

export declare function parse(text: TextData, options?: ParseXYOptions): {
info: {
info: Array<{
position: number;
value: string;
}[];
}>;
data: DataXY;
};
//# sourceMappingURL=parse.d.ts.map

@@ -5,3 +5,2 @@ import { ensureString } from 'ensure-string';

* General internal parsing function
*
* @param text - Csv or tsv strings.

@@ -12,5 +11,6 @@ * @param options - Parsing options

export function parse(text, options = {}) {
let { rescale = false, uniqueX = false, xColumn = 0, yColumn = 1, bestGuess = false,
const { rescale = false, uniqueX = false, bestGuess = false,
//@ts-expect-error old library used this property and we want to throw an error so that people are forced to migrate
keepInfo, numberColumns = Number.MAX_SAFE_INTEGER, maxNumberColumns = Number.MAX_SAFE_INTEGER, minNumberColumns = 2, } = options;
keepInfo, } = options;
let { xColumn = 0, yColumn = 1, numberColumns = Number.MAX_SAFE_INTEGER, maxNumberColumns = Number.MAX_SAFE_INTEGER, minNumberColumns = 2, } = options;
if (keepInfo !== undefined) {

@@ -22,5 +22,5 @@ throw new Error('keepInfo has been deprecated, pelase use the new method parseXYAndKeepInfo');

minNumberColumns = Math.max(xColumn + 1, yColumn + 1, minNumberColumns);
let lines = text.split(/[\r\n]+/);
const lines = text.split(/[\r\n]+/);
let matrix = [];
let info = [];
const info = [];
let position = 0;

@@ -65,3 +65,3 @@ lines.forEach((line) => {

const xs = [];
for (let row of matrix) {
for (const row of matrix) {
for (let i = xColumn; i < row.length; i += 2) {

@@ -93,3 +93,3 @@ xs.push(row[i]);

if (rescale) {
let maxY = xMaxValue(result.y);
const maxY = xMaxValue(result.y);
for (let i = 0; i < result.y.length; i++) {

@@ -96,0 +96,0 @@ result.y[i] /= maxY;

export interface ParseXYOptions {
/**
* Will set the maximum value to 1.
*
* @default false

@@ -10,3 +9,2 @@ */

* Make the X values unique (works only with 'xxyy' format). If the X value is repeated the sum of Y is done.
*
* @default false

@@ -17,3 +15,2 @@ */

* A number that specifies the x column.
*
* @default 0

@@ -24,3 +21,2 @@ */

* A number that specifies the y column.
*
* @default 1

@@ -31,3 +27,2 @@ */

* Will try to guess which columns are the best.
*
* @default false

@@ -38,3 +33,2 @@ */

* If the file has 10 columns and you specify here 2 it will reflow the file.
*
* @default Number.MAX_SAFE_INTEGER

@@ -45,3 +39,2 @@ */

* A number that specifies the maximum number of y columns.
*
* @default "Math.max(xColumn, yColumn)+1"

@@ -52,3 +45,2 @@ */

* A number that specifies the minimum number of y columns.
*
* @default "Math.min(xColumn, yColumn)+1"

@@ -55,0 +47,0 @@ */

@@ -6,3 +6,2 @@ import type { TextData } from 'cheminfo-types';

* Parse a text-file and convert it to an object {x:[], y:[]}
*
* @param text - Csv or tsv strings.

@@ -15,3 +14,2 @@ * @param options - Parsing options

* Parse a text-file and returns the parsed data and information about the columns
*
* @param text - Csv or tsv strings.

@@ -18,0 +16,0 @@ * @param options - Parsing options

@@ -22,3 +22,2 @@ "use strict";

* Parse a text-file and convert it to an object {x:[], y:[]}
*
* @param text - Csv or tsv strings.

@@ -34,3 +33,2 @@ * @param options - Parsing options

* Parse a text-file and returns the parsed data and information about the columns
*
* @param text - Csv or tsv strings.

@@ -37,0 +35,0 @@ * @param options - Parsing options

@@ -5,3 +5,2 @@ import { DataXY, TextData } from 'cheminfo-types';

* General internal parsing function
*
* @param text - Csv or tsv strings.

@@ -12,8 +11,8 @@ * @param options - Parsing options

export declare function parse(text: TextData, options?: ParseXYOptions): {
info: {
info: Array<{
position: number;
value: string;
}[];
}>;
data: DataXY;
};
//# sourceMappingURL=parse.d.ts.map

@@ -8,3 +8,2 @@ "use strict";

* General internal parsing function
*
* @param text - Csv or tsv strings.

@@ -15,5 +14,6 @@ * @param options - Parsing options

function parse(text, options = {}) {
let { rescale = false, uniqueX = false, xColumn = 0, yColumn = 1, bestGuess = false,
const { rescale = false, uniqueX = false, bestGuess = false,
//@ts-expect-error old library used this property and we want to throw an error so that people are forced to migrate
keepInfo, numberColumns = Number.MAX_SAFE_INTEGER, maxNumberColumns = Number.MAX_SAFE_INTEGER, minNumberColumns = 2, } = options;
keepInfo, } = options;
let { xColumn = 0, yColumn = 1, numberColumns = Number.MAX_SAFE_INTEGER, maxNumberColumns = Number.MAX_SAFE_INTEGER, minNumberColumns = 2, } = options;
if (keepInfo !== undefined) {

@@ -25,5 +25,5 @@ throw new Error('keepInfo has been deprecated, pelase use the new method parseXYAndKeepInfo');

minNumberColumns = Math.max(xColumn + 1, yColumn + 1, minNumberColumns);
let lines = text.split(/[\r\n]+/);
const lines = text.split(/[\r\n]+/);
let matrix = [];
let info = [];
const info = [];
let position = 0;

@@ -68,3 +68,3 @@ lines.forEach((line) => {

const xs = [];
for (let row of matrix) {
for (const row of matrix) {
for (let i = xColumn; i < row.length; i += 2) {

@@ -96,3 +96,3 @@ xs.push(row[i]);

if (rescale) {
let maxY = (0, ml_spectra_processing_1.xMaxValue)(result.y);
const maxY = (0, ml_spectra_processing_1.xMaxValue)(result.y);
for (let i = 0; i < result.y.length; i++) {

@@ -99,0 +99,0 @@ result.y[i] /= maxY;

export interface ParseXYOptions {
/**
* Will set the maximum value to 1.
*
* @default false

@@ -10,3 +9,2 @@ */

* Make the X values unique (works only with 'xxyy' format). If the X value is repeated the sum of Y is done.
*
* @default false

@@ -17,3 +15,2 @@ */

* A number that specifies the x column.
*
* @default 0

@@ -24,3 +21,2 @@ */

* A number that specifies the y column.
*
* @default 1

@@ -31,3 +27,2 @@ */

* Will try to guess which columns are the best.
*
* @default false

@@ -38,3 +33,2 @@ */

* If the file has 10 columns and you specify here 2 it will reflow the file.
*
* @default Number.MAX_SAFE_INTEGER

@@ -45,3 +39,2 @@ */

* A number that specifies the maximum number of y columns.
*
* @default "Math.max(xColumn, yColumn)+1"

@@ -52,3 +45,2 @@ */

* A number that specifies the minimum number of y columns.
*
* @default "Math.min(xColumn, yColumn)+1"

@@ -55,0 +47,0 @@ */

{
"name": "xy-parser",
"version": "5.0.4",
"version": "5.0.5",
"description": "Parse a text-file and convert it to an array of XY points",

@@ -14,2 +14,3 @@ "main": "./lib/index.js",

"scripts": {
"build": "npm run tsc-esm && cheminfo-build --entry lib-esm/index.js --root XYParser",
"build-doc": "cheminfo doc",

@@ -23,5 +24,4 @@ "check-types": "tsc --noEmit",

"prettier-write": "prettier --write src",
"test": "npm run test-only && npm run eslint && npm run check-types",
"test-coverage": "jest --coverage",
"test-only": "jest",
"test": "npm run test-only && npm run eslint && npm run prettier && npm run check-types",
"test-only": "jest --coverage",
"tsc": "npm run clean && npm run tsc-cjs && npm run tsc-esm",

@@ -46,19 +46,20 @@ "tsc-cjs": "tsc --project tsconfig.cjs.json",

"devDependencies": {
"@types/jest": "^29.5.0",
"@types/jest": "^29.5.12",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"cheminfo-build": "^1.2.0",
"cheminfo-tools": "^1.23.3",
"codecov": "^3.8.3",
"eslint": "^8.36.0",
"eslint-config-cheminfo-typescript": "^11.3.1",
"jest": "^29.5.0",
"prettier": "^2.8.7",
"rimraf": "^4.4.1",
"ts-jest": "^29.0.5",
"typescript": "^5.0.2"
"eslint": "^8.57.0",
"eslint-config-cheminfo-typescript": "^12.2.0",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"rimraf": "^5.0.5",
"ts-jest": "^29.1.2",
"typescript": "^5.4.2"
},
"dependencies": {
"cheminfo-types": "^1.4.0",
"cheminfo-types": "^1.7.2",
"ensure-string": "^1.2.0",
"ml-spectra-processing": "^12.0.0"
"ml-spectra-processing": "^14.2.0"
}
}

@@ -8,6 +8,6 @@ import { readFileSync } from 'fs';

test('ir.asc', () => {
let filename = 'ir.asc';
let data = readFileSync(path + filename).toString();
const filename = 'ir.asc';
const data = readFileSync(path + filename).toString();
let result = parseXY(data);
const result = parseXY(data);
expect(result.x).toBeInstanceOf(Array);

@@ -20,9 +20,9 @@ expect(result.y).toBeInstanceOf(Array);

test('ir2.asc', () => {
let filename = 'ir2.asc';
let data = readFileSync(path + filename).toString();
const filename = 'ir2.asc';
const data = readFileSync(path + filename).toString();
let result = parseXY(data);
const result = parseXY(data);
let min = Math.min(...result.y);
let max = Math.max(...result.y);
const min = Math.min(...result.y);
const max = Math.max(...result.y);

@@ -29,0 +29,0 @@ expect(min).toBeCloseTo(5.604768, 3);

@@ -9,6 +9,6 @@ import { readFileSync } from 'fs';

it('mass1.txt', () => {
let filename = 'mass1.txt';
let data = readFileSync(path + filename).toString();
const filename = 'mass1.txt';
const data = readFileSync(path + filename).toString();
let result = parseXY(data);
const result = parseXY(data);
expect(result.x).toHaveLength(20);

@@ -19,3 +19,3 @@ expect(result.y).toHaveLength(20);

let result2 = parseXY(data, { bestGuess: true });
const result2 = parseXY(data, { bestGuess: true });
expect(result2.x).toHaveLength(20);

@@ -28,6 +28,6 @@ expect(result2.y).toHaveLength(20);

it('mass2.csv', () => {
let filename = 'mass2.csv';
let data = readFileSync(path + filename).toString();
const filename = 'mass2.csv';
const data = readFileSync(path + filename).toString();
let result = parseXY(data, { xColumn: 1, yColumn: 2 });
const result = parseXY(data, { xColumn: 1, yColumn: 2 });
expect(result.x).toHaveLength(20);

@@ -38,3 +38,3 @@ expect(result.y).toHaveLength(20);

let result2 = parseXY(data, { bestGuess: true });
const result2 = parseXY(data, { bestGuess: true });
expect(result2.x).toHaveLength(20);

@@ -47,6 +47,6 @@ expect(result2.y).toHaveLength(20);

it('mass3.asc', () => {
let filename = 'mass3.asc';
let data = readFileSync(path + filename).toString();
const filename = 'mass3.asc';
const data = readFileSync(path + filename).toString();
let result = parseXY(data);
const result = parseXY(data);
expect(result.x).toHaveLength(20);

@@ -57,3 +57,3 @@ expect(result.y).toHaveLength(20);

let result2 = parseXY(data, { bestGuess: true });
const result2 = parseXY(data, { bestGuess: true });
expect(result2.x).toHaveLength(20);

@@ -66,5 +66,5 @@ expect(result2.y).toHaveLength(20);

it('mass4.spectrum', () => {
let filename = 'mass4.spectrum';
let data = readFileSync(path + filename).toString();
let result = parseXY(data, { numberColumns: 2 });
const filename = 'mass4.spectrum';
const data = readFileSync(path + filename).toString();
const result = parseXY(data, { numberColumns: 2 });
expect(result.x).toHaveLength(34);

@@ -75,3 +75,3 @@ expect(result.y).toHaveLength(34);

let result2 = parseXY(data, { bestGuess: true });
const result2 = parseXY(data, { bestGuess: true });
expect(result2.x).toHaveLength(34);

@@ -78,0 +78,0 @@ expect(result2.y).toHaveLength(34);

@@ -7,7 +7,7 @@ import { readFileSync } from 'fs';

const filename = 'simple.txt';
let data = readFileSync(path + filename).toString();
const data = readFileSync(path + filename).toString();
describe('simple test', () => {
it('Check array and length without options', () => {
let result1 = parseXY(data);
const result1 = parseXY(data);
expect(result1).toStrictEqual({ x: [1, 3, 5, 7], y: [2, 4, 6, 8] });

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

it('Check array and length with options normalize:true', () => {
let result2 = parseXY(data, { rescale: true });
const result2 = parseXY(data, { rescale: true });
expect(result2).toStrictEqual({ x: [1, 3, 5, 7], y: [0.25, 0.5, 0.75, 1] });
});
});

@@ -8,6 +8,6 @@ import { readFileSync } from 'fs';

test('uv.csv', () => {
let filename = 'uv.csv';
let data = readFileSync(path + filename).toString();
const filename = 'uv.csv';
const data = readFileSync(path + filename).toString();
let result = parseXY(data);
const result = parseXY(data);

@@ -14,0 +14,0 @@ expect(result.x).toBeInstanceOf(Array);

@@ -8,5 +8,5 @@ import { readFileSync } from 'fs';

test('binary', () => {
let filename = 'text1.txt';
let data = readFileSync(path + filename);
let result = parseXY(data);
const filename = 'text1.txt';
const data = readFileSync(path + filename);
const result = parseXY(data);

@@ -20,5 +20,5 @@ expect(result.x).toBeInstanceOf(Array);

test('text1', () => {
let filename = 'text1.txt';
let data = readFileSync(path + filename).toString();
let result = parseXY(data);
const filename = 'text1.txt';
const data = readFileSync(path + filename).toString();
const result = parseXY(data);

@@ -32,5 +32,5 @@ expect(result.x).toBeInstanceOf(Array);

test('text2', () => {
let filename = 'text2.txt';
let data = readFileSync(path + filename).toString();
let result = parseXY(data);
const filename = 'text2.txt';
const data = readFileSync(path + filename).toString();
const result = parseXY(data);

@@ -44,5 +44,5 @@ expect(result.x).toBeInstanceOf(Array);

test('text3', () => {
let filename = 'text3.txt';
let data = readFileSync(path + filename).toString();
let result = parseXY(data, {
const filename = 'text3.txt';
const data = readFileSync(path + filename).toString();
const result = parseXY(data, {
uniqueX: true,

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

test('with some spaces', () => {
let filename = 'text4.txt';
let data = readFileSync(path + filename).toString();
let result = parseXY(data, {
const filename = 'text4.txt';
const data = readFileSync(path + filename).toString();
const result = parseXY(data, {
uniqueX: true,

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

test('with some spaces and taking second and third column', () => {
let filename = 'text5.txt';
let data = readFileSync(path + filename).toString();
let result = parseXY(data, {
const filename = 'text5.txt';
const data = readFileSync(path + filename).toString();
const result = parseXY(data, {
xColumn: 1,

@@ -79,5 +79,5 @@ yColumn: 2,

test('with some non numeric lines', () => {
let filename = 'text6.txt';
let data = readFileSync(path + filename).toString();
let result = parseXY(data, {});
const filename = 'text6.txt';
const data = readFileSync(path + filename).toString();
const result = parseXY(data, {});
expect(result).toStrictEqual({ x: [1, 3, 5], y: [4, 6, 8] });

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

test('with some non numeric lines and keeping info', () => {
let filename = 'text6.txt';
let data = readFileSync(path + filename).toString();
let result = parseXYAndKeepInfo(data);
const filename = 'text6.txt';
const data = readFileSync(path + filename).toString();
const result = parseXYAndKeepInfo(data);
expect(result).toStrictEqual({

@@ -102,5 +102,5 @@ data: { x: [1, 3, 5], y: [4, 6, 8] },

test('with comma as decimal delimiter', () => {
let filename = 'text7.txt';
let data = readFileSync(path + filename).toString();
let result = parseXY(data, {});
const filename = 'text7.txt';
const data = readFileSync(path + filename).toString();
const result = parseXY(data, {});
expect(result).toStrictEqual({ x: [1.1, 2.2, 3.3], y: [1, 2, 3] });

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

test('with scientific notation', () => {
let filename = 'text8.txt';
let data = readFileSync(path + filename).toString();
let result = parseXYAndKeepInfo(data);
const filename = 'text8.txt';
const data = readFileSync(path + filename).toString();
const result = parseXYAndKeepInfo(data);
expect(result).toStrictEqual({

@@ -130,7 +130,7 @@ data: { x: [0.11, -11, 0.11], y: [0.22, -22, 0.22] },

test('large IV scientific notation file', () => {
let filename = 'text9.txt';
let data = readFileSync(path + filename).toString();
let result = parseXY(data, {});
const filename = 'text9.txt';
const data = readFileSync(path + filename).toString();
const result = parseXY(data, {});
expect(result.x).toHaveLength(6472);
expect(result.y).toHaveLength(6472);
});

@@ -10,3 +10,2 @@ import type { TextData } from 'cheminfo-types';

* Parse a text-file and convert it to an object {x:[], y:[]}
*
* @param text - Csv or tsv strings.

@@ -22,3 +21,2 @@ * @param options - Parsing options

* Parse a text-file and returns the parsed data and information about the columns
*
* @param text - Csv or tsv strings.

@@ -25,0 +23,0 @@ * @param options - Parsing options

@@ -9,3 +9,2 @@ import { DataXY, TextData } from 'cheminfo-types';

* General internal parsing function
*
* @param text - Csv or tsv strings.

@@ -19,13 +18,15 @@ * @param options - Parsing options

): {
info: { position: number; value: string }[];
info: Array<{ position: number; value: string }>;
data: DataXY;
} {
let {
const {
rescale = false,
uniqueX = false,
xColumn = 0,
yColumn = 1,
bestGuess = false,
//@ts-expect-error old library used this property and we want to throw an error so that people are forced to migrate
keepInfo,
} = options;
let {
xColumn = 0,
yColumn = 1,
numberColumns = Number.MAX_SAFE_INTEGER,

@@ -47,6 +48,6 @@ maxNumberColumns = Number.MAX_SAFE_INTEGER,

let lines = text.split(/[\r\n]+/);
const lines = text.split(/[\r\n]+/);
let matrix: number[][] = [];
let info: { position: number; value: string }[] = [];
const info: Array<{ position: number; value: string }> = [];
let position = 0;

@@ -95,3 +96,3 @@ lines.forEach((line) => {

const xs: number[] = [];
for (let row of matrix) {
for (const row of matrix) {
for (let i = xColumn; i < row.length; i += 2) {

@@ -126,3 +127,3 @@ xs.push(row[i]);

if (rescale) {
let maxY = xMaxValue(result.y);
const maxY = xMaxValue(result.y);
for (let i = 0; i < result.y.length; i++) {

@@ -129,0 +130,0 @@ result.y[i] /= maxY;

export interface ParseXYOptions {
/**
* Will set the maximum value to 1.
*
* @default false

@@ -10,3 +9,2 @@ */

* Make the X values unique (works only with 'xxyy' format). If the X value is repeated the sum of Y is done.
*
* @default false

@@ -17,3 +15,2 @@ */

* A number that specifies the x column.
*
* @default 0

@@ -24,3 +21,2 @@ */

* A number that specifies the y column.
*
* @default 1

@@ -31,3 +27,2 @@ */

* Will try to guess which columns are the best.
*
* @default false

@@ -38,3 +33,2 @@ */

* If the file has 10 columns and you specify here 2 it will reflow the file.
*
* @default Number.MAX_SAFE_INTEGER

@@ -45,3 +39,2 @@ */

* A number that specifies the maximum number of y columns.
*
* @default "Math.max(xColumn, yColumn)+1"

@@ -52,3 +45,2 @@ */

* A number that specifies the minimum number of y columns.
*
* @default "Math.min(xColumn, yColumn)+1"

@@ -55,0 +47,0 @@ */

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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