Skip to content

kozlown/object-pipe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

object-pipe Build Status License: MIT

Extend Object prototype with pipe function.

Installation

yarn add object-pipe

or

npm install object-pipe

Usage

require('object-pipe')()

Nothing else needed, this will mutate the Object prototype. By default the pipe function is named do and it's used like this in the examples below.

But you can setup another name for it

require('object-pipe')('pipe')
// the pipe function will be 'pipe'

Examples

Double

require('object-pipe')()

function double () {
  return this + this
  // 'this' is referring to the object calling the pipe function
}

console.info((5).do(double)) // 10

console.info('Hey'.do(double)) // "HeyHey"

console.info([1, 2, 3].do(double)) // "1,2,31,2,3"

Reduce on string

require('object-pipe')()
const reduce = Array.prototype.reduce
const sumFunction = (accumulator, number) => accumulator + parseInt(number)

let sum = '13544862'.do(reduce, sumFunction, 0)

console.info(sum) // 33

sum = sum.toString().do(reduce, sumFunction, 0)

console.info(sum) // 6

Releases

No releases published

Packages

No packages published