Skip to content

Commit

Permalink
Avoid regex look-behind
Browse files Browse the repository at this point in the history
It doesn't work in Safari.
  • Loading branch information
manthey committed Feb 9, 2023
1 parent 6bf3f49 commit cfc3521
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions web/shapeworks/src/charts.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// functions for generating analysis charts

export type lineChartProps = {
title: string,
x_label: string,
y_label: string,
x: Array<number>,
y: Array<number>
export type lineChartProps = {
title: string,
x_label: string,
y_label: string,
x: Array<number>,
y: Array<number>
}

export function lineChartOptions (data: lineChartProps) {
Expand Down Expand Up @@ -127,7 +127,9 @@ function copyData(text: string) {

function getDownloadURL(text: string) {
const csvstring = getTextAsCSV(text);
const csvarray = csvstring.split(/(?<=\n)/gi); // uses positive look-behind to keep \n intact after split
// const csvarray = csvstring.split(/(?<=\n)/gi); // uses positive look-behind to keep \n intact after split
// this should do the same thing without the look-behind
const csvarray = csvstring.split(/\n/g).map((v, idx) => idx ? v + '\n' : v);

const blob = new Blob(csvarray);

Expand All @@ -146,7 +148,7 @@ function getTextAsCSV(text: string) {
splitstring[rowindex] = h.join(',');
}
})

return splitstring.join('\n');
}

Expand Down Expand Up @@ -176,7 +178,7 @@ function showData(data: lineChartProps) {

csvtext += `${data.x[i]},${data.y[i]}\n`
}

const div = document.createElement('div');
div.className = "dataview";

Expand Down Expand Up @@ -209,4 +211,3 @@ function roundTo(num: number, place: number) {
const factor = 10 ** place;
return Math.round(num * factor) / factor;
}

0 comments on commit cfc3521

Please sign in to comment.