-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 65c5d51
Showing
8 changed files
with
6,579 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
yarn-error.log | ||
lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "mdast-builder", | ||
"description": "Composable functions to easily build mdast structures", | ||
"keywords": [ | ||
"mdast" | ||
], | ||
"license": "BSD-2-Clause", | ||
"scripts": { | ||
"build": "tsc -b .", | ||
"build:watch": "yarn build -- --watch", | ||
"test": "mocha", | ||
"test:watch": "mocha --watch" | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "7.5.2", | ||
"@commitlint/config-conventional": "7.5.0", | ||
"@commitlint/travis-cli": "7.5.2", | ||
"@mike-north/js-lib-renovate-config": "1.1.1", | ||
"@mike-north/js-lib-semantic-release-config": "1.0.1", | ||
"@types/chai": "^4.1.7", | ||
"@types/mocha": "^5.2.6", | ||
"chai": "^4.2.0", | ||
"husky": "^1.3.1", | ||
"mocha": "^5.2.0", | ||
"nyc": "^13.3.0", | ||
"source-map-support": "^0.5.10", | ||
"ts-node": "^8.0.2", | ||
"typescript": "^3.3.3" | ||
}, | ||
"dependencies": { | ||
"@types/unist": "^2.0.3" | ||
}, | ||
"commitlint": { | ||
"extends": [ | ||
"@commitlint/config-conventional" | ||
] | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"commit-msg": "./node_modules/.bin/commitlint -e $HUSKY_GIT_PARAMS" | ||
} | ||
}, | ||
"release": { | ||
"extends": "@mike-north/js-lib-semantic-release-config" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": ["@mike-north/js-lib-renovate-config"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { Node, Parent } from 'unist'; | ||
|
||
export type Children = Node | Node[] | (() => Node | Node[]); | ||
|
||
function normalizeChildren(children?: Children): Node[] { | ||
if (Array.isArray(children)) { | ||
return children; | ||
} else if (typeof children === 'function') { | ||
const res = children(); | ||
return normalizeChildren(res); | ||
} else if (typeof children === 'undefined') { | ||
return []; | ||
} else { | ||
return [children]; | ||
} | ||
} | ||
|
||
const valueNode = (type: string, value: string): Node => ({ | ||
type, | ||
value | ||
}); | ||
|
||
const nodeWithChildren = (type: string, kids?: Children): Parent => { | ||
const children = kids ? normalizeChildren(kids) : []; | ||
|
||
return { | ||
type, | ||
children | ||
}; | ||
}; | ||
|
||
export const text = (value: string) => valueNode('text', value); | ||
export const inlineCode = (value: string) => valueNode('inlineCode', value); | ||
|
||
export const strong = (kids?: Children) => nodeWithChildren('strong', kids); | ||
export const tableCell = (kids?: Children) => | ||
nodeWithChildren('tableCell', kids); | ||
export const tableRow = (kids?: Children) => nodeWithChildren('tableRow', kids); | ||
export const table = ( | ||
align?: ['left' | 'right', 'left' | 'right' | 'center'], | ||
kids?: Children | ||
) => ({ ...nodeWithChildren('table', kids), align }); | ||
|
||
export const link = (url: string, title: string = '', kids?: Children) => ({ | ||
...nodeWithChildren('link', kids), | ||
url, | ||
title | ||
}); | ||
|
||
export const root = (kids?: Children) => nodeWithChildren('root', kids); | ||
|
||
export const rootWithTitle = ( | ||
depth: number, | ||
title: Children, | ||
kids?: Children | ||
) => root([heading(depth, title), paragraph(kids)]); | ||
|
||
export const paragraph = (kids?: Children) => | ||
nodeWithChildren('paragraph', kids); | ||
export const code = (lang: string, value: string) => ({ | ||
...valueNode('code', value), | ||
lang | ||
}); | ||
|
||
export const heading = (depth: number, kids: Children): Parent => ({ | ||
...nodeWithChildren('heading', kids), | ||
depth | ||
}); | ||
|
||
export const list = ( | ||
ordered: 'ordered' | 'unordered', | ||
kids: Children | ||
): Parent => ({ | ||
...nodeWithChildren('list', kids), | ||
ordered: ordered === 'ordered' | ||
}); | ||
export const listItem = (kids: Children): Parent => | ||
nodeWithChildren('listItem', kids); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { suite, test } from 'mocha'; | ||
import { expect } from 'chai'; | ||
|
||
suite('first tests', () => { | ||
test('a thing', () => { | ||
expect(true).to.eq(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--require ts-node/register | ||
--require source-map-support/register | ||
--timeout 60000 | ||
--watch-extensions js,ts,json | ||
**/*.test.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2015", | ||
"outDir": "lib", | ||
"moduleResolution": "node", | ||
"declaration": true, | ||
"sourceMap": true, | ||
"strict": true | ||
}, | ||
"include": ["src"] | ||
} |
Oops, something went wrong.