1 | # comma-separated-tokens
|
---|
2 |
|
---|
3 | [![Build][build-badge]][build]
|
---|
4 | [![Coverage][coverage-badge]][coverage]
|
---|
5 | [![Downloads][downloads-badge]][downloads]
|
---|
6 | [![Size][size-badge]][size]
|
---|
7 |
|
---|
8 | Parse and stringify comma-separated tokens according to the [spec][].
|
---|
9 |
|
---|
10 | ## Install
|
---|
11 |
|
---|
12 | [npm][]:
|
---|
13 |
|
---|
14 | ```sh
|
---|
15 | npm install comma-separated-tokens
|
---|
16 | ```
|
---|
17 |
|
---|
18 | ## Use
|
---|
19 |
|
---|
20 | ```js
|
---|
21 | var commaSeparated = require('comma-separated-tokens')
|
---|
22 |
|
---|
23 | commaSeparated.parse(' a ,b,,d d ') //=> ['a', 'b', '', 'd d']
|
---|
24 | commaSeparated.stringify(['a', 'b', '', 'd d']) //=> 'a, b, , d d'
|
---|
25 | ```
|
---|
26 |
|
---|
27 | ## API
|
---|
28 |
|
---|
29 | ### `commaSeparated.parse(value)`
|
---|
30 |
|
---|
31 | Parse comma-separated tokens (`string`) to an array of strings, according
|
---|
32 | to the [spec][].
|
---|
33 |
|
---|
34 | ### `commaSeparated.stringify(values[, options])`
|
---|
35 |
|
---|
36 | Compile an array of strings to comma-separated tokens (`string`).
|
---|
37 | Handles empty items at start or end correctly.
|
---|
38 | Note that it’s not possible to specify initial or final whitespace per value.
|
---|
39 |
|
---|
40 | ##### `options`
|
---|
41 |
|
---|
42 | ###### `options.padLeft`
|
---|
43 |
|
---|
44 | Whether to pad a space before a token (`boolean`, default: `true`).
|
---|
45 |
|
---|
46 | ###### `options.padRight`
|
---|
47 |
|
---|
48 | Whether to pad a space after a token (`boolean`, default: `false`).
|
---|
49 |
|
---|
50 | ## Related
|
---|
51 |
|
---|
52 | * [`collapse-white-space`](https://github.com/wooorm/collapse-white-space)
|
---|
53 | — Replace multiple white-space characters with a single space
|
---|
54 | * [`property-information`](https://github.com/wooorm/property-information)
|
---|
55 | — Information on HTML properties
|
---|
56 | * [`space-separated-tokens`](https://github.com/wooorm/space-separated-tokens)
|
---|
57 | — Parse/stringify space-separated tokens
|
---|
58 |
|
---|
59 | ## License
|
---|
60 |
|
---|
61 | [MIT][license] © [Titus Wormer][author]
|
---|
62 |
|
---|
63 | <!-- Definitions -->
|
---|
64 |
|
---|
65 | [build-badge]: https://img.shields.io/travis/wooorm/comma-separated-tokens.svg
|
---|
66 |
|
---|
67 | [build]: https://travis-ci.org/wooorm/comma-separated-tokens
|
---|
68 |
|
---|
69 | [coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/comma-separated-tokens.svg
|
---|
70 |
|
---|
71 | [coverage]: https://codecov.io/github/wooorm/comma-separated-tokens
|
---|
72 |
|
---|
73 | [downloads-badge]: https://img.shields.io/npm/dm/comma-separated-tokens.svg
|
---|
74 |
|
---|
75 | [downloads]: https://www.npmjs.com/package/comma-separated-tokens
|
---|
76 |
|
---|
77 | [size-badge]: https://img.shields.io/bundlephobia/minzip/comma-separated-tokens.svg
|
---|
78 |
|
---|
79 | [size]: https://bundlephobia.com/result?p=comma-separated-tokens
|
---|
80 |
|
---|
81 | [npm]: https://docs.npmjs.com/cli/install
|
---|
82 |
|
---|
83 | [license]: license
|
---|
84 |
|
---|
85 | [author]: https://wooorm.com
|
---|
86 |
|
---|
87 | [spec]: https://html.spec.whatwg.org/#comma-separated-tokens
|
---|