mdast-builder
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -0,1 +1,8 @@ | ||
# [1.1.0](https://github.com/mike-north/mdast-builder/compare/v1.0.1...v1.1.0) (2019-02-22) | ||
### Features | ||
* separator ([6c58a84](https://github.com/mike-north/mdast-builder/commit/6c58a84)) | ||
## [1.0.1](https://github.com/mike-north/mdast-builder/compare/v1.0.0...v1.0.1) (2019-02-16) | ||
@@ -2,0 +9,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { Node, Parent } from 'unist'; | ||
import { Node, Parent } from "unist"; | ||
export declare type Children = Node | Node[] | (() => Node | Node[]); | ||
@@ -18,5 +18,4 @@ export declare const text: (value: string) => Node; | ||
}; | ||
export declare const brk: Readonly<{ | ||
type: string; | ||
}>; | ||
export declare const brk: Node; | ||
export declare const separator: Node; | ||
export declare const link: (url: string, title?: string, kids?: Node | Node[] | (() => Node | Node[]) | undefined) => { | ||
@@ -23,0 +22,0 @@ url: string; |
@@ -7,7 +7,7 @@ "use strict"; | ||
} | ||
else if (typeof children === 'function') { | ||
else if (typeof children === "function") { | ||
const res = children(); | ||
return normalizeChildren(res); | ||
} | ||
else if (typeof children === 'undefined') { | ||
else if (typeof children === "undefined") { | ||
return []; | ||
@@ -27,29 +27,30 @@ } | ||
}); | ||
exports.text = (value) => valueNode('text', value); | ||
exports.inlineCode = (value) => valueNode('inlineCode', value); | ||
exports.html = (value) => valueNode('html', value); | ||
exports.strong = (kids) => nodeWithChildren('strong', kids); | ||
exports.emphasis = (kids) => nodeWithChildren('emphasis', kids); | ||
exports.strike = (kids) => nodeWithChildren('delete', kids); | ||
exports.tableCell = (kids) => nodeWithChildren('tableCell', kids); | ||
exports.tableRow = (kids) => nodeWithChildren('tableRow', kids); | ||
exports.table = (align, kids) => (Object.assign({}, nodeWithChildren('table', kids), { align })); | ||
exports.brk = Object.freeze({ type: 'break' }); | ||
exports.link = (url, title = '', kids) => (Object.assign({}, nodeWithChildren('link', kids), { url, | ||
exports.text = (value) => valueNode("text", value); | ||
exports.inlineCode = (value) => valueNode("inlineCode", value); | ||
exports.html = (value) => valueNode("html", value); | ||
exports.strong = (kids) => nodeWithChildren("strong", kids); | ||
exports.emphasis = (kids) => nodeWithChildren("emphasis", kids); | ||
exports.strike = (kids) => nodeWithChildren("delete", kids); | ||
exports.tableCell = (kids) => nodeWithChildren("tableCell", kids); | ||
exports.tableRow = (kids) => nodeWithChildren("tableRow", kids); | ||
exports.table = (align, kids) => (Object.assign({}, nodeWithChildren("table", kids), { align })); | ||
exports.brk = Object.freeze({ type: "break" }); | ||
exports.separator = exports.text("---"); | ||
exports.link = (url, title = "", kids) => (Object.assign({}, nodeWithChildren("link", kids), { url, | ||
title })); | ||
exports.root = (kids) => nodeWithChildren('root', kids); | ||
exports.root = (kids) => nodeWithChildren("root", kids); | ||
exports.rootWithTitle = (depth, title, kids) => { | ||
return exports.root([exports.heading(depth, title), ...normalizeChildren(kids)]); | ||
}; | ||
exports.paragraph = (kids) => nodeWithChildren('paragraph', kids); | ||
exports.image = (url, title, alt, kids) => (Object.assign({}, nodeWithChildren('image', kids), { url, title, alt })); | ||
exports.blockquote = (kids) => nodeWithChildren('blockquote', kids); | ||
exports.code = (lang, value) => (Object.assign({}, valueNode('code', value), { lang })); | ||
exports.paragraph = (kids) => nodeWithChildren("paragraph", kids); | ||
exports.image = (url, title, alt, kids) => (Object.assign({}, nodeWithChildren("image", kids), { url, title, alt })); | ||
exports.blockquote = (kids) => nodeWithChildren("blockquote", kids); | ||
exports.code = (lang, value) => (Object.assign({}, valueNode("code", value), { lang })); | ||
exports.heading = (depth, kids) => { | ||
if (depth < 1) | ||
throw new Error(`Invalid depth: ${depth}`); | ||
return Object.assign({}, nodeWithChildren('heading', kids), { depth }); | ||
return Object.assign({}, nodeWithChildren("heading", kids), { depth }); | ||
}; | ||
exports.list = (ordered, kids) => (Object.assign({}, nodeWithChildren('list', kids), { ordered: ordered === 'ordered' })); | ||
exports.listItem = (kids) => nodeWithChildren('listItem', kids); | ||
exports.list = (ordered, kids) => (Object.assign({}, nodeWithChildren("list", kids), { ordered: ordered === "ordered" })); | ||
exports.listItem = (kids) => nodeWithChildren("listItem", kids); | ||
//# sourceMappingURL=index.js.map |
@@ -74,4 +74,16 @@ "use strict"; | ||
}); | ||
mocha_1.it('brk', () => { | ||
expectMd(index_1.brk).to.eq(' \n'); | ||
mocha_1.it('separator', () => { | ||
expectMd(index_1.root([ | ||
index_1.heading(1, index_1.text('hello')), | ||
index_1.paragraph(index_1.text('this is a thing')), | ||
index_1.separator, | ||
index_1.paragraph(index_1.text('another thing')) | ||
])).to.eq(`# hello | ||
this is a thing | ||
--- | ||
another thing | ||
`); | ||
}); | ||
@@ -78,0 +90,0 @@ mocha_1.it('emphasis', () => { |
@@ -7,3 +7,3 @@ { | ||
], | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"license": "BSD-2-Clause", | ||
@@ -29,3 +29,3 @@ "scripts": { | ||
"@commitlint/travis-cli": "7.5.2", | ||
"@mike-north/js-lib-renovate-config": "1.1.1", | ||
"@mike-north/js-lib-renovate-config": "1.3.1", | ||
"@mike-north/js-lib-semantic-release-config": "1.0.1", | ||
@@ -36,3 +36,3 @@ "@types/chai": "4.1.7", | ||
"husky": "1.3.1", | ||
"mocha": "5.2.0", | ||
"mocha": "6.0.1", | ||
"mocha-typescript": "1.1.17", | ||
@@ -43,3 +43,3 @@ "nyc": "13.3.0", | ||
"ts-node": "8.0.2", | ||
"typescript": "^3.3.3", | ||
"typescript": "3.3.3", | ||
"unified": "7.1.0" | ||
@@ -46,0 +46,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
import { Node, Parent } from 'unist'; | ||
import { Node, Parent } from "unist"; | ||
@@ -8,6 +8,6 @@ export type Children = Node | Node[] | (() => Node | Node[]); | ||
return children; | ||
} else if (typeof children === 'function') { | ||
} else if (typeof children === "function") { | ||
const res = children(); | ||
return normalizeChildren(res); | ||
} else if (typeof children === 'undefined') { | ||
} else if (typeof children === "undefined") { | ||
return []; | ||
@@ -29,21 +29,23 @@ } else { | ||
export const text = (value: string) => valueNode('text', value); | ||
export const inlineCode = (value: string) => valueNode('inlineCode', value); | ||
export const html = (value: string) => valueNode('html', value); | ||
export const text = (value: string) => valueNode("text", value); | ||
export const inlineCode = (value: string) => valueNode("inlineCode", value); | ||
export const html = (value: string) => valueNode("html", value); | ||
export const strong = (kids?: Children) => nodeWithChildren('strong', kids); | ||
export const emphasis = (kids?: Children) => nodeWithChildren('emphasis', kids); | ||
export const strike = (kids?: Children) => nodeWithChildren('delete', kids); | ||
export const strong = (kids?: Children) => nodeWithChildren("strong", kids); | ||
export const emphasis = (kids?: Children) => nodeWithChildren("emphasis", kids); | ||
export const strike = (kids?: Children) => nodeWithChildren("delete", kids); | ||
export const tableCell = (kids?: Children) => | ||
nodeWithChildren('tableCell', kids); | ||
export const tableRow = (kids?: Children) => nodeWithChildren('tableRow', kids); | ||
nodeWithChildren("tableCell", kids); | ||
export const tableRow = (kids?: Children) => nodeWithChildren("tableRow", kids); | ||
export const table = ( | ||
align?: ['left' | 'right', 'left' | 'right' | 'center'], | ||
align?: ["left" | "right", "left" | "right" | "center"], | ||
kids?: Children | ||
) => ({ ...nodeWithChildren('table', kids), align }); | ||
) => ({ ...nodeWithChildren("table", kids), align }); | ||
export const brk = Object.freeze({ type: 'break' }); | ||
export const brk: Node = Object.freeze({ type: "break" }); | ||
export const link = (url: string, title: string = '', kids?: Children) => ({ | ||
...nodeWithChildren('link', kids), | ||
export const separator: Node = text("---"); | ||
export const link = (url: string, title: string = "", kids?: Children) => ({ | ||
...nodeWithChildren("link", kids), | ||
url, | ||
@@ -53,3 +55,3 @@ title | ||
export const root = (kids?: Children) => nodeWithChildren('root', kids); | ||
export const root = (kids?: Children) => nodeWithChildren("root", kids); | ||
@@ -65,3 +67,3 @@ export const rootWithTitle = ( | ||
export const paragraph = (kids?: Children) => | ||
nodeWithChildren('paragraph', kids); | ||
nodeWithChildren("paragraph", kids); | ||
@@ -73,9 +75,9 @@ export const image = ( | ||
kids?: Children | ||
) => ({ ...nodeWithChildren('image', kids), url, title, alt }); | ||
) => ({ ...nodeWithChildren("image", kids), url, title, alt }); | ||
export const blockquote = (kids?: Children) => | ||
nodeWithChildren('blockquote', kids); | ||
nodeWithChildren("blockquote", kids); | ||
export const code = (lang: string, value: string) => ({ | ||
...valueNode('code', value), | ||
...valueNode("code", value), | ||
lang | ||
@@ -87,3 +89,3 @@ }); | ||
return { | ||
...nodeWithChildren('heading', kids), | ||
...nodeWithChildren("heading", kids), | ||
depth | ||
@@ -94,9 +96,9 @@ }; | ||
export const list = ( | ||
ordered: 'ordered' | 'unordered', | ||
ordered: "ordered" | "unordered", | ||
kids: Children | ||
): Parent => ({ | ||
...nodeWithChildren('list', kids), | ||
ordered: ordered === 'ordered' | ||
...nodeWithChildren("list", kids), | ||
ordered: ordered === "ordered" | ||
}); | ||
export const listItem = (kids: Children): Parent => | ||
nodeWithChildren('listItem', kids); | ||
nodeWithChildren("listItem", kids); |
@@ -26,3 +26,4 @@ import { expect } from 'chai'; | ||
text, | ||
image | ||
image, | ||
separator | ||
} from '../src/index'; | ||
@@ -113,4 +114,18 @@ | ||
it('brk', () => { | ||
expectMd(brk).to.eq(' \n'); | ||
it('separator', () => { | ||
expectMd( | ||
root([ | ||
heading(1, text('hello')), | ||
paragraph(text('this is a thing')), | ||
separator, | ||
paragraph(text('another thing')) | ||
]) | ||
).to.eq(`# hello | ||
this is a thing | ||
--- | ||
another thing | ||
`); | ||
}); | ||
@@ -117,0 +132,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
321070
28
600