Modules@robinpath/csv
csv

@robinpath/csv

0.1.2Node.jsPublic

Parse and stringify CSV data

CSV

Parse and stringify CSV data

Package: @robinpath/csv | Category: Utility | Type: Utility

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the csv module when you need to:

  • Parse a CSV string into an array of objects (first row = headers) -- Use csv.parse to perform this operation
  • Convert an array of objects into a CSV string -- Use csv.stringify to perform this operation
  • Extract header names from a CSV string -- Use csv.headers to perform this operation
  • Extract all values from a specific column -- Use csv.column to perform this operation
  • Parse a CSV string into an array of arrays (raw, no header mapping) -- Use csv.rows to perform this operation

Quick Reference

FunctionDescriptionReturns
parseParse a CSV string into an array of objects (first row = headers)Array of objects where keys are header names
stringifyConvert an array of objects into a CSV stringCSV formatted string
headersExtract header names from a CSV stringArray of header name strings
columnExtract all values from a specific columnArray of values from the specified column
rowsParse a CSV string into an array of arrays (raw, no header mapping)Array of arrays (each inner array is a row of strings)

Functions

parse

Parse a CSV string into an array of objects (first row = headers)

Module: csv | Returns: array -- Array of objects where keys are header names

csv.parse "name,age\nAlice,30\nBob,25"
ParameterTypeRequiredDescription
csvStringstringYesThe CSV string to parse
delimiterstringNoColumn delimiter (default: comma)

stringify

Convert an array of objects into a CSV string

Module: csv | Returns: string -- CSV formatted string

csv.stringify $data
ParameterTypeRequiredDescription
dataarrayYesArray of objects to convert
delimiterstringNoColumn delimiter (default: comma)

headers

Extract header names from a CSV string

Module: csv | Returns: array -- Array of header name strings

csv.headers "name,age\nAlice,30"
ParameterTypeRequiredDescription
csvStringstringYesThe CSV string

column

Extract all values from a specific column

Module: csv | Returns: array -- Array of values from the specified column

csv.column "name,age\nAlice,30" "name"
ParameterTypeRequiredDescription
csvStringstringYesThe CSV string
columnNamestringYesName of the column to extract

rows

Parse a CSV string into an array of arrays (raw, no header mapping)

Module: csv | Returns: array -- Array of arrays (each inner array is a row of strings)

csv.rows "name,age\nAlice,30"
ParameterTypeRequiredDescription
csvStringstringYesThe CSV string to parse
delimiterstringNoColumn delimiter (default: comma)

Error Handling

All functions throw on failure. Common errors:

ErrorCause
(standard errors)Check function parameters and authentication
@desc "Parse and validate result"
do
  set $result as csv.parse "name,age\nAlice,30\nBob,25"
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. Multi-step CSV workflow

Chain multiple csv operations together.

@desc "Parse, stringify, and more"
do
  set $r_parse as csv.parse "name,age\nAlice,30\nBob,25"
  set $r_stringify as csv.stringify $data
  set $r_headers as csv.headers "name,age\nAlice,30"
  print "All operations complete"
enddo

2. Safe parse with validation

Check results before proceeding.

@desc "Parse and validate result"
do
  set $result as csv.parse "name,age\nAlice,30\nBob,25"
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.2latest1 months ago
Install
$ robinpath add @robinpath/csv

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.2
LicenseMIT
Unpacked Size6.2 KB
Versions1
Weekly Downloads27
Total Downloads27
Stars0
Last Publish1 months ago
Created1 months ago

Keywords

Category

utilities