1 | # space-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 space-separated tokens according to the [spec][].
|
---|
9 |
|
---|
10 | ## Install
|
---|
11 |
|
---|
12 | [npm][]:
|
---|
13 |
|
---|
14 | ```sh
|
---|
15 | npm install space-separated-tokens
|
---|
16 | ```
|
---|
17 |
|
---|
18 | ## Usage
|
---|
19 |
|
---|
20 | ```js
|
---|
21 | var spaceSeparated = require('space-separated-tokens')
|
---|
22 |
|
---|
23 | spaceSeparated.parse(' foo\tbar\nbaz ')
|
---|
24 | //=> ['foo', 'bar', 'baz']
|
---|
25 |
|
---|
26 | spaceSeparated.stringify(['foo', 'bar', 'baz'])
|
---|
27 | //=> 'foo bar baz'
|
---|
28 | ```
|
---|
29 |
|
---|
30 | ## API
|
---|
31 |
|
---|
32 | ### `spaceSeparated.parse(value)`
|
---|
33 |
|
---|
34 | Parse space-separated tokens to an array of strings, according to the [spec][].
|
---|
35 |
|
---|
36 | ###### Parameters
|
---|
37 |
|
---|
38 | * `value` (`string`) — space-separated tokens
|
---|
39 |
|
---|
40 | ###### Returns
|
---|
41 |
|
---|
42 | `Array.<string>` — List of tokens.
|
---|
43 |
|
---|
44 | ### `spaceSeparated.stringify(values)`
|
---|
45 |
|
---|
46 | Serialize an array of strings to space-separated tokens.
|
---|
47 | Note that it’s not possible to specify empty or whitespace only values.
|
---|
48 |
|
---|
49 | ###### Parameters
|
---|
50 |
|
---|
51 | * `values` (`Array.<string>`) — List of tokens
|
---|
52 |
|
---|
53 | ###### Returns
|
---|
54 |
|
---|
55 | `string` — Space-separated tokens.
|
---|
56 |
|
---|
57 | ## Related
|
---|
58 |
|
---|
59 | * [`collapse-white-space`](https://github.com/wooorm/collapse-white-space)
|
---|
60 | — Replace multiple white-space characters with a single space
|
---|
61 | * [`property-information`](https://github.com/wooorm/property-information)
|
---|
62 | — Information on HTML properties
|
---|
63 | * [`comma-separated-tokens`](https://github.com/wooorm/comma-separated-tokens)
|
---|
64 | — Parse/stringify comma-separated tokens
|
---|
65 |
|
---|
66 | ## License
|
---|
67 |
|
---|
68 | [MIT][license] © [Titus Wormer][author]
|
---|
69 |
|
---|
70 | <!-- Definition -->
|
---|
71 |
|
---|
72 | [build-badge]: https://img.shields.io/travis/wooorm/space-separated-tokens.svg
|
---|
73 |
|
---|
74 | [build]: https://travis-ci.org/wooorm/space-separated-tokens
|
---|
75 |
|
---|
76 | [coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/space-separated-tokens.svg
|
---|
77 |
|
---|
78 | [coverage]: https://codecov.io/github/wooorm/space-separated-tokens
|
---|
79 |
|
---|
80 | [downloads-badge]: https://img.shields.io/npm/dm/space-separated-tokens.svg
|
---|
81 |
|
---|
82 | [downloads]: https://www.npmjs.com/package/space-separated-tokens
|
---|
83 |
|
---|
84 | [size-badge]: https://img.shields.io/bundlephobia/minzip/space-separated-tokens.svg
|
---|
85 |
|
---|
86 | [size]: https://bundlephobia.com/result?p=space-separated-tokens
|
---|
87 |
|
---|
88 | [npm]: https://docs.npmjs.com/cli/install
|
---|
89 |
|
---|
90 | [license]: license
|
---|
91 |
|
---|
92 | [author]: https://wooorm.com
|
---|
93 |
|
---|
94 | [spec]: https://html.spec.whatwg.org/#space-separated-tokens
|
---|