Skip to content

Commit 57d0066

Browse files
committed
feat(factory-space): factorySpace
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent e3c5bfe commit 57d0066

17 files changed

Lines changed: 443 additions & 21 deletions

File tree

.commitlintrc.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ const config: UserConfig = {
2424
'factory-space',
2525
'subtokenize',
2626
'symbol'
27-
])]
27+
])],
28+
'scope-max-length': [Severity.Error, 'always', Number.POSITIVE_INFINITY]
2829
}
2930
}
3031

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,14 @@
7272
"@edge-runtime/vm": "5.0.0",
7373
"@flex-development/colors": "2.0.0",
7474
"@flex-development/commitlint-config": "1.0.1",
75+
"@flex-development/docmark-util-symbol": "workspace:*",
76+
"@flex-development/docmark-util-types": "workspace:*",
7577
"@flex-development/eslint-config": "1.1.1",
7678
"@flex-development/export-regex": "2.0.0",
7779
"@flex-development/grease": "3.0.0-alpha.9",
7880
"@flex-development/import-regex": "3.0.0",
7981
"@flex-development/mark": "flex-development/mark#commit=9a157dbfc5822e3bd6c513e32855bceace566320",
82+
"@flex-development/mark-parser": "flex-development/mark-parser#commit=8c66ac342e53f1b7a23308597be4a38bd23de4d4",
8083
"@flex-development/mlly": "1.0.0-beta.7",
8184
"@flex-development/pathe": "4.0.2",
8285
"@flex-development/pkg-types": "4.1.0",

