2.0.3 • Published 2 years ago

comma-separated-tokens v2.0.3

Weekly downloads
2,790,976
License
MIT
Repository
github
Last release
2 years ago

comma-separated-tokens

Build Coverage Downloads Size

Parse and stringify comma-separated tokens.

Contents

What is this?

This is a tiny package that can parse and stringify comma-separated tokens, as used for example in the HTML accept attribute, according to the WHATWG spec.

When should I use this?

This package is rather niche, it’s low-level and particularly useful when working with hast.

Install

This package is ESM only. In Node.js (version 14.14+, 16.0+), install with npm:

npm install comma-separated-tokens

In Deno with esm.sh:

import {parse, stringify} from 'https://esm.sh/comma-separated-tokens@2'

In browsers with esm.sh:

<script type="module">
  import {parse, stringify} from 'https://esm.sh/comma-separated-tokens@2?bundle'
</script>

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 identifier parse and stringify. There is no default export.

parse(value)

Parse commma-separated tokens (string) to an array of strings (Array<string>), according to the WHATWG spec.

stringify(values[, options])

Serialize an array of strings or numbers (Array<string|number>) to comma-separated tokens (string). Handles empty items at start or end correctly.

👉 Note: it’s not possible to specify initial or final whitespace per value.

options

Configuration (optional).

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).

Types

This package is fully typed with TypeScript. It exports the additional type Options.

Compatibility

This package is at least compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+ and 16.0+. It also works in Deno and modern browsers.

Related

Contribute

Yes please! See How to Contribute to Open Source.

Security

This package is safe.

License

MIT © Titus Wormer

hastscripthast-util-to-parse5@daimond113/solid-markdowntmp-hast-util-to-jsxcogoportutils@infinitebrahmanuniverse/nolb-comma@saaspe/components@everything-registry/sub-chunk-1360xast-util-selectrehype-minify-meta-contentsequelcomponentsvelte-component-libqjc2-blockzzzxxxyyy321123hast-util-selecthast-util-to-estreehast-util-to-htmlhast-util-to-html-nshast-util-to-jsx-runtimehast-util-properties-to-mdx-jsx-attributeshast-util-to-xasthastscript-case-sensitivehastscript-jsxhastscript-nsglobal_components_assignmentmarkdown-vueparvan_componentsparvan_reactjs_componentsmypluginlolreact-form-component-librarynois-react-toastrainbowprokovanmailreact-markdown-customkeypropreact-markdown-v8.0.3solid-markdownu-librarytldrawlignin@beeswax/react-markdown-async@azu/hast-util-to-html@breadio/markdown@cquiroz/react-markdownunified-argszerionprokovanmail@furmeet/solid-markdown@frctl/fractal-plugin-preprocess-templates@kunet/solid-markdown-but-updated@lskjs/markdown@lego-js/tests@newageerp/v3.utils.markdown@enyaxu/hast-util-to-html@pretext-book/jsx@qihoo/wx2qh@starptech/prettyhtml-hast-to-html@starptech/prettyhtml-hastscript@podlubnaja/ui-kit@skeetboothppq/component-library@soyjak/utils@shivarajapple/first-library@zalastax/nolb-comma@zentered/solid-markdownappcharge-checkout@dlinc/file-guard-config@cute-apocalypse/react-tree@blkmarketco/components-library@uivjs/vue-markdown-preview@vitali_shcherbina/styled-lib@wayowe/prettyhtml-hast-to-html@wayowe/prettyhtml-hastscriptadarshsinghal-editor-previewcreate-express-appcommoditeneturdesign-system-fitbank-450fn-lib-examplegformat-hast-to-htmlgformat-hast-to-html-tmp
2.0.3

2 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.8

5 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

9 years ago

1.0.0

9 years ago