comma-separated-tokens

Parse and stringify comma-separated tokens

Usage no npm install needed!

<script type="module">
  import commaSeparatedTokens from 'https://cdn.skypack.dev/comma-separated-tokens';
</script>

README

comma-separated-tokens

Build Coverage Downloads Size

Parse and stringify comma separated tokens according to the spec.

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

npm:

npm install comma-separated-tokens

Use

import {parse, stringify} from 'comma-separated-tokens'

parse(' a ,b,,d d ') //=> ['a', 'b', '', 'd d']
stringify(['a', 'b', '', 'd d']) //=> 'a, b, , d d'

API

This package exports the following identifiers: parse, stringify. There is no default export.

parse(value)

Parse comma separated tokens (string) to an array of strings, according to the spec.

stringify(values[, options])

Compile an array of strings to comma separated tokens (string). Handles empty items at start or end correctly. Note that it’s not possible to specify initial or final whitespace per value.

options
options.padLeft

Whether to pad a space before a token (boolean, default: true).

options.padRight

Whether to pad a space after a token (boolean, default: false).

Related

License

MIT © Titus Wormer