packages/docmark-factory-space/README.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
[![npm](https://img.shields.io/npm/v/@flex-development/docmark-factory-space.svg)](https://npmjs.com/package/@flex-development/docmark-factory-space)
44
[![npm downloads](https://img.shields.io/npm/dm/@flex-development/docmark-factory-space.svg)](https://www.npmcharts.com/compare/@flex-development/docmark-factory-space?interval=30)
55
[![install size](https://packagephobia.now.sh/badge?p=@flex-development/docmark-factory-space)](https://packagephobia.now.sh/result?p=@flex-development/docmark-factory-space)
6+
[![minified bundle size](https://badgen.net/bundlephobia/min/@flex-development/docmark-factory-space?cache)](https://bundlephobia.com/package/@flex-development/docmark-factory-space)
7+
[![tree shaking suppport](https://badgen.net/bundlephobia/tree-shaking/@flex-development/docmark-factory-space)](https://bundlephobia.com/package/@flex-development/docmark-factory-space)
68
[![module type: esm](https://img.shields.io/badge/module%20type-esm-brightgreen)](https://github.com/voxpelli/badges-cjs-esm)
9+
[![license](https://img.shields.io/github/license/flex-development/docmark-factory-space.svg)](LICENSE.md)
10+
[![typescript](https://img.shields.io/badge/-typescript-3178c6?logo=typescript\&logoColor=ffffff)](https://typescriptlang.org)
11+
[![yarn](https://img.shields.io/badge/-yarn-2c8ebb?style=flat\&logo=yarn\&logoColor=ffffff)](https://yarnpkg.com)
712

813
[docmark][] factory to parse [docdown space][ws].
914

@@ -29,7 +34,7 @@ This package may be useful when making your own docmark extensions.
2934

3035
This package is [ESM only][esm].
3136

32-
In Node.js (version 20+) with [yarn][]:
37+
In Node.js with [yarn][]:
3338

3439
```sh
3540
yarn add @flex-development/docmark-factory-space
@@ -67,20 +72,34 @@ In browsers with [`esm.sh`][esmsh]:
6772
## Types
6873

6974
This package is fully typed with [TypeScript][].
75+
It exports no additional types.
7076

71-
## Contribute
77+
## Project
78+
79+
### Version
80+
81+
docmark-factory-space adheres to [semver][].
82+
83+
### Contribute
7284

7385
See [`CONTRIBUTING.md`](../../CONTRIBUTING.md).
7486

75-
This project has a [code of conduct](../../CODE_OF_CONDUCT.md). By interacting with this repository, organization, or
76-
community you agree to abide by its terms.
87+
This project has a [code of conduct](../../CODE_OF_CONDUCT.md).
88+
By interacting with this repository, organization, or community you agree to abide by its terms.
89+
90+
### Sponsor
91+
92+
Small primitives power larger systems.
93+
Support long-term stability by sponsoring Flex Development.
7794

7895
[docmark]: ../../README.md
7996

8097
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
8198

8299
[esmsh]: https://esm.sh
83100

101+
[semver]: https://semver.org
102+
84103
[typescript]: https://www.typescriptlang.org
85104

86105
[ws]: https://github.com/micromark/micromark/tree/main/packages/micromark-util-character#markdownlineendingorspacecode

packages/docmark-factory-space/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
},
3636
"type": "module",
3737
"files": [
38-
"CHANGELOG.md",
3938
"LICENSE.md",
4039
"README.md",
4140
"dist"
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`e2e:docmark-factory-space > should expose public api 1`] = `[]`;
3+
exports[`e2e:docmark-factory-space > should expose public api 1`] = `
4+
[
5+
"factorySpace",
6+
]
7+
`;
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`e2e:docmark-factory-space > should expose public api 1`] = `[]`;
3+
exports[`e2e:docmark-factory-space > should expose public api 1`] = `
4+
[
5+
"factorySpace",
6+
]
7+
`;
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`e2e:docmark-factory-space > should expose public api 1`] = `[]`;
3+
exports[`e2e:docmark-factory-space > should expose public api 1`] = `
4+
[
5+
"factorySpace",
6+
]
7+
`;
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
/**
2+
* @file Unit Tests - factory
3+
* @module docmark-factory-space/tests/unit/factory
4+
*/
5+
6+
import { codes, tt } from '@flex-development/docmark-util-symbol'
7+
import type {
8+
Code,
9+
Construct,
10+
Effects,
11+
State,
12+
TokenizeContext
13+
} from '@flex-development/docmark-util-types'
14+
import {
15+
createTokenizer,
16+
initialize as initial
17+
} from '@flex-development/mark-parser'
18+
import type { InitialConstruct } from '@flex-development/mark/parse'
19+
import testSubject from '../factory.mts'
20+
21+
describe('unit:factory', () => {
22+
it.each<[Construct]>([
23+
[
24+
{
25+
/**
26+
* @this {TokenizeContext}
27+
*
28+
* @param {Effects} effects
29+
* The context object to transition the state machine
30+
* @param {State} ok
31+
* The successful tokenization state
32+
* @return {State}
33+
* The initial state
34+
*/
35+
tokenize(this: TokenizeContext, effects: Effects, ok: State): State {
36+
return testSubject(effects, eat, tt.whitespace)
37+
38+
/**
39+
* @this {void}
40+
*
41+
* @param {Code} code
42+
* The current character code
43+
* @return {State | undefined}
44+
* The next state
45+
*/
46+
function eat(this: void, code: Code): State | undefined {
47+
return effects.consume(code), ok
48+
}
49+
}
50+
}
51+
],
52+
[
53+
{
54+
/**
55+
* @this {TokenizeContext}
56+
*
57+
* @param {Effects} effects
58+
* The context object to transition the state machine
59+
* @param {State} ok
60+
* The successful tokenization state
61+
* @return {State}
62+
* The initial state
63+
*/
64+
tokenize(this: TokenizeContext, effects: Effects, ok: State): State {
65+
return testSubject(effects, munch, tt.whitespace, 2)
66+
67+
/**
68+
* @this {void}
69+
*
70+
* @param {Code} code
71+
* The current character code
72+
* @return {State | undefined}
73+
* The next state
74+
*/
75+
function munch(this: void, code: Code): State | undefined {
76+
return effects.consume(code), ok
77+
}
78+
}
79+
}
80+
]
81+
])('should consume codes and produce `type` events (%#)', construct => {
82+
// Arrange
83+
const initialize: InitialConstruct = initial(construct)
84+
const context: TokenizeContext = createTokenizer({ initialize })
85+
86+
// Setup
87+
vi.spyOn(context.effects, 'enter')
88+
vi.spyOn(context.effects, 'exit')
89+
90+
// Act
91+
context.write([codes.space, codes.eos])
92+
93+
// Expect
94+
expect(context.effects.enter).toHaveBeenCalled()
95+
expect(context.effects.exit).toHaveBeenCalled()
96+
expect(context.events).to.be.of.length(2)
97+
expect(context.events).to.each.have.nested.property('1.type', tt.whitespace)
98+
})
99+
100+
it.each<[Construct]>([
101+
[
102+
{
103+
/**
104+
* @this {TokenizeContext}
105+
*
106+
* @param {Effects} effects
107+
* The context object to transition the state machine
108+
* @param {State} ok
109+
* The successful tokenization state
110+
* @return {State}
111+
* The initial state
112+
*/
113+
tokenize(this: TokenizeContext, effects: Effects, ok: State): State {
114+
return testSubject(effects, eat)
115+
116+
/**
117+
* @this {void}
118+
*
119+
* @param {Code} code
120+
* The current character code
121+
* @return {State | undefined}
122+
* The next state
123+
*/
124+
function eat(this: void, code: Code): State | undefined {
125+
return effects.consume(code), ok
126+
}
127+
}
128+
}
129+
],
130+
[
131+
{
132+
/**
133+
* @this {TokenizeContext}
134+
*
135+
* @param {Effects} effects
136+
* The context object to transition the state machine
137+
* @param {State} ok
138+
* The successful tokenization state
139+
* @return {State}
140+
* The initial state
141+
*/
142+
tokenize(this: TokenizeContext, effects: Effects, ok: State): State {
143+
return testSubject(effects, munch, null, 2)
144+
145+
/**
146+
* @this {void}
147+
*
148+
* @param {Code} code
149+
* The current character code
150+
* @return {State | undefined}
151+
* The next state
152+
*/
153+
function munch(this: void, code: Code): State | undefined {
154+
return effects.consume(code), ok
155+
}
156+
}
157+
}
158+
]
159+
])('should consume codes without producing events (%#)', construct => {
160+
// Arrange
161+
const initialize: InitialConstruct = initial(construct)
162+
const context: TokenizeContext = createTokenizer({ initialize })
163+
164+
// Setup
165+
vi.spyOn(context.effects, 'enter')
166+
vi.spyOn(context.effects, 'exit')
167+
168+
// Act
169+
context.write([codes.space, codes.eos])
170+
171+
// Expect
172+
expect(context.effects.enter).not.toHaveBeenCalled()
173+
expect(context.effects.exit).not.toHaveBeenCalled()
174+
expect(context.events).to.be.empty
175+
})
176+
177+
it.each<[Construct]>([
178+
[
179+
{
180+
/**
181+
* @this {TokenizeContext}
182+
*
183+
* @param {Effects} effects
184+
* The context object to transition the state machine
185+
* @param {State} ok
186+
* The successful tokenization state
187+
* @return {State}
188+
* The initial state
189+
*/
190+
tokenize(this: TokenizeContext, effects: Effects, ok: State): State {
191+
return testSubject(effects, eat, tt.whitespace)
192+
193+
/**
194+
* @this {void}
195+
*
196+
* @param {Code} code
197+
* The current character code
198+
* @return {State | undefined}
199+
* The next state
200+
*/
201+
function eat(this: void, code: Code): State | undefined {
202+
return effects.consume(code), ok
203+
}
204+
}
205+
}
206+
],
207+
[
208+
{
209+
/**
210+
* @this {TokenizeContext}
211+
*
212+
* @param {Effects} effects
213+
* The context object to transition the state machine
214+
* @param {State} ok
215+
* The successful tokenization state
216+
* @return {State}
217+
* The initial state
218+
*/
219+
tokenize(this: TokenizeContext, effects: Effects, ok: State): State {
220+
return testSubject(effects, munch, tt.whitespace, 2)
221+
222+
/**
223+
* @this {void}
224+
*
225+
* @param {Code} code
226+
* The current character code
227+
* @return {State | undefined}
228+
* The next state
229+
*/
230+
function munch(this: void, code: Code): State | undefined {
231+
return effects.consume(code), ok
232+
}
233+
}
234+
}
235+
]
236+
])('should do nothing without markdown spaces (%#)', construct => {
237+
// Arrange
238+
const initialize: InitialConstruct = initial(construct)
239+
const context: TokenizeContext = createTokenizer({ initialize })
240+
241+
// Setup
242+
vi.spyOn(context.effects, 'enter')
243+
244+
// Act
245+
context.write([codes.lowercaseA, codes.eos])
246+
247+
// Expect
248+
expect(context.effects.enter).not.toHaveBeenCalled()
249+
})
250+
})

0 commit comments

Comments
 (0)