← All procedures

csv.stringify

Write rows as CSV text

CLI
Package
@procedures/json · README
Path
["csv","stringify"]
CLI
mark csv stringify --rows <any[]>
As data
{"$proc":["csv","stringify"],"input":{}}

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/json/register"; // registers its procedures

const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["csv","stringify"], { rows: [] });
console.log(JSON.stringify(result));

From the command line

$ mark csv stringify --rows <any[]>

As data, in a program

{ "$proc": ["csv", "stringify"], "input": { "rows": [] } }

Input

FieldTypeRequiredDefaultDescription
rowsany[]yesThe rows: all arrays or all objects. A field is a string, a number, a boolean or null
columnsstring[]noThe names of the columns. For objects, they select the keys and give their order. For arrays, they are the first row
headerbooleannoFalse: no row with the names of the columns (default: true)
delimiterstringnoThe character between two fields (default: a comma)
lineBreak"\r\n" | "\n"noThe line break after each row (default: CRLF)

Output

FieldTypeRequiredDefaultDescription
textstringyesThe CSV text
JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "rows": {
        "type": "array",
        "items": {
          "description": "A row: an array of fields, or an object of fields by column name"
        },
        "description": "The rows: all arrays or all objects. A field is a string, a number, a boolean or null"
      },
      "columns": {
        "description": "The names of the columns. For objects, they select the keys and give their order. For arrays, they are the first row",
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "header": {
        "description": "False: no row with the names of the columns (default: true)",
        "type": "boolean"
      },
      "delimiter": {
        "description": "The character between two fields (default: a comma)",
        "type": "string",
        "minLength": 1,
        "maxLength": 1
      },
      "lineBreak": {
        "description": "The line break after each row (default: CRLF)",
        "type": "string",
        "enum": [
          "\r\n",
          "\n"
        ]
      }
    },
    "required": [
      "rows"
    ]
  },
  "output": {
    "type": "object",
    "properties": {
      "text": {
        "type": "string",
        "description": "The CSV text"
      }
    },
    "required": [
      "text"
    ],
    "additionalProperties": false
  }
}