Created
June 24, 2015 02:21
-
-
Save nateabele/e3010459c4c18b31f8f7 to your computer and use it in GitHub Desktop.
Domp
This file contains hidden or 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
| import R from 'ramda'; | |
| let { is, complement, filter, map, mapObj, mapObjIndexed, prop, pipe, identity, mergeAll, toLower } = R; | |
| class Domp { | |
| constructor() { | |
| this.propMap = { | |
| name: pipe(prop('nodeName'), toLower), | |
| type: prop('nodeType'), | |
| text: prop('nodeValue'), | |
| attributes: pipe(prop('attributes'), filter(complement(is(Function))), map(node => ({ [node.name]: node.value })), mergeAll), | |
| children: pipe(prop('children'), map(this.toObject.bind(this))) | |
| }; | |
| } | |
| toObject(node) { | |
| return mapObj(fn => fn(node))(this.propMap); | |
| } | |
| toJSON(node) { | |
| return JSON.stringify(this.toObject(node)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment