initial
This commit is contained in:
commit
ef3f1a3188
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
node_modules/
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
59
.gitlab-ci.yml
Normal file
59
.gitlab-ci.yml
Normal file
@ -0,0 +1,59 @@
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
|
||||
stages:
|
||||
- test
|
||||
- release
|
||||
- trigger
|
||||
- pages
|
||||
|
||||
testLEGACY:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test legacy
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test lts
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
tags:
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
|
||||
trigger:
|
||||
stage: trigger
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmpage
|
||||
stage: pages
|
||||
script:
|
||||
- npmci command npmpage --host gitlab
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
68
README.md
Normal file
68
README.md
Normal file
@ -0,0 +1,68 @@
|
||||
# smartfm
|
||||
smartfm handles frontmatter of files
|
||||
|
||||
## Availabililty
|
||||
[![npm](https://push.rocks/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartfm)
|
||||
[![git](https://push.rocks/assets/repo-button-git.svg)](https://gitlab.com/pushrocks/smartfm)
|
||||
[![git](https://push.rocks/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartfm)
|
||||
[![docs](https://push.rocks/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartfm/)
|
||||
|
||||
## Status for master
|
||||
[![build status](https://gitlab.com/pushrocks/smartfm/badges/master/build.svg)](https://gitlab.com/pushrocks/smartfm/commits/master)
|
||||
[![coverage report](https://gitlab.com/pushrocks/smartfm/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartfm/commits/master)
|
||||
[![Dependency Status](https://david-dm.org/pushrocks/smartfm.svg)](https://david-dm.org/pushrocks/smartfm)
|
||||
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartfm/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartfm/master/dependencies/npm)
|
||||
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartfm/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartfm)
|
||||
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
|
||||
|
||||
## Usage
|
||||
|
||||
say you have the following markdown file:
|
||||
```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
|
||||
import * as smartfm from * smartfm
|
||||
|
||||
let markdownfile = `---
|
||||
testKey: testValue
|
||||
testKey2: testValue2
|
||||
---
|
||||
# some markdown`
|
||||
|
||||
// easy methods
|
||||
let parsedData = smartfm.parse(markdownfile)
|
||||
|
||||
// parsedData will be object
|
||||
/*
|
||||
{
|
||||
data: {
|
||||
testKey: testValue,
|
||||
testKey2: testValue2
|
||||
},
|
||||
content: '# some markdown',
|
||||
orig: '---\ntestKey: testValue\ntestKey2: testValue2\n---\n# some markdown'
|
||||
}
|
||||
*/
|
||||
|
||||
let newFmString = smartfm.stringify('My awesome string', {testKey1: testValue1})
|
||||
// newFmString will be '---\testKey1: testValue1\n---\nMyawesomeString'
|
||||
|
||||
# class Smartfm
|
||||
let mySmartfm = new smartfm.Smartfm({
|
||||
fmType: 'yaml' // can be yaml or json atm
|
||||
})
|
||||
```
|
||||
|
||||
[![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks)
|
27
dist/index.d.ts
vendored
Normal file
27
dist/index.d.ts
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
import 'typings-global';
|
||||
export interface IParsedFM {
|
||||
data: any;
|
||||
content: string;
|
||||
orig: string;
|
||||
}
|
||||
/**
|
||||
* class smartfm handles frontmatter
|
||||
*/
|
||||
export declare class Smartfm {
|
||||
/**
|
||||
* add frontmatter to a string
|
||||
*/
|
||||
stringify(bodyString: string, frontmatterData: any): void;
|
||||
/**
|
||||
* 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) => void;
|
34
dist/index.js
vendored
Normal file
34
dist/index.js
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
let grayMatter = require('gray-matter');
|
||||
/**
|
||||
* class smartfm handles frontmatter
|
||||
*/
|
||||
class Smartfm {
|
||||
/**
|
||||
* 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) => {
|
||||
grayMatter.stringify(bodyString, frontmatterData);
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLElBQUksVUFBVSxHQUFHLE9BQU8sQ0FBQyxhQUFhLENBQUMsQ0FBQTtBQVF2Qzs7R0FFRztBQUNIO0lBQ0k7O09BRUc7SUFDSCxTQUFTLENBQUMsVUFBa0IsRUFBRSxlQUFvQjtRQUM5QyxNQUFNLENBQUMsaUJBQVMsQ0FBQyxVQUFVLEVBQUUsZUFBZSxDQUFDLENBQUE7SUFDakQsQ0FBQztJQUVEOztPQUVHO0lBQ0gsS0FBSyxDQUFDLGFBQXFCO1FBQ3ZCLE1BQU0sQ0FBQyxhQUFLLENBQUMsYUFBYSxDQUFDLENBQUE7SUFDL0IsQ0FBQztDQUNKO0FBZEQsMEJBY0M7QUFFRDs7R0FFRztBQUNRLFFBQUEsS0FBSyxHQUFHLENBQUMsYUFBcUI7SUFDckMsTUFBTSxDQUFDLFVBQVUsQ0FBQyxhQUFhLENBQUMsQ0FBQTtBQUNwQyxDQUFDLENBQUE7QUFFRDs7R0FFRztBQUNRLFFBQUEsU0FBUyxHQUFHLENBQUMsVUFBa0IsRUFBRSxlQUFvQjtJQUM1RCxVQUFVLENBQUMsU0FBUyxDQUFDLFVBQVUsRUFBRSxlQUFlLENBQUMsQ0FBQTtBQUNyRCxDQUFDLENBQUEifQ==
|
32
package.json
Normal file
32
package.json
Normal file
@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "smartfm",
|
||||
"version": "1.0.0",
|
||||
"description": "frontmatter done right",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(npmts)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@gitlab.com/pushrocks/smartfm.git"
|
||||
},
|
||||
"keywords": [
|
||||
"frontmatter"
|
||||
],
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/pushrocks/smartfm/issues"
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartfm#README",
|
||||
"dependencies": {
|
||||
"gray-matter": "^2.1.0",
|
||||
"typings-global": "^1.0.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/should": "^8.1.30",
|
||||
"should": "^11.1.1",
|
||||
"typings-test": "^1.0.3"
|
||||
}
|
||||
}
|
1
test/test.d.ts
vendored
Normal file
1
test/test.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
import 'typings-test';
|
25
test/test.js
Normal file
25
test/test.js
Normal file
@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
require("typings-test");
|
||||
const should = require("should");
|
||||
const smartfm = require("../dist/index");
|
||||
describe('smartfm', function () {
|
||||
let testSmartfm = new smartfm.Smartfm;
|
||||
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
|
||||
some first row`;
|
||||
let testStringCombined = testSmartfm.stringify(testStringPure, { testData: 'hi' });
|
||||
console.log(testStringCombined);
|
||||
});
|
||||
});
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Q0FBQTtJQUNuQyxDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFBIn0=
|
25
test/test.ts
Normal file
25
test/test.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import 'typings-test'
|
||||
import * as should from 'should'
|
||||
|
||||
import * as smartfm from '../dist/index'
|
||||
|
||||
describe('smartfm', function() {
|
||||
let testSmartfm = new smartfm.Smartfm
|
||||
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
|
||||
some first row`
|
||||
let testStringCombined = testSmartfm.stringify(testStringPure, {testData: 'hi'})
|
||||
console.log(testStringCombined)
|
||||
})
|
||||
})
|
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)
|
||||
}
|
3
tslint.json
Normal file
3
tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "tslint-config-standard"
|
||||
}
|
Loading…
Reference in New Issue
Block a user