Skip to content

Commit c74c59d

Browse files
authored
breaking: move construct to /artisan as matter (#150)
1 parent 1ab8f90 commit c74c59d

File tree

15 files changed

+458
-446
lines changed

15 files changed

+458
-446
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
"prettier": "mauss/prettier.config.js",
1414
"devDependencies": {
1515
"@types/node": "^24.0.3",
16+
"dts-buddy": "^0.6.2",
1617
"mauss": "^0.10.0",
1718
"prettier": "^3.5.3",
1819
"prettier-plugin-sort-package-json": "^1.1.0",
1920
"prettier-plugin-svelte": "^3.4.0",
21+
"tsm": "^2.3.0",
2022
"typescript": "^5.8.3",
2123
"vitest": "^3.2.4"
2224
}

pnpm-lock.yaml

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

workspace/aubade/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
"license": "MIT",
99
"type": "module",
1010
"scripts": {
11+
"dev": "vitest",
1112
"test": "pnpm run \"/^test:.*/\"",
12-
"test:core": "vitest src",
13-
"test:apps": "vitest test/apps",
13+
"test:core": "vitest run src",
14+
"test:apps": "vitest run test/apps",
1415
"test:types": "tsc -p src/tsconfig.test.json",
1516
"build:types": "tsm scripts/compile-types.ts",
1617
"build:files": "tsc --project src",
@@ -67,11 +68,9 @@
6768
"dependencies": {
6869
"@types/markdown-it": "^14.1.2",
6970
"markdown-it": "^14.1.0",
70-
"mauss": "^0.10.0",
7171
"shiki": "^3.6.0"
7272
},
7373
"devDependencies": {
74-
"dts-buddy": "^0.6.2",
75-
"tsm": "^2.3.0"
74+
"mauss": "^0.10.0"
7675
}
7776
}
Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
import { describe } from 'vitest';
2+
import { matter } from './index.js';
3+
4+
describe('matter', ({ concurrent: it }) => {
5+
it('simple index', ({ expect }) => {
6+
const index = matter(
7+
`
8+
title: Simple Index
9+
tags: [x, y, z]
10+
`.trim(),
11+
);
12+
13+
expect(index).toEqual({
14+
title: 'Simple Index',
15+
tags: ['x', 'y', 'z'],
16+
});
17+
});
18+
19+
it('aubade rules', ({ expect }) => {
20+
const index = matter(
21+
`
22+
title: Aubade Rules
23+
date:published: 2023-02-01
24+
a:b:x: 0
25+
a:b:y: 1
26+
a:b:z: 2
27+
`.trim(),
28+
);
29+
30+
expect(index).toEqual({
31+
title: 'Aubade Rules',
32+
date: { published: '2023-02-01' },
33+
a: { b: { x: '0', y: '1', z: '2' } },
34+
});
35+
});
36+
37+
it('boolean values', ({ expect }) => {
38+
const index = matter(
39+
`
40+
title: Casting Boolean
41+
draft: false
42+
hex: ["x", true, 0, false]
43+
`.trim(),
44+
);
45+
46+
expect(index).toEqual({
47+
title: 'Casting Boolean',
48+
draft: false,
49+
hex: ['x', true, '0', false],
50+
});
51+
});
52+
53+
it('literal block', ({ expect }) => {
54+
const index = matter(
55+
`
56+
title: Literal Block
57+
data: |
58+
Hello World
59+
Lorem Ipsum
60+
`.trim(),
61+
);
62+
63+
expect(index).toEqual({
64+
title: 'Literal Block',
65+
data: 'Hello World\nLorem Ipsum',
66+
});
67+
});
68+
it('sequences', ({ expect }) => {
69+
const index = matter(
70+
`
71+
title: List Sequence
72+
hex:
73+
- 'x'
74+
- true
75+
- 0
76+
`.trim(),
77+
);
78+
79+
expect(index).toEqual({
80+
title: 'List Sequence',
81+
hex: ['x', true, '0'],
82+
});
83+
});
84+
it('nested sequences', ({ expect }) => {
85+
const index = matter(
86+
`
87+
title: Nested Sequences
88+
colors:
89+
- red:
90+
- ff0000
91+
- 255-0-0
92+
green:
93+
- 00ff00
94+
- 0-255-0
95+
blue:
96+
- 0000ff
97+
- 0-0-255
98+
- red:
99+
- ff0000
100+
- 255-0-0
101+
green:
102+
- 00ff00
103+
- 0-255-0
104+
blue:
105+
- 0000ff
106+
- 0-0-255
107+
`.trim(),
108+
);
109+
110+
expect(index).toEqual({
111+
title: 'Nested Sequences',
112+
colors: [
113+
{ red: ['ff0000', '255-0-0'], green: ['00ff00', '0-255-0'], blue: ['0000ff', '0-0-255'] },
114+
{ red: ['ff0000', '255-0-0'], green: ['00ff00', '0-255-0'], blue: ['0000ff', '0-0-255'] },
115+
],
116+
});
117+
});
118+
it('indents', ({ expect }) => {
119+
const index = matter(
120+
`
121+
title: Indented Objects
122+
jobs:
123+
test:
124+
with: node
125+
path: ./test
126+
sync:
127+
with: pnpm
128+
`.trim(),
129+
);
130+
131+
expect(index).toEqual({
132+
title: 'Indented Objects',
133+
jobs: {
134+
test: { with: 'node', path: './test' },
135+
sync: { with: 'pnpm' },
136+
},
137+
});
138+
});
139+
it('indented sequences', ({ expect }) => {
140+
const index = matter(
141+
`
142+
title: Indented Objects and Arrays
143+
jobs:
144+
test:
145+
- with: node
146+
os: windows
147+
sync:
148+
- with: pnpm
149+
os: linux
150+
env:
151+
TOKEN: 123
152+
`.trim(),
153+
);
154+
155+
expect(index).toEqual({
156+
title: 'Indented Objects and Arrays',
157+
jobs: {
158+
test: [{ with: 'node', os: 'windows' }],
159+
sync: [{ with: 'pnpm', os: 'linux', env: { TOKEN: '123' } }],
160+
},
161+
});
162+
});
163+
it('handle carriage returns', ({ expect }) => {
164+
// with tabs
165+
expect(matter(`link:\r\n\tmal: abc\r\n\timdb:\r\n\t\t- abc\r\n\t\t- def`)).toEqual({
166+
link: { mal: 'abc', imdb: ['abc', 'def'] },
167+
});
168+
169+
// with spaces
170+
expect(matter(`link:\r\n mal: abc\r\n imdb:\r\n - abc\r\n - def`)).toEqual({
171+
link: { mal: 'abc', imdb: ['abc', 'def'] },
172+
});
173+
});
174+
it('handle edge cases', ({ expect }) => {
175+
expect(
176+
matter(
177+
`
178+
title: Edge Cases
179+
empty:
180+
181+
name: "Hello: World"
182+
link:
183+
normal: https://github.com
184+
dashed:
185+
- https://myanimelist.net/anime/25537/Fate_stay_night_Movie__Heavens_Feel_-_I_Presage_Flower
186+
- https://myanimelist.net/anime/33049/Fate_stay_night_Movie__Heavens_Feel_-_II_Lost_Butterfly
187+
- https://myanimelist.net/anime/33050/Fate_stay_night_Movie__Heavens_Feel_-_III_Spring_Song
188+
`.trim(),
189+
),
190+
).toEqual({
191+
title: 'Edge Cases',
192+
empty: '',
193+
name: 'Hello: World',
194+
link: {
195+
normal: 'https://github.com',
196+
dashed: [
197+
'https://myanimelist.net/anime/25537/Fate_stay_night_Movie__Heavens_Feel_-_I_Presage_Flower',
198+
'https://myanimelist.net/anime/33049/Fate_stay_night_Movie__Heavens_Feel_-_II_Lost_Butterfly',
199+
'https://myanimelist.net/anime/33050/Fate_stay_night_Movie__Heavens_Feel_-_III_Spring_Song',
200+
],
201+
},
202+
});
203+
204+
expect(
205+
matter(
206+
`
207+
trailing:\t
208+
- tab
209+
invisible:
210+
- trailing space
211+
multiple:\t\t\t
212+
- tabs
213+
voyager:
214+
- multiple space
215+
`.trim(),
216+
),
217+
).toEqual({
218+
trailing: ['tab'],
219+
invisible: ['trailing space'],
220+
multiple: ['tabs'],
221+
voyager: ['multiple space'],
222+
});
223+
});
224+
it('construct with spaces indents', ({ expect }) => {
225+
const index = matter(
226+
`
227+
jobs:
228+
test:
229+
with: node
230+
path: ./test
231+
cache:
232+
- ./.cache
233+
- ~/.cache
234+
- /tmp/cache
235+
sync:
236+
- with: npm
237+
os: linux
238+
- with: pnpm
239+
os: windows
240+
241+
link:
242+
github: https://github.com
243+
youtube: https://youtube.com
244+
search-engines:
245+
- https://duckduckgo.com
246+
- https://google.com
247+
- https://bing.com
248+
`.trim(),
249+
);
250+
251+
expect(index).toEqual({
252+
jobs: {
253+
test: {
254+
with: 'node',
255+
path: './test',
256+
cache: ['./.cache', '~/.cache', '/tmp/cache'],
257+
},
258+
sync: [
259+
{ with: 'npm', os: 'linux' },
260+
{ with: 'pnpm', os: 'windows' },
261+
],
262+
},
263+
link: {
264+
github: 'https://github.com',
265+
youtube: 'https://youtube.com',
266+
'search-engines': ['https://duckduckgo.com', 'https://google.com', 'https://bing.com'],
267+
},
268+
});
269+
});
270+
});

0 commit comments

Comments
 (0)