s
s
spellbook
Search
⌃K

Chain Methods

This method is usable from 0.1.x version.
sb.chain([{ a: 'asdasd' }, { a: 35 }])
.reverse()
.toString()
.toJSON()
.filterBy({ a : 35 })
.first()
.repeatify(5)
.size()
.repeatify(10)
.toString()
.json()
.get('2')
.duplicate()
.repeatify(2)
.map(x => x + 1)
.contains(11)
.return()
-> true

Can chain any method from Spellbook

sb.chain([{ a: 'hi' }, { a: 35 }])
.first()
.get('a')
.toUpperCase()
.return()
-> "HI"

For return a value can use method "value()", "return()", "v()" or "r()"

sb.chain(100)
.numerator(2)
.mult(1002)
.toString()
.size()
.divide(2)
.sum(6)
.toString()
.split('.')
.map(sb.toInt)
.max()
.value()
-> 8

Playing with chain

sb.chain([{ a: 'asdasd' }, { a: 35 }])
.reverse()
.toString()
.toJSON()
.filterBy({ a: 35 })
.first()
.repeatify(5)
.size()
.repeatify(10)
.toString()
.json()
.get('2')
.duplicate()
.repeatify(2)
.map(x => x + 1)
.value()
-> [11,11]

Chaining comparision and functions

sb.chain(sb.range(1,5))
.size()
.isNumber()
.ifElse(
() => "hello",
() => "bye"
)
.function(x => `Res: ${x}`)
.value()
-> "Res: hello"

Make a normal event

sb.on('evrec', console.log)

Make an event from chain

sb.chain('message')
.on('evrec2', (x, y) => {
console.log(`${y} : ${x}`)
})
.value()
-> "message"

Emit from chain

sb.chain([{ a: 'asdasd' }, { a: 35 }])
.reverse()
.toString()
.toJSON()
.filterBy({ a: 35 })
.first()
.repeatify(5)
.size()
.repeatify(10)
.toString()
.json()
.get('2')
.duplicate()
.repeatify(2)
.map(x => x + 1)
.emit('evrec')
.value()
-> Rec: 11 -> [11,11]
Last modified 2yr ago