MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / normalize

Function normalize

packages/ast/parse/linen/normalize/index.js:1–30  ·  view source on GitHub ↗
(token)

Source from the content-addressed store, hash-verified

1function normalize(token) {
2 if (token.type === 'code') {
3 const { value } = token;
4 token.source = value;
5 token.value = value.replace(/^`|`$/g, '');
6 }
7 if (token.type === 'pre') {
8 const { value } = token;
9 token.source = value;
10 token.value = value.replace(/^```|```$/g, '');
11 const match = token.value.match(/^\w*\s/);
12 if (match) {
13 const [language] = match;
14 token.language = language.trim();
15 }
16 }
17 if (token.type === 'user') {
18 const { value } = token;
19 token.source = value;
20 token.id = value.replace(/^@/, '');
21 delete token.value;
22 }
23 if (token.type === 'signal') {
24 const { value } = token;
25 token.source = value;
26 token.id = value.replace(/^\!/, '');
27 delete token.value;
28 }
29 return token;
30}
31
32module.exports = normalize;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected