Comparing version 1.3.0 to 1.5.0
{ | ||
"name": "xy-parser", | ||
"version": "1.3.0", | ||
"version": "1.5.0", | ||
"description": "Parse a text-file and convert it to an array of XY points", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
{ | ||
"name": "xy-parser", | ||
"version": "1.3.0", | ||
"version": "1.5.0", | ||
"description": "Parse a text-file and convert it to an array of XY points", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
'use strict'; | ||
var uniqueX = require('ml-arrayxy-uniquex'); | ||
var uniqueXFunction = require('ml-arrayxy-uniquex'); | ||
@@ -9,7 +9,24 @@ /** | ||
* @param options | ||
* @param options.arrayType xxyy or xyxy | ||
* @param {boolean} options.normalize=false | ||
* @param {boolean} options.uniqueX | ||
* @param {number} [options.xColumn=0] - A number that specifies the xColumn | ||
* @param {number} [options.yColumn=1] - A number that specifies the yColumn | ||
* @param {number} [options.maxNumberColumns=(Math.max(xColumn, yColumn)+1 || 2)] - A number that specifies the yColumn | ||
* @param {number} [options.minNumberColumns=(Math.max(xColumn, yColumn)+1 || 2)] - A number that specifies the yColumn | ||
* @returns {*[]|Array} | ||
*/ | ||
function parseXY (text, options) { | ||
var options = options || {}; | ||
function parseXY (text, options={}) { | ||
let { | ||
normalize=false, | ||
uniqueX=false, | ||
arrayType='xyxy', | ||
xColumn=0, | ||
yColumn=1, | ||
maxNumberColumns, | ||
minNumberColumns | ||
} = options; | ||
if (!maxNumberColumns) maxNumberColumns=(Math.max(xColumn, yColumn)+1) || 2; | ||
if (!minNumberColumns) minNumberColumns=(Math.max(xColumn, yColumn)+1) || 2; | ||
var lines = text.split(/[\r\n]+/); | ||
@@ -20,3 +37,3 @@ | ||
var counter=0; | ||
var xxyy= (options.arrayType==='xxyy') ? true : false; | ||
var xxyy= (arrayType==='xxyy') ? true : false; | ||
if (xxyy) { | ||
@@ -30,3 +47,2 @@ var result = [ | ||
} | ||
for (var i = 0; i < lines.length; i++) { | ||
@@ -38,5 +54,5 @@ var line = lines[i]; | ||
var fields = line.split(/[,; \t]+/); | ||
if (fields && fields.length == 2) { | ||
var x = parseFloat(fields[0]); | ||
var y = parseFloat(fields[1]); | ||
if (fields && fields.length >= minNumberColumns && fields.length <= maxNumberColumns) { | ||
let x = parseFloat(fields[xColumn]); | ||
let y = parseFloat(fields[yColumn]); | ||
@@ -61,3 +77,3 @@ if (y > maxY) maxY = y; | ||
if (options.normalize) { | ||
if (normalize) { | ||
if (xxyy) { | ||
@@ -75,5 +91,5 @@ for (var i = 0; i < counter; i++) { | ||
if (options.uniqueX) { | ||
if (uniqueX) { | ||
if (! xxyy) throw new Error('Can only make unique X for xxyy format'); | ||
uniqueX(result[0], result[1]) | ||
uniqueXFunction(result[0], result[1]) | ||
} | ||
@@ -80,0 +96,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6836
109