fix(core): update
This commit is contained in:
parent
8db0cac292
commit
fdc9cb6784
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "current file",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"${relativeFile}"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "test.ts",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"test/test.ts"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
16
test/test.ts
16
test/test.ts
@ -23,7 +23,23 @@ tap.test('should stringify data', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should parse a normal frontmatter file', async () => {
|
tap.test('should parse a normal frontmatter file', async () => {
|
||||||
|
const normalFile = `---
|
||||||
|
heythere: awesome
|
||||||
|
---
|
||||||
|
really
|
||||||
|
`;
|
||||||
|
let result = testSmartfm.parse(normalFile);
|
||||||
|
expect(result.data.heythere).to.equal('awesome')
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should parse a commented out frontmatter file', async () => {
|
||||||
|
const commentedFile = `# ---
|
||||||
|
# heythere: awesome
|
||||||
|
# ---
|
||||||
|
really
|
||||||
|
`;
|
||||||
|
let result = testSmartfm.parseFromComments('# ', commentedFile);
|
||||||
|
console.log(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
13
ts/index.ts
13
ts/index.ts
@ -29,4 +29,17 @@ export class Smartfm {
|
|||||||
parse(stringToParse: string) {
|
parse(stringToParse: string) {
|
||||||
return grayMatter(stringToParse);
|
return grayMatter(stringToParse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* parse from commnets
|
||||||
|
*/
|
||||||
|
parseFromComments(commentStart: string, stringToParse: string) {
|
||||||
|
const diffFunc = (diffMe, diffBy) => diffMe.split(diffBy).join('');
|
||||||
|
let lines = stringToParse.split('\n');
|
||||||
|
lines = lines.map(line => {
|
||||||
|
return diffFunc(line, commentStart);
|
||||||
|
});
|
||||||
|
const cleanedString = lines.join('\n');
|
||||||
|
return this.parse(cleanedString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user