space-separated-tokens

2.0.2last stable release 2 years ago
Complexity Score
Low
Open Issues
N/A
Dependent Projects
82
Weekly Downloadsglobal
11,516,157

License

  • MIT
    • Yesattribution
    • Permissivelinking
    • Permissivedistribution
    • Permissivemodification
    • Nopatent grant
    • Yesprivate use
    • Permissivesublicensing
    • Notrademark grant

Downloads

Readme

space-separated-tokens

Parse and stringify space-separated tokens.

Contents

  • What is this?
  • When should I use this?
  • Install
  • Use
  • API
    • parse(value)
    • stringify(values)
  • Types
  • Compatibility
  • Related
  • Contribute
  • Security
  • License

What is this?

This is a tiny package that can parse and stringify space-separated tokens, as used for example in the HTML class 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 space-separated-tokens

In Deno with esm.sh:

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

In browsers with esm.sh:

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

Use

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

parse(' foo\tbar\nbaz  ')
//=> ['foo', 'bar', 'baz']

stringify(['foo', 'bar', 'baz'])
//=> 'foo bar baz'

API

This package exports the identifiers parse and stringify. There is no default export.

parse(value)

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

stringify(values)

Serialize an array of strings or numbers (Array<string|number>) to space-separated tokens (string).

πŸ‘‰ Note: it’s not possible to specify empty or whitespace only values.

Types

This package is fully typed with TypeScript. It exports no additional types.

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

  • comma-separated-tokens β€” parse/stringify comma-separated tokens
  • collapse-white-space β€” replace multiple white-space characters with a single space
  • property-information β€” info on HTML properties

Contribute

Yes please! See How to Contribute to Open Source.

Security

This package is safe.

License

MIT Β© Titus Wormer

Dependencies

No runtime dependency information found for this package.

CVE IssuesActive
0
Scorecards Score
3.10
Test Coverage
No Data
Follows Semver
Yes
Github Stars
10
Dependenciestotal
0
DependenciesOutdated
0
DependenciesDeprecated
0
Threat Modelling
No Data
Repo Audits
No Data

Learn how to distribute space-separated-tokens in your own private NPM registry

npm config set registry  https://npm.cloudsmith.com/owner/repo
Processing...
Done
npm install space-separated-tokens
Processing...
Done

10 Releases

NPM on Cloudsmith

Getting started with NPM on Cloudsmith is fast and easy.