gum
Small method chaining library, that can be used to create jQuery like DSLs from arbitrary functions.
Usage
Lets define few utility functions that operate on hashes that we'll create DSL for (feel free to skip to a next session)
// General funciton definitions (You can skip this part) { return Object} { var sources = Arrayprototypeslice return merge} { var sources = Arrayprototypeslice var whitelist = {} sources return Object} { var names = Arrayprototypeslice var source = names var properties = var whitelist = {} names return Object}
Hash of functions can be used to assemble DSL providing method chaining interface.
var gum = var hash =
Chained operations result in a simple functions that execute chained tasks when invoked:
var setDefaults = hash // => { x: 0, y: 0 } // => { x: 1, y: 0 }
Each composed function has is aware of the DSL it's part of, so new compostions can be created by further chaining:
var adjust = setDefualts // => { y: 0, z: 17 } // => { y: 15, z: 17 }
Composed chains could also be bound to the input known up front:
var value = // => { x: 12, a: 1, b: 2 }
Install
npm install gum