Turns non fluent APIs into fluent APIs
npm install taptaptap
Examples
Take Array.prototype.push
for example. It returns the new length of the array, making chaining impossible.
const numbers = []
numbers.push(1)
numbers.push(2)
Wrapping the array inside "tap" allows us to chain everything together nicely.
const { tap } = require('taptaptap')
const numbers = tap([])
.push(1)
.push(2)
tap
uses ES6 proxies to make sure each function gets executed, but returns the initially passed value (in this case, the numbers array).
One more example using classes
class User {
name = null
setName(name) {
this.name = name
}
getId() {
return this.id
}
save() {
// persist data
this.id = this.createUUID
ā¦