]> git.ardis.lu - csvio/commitdiff
Use paths relative to JS file location, not execution location
authorArdis Lu <ardisglu@gmail.com>
Thu, 9 Jan 2025 07:29:35 +0000 (23:29 -0800)
committerArdis Lu <ardisglu@gmail.com>
Thu, 9 Jan 2025 07:29:35 +0000 (23:29 -0800)
Allows the example files to be run from any directory, not just /examples

examples/README.md
examples/ex1.js
examples/ex2.js
examples/ex3.js
examples/ex4.js
examples/ex5.js

index 97cfdb7b3f6ad7812b8ffe3a51c9e2ba10ddfd6b..de076f28854816c464172c9f6e89211d83b4cd7e 100644 (file)
@@ -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
 ```
index 77b63e9b2c27d2f3ace686995c0139855ef0173e..b2457d9c8ab5df7ffdf5749716e361f5207dc582 100644 (file)
@@ -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
index 907f4828b803d3969c08f60f377063c730ad0da8..16c1c606eae59ad65819d42c13b57e41d0257b5b 100644 (file)
@@ -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
index f841e6ea1309c54d1869d10110cb313dc2b77193..32a907d61f1a8aac6693c04b17fcc7fa76efea1e 100644 (file)
@@ -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
index 18a05f4e06e020f8516fd79133839ff13454ce9d..638605f39a7849801d22c7175af2ecc2b0c0f843 100644 (file)
@@ -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
index e08db19c17bb02d46f4c6bfcd7f3c23714b218a9..2b0f9a383130f3233788c15d3ac435bf4679e5a7 100644 (file)
@@ -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
This page took 0.040317 seconds and 4 git commands to generate.