micromark-factory-space
Advanced tools
Comparing version 1.0.0 to 1.1.0
/** | ||
* Parse spaces and tabs. | ||
* | ||
* There is no `nok` parameter: | ||
* | ||
* * spaces in markdown are often optional, in which case this factory can be | ||
* used and `ok` will be switched to whether spaces were found or not | ||
* * one line ending or space can be detected with `markdownSpace(code)` right | ||
* before using `factorySpace` | ||
* | ||
* ###### Examples | ||
* | ||
* Where `␉` represents a tab (plus how much it expands) and `␠` represents a | ||
* single space. | ||
* | ||
* ```markdown | ||
* ␉ | ||
* ␠␠␠␠ | ||
* ␉␠ | ||
* ``` | ||
* | ||
* @param {Effects} effects | ||
* Context. | ||
* @param {State} ok | ||
* @param {string} type | ||
* @param {number} [max=Infinity] | ||
* @returns {State} | ||
* State switched to when successful. | ||
* @param {TokenType} type | ||
* Type (`' \t'`). | ||
* @param {number | undefined} [max=Infinity] | ||
* Max (exclusive). | ||
* @returns | ||
* Start state. | ||
*/ | ||
@@ -11,6 +36,9 @@ export function factorySpace( | ||
ok: State, | ||
type: string, | ||
type: TokenType, | ||
max?: number | undefined | ||
): State | ||
): ( | ||
code: import('micromark-util-types').Code | ||
) => void | import('micromark-util-types').State | ||
export type Effects = import('micromark-util-types').Effects | ||
export type State = import('micromark-util-types').State | ||
export type TokenType = import('micromark-util-types').TokenType |
/** | ||
* @typedef {import('micromark-util-types').Effects} Effects | ||
* @typedef {import('micromark-util-types').State} State | ||
* @typedef {import('micromark-util-types').TokenType} TokenType | ||
*/ | ||
@@ -8,8 +9,35 @@ | ||
// To do: implement `spaceOrTab`, `spaceOrTabMinMax`, `spaceOrTabWithOptions`. | ||
/** | ||
* Parse spaces and tabs. | ||
* | ||
* There is no `nok` parameter: | ||
* | ||
* * spaces in markdown are often optional, in which case this factory can be | ||
* used and `ok` will be switched to whether spaces were found or not | ||
* * one line ending or space can be detected with `markdownSpace(code)` right | ||
* before using `factorySpace` | ||
* | ||
* ###### Examples | ||
* | ||
* Where `␉` represents a tab (plus how much it expands) and `␠` represents a | ||
* single space. | ||
* | ||
* ```markdown | ||
* ␉ | ||
* ␠␠␠␠ | ||
* ␉␠ | ||
* ``` | ||
* | ||
* @param {Effects} effects | ||
* Context. | ||
* @param {State} ok | ||
* @param {string} type | ||
* @param {number} [max=Infinity] | ||
* @returns {State} | ||
* State switched to when successful. | ||
* @param {TokenType} type | ||
* Type (`' \t'`). | ||
* @param {number | undefined} [max=Infinity] | ||
* Max (exclusive). | ||
* @returns | ||
* Start state. | ||
*/ | ||
@@ -16,0 +44,0 @@ export function factorySpace(effects, ok, type, max) { |
/** | ||
* Parse spaces and tabs. | ||
* | ||
* There is no `nok` parameter: | ||
* | ||
* * spaces in markdown are often optional, in which case this factory can be | ||
* used and `ok` will be switched to whether spaces were found or not | ||
* * one line ending or space can be detected with `markdownSpace(code)` right | ||
* before using `factorySpace` | ||
* | ||
* ###### Examples | ||
* | ||
* Where `␉` represents a tab (plus how much it expands) and `␠` represents a | ||
* single space. | ||
* | ||
* ```markdown | ||
* ␉ | ||
* ␠␠␠␠ | ||
* ␉␠ | ||
* ``` | ||
* | ||
* @param {Effects} effects | ||
* Context. | ||
* @param {State} ok | ||
* @param {string} type | ||
* @param {number} [max=Infinity] | ||
* @returns {State} | ||
* State switched to when successful. | ||
* @param {TokenType} type | ||
* Type (`' \t'`). | ||
* @param {number | undefined} [max=Infinity] | ||
* Max (exclusive). | ||
* @returns | ||
* Start state. | ||
*/ | ||
@@ -11,6 +36,9 @@ export function factorySpace( | ||
ok: State, | ||
type: string, | ||
type: TokenType, | ||
max?: number | undefined | ||
): State | ||
): ( | ||
code: import('micromark-util-types').Code | ||
) => void | import('micromark-util-types').State | ||
export type Effects = import('micromark-util-types').Effects | ||
export type State = import('micromark-util-types').State | ||
export type TokenType = import('micromark-util-types').TokenType |
43
index.js
/** | ||
* @typedef {import('micromark-util-types').Effects} Effects | ||
* @typedef {import('micromark-util-types').State} State | ||
* @typedef {import('micromark-util-types').TokenType} TokenType | ||
*/ | ||
import {markdownSpace} from 'micromark-util-character' | ||
// To do: implement `spaceOrTab`, `spaceOrTabMinMax`, `spaceOrTabWithOptions`. | ||
/** | ||
* Parse spaces and tabs. | ||
* | ||
* There is no `nok` parameter: | ||
* | ||
* * spaces in markdown are often optional, in which case this factory can be | ||
* used and `ok` will be switched to whether spaces were found or not | ||
* * one line ending or space can be detected with `markdownSpace(code)` right | ||
* before using `factorySpace` | ||
* | ||
* ###### Examples | ||
* | ||
* Where `␉` represents a tab (plus how much it expands) and `␠` represents a | ||
* single space. | ||
* | ||
* ```markdown | ||
* ␉ | ||
* ␠␠␠␠ | ||
* ␉␠ | ||
* ``` | ||
* | ||
* @param {Effects} effects | ||
* Context. | ||
* @param {State} ok | ||
* @param {string} type | ||
* @param {number} [max=Infinity] | ||
* @returns {State} | ||
* State switched to when successful. | ||
* @param {TokenType} type | ||
* Type (`' \t'`). | ||
* @param {number | undefined} [max=Infinity] | ||
* Max (exclusive). | ||
* @returns | ||
* Start state. | ||
*/ | ||
export function factorySpace(effects, ok, type, max) { | ||
@@ -18,4 +47,4 @@ const limit = max ? max - 1 : Number.POSITIVE_INFINITY | ||
return start | ||
/** @type {State} */ | ||
function start(code) { | ||
@@ -26,7 +55,6 @@ if (markdownSpace(code)) { | ||
} | ||
return ok(code) | ||
} | ||
/** @type {State} */ | ||
function prefix(code) { | ||
@@ -37,3 +65,2 @@ if (markdownSpace(code) && size++ < limit) { | ||
} | ||
effects.exit(type) | ||
@@ -40,0 +67,0 @@ return ok(code) |
{ | ||
"name": "micromark-factory-space", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "micromark factory to parse markdown space (found in lots of places)", | ||
@@ -37,2 +37,3 @@ "license": "MIT", | ||
"exports": { | ||
"types": "./dev/index.d.ts", | ||
"development": "./dev/index.js", | ||
@@ -46,3 +47,3 @@ "default": "./index.js" | ||
"scripts": { | ||
"build": "rimraf \"*.d.ts\" \"{dev/,lib/}**/*.d.ts\" && tsc && micromark-build && type-coverage" | ||
"build": "micromark-build" | ||
}, | ||
@@ -49,0 +50,0 @@ "xo": false, |
113
readme.md
@@ -11,7 +11,9 @@ # micromark-factory-space | ||
micromark factory to parse [markdown space][markdown-space] (found in lots of | ||
places). | ||
[micromark][] factory to parse [markdown space][markdown-space] (found in lots | ||
of places). | ||
## Contents | ||
* [What is this?](#what-is-this) | ||
* [When should I use this?](#when-should-i-use-this) | ||
* [Install](#install) | ||
@@ -21,2 +23,4 @@ * [Use](#use) | ||
* [`factorySpace(…)`](#factoryspace) | ||
* [Types](#types) | ||
* [Compatibility](#compatibility) | ||
* [Security](#security) | ||
@@ -26,5 +30,14 @@ * [Contribute](#contribute) | ||
## What is this? | ||
This package exposes states to parse spaces and/or tabs. | ||
## When should I use this? | ||
This package is useful when you are making your own micromark extensions. | ||
## Install | ||
[npm][]: | ||
This package is [ESM only][esm]. | ||
In Node.js (version 16+), install with [npm][]: | ||
@@ -35,2 +48,16 @@ ```sh | ||
In Deno with [`esm.sh`][esmsh]: | ||
```js | ||
import {factorySpace} from 'https://esm.sh/micromark-factory-space@1' | ||
``` | ||
In browsers with [`esm.sh`][esmsh]: | ||
```html | ||
<script type="module"> | ||
import {factorySpace} from 'https://esm.sh/micromark-factory-space@1?bundle' | ||
</script> | ||
``` | ||
## Use | ||
@@ -44,3 +71,6 @@ | ||
// A micromark tokenizer that uses the factory: | ||
/** @type {Tokenizer} */ | ||
/** | ||
* @this {TokenizeContext} | ||
* @type {Tokenizer} | ||
*/ | ||
function tokenizeCodeFenced(effects, ok, nok) { | ||
@@ -70,3 +100,3 @@ return start | ||
This module exports the following identifiers: `factorySpace`. | ||
This module exports the identifier [`factorySpace`][api-factory-space]. | ||
There is no default export. | ||
@@ -76,20 +106,11 @@ | ||
Note that there is no `nok` parameter: | ||
Parse spaces and tabs. | ||
There is no `nok` parameter: | ||
* spaces in markdown are often optional, in which case this factory can be | ||
used and `ok` will be switched to whether spaces were found or not, | ||
* One space character can be detected with | ||
[markdownSpace(code)][markdown-space] right before using `factorySpace` | ||
used and `ok` will be switched to whether spaces were found or not | ||
* one line ending or space can be detected with `markdownSpace(code)` right | ||
before using `factorySpace` | ||
###### Parameters | ||
* `effects` (`Effects`) — Context | ||
* `ok` (`State`) — State switched to when successful | ||
* `type` (`string`) — Token type for whole (`' \t'`) | ||
* `max` (`number`, default: `Infinity`) — Max size of whitespace | ||
###### Returns | ||
`State`. | ||
###### Examples | ||
@@ -106,4 +127,34 @@ | ||
###### Parameters | ||
* `effects` (`Effects`) | ||
— context | ||
* `ok` (`State`) | ||
— state switched to when successful | ||
* `type` (`string`) | ||
— type (`' \t'`) | ||
* `max` (`number`, default: `Infinity`) | ||
— max (exclusive) | ||
###### Returns | ||
Start state (`State`). | ||
## Types | ||
This package is fully typed with [TypeScript][]. | ||
It exports no additional types. | ||
## Compatibility | ||
Projects maintained by the unified collective are compatible with all maintained | ||
versions of Node.js. | ||
As of now, that is Node.js 16+. | ||
Our projects sometimes work with older versions, but this is not guaranteed. | ||
This package works with `micromark` version 3+. | ||
## Security | ||
This package is safe. | ||
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to | ||
@@ -140,5 +191,5 @@ submit a security report. | ||
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-factory-space.svg | ||
[bundle-size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-factory-space | ||
[bundle-size]: https://bundlephobia.com/result?p=micromark-factory-space | ||
[bundle-size]: https://bundlejs.com/?q=micromark-factory-space | ||
@@ -153,2 +204,6 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg | ||
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c | ||
[esmsh]: https://esm.sh | ||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg | ||
@@ -164,10 +219,16 @@ | ||
[securitymd]: https://github.com/micromark/.github/blob/HEAD/security.md | ||
[securitymd]: https://github.com/micromark/.github/blob/main/security.md | ||
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md | ||
[contributing]: https://github.com/micromark/.github/blob/main/contributing.md | ||
[support]: https://github.com/micromark/.github/blob/HEAD/support.md | ||
[support]: https://github.com/micromark/.github/blob/main/support.md | ||
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md | ||
[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md | ||
[markdown-space]: https://github.com/micromark/micromark/tree/main/packages/micromark-util-character#markdownspacecode | ||
[typescript]: https://www.typescriptlang.org | ||
[micromark]: https://github.com/micromark/micromark | ||
[api-factory-space]: #factoryspace |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12563
208
224