s
s
spellbook
Search…
Chain Methods
This method is usable from 0.1.x version.
1
sb.chain([{ a: 'asdasd' }, { a: 35 }])
2
.reverse()
3
.toString()
4
.toJSON()
5
.filterBy({ a : 35 })
6
.first()
7
.repeatify(5)
8
.size()
9
.repeatify(10)
10
.toString()
11
.json()
12
.get('2')
13
.duplicate()
14
.repeatify(2)
15
.map(x => x + 1)
16
.contains(11)
17
.return()
Copied!
-> true

Can chain any method from Spellbook

1
sb.chain([{ a: 'hi' }, { a: 35 }])
2
.first()
3
.get('a')
4
.toUpperCase()
5
.return()
Copied!
-> "HI"

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

1
sb.chain(100)
2
.numerator(2)
3
.mult(1002)
4
.toString()
5
.size()
6
.divide(2)
7
.sum(6)
8
.toString()
9
.split('.')
10
.map(sb.toInt)
11
.max()
12
.value()
Copied!
-> 8

Playing with chain

1
sb.chain([{ a: 'asdasd' }, { a: 35 }])
2
.reverse()
3
.toString()
4
.toJSON()
5
.filterBy({ a: 35 })
6
.first()
7
.repeatify(5)
8
.size()
9
.repeatify(10)
10
.toString()
11
.json()
12
.get('2')
13
.duplicate()
14
.repeatify(2)
15
.map(x => x + 1)
16
.value()
Copied!
-> [11,11]

Chaining comparision and functions

1
sb.chain(sb.range(1,5))
2
.size()
3
.isNumber()
4
.ifElse(
5
() => "hello",
6
() => "bye"
7
)
8
.function(x => `Res: ${x}`)
9
.value()
Copied!
-> "Res: hello"

Make a normal event

1
sb.on('evrec', console.log)
Copied!

Make an event from chain

1
sb.chain('message')
2
.on('evrec2', (x, y) => {
3
console.log(`${y} : ${x}`)
4
})
5
.value()
Copied!
-> "message"

Emit from chain

1
sb.chain([{ a: 'asdasd' }, { a: 35 }])
2
.reverse()
3
.toString()
4
.toJSON()
5
.filterBy({ a: 35 })
6
.first()
7
.repeatify(5)
8
.size()
9
.repeatify(10)
10
.toString()
11
.json()
12
.get('2')
13
.duplicate()
14
.repeatify(2)
15
.map(x => x + 1)
16
.emit('evrec')
17
.value()
Copied!
-> Rec: 11 -> [11,11]
Last modified 1yr ago