https://github.com/lamansky/sanitize-tokens
Returns an array of tokens found in the provided strings.
https://github.com/lamansky/sanitize-tokens
Last synced: 2 months ago
JSON representation
Returns an array of tokens found in the provided strings.
- Host: GitHub
- URL: https://github.com/lamansky/sanitize-tokens
- Owner: lamansky
- License: mit
- Created: 2018-08-22T15:28:36.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-22T15:35:01.000Z (almost 8 years ago)
- Last Synced: 2025-10-05T02:25:49.716Z (9 months ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
# sanitize-tokens
Returns an array of tokens found in the provided strings.
Tokens are separated by whitespace. In HTML, [tokens](https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList) are used in `class` and `rel` attributes, for example.
## Installation
Requires [Node.js](https://nodejs.org/) 7.0.0 or above.
```bash
npm i sanitize-tokens
```
## API
The module exports a single function.
### Parameters
1. Bindable: `tokens` (string or array): A string of space-separated tokens, or an array (which may contain nested arrays) of such strings.
2. Optional: Object argument:
* `elseThrow` (boolean, string, or Error): The error to throw if an invalid token is encountered. An `Error` object, if provided, will be thrown as-is. A string will be wrapped in a `TypeError` and thrown. If set to `true`, a `TypeError` will be thrown. Defaults to `false`.
* `unique` (boolean): Whether to remove duplicate tokens. Defaults to `false`.
### Return Value
An array of tokens.
## Example
```javascript
const sanitizeTokens = require('sanitize-tokens')
sanitizeTokens(['this is', [['a'], 'test']]) // ['this', 'is', 'a', 'test']
```