@rip-lang/csv 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/csv.rip +6 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -199,8 +199,8 @@ CSV.write rows, mode: 'compact'
|
|
|
199
199
|
# Full: quote every field
|
|
200
200
|
CSV.write rows, mode: 'full'
|
|
201
201
|
|
|
202
|
-
#
|
|
203
|
-
CSV.write rows,
|
|
202
|
+
# Protect leading zeros for spreadsheets
|
|
203
|
+
CSV.write rows, zeros: true
|
|
204
204
|
|
|
205
205
|
# Drop trailing empty columns
|
|
206
206
|
CSV.write rows, drop: true
|
|
@@ -232,7 +232,7 @@ CSV.write rows, drop: true
|
|
|
232
232
|
| `quote` | string | `'"'` | Quote character |
|
|
233
233
|
| `escape` | string | same as `quote` | Escape character |
|
|
234
234
|
| `mode` | string | `'compact'` | `'compact'` or `'full'` |
|
|
235
|
-
| `
|
|
235
|
+
| `zeros` | boolean | `false` | Protect leading zeros with `="0123"` |
|
|
236
236
|
| `drop` | boolean | `false` | Drop trailing empty columns |
|
|
237
237
|
| `rowsep` | string | `'\n'` | Row separator |
|
|
238
238
|
|
package/csv.rip
CHANGED
|
@@ -362,7 +362,7 @@ class Writer
|
|
|
362
362
|
@quote = opts.quote ?? '"'
|
|
363
363
|
@escape = opts.escape ?? @quote
|
|
364
364
|
@mode = opts.mode ?? 'compact'
|
|
365
|
-
@
|
|
365
|
+
@zeros = opts.zeros ?? false
|
|
366
366
|
@drop = opts.drop ?? false
|
|
367
367
|
@rowsep = opts.rowsep ?? '\n'
|
|
368
368
|
|
|
@@ -390,11 +390,11 @@ class Writer
|
|
|
390
390
|
|
|
391
391
|
formatted = switch @mode
|
|
392
392
|
when 'compact'
|
|
393
|
-
if not @
|
|
393
|
+
if not @zeros and not @needsQuote(cells.join(''))
|
|
394
394
|
cells
|
|
395
395
|
else
|
|
396
396
|
for cell in cells
|
|
397
|
-
if @
|
|
397
|
+
if @zeros and @leadZero.test(cell)
|
|
398
398
|
"=#{q}#{cell}#{q}"
|
|
399
399
|
else if @needsQuote(cell)
|
|
400
400
|
"#{q}#{cell.replaceAll(q, esc)}#{q}"
|
|
@@ -402,7 +402,7 @@ class Writer
|
|
|
402
402
|
cell
|
|
403
403
|
when 'full'
|
|
404
404
|
for cell in cells
|
|
405
|
-
if @
|
|
405
|
+
if @zeros and @leadZero.test(cell)
|
|
406
406
|
"=#{q}#{cell}#{q}"
|
|
407
407
|
else
|
|
408
408
|
"#{q}#{cell.replaceAll(q, esc)}#{q}"
|
|
@@ -460,7 +460,7 @@ if import.meta.main
|
|
|
460
460
|
|
|
461
461
|
args = process.argv.slice(2)
|
|
462
462
|
readOpts = {relax: false, excel: false, strip: false}
|
|
463
|
-
writeOpts = {
|
|
463
|
+
writeOpts = {zeros: false}
|
|
464
464
|
files = []
|
|
465
465
|
|
|
466
466
|
for arg in args
|
|
@@ -490,7 +490,7 @@ if import.meta.main
|
|
|
490
490
|
when '-r', '--relax' then readOpts.relax = true
|
|
491
491
|
when '-e', '--excel' then readOpts.excel = true
|
|
492
492
|
when '-s', '--strip' then readOpts.strip = true
|
|
493
|
-
when '-z', '--zeros' then writeOpts.
|
|
493
|
+
when '-z', '--zeros' then writeOpts.zeros = true
|
|
494
494
|
else files.push arg
|
|
495
495
|
|
|
496
496
|
unless files.length
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rip-lang/csv",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "Fast, flexible CSV parser and writer for Rip — indexOf ratchet engine, auto-detection, zero dependencies",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "csv.rip",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"author": "Steve Shreeve <steve.shreeve@gmail.com>",
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"rip-lang": "
|
|
34
|
+
"rip-lang": ">=3.13.8"
|
|
35
35
|
},
|
|
36
36
|
"files": [
|
|
37
37
|
"csv.rip",
|