Compare commits
17 Commits
Author | SHA1 | Date | |
---|---|---|---|
8db0cac292 | |||
dad6119945 | |||
369cb0a58c | |||
67ef49ddce | |||
d6cf698327 | |||
4fe9acb0ec | |||
f8f74e32b5 | |||
471b52c78e | |||
5db9964480 | |||
fb94ff3be6 | |||
0af5016d43 | |||
e52ff07b07 | |||
b056ab998d | |||
b5f0bdc8e8 | |||
a5a69ef25e | |||
92da6611c7 | |||
9288ed3d2c |
20
.gitignore
vendored
20
.gitignore
vendored
@ -1,4 +1,22 @@
|
|||||||
node_modules/
|
.nogit/
|
||||||
|
|
||||||
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
public/
|
public/
|
||||||
pages/
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_web/
|
||||||
|
dist_serve/
|
||||||
|
dist_ts_web/
|
||||||
|
|
||||||
|
# custom
|
110
.gitlab-ci.yml
110
.gitlab-ci.yml
@ -1,59 +1,119 @@
|
|||||||
image: hosttoday/ht-docker-node:npmts
|
# gitzone ci_default
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
|
cache:
|
||||||
|
paths:
|
||||||
|
- .npmci_cache/
|
||||||
|
key: "$CI_BUILD_STAGE"
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- trigger
|
- metadata
|
||||||
- pages
|
|
||||||
|
|
||||||
testLEGACY:
|
# ====================
|
||||||
stage: test
|
# security stage
|
||||||
|
# ====================
|
||||||
|
mirror:
|
||||||
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci test legacy
|
- npmci git mirror
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
allow_failure: true
|
- notpriv
|
||||||
|
|
||||||
testLTS:
|
snyk:
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install -g snyk
|
||||||
|
- npmci command npm install --ignore-scripts
|
||||||
|
- npmci command snyk test
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# test stage
|
||||||
|
# ====================
|
||||||
|
|
||||||
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci test lts
|
- npmci npm prepare
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- priv
|
||||||
testSTABLE:
|
|
||||||
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci test stable
|
- npmci npm prepare
|
||||||
|
- npmci node install lts
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci publish
|
- npmci node install lts
|
||||||
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# metadata stage
|
||||||
|
# ====================
|
||||||
|
codequality:
|
||||||
|
stage: metadata
|
||||||
|
allow_failure: true
|
||||||
|
script:
|
||||||
|
- npmci command npm install -g tslint typescript
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: trigger
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmpage
|
image: hosttoday/ht-docker-dbase:npmci
|
||||||
stage: pages
|
services:
|
||||||
|
- docker:stable-dind
|
||||||
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npmpage --host gitlab
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command tsdoc
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
|
allow_failure: true
|
||||||
|
13
.snyk
Normal file
13
.snyk
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
||||||
|
version: v1.13.5
|
||||||
|
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
|
||||||
|
ignore:
|
||||||
|
SNYK-JS-JSYAML-173999:
|
||||||
|
- gray-matter > js-yaml:
|
||||||
|
reason: None given
|
||||||
|
expires: '2019-10-04T12:19:33.385Z'
|
||||||
|
SNYK-JS-JSYAML-174129:
|
||||||
|
- gray-matter > js-yaml:
|
||||||
|
reason: None given
|
||||||
|
expires: '2019-10-04T12:19:33.385Z'
|
||||||
|
patch: {}
|
47
README.md
47
README.md
@ -1,36 +1,26 @@
|
|||||||
# smartfm
|
# @pushrocks/smartfm
|
||||||
smartfm handles frontmatter of files
|
frontmatter done right
|
||||||
|
|
||||||
## Availabililty
|
> Please consider following us on https://beta.news/lossless to subscribe to infos on changes and updates.
|
||||||
[](https://www.npmjs.com/package/smartfm)
|
|
||||||
[](https://gitlab.com/pushrocks/smartfm)
|
## Availabililty and Links
|
||||||
[](https://github.com/pushrocks/smartfm)
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartfm)
|
||||||
[](https://pushrocks.gitlab.io/smartfm/)
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartfm)
|
||||||
|
* [github.com (source mirror)](https://github.com/pushrocks/smartfm)
|
||||||
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartfm/)
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
[](https://gitlab.com/pushrocks/smartfm/commits/master)
|
[](https://gitlab.com/pushrocks/smartfm/commits/master)
|
||||||
[](https://gitlab.com/pushrocks/smartfm/commits/master)
|
[](https://gitlab.com/pushrocks/smartfm/commits/master)
|
||||||
[](https://david-dm.org/pushrocks/smartfm)
|
[](https://www.npmjs.com/package/@pushrocks/smartfm)
|
||||||
[](https://www.bithound.io/github/pushrocks/smartfm/master/dependencies/npm)
|
[](https://snyk.io/test/npm/@pushrocks/smartfm)
|
||||||
[](https://www.bithound.io/github/pushrocks/smartfm)
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
[](https://prettier.io/)
|
||||||
[](http://standardjs.com/)
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
say you have the following markdown file:
|
We recommend TypeScript for best in class Intellisense.
|
||||||
```markdown
|
|
||||||
---
|
|
||||||
title: A really awesome article
|
|
||||||
date: 23-10-2020
|
|
||||||
type: feature
|
|
||||||
---
|
|
||||||
# A Awesome Title
|
|
||||||
The world is cool. And here is why
|
|
||||||
* reason 1
|
|
||||||
* reason 2
|
|
||||||
```
|
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
import * as smartfm from * smartfm
|
import * as smartfm from * smartfm
|
||||||
@ -65,4 +55,9 @@ let mySmartfm = new smartfm.Smartfm({
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
[](https://push.rocks)
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
|
[](https://maintainedby.lossless.com)
|
||||||
|
33
dist/index.d.ts
vendored
33
dist/index.d.ts
vendored
@ -1,33 +0,0 @@
|
|||||||
import 'typings-global';
|
|
||||||
export declare type TFrontMatter = 'yaml' | 'json';
|
|
||||||
export interface IParsedFM {
|
|
||||||
data: any;
|
|
||||||
content: string;
|
|
||||||
orig: string;
|
|
||||||
}
|
|
||||||
export interface ISmartfmContructorOptions {
|
|
||||||
fmType: TFrontMatter;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* class smartfm handles frontmatter
|
|
||||||
*/
|
|
||||||
export declare class Smartfm {
|
|
||||||
fmType: TFrontMatter;
|
|
||||||
constructor(optionsArg: ISmartfmContructorOptions);
|
|
||||||
/**
|
|
||||||
* add frontmatter to a string
|
|
||||||
*/
|
|
||||||
stringify(bodyString: string, frontmatterData: any): any;
|
|
||||||
/**
|
|
||||||
* parse a string that has frontmatter attached, YAML notation
|
|
||||||
*/
|
|
||||||
parse(stringToParse: string): IParsedFM;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* parse a string that has frontmatter attached, YAML notation
|
|
||||||
*/
|
|
||||||
export declare let parse: (stringToParse: string) => IParsedFM;
|
|
||||||
/**
|
|
||||||
* add frontmatter to a string
|
|
||||||
*/
|
|
||||||
export declare let stringify: (bodyString: string, frontmatterData: any) => any;
|
|
37
dist/index.js
vendored
37
dist/index.js
vendored
@ -1,37 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
require("typings-global");
|
|
||||||
let grayMatter = require('gray-matter');
|
|
||||||
/**
|
|
||||||
* class smartfm handles frontmatter
|
|
||||||
*/
|
|
||||||
class Smartfm {
|
|
||||||
constructor(optionsArg) {
|
|
||||||
this.fmType = optionsArg.fmType;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* add frontmatter to a string
|
|
||||||
*/
|
|
||||||
stringify(bodyString, frontmatterData) {
|
|
||||||
return exports.stringify(bodyString, frontmatterData);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* parse a string that has frontmatter attached, YAML notation
|
|
||||||
*/
|
|
||||||
parse(stringToParse) {
|
|
||||||
return exports.parse(stringToParse);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.Smartfm = Smartfm;
|
|
||||||
/**
|
|
||||||
* parse a string that has frontmatter attached, YAML notation
|
|
||||||
*/
|
|
||||||
exports.parse = (stringToParse) => {
|
|
||||||
return grayMatter(stringToParse);
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* add frontmatter to a string
|
|
||||||
*/
|
|
||||||
exports.stringify = (bodyString, frontmatterData) => {
|
|
||||||
return grayMatter.stringify(bodyString, frontmatterData);
|
|
||||||
};
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLElBQUksVUFBVSxHQUFHLE9BQU8sQ0FBQyxhQUFhLENBQUMsQ0FBQTtBQWN2Qzs7R0FFRztBQUNIO0lBR0ksWUFBWSxVQUFxQztRQUM3QyxJQUFJLENBQUMsTUFBTSxHQUFHLFVBQVUsQ0FBQyxNQUFNLENBQUE7SUFDbkMsQ0FBQztJQUVEOztPQUVHO0lBQ0gsU0FBUyxDQUFDLFVBQWtCLEVBQUUsZUFBb0I7UUFDOUMsTUFBTSxDQUFDLGlCQUFTLENBQUMsVUFBVSxFQUFFLGVBQWUsQ0FBQyxDQUFBO0lBQ2pELENBQUM7SUFFRDs7T0FFRztJQUNILEtBQUssQ0FBQyxhQUFxQjtRQUN2QixNQUFNLENBQUMsYUFBSyxDQUFDLGFBQWEsQ0FBQyxDQUFBO0lBQy9CLENBQUM7Q0FDSjtBQXBCRCwwQkFvQkM7QUFFRDs7R0FFRztBQUNRLFFBQUEsS0FBSyxHQUFHLENBQUMsYUFBcUI7SUFDckMsTUFBTSxDQUFDLFVBQVUsQ0FBQyxhQUFhLENBQUMsQ0FBQTtBQUNwQyxDQUFDLENBQUE7QUFFRDs7R0FFRztBQUNRLFFBQUEsU0FBUyxHQUFHLENBQUMsVUFBa0IsRUFBRSxlQUFvQjtJQUM1RCxNQUFNLENBQUMsVUFBVSxDQUFDLFNBQVMsQ0FBQyxVQUFVLEVBQUUsZUFBZSxDQUFDLENBQUE7QUFDNUQsQ0FBQyxDQUFBIn0=
|
|
16
npmextra.json
Normal file
16
npmextra.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"npmci": {
|
||||||
|
"npmGlobalTools": [],
|
||||||
|
"npmAccessLevel": "public"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "pushrocks",
|
||||||
|
"gitrepo": "smartfm",
|
||||||
|
"shortDescription": "frontmatter done right",
|
||||||
|
"npmPackagename": "@pushrocks/smartfm",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1655
package-lock.json
generated
Normal file
1655
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
32
package.json
32
package.json
@ -1,11 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "smartfm",
|
"name": "@pushrocks/smartfm",
|
||||||
"version": "1.0.1",
|
"version": "2.0.3",
|
||||||
|
"private": false,
|
||||||
"description": "frontmatter done right",
|
"description": "frontmatter done right",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(npmts)"
|
"test": "(tstest test/)",
|
||||||
|
"build": "tsbuild"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -21,12 +23,24 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartfm#README",
|
"homepage": "https://gitlab.com/pushrocks/smartfm#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"gray-matter": "^2.1.0",
|
"gray-matter": "^4.0.2"
|
||||||
"typings-global": "^1.0.14"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/should": "^8.1.30",
|
"@gitzone/tsbuild": "^2.1.17",
|
||||||
"should": "^11.1.1",
|
"@gitzone/tsrun": "^1.2.8",
|
||||||
"typings-test": "^1.0.3"
|
"@gitzone/tstest": "^1.0.24",
|
||||||
}
|
"@pushrocks/tapbundle": "^3.0.13",
|
||||||
|
"@types/node": "^12.7.4"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/*",
|
||||||
|
"ts_web/*",
|
||||||
|
"dist/*",
|
||||||
|
"dist_web/*",
|
||||||
|
"dist_ts_web/*",
|
||||||
|
"assets/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
1
test/test.d.ts
vendored
1
test/test.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
import 'typings-test';
|
|
25
test/test.js
25
test/test.js
@ -1,25 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
require("typings-test");
|
|
||||||
const should = require("should");
|
|
||||||
const smartfm = require("../dist/index");
|
|
||||||
describe('smartfm', function () {
|
|
||||||
let testSmartfm = new smartfm.Smartfm({ fmType: 'yaml' });
|
|
||||||
it('.parse()', function () {
|
|
||||||
let testString = `---
|
|
||||||
testKey: testValue
|
|
||||||
testKey2: testValue2
|
|
||||||
---
|
|
||||||
# some markdown`;
|
|
||||||
let parsedString = testSmartfm.parse(testString);
|
|
||||||
should(parsedString.data).have.property('testKey', 'testValue');
|
|
||||||
should(parsedString.data).have.property('testKey2', 'testValue2');
|
|
||||||
should(parsedString.orig).equal(testString);
|
|
||||||
});
|
|
||||||
it('.stringify', function () {
|
|
||||||
let testStringPure = `# some markdown heading\nsome first row`;
|
|
||||||
let testStringCombined = testSmartfm.stringify(testStringPure, { testData: 'hi' });
|
|
||||||
let resultString = '---\ntestData: hi\n---\n# some markdown heading\nsome first row\n';
|
|
||||||
should(resultString).equal(testStringCombined);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFFaEMseUNBQXdDO0FBRXhDLFFBQVEsQ0FBQyxTQUFTLEVBQUU7SUFDaEIsSUFBSSxXQUFXLEdBQUcsSUFBSSxPQUFPLENBQUMsT0FBTyxDQUFDLEVBQUUsTUFBTSxFQUFFLE1BQU0sRUFBRSxDQUFDLENBQUE7SUFDekQsRUFBRSxDQUFDLFVBQVUsRUFBRTtRQUNYLElBQUksVUFBVSxHQUFHOzs7O2dCQUlULENBQUE7UUFDUixJQUFJLFlBQVksR0FBRyxXQUFXLENBQUMsS0FBSyxDQUFDLFVBQVUsQ0FBQyxDQUFBO1FBQ2hELE1BQU0sQ0FBQyxZQUFZLENBQUMsSUFBSSxDQUFDLENBQUMsSUFBSSxDQUFDLFFBQVEsQ0FBQyxTQUFTLEVBQUUsV0FBVyxDQUFDLENBQUE7UUFDL0QsTUFBTSxDQUFDLFlBQVksQ0FBQyxJQUFJLENBQUMsQ0FBQyxJQUFJLENBQUMsUUFBUSxDQUFDLFVBQVUsRUFBRSxZQUFZLENBQUMsQ0FBQTtRQUNqRSxNQUFNLENBQUMsWUFBWSxDQUFDLElBQUksQ0FBQyxDQUFDLEtBQUssQ0FBQyxVQUFVLENBQUMsQ0FBQTtJQUMvQyxDQUFDLENBQUMsQ0FBQTtJQUNGLEVBQUUsQ0FBQyxZQUFZLEVBQUU7UUFDYixJQUFJLGNBQWMsR0FBRyx5Q0FBeUMsQ0FBQTtRQUM5RCxJQUFJLGtCQUFrQixHQUFHLFdBQVcsQ0FBQyxTQUFTLENBQUMsY0FBYyxFQUFFLEVBQUUsUUFBUSxFQUFFLElBQUksRUFBRSxDQUFDLENBQUE7UUFDbEYsSUFBSSxZQUFZLEdBQUcsbUVBQW1FLENBQUE7UUFDdEYsTUFBTSxDQUFDLFlBQVksQ0FBQyxDQUFDLEtBQUssQ0FBQyxrQkFBa0IsQ0FBQyxDQUFBO0lBQ2xELENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==
|
|
44
test/test.ts
44
test/test.ts
@ -1,25 +1,29 @@
|
|||||||
import 'typings-test'
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
import * as should from 'should'
|
|
||||||
|
|
||||||
import * as smartfm from '../dist/index'
|
import * as smartfm from '../ts/index';
|
||||||
|
|
||||||
describe('smartfm', function () {
|
let testSmartfm = new smartfm.Smartfm({ fmType: 'yaml' });
|
||||||
let testSmartfm = new smartfm.Smartfm({ fmType: 'yaml' })
|
tap.test('.parse()', async () => {
|
||||||
it('.parse()', function () {
|
let testString = `---
|
||||||
let testString = `---
|
|
||||||
testKey: testValue
|
testKey: testValue
|
||||||
testKey2: testValue2
|
testKey2: testValue2
|
||||||
---
|
---
|
||||||
# some markdown`
|
# some markdown
|
||||||
let parsedString = testSmartfm.parse(testString)
|
`;
|
||||||
should(parsedString.data).have.property('testKey', 'testValue')
|
let parsedString = testSmartfm.parse(testString);
|
||||||
should(parsedString.data).have.property('testKey2', 'testValue2')
|
expect(parsedString.data).to.have.property('testKey', 'testValue');
|
||||||
should(parsedString.orig).equal(testString)
|
expect(parsedString.data).to.have.property('testKey2', 'testValue2');
|
||||||
})
|
expect(parsedString.orig.toString()).to.equal(testString);
|
||||||
it('.stringify', function () {
|
});
|
||||||
let testStringPure = `# some markdown heading\nsome first row`
|
tap.test('should stringify data', async () => {
|
||||||
let testStringCombined = testSmartfm.stringify(testStringPure, { testData: 'hi' })
|
let testStringPure = `# some markdown heading\nsome first row`;
|
||||||
let resultString = '---\ntestData: hi\n---\n# some markdown heading\nsome first row\n'
|
let testStringCombined = testSmartfm.stringify(testStringPure, { testData: 'hi' });
|
||||||
should(resultString).equal(testStringCombined)
|
let resultString = '---\ntestData: hi\n---\n# some markdown heading\nsome first row\n';
|
||||||
})
|
expect(resultString).to.equal(testStringCombined);
|
||||||
})
|
});
|
||||||
|
|
||||||
|
tap.test('should parse a normal frontmatter file', async () => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
||||||
|
59
ts/index.ts
59
ts/index.ts
@ -1,53 +1,32 @@
|
|||||||
import 'typings-global'
|
import grayMatter from 'gray-matter';
|
||||||
let grayMatter = require('gray-matter')
|
|
||||||
|
|
||||||
export type TFrontMatter = 'yaml' | 'json'
|
export type TFrontMatter = 'yaml' | 'json';
|
||||||
|
|
||||||
export interface IParsedFM {
|
|
||||||
data: any
|
|
||||||
content: string
|
|
||||||
orig: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ISmartfmContructorOptions {
|
export interface ISmartfmContructorOptions {
|
||||||
fmType: TFrontMatter
|
fmType: TFrontMatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class smartfm handles frontmatter
|
* class smartfm handles frontmatter
|
||||||
*/
|
*/
|
||||||
export class Smartfm {
|
export class Smartfm {
|
||||||
fmType: TFrontMatter
|
fmType: TFrontMatter;
|
||||||
|
|
||||||
constructor(optionsArg: ISmartfmContructorOptions) {
|
constructor(optionsArg: ISmartfmContructorOptions) {
|
||||||
this.fmType = optionsArg.fmType
|
this.fmType = optionsArg.fmType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add frontmatter to a string
|
* add frontmatter to a string
|
||||||
*/
|
*/
|
||||||
stringify(bodyString: string, frontmatterData: any) {
|
stringify(bodyString: string, frontmatterData: any) {
|
||||||
return stringify(bodyString, frontmatterData)
|
return grayMatter.stringify(bodyString, frontmatterData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parse a string that has frontmatter attached, YAML notation
|
* parse a string that has frontmatter attached, YAML notation
|
||||||
*/
|
*/
|
||||||
parse(stringToParse: string): IParsedFM {
|
parse(stringToParse: string) {
|
||||||
return parse(stringToParse)
|
return grayMatter(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) => {
|
|
||||||
return grayMatter.stringify(bodyString, frontmatterData)
|
|
||||||
}
|
}
|
||||||
|
16
tslint.json
16
tslint.json
@ -1,3 +1,17 @@
|
|||||||
{
|
{
|
||||||
"extends": "tslint-config-standard"
|
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||||
|
"rules": {
|
||||||
|
"semicolon": [true, "always"],
|
||||||
|
"no-console": false,
|
||||||
|
"ordered-imports": false,
|
||||||
|
"object-literal-sort-keys": false,
|
||||||
|
"member-ordering": {
|
||||||
|
"options":{
|
||||||
|
"order": [
|
||||||
|
"static-method"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultSeverity": "warning"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user