initial
This commit is contained in:
53
ts/index.ts
Normal file
53
ts/index.ts
Normal file
@ -0,0 +1,53 @@
|
||||
import 'typings-global'
|
||||
let grayMatter = require('gray-matter')
|
||||
|
||||
export type TFrontMatter = 'yaml' | 'json'
|
||||
|
||||
export interface IParsedFM {
|
||||
data: any
|
||||
content: string
|
||||
orig: string
|
||||
}
|
||||
|
||||
export interface ISmartfmContructorOptions {
|
||||
fmType: TFrontMatter
|
||||
}
|
||||
|
||||
/**
|
||||
* class smartfm handles frontmatter
|
||||
*/
|
||||
export class Smartfm {
|
||||
fmType: TFrontMatter
|
||||
|
||||
constructor(optionsArg: ISmartfmContructorOptions) {
|
||||
this.fmType = optionsArg.fmType
|
||||
}
|
||||
|
||||
/**
|
||||
* add frontmatter to a string
|
||||
*/
|
||||
stringify(bodyString: string, frontmatterData: any) {
|
||||
return stringify(bodyString, frontmatterData)
|
||||
}
|
||||
|
||||
/**
|
||||
* parse a string that has frontmatter attached, YAML notation
|
||||
*/
|
||||
parse(stringToParse: string): IParsedFM {
|
||||
return parse(stringToParse)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* parse a string that has frontmatter attached, YAML notation
|
||||
*/
|
||||
export let parse = (stringToParse: string): IParsedFM => {
|
||||
return grayMatter(stringToParse)
|
||||
}
|
||||
|
||||
/**
|
||||
* add frontmatter to a string
|
||||
*/
|
||||
export let stringify = (bodyString: string, frontmatterData: any) => {
|
||||
grayMatter.stringify(bodyString, frontmatterData)
|
||||
}
|
Reference in New Issue
Block a user