Skip to content

Commit

Permalink
chore: remove dependency upon argx
Browse files Browse the repository at this point in the history
  • Loading branch information
zkochan committed May 21, 2016
1 parent fb841d9 commit 50f8a2b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ console.log(h3([paragraph(['Foo bar'])]))
<!--@dependencies({ shield: 'flat-square' })-->
## <a name="dependencies">Dependencies</a> [![Dependency status for master](https://img.shields.io/david/zkochan/markdownscript/master.svg?style=flat-square)](https://david-dm.org/zkochan/markdownscript/master)

- [argx](https://github.com/okunishinishi/node-argx): Parse function arguments. Useful to implement variadic functions.

None
<!--/@-->

<!--@devDependencies({ shield: 'flat-square' })-->
Expand Down
23 changes: 12 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
'use strict'
const slice = Array.prototype.slice
const argx = require('argx')

function markdownScript () {
const args = argx(arguments)
const node = {
type: args.shift(String),
}
let children = args.pop(Array)
function popChildren (args) {
return args[args.length - 1] instanceof Array ? args.pop() : undefined
}

function markdownScript (type) {
const args = slice.call(arguments, 1)
const node = {type}
const children = popChildren(args)
if (children) {
node.children = children
.map(child => {
Expand All @@ -22,7 +23,7 @@ function markdownScript () {
return merged.concat(child)
}, [])
}
const attributes = args.shift(Object) || {}
const attributes = args.shift() || {}
return Object.assign(node, attributes)
}

Expand Down Expand Up @@ -62,9 +63,9 @@ types.forEach(type => {

;[1, 2, 3, 4, 5, 6].forEach(depth => {
markdownScript[`h${depth}`] = function () {
const args = argx(arguments)
let children = args.pop(Array)
const attributes = Object.assign(args.shift(Object) || {}, { depth })
const args = slice.call(arguments)
const children = popChildren(args)
const attributes = Object.assign(args.shift() || {}, { depth })
const newargs = ['heading', attributes]
if (children) newargs.push(children)
return markdownScript.apply(null, newargs)
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@
},
"homepage": "https://github.com/zkochan/markdownscript#readme",
"tonicExampleFilename": "tonic-example.js",
"dependencies": {
"argx": "^2.0.2"
},
"dependencies": {},
"devDependencies": {
"chai": "^3.4.1",
"cz-conventional-changelog": "1.1.5",
Expand Down

0 comments on commit 50f8a2b

Please sign in to comment.