now working

This commit is contained in:
Philipp Kunz 2016-11-14 13:04:25 +01:00
parent ef3f1a3188
commit a1fec28d18
5 changed files with 29 additions and 20 deletions

10
dist/index.d.ts vendored
View File

@ -1,17 +1,23 @@
import 'typings-global'; import 'typings-global';
export declare type TFrontMatter = 'yaml' | 'json';
export interface IParsedFM { export interface IParsedFM {
data: any; data: any;
content: string; content: string;
orig: string; orig: string;
} }
export interface ISmartfmContructorOptions {
fmType: TFrontMatter;
}
/** /**
* class smartfm handles frontmatter * class smartfm handles frontmatter
*/ */
export declare class Smartfm { export declare class Smartfm {
fmType: TFrontMatter;
constructor(optionsArg: ISmartfmContructorOptions);
/** /**
* add frontmatter to a string * add frontmatter to a string
*/ */
stringify(bodyString: string, frontmatterData: any): void; stringify(bodyString: string, frontmatterData: any): any;
/** /**
* parse a string that has frontmatter attached, YAML notation * parse a string that has frontmatter attached, YAML notation
*/ */
@ -24,4 +30,4 @@ export declare let parse: (stringToParse: string) => IParsedFM;
/** /**
* add frontmatter to a string * add frontmatter to a string
*/ */
export declare let stringify: (bodyString: string, frontmatterData: any) => void; export declare let stringify: (bodyString: string, frontmatterData: any) => any;

7
dist/index.js vendored
View File

@ -5,6 +5,9 @@ let grayMatter = require('gray-matter');
* class smartfm handles frontmatter * class smartfm handles frontmatter
*/ */
class Smartfm { class Smartfm {
constructor(optionsArg) {
this.fmType = optionsArg.fmType;
}
/** /**
* add frontmatter to a string * add frontmatter to a string
*/ */
@ -29,6 +32,6 @@ exports.parse = (stringToParse) => {
* add frontmatter to a string * add frontmatter to a string
*/ */
exports.stringify = (bodyString, frontmatterData) => { exports.stringify = (bodyString, frontmatterData) => {
grayMatter.stringify(bodyString, frontmatterData); return grayMatter.stringify(bodyString, frontmatterData);
}; };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm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PQUVHO0lBQ0gsU0FBUyxDQUFDLFVBQWtCLEVBQUUsZUFBb0I7UUFDOUMsTUFBTSxDQUFDLGlCQUFTLENBQUMsVUFBVSxFQUFFLGVBQWUsQ0FBQyxDQUFBO0lBQ2pELENBQUM7SUFFRDs7T0FFRztJQUNILEtBQUssQ0FBQyxhQUFxQjtRQUN2QixNQUFNLENBQUMsYUFBSyxDQUFDLGFBQWEsQ0FBQyxDQUFBO0lBQy9CLENBQUM7Q0FDSjtBQXBCRCwwQkFvQkM7QUFFRDs7R0FFRztBQUNRLFFBQUEsS0FBSyxHQUFHLENBQUMsYUFBcUI7SUFDckMsTUFBTSxDQUFDLFVBQVUsQ0FBQyxhQUFhLENBQUMsQ0FBQTtBQUNwQyxDQUFDLENBQUE7QUFFRDs7R0FFRztBQUNRLFFBQUEsU0FBUyxHQUFHLENBQUMsVUFBa0IsRUFBRSxlQUFvQjtJQUM1RCxNQUFNLENBQUMsVUFBVSxDQUFDLFNBQVMsQ0FBQyxVQUFVLEVBQUUsZUFBZSxDQUFDLENBQUE7QUFDNUQsQ0FBQyxDQUFBIn0=

View File

@ -3,7 +3,7 @@ require("typings-test");
const should = require("should"); const should = require("should");
const smartfm = require("../dist/index"); const smartfm = require("../dist/index");
describe('smartfm', function () { describe('smartfm', function () {
let testSmartfm = new smartfm.Smartfm; let testSmartfm = new smartfm.Smartfm({ fmType: 'yaml' });
it('.parse()', function () { it('.parse()', function () {
let testString = `--- let testString = `---
testKey: testValue testKey: testValue
@ -16,10 +16,10 @@ testKey2: testValue2
should(parsedString.orig).equal(testString); should(parsedString.orig).equal(testString);
}); });
it('.stringify', function () { it('.stringify', function () {
let testStringPure = `# some markdown heading let testStringPure = `# some markdown heading\nsome first row`;
some first row`;
let testStringCombined = testSmartfm.stringify(testStringPure, { testData: 'hi' }); let testStringCombined = testSmartfm.stringify(testStringPure, { testData: 'hi' });
console.log(testStringCombined); let resultString = '---\ntestData: hi\n---\n# some markdown heading\nsome first row\n';
should(resultString).equal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BQUMsY0FBYyxFQUFFLEVBQUUsUUFBUSxFQUFFLElBQUksRUFBRSxDQUFDLENBQUE7UUFDbEYsSUFBSSxZQUFZLEdBQUcsbUVBQW1FLENBQUE7UUFDdEYsTUFBTSxDQUFDLFlBQVksQ0FBQyxDQUFDLEtBQUssQ0FBQyxrQkFBa0IsQ0FBQyxDQUFBO0lBQ2xELENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==

View File

@ -3,23 +3,23 @@ import * as should from 'should'
import * as smartfm from '../dist/index' import * as smartfm from '../dist/index'
describe('smartfm', function() { describe('smartfm', function () {
let testSmartfm = new smartfm.Smartfm let testSmartfm = new smartfm.Smartfm({ fmType: 'yaml' })
it('.parse()', function() { it('.parse()', function () {
let testString = `--- let testString = `---
testKey: testValue testKey: testValue
testKey2: testValue2 testKey2: testValue2
--- ---
# some markdown` # some markdown`
let parsedString = testSmartfm.parse(testString) let parsedString = testSmartfm.parse(testString)
should(parsedString.data).have.property('testKey','testValue') should(parsedString.data).have.property('testKey', 'testValue')
should(parsedString.data).have.property('testKey2','testValue2') should(parsedString.data).have.property('testKey2', 'testValue2')
should(parsedString.orig).equal(testString) should(parsedString.orig).equal(testString)
}) })
it('.stringify', function(){ it('.stringify', function () {
let testStringPure = `# some markdown heading let testStringPure = `# some markdown heading\nsome first row`
some first row` let testStringCombined = testSmartfm.stringify(testStringPure, { testData: 'hi' })
let testStringCombined = testSmartfm.stringify(testStringPure, {testData: 'hi'}) let resultString = '---\ntestData: hi\n---\n# some markdown heading\nsome first row\n'
console.log(testStringCombined) should(resultString).equal(testStringCombined)
}) })
}) })

View File

@ -49,5 +49,5 @@ export let parse = (stringToParse: string): IParsedFM => {
* add frontmatter to a string * add frontmatter to a string
*/ */
export let stringify = (bodyString: string, frontmatterData: any) => { export let stringify = (bodyString: string, frontmatterData: any) => {
grayMatter.stringify(bodyString, frontmatterData) return grayMatter.stringify(bodyString, frontmatterData)
} }