From 1472d63b3ef983bfe3e622a84a5200e32ff2793a Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Wed, 8 Jan 2025 23:29:35 -0800 Subject: [PATCH] Use paths relative to JS file location, not execution location Allows the example files to be run from any directory, not just /examples --- examples/README.md | 5 ++--- examples/ex1.js | 4 ++-- examples/ex2.js | 4 ++-- examples/ex3.js | 4 ++-- examples/ex4.js | 4 ++-- examples/ex5.js | 4 ++-- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/examples/README.md b/examples/README.md index 97cfdb7..de076f2 100644 --- a/examples/README.md +++ b/examples/README.md @@ -2,9 +2,8 @@ This folder contains end-to-end examples of using this library. -All examples assume your current working directory is **this folder**. All examples can be run directly without additional setup using `node`. E.g.: +All examples can be run directly without additional setup using `node`. E.g.: ``` -cd examples -node ./ex1.js +node ./examples/ex1.js ``` diff --git a/examples/ex1.js b/examples/ex1.js index 77b63e9..b2457d9 100644 --- a/examples/ex1.js +++ b/examples/ex1.js @@ -14,6 +14,6 @@ function timesTwo(row) { return [Number(row[0]) * 2, Number(row[1]) * 2]; } -createCSVReadableStream('./data/ex1-in.csv') +createCSVReadableStream(new URL('./data/ex1-in.csv', import.meta.url)) .pipeThrough(createCSVTransformStream(timesTwo)) - .pipeTo(createCSVWritableStream('./data/ex1-out.csv')); \ No newline at end of file + .pipeTo(createCSVWritableStream(new URL('./data/ex1-out.csv', import.meta.url))); \ No newline at end of file diff --git a/examples/ex2.js b/examples/ex2.js index 907f482..16c1c60 100644 --- a/examples/ex2.js +++ b/examples/ex2.js @@ -18,6 +18,6 @@ function sum(row) { return [...row, Number(row[0]) + Number(row[1])]; } -createCSVReadableStream('./data/ex2-in.csv') +createCSVReadableStream(new URL('./data/ex2-in.csv', import.meta.url)) .pipeThrough(createCSVTransformStream(sum, { includeHeaders: true })) - .pipeTo(createCSVWritableStream('./data/ex2-out.csv')); \ No newline at end of file + .pipeTo(createCSVWritableStream(new URL('./data/ex2-out.csv', import.meta.url))); \ No newline at end of file diff --git a/examples/ex3.js b/examples/ex3.js index f841e6e..32a907d 100644 --- a/examples/ex3.js +++ b/examples/ex3.js @@ -22,7 +22,7 @@ function calculate(obj) { return [name, paddedId]; } -createCSVReadableStream('./data/ex3-in.csv') +createCSVReadableStream(new URL('./data/ex3-in.csv', import.meta.url)) .pipeThrough(createCSVTransformStream(parse, { includeHeaders: true, rawOutput: true })) .pipeThrough(createCSVTransformStream(calculate, { includeHeaders: true, rawInput: true })) - .pipeTo(createCSVWritableStream('./data/ex3-out.csv')); \ No newline at end of file + .pipeTo(createCSVWritableStream(new URL('./data/ex3-out.csv', import.meta.url))); \ No newline at end of file diff --git a/examples/ex4.js b/examples/ex4.js index 18a05f4..638605f 100644 --- a/examples/ex4.js +++ b/examples/ex4.js @@ -30,7 +30,7 @@ const headers = [ } ]; -createCSVReadableStream('./data/ex4-in.csv') +createCSVReadableStream(new URL('./data/ex4-in.csv', import.meta.url)) .pipeThrough(createCSVNormalizationStream(headers)) .pipeThrough(createCSVDenormalizationStream()) - .pipeTo(createCSVWritableStream('./data/ex4-out.csv')); \ No newline at end of file + .pipeTo(createCSVWritableStream(new URL('./data/ex4-out.csv', import.meta.url))); \ No newline at end of file diff --git a/examples/ex5.js b/examples/ex5.js index e08db19..2b0f9a3 100644 --- a/examples/ex5.js +++ b/examples/ex5.js @@ -24,6 +24,6 @@ function parse(row) { return [report, id, date, ...row]; } -createCSVReadableStream('./data/ex5-in.csv') +createCSVReadableStream(new URL('./data/ex5-in.csv', import.meta.url)) .pipeThrough(createCSVTransformStream(parse, { includeHeaders: true })) - .pipeTo(createCSVWritableStream('./data/ex5-out.csv')); \ No newline at end of file + .pipeTo(createCSVWritableStream(new URL('./data/ex5-out.csv', import.meta.url))); \ No newline at end of file -- 2.47.3