Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alvarolorentedev/array-peek
extend array functionality to allow peek method
https://github.com/alvarolorentedev/array-peek
array functional javascript peek
Last synced: 23 days ago
JSON representation
extend array functionality to allow peek method
- Host: GitHub
- URL: https://github.com/alvarolorentedev/array-peek
- Owner: alvarolorentedev
- License: mit
- Created: 2018-10-04T07:51:22.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-08T00:21:24.000Z (8 months ago)
- Last Synced: 2024-04-13T19:31:19.538Z (7 months ago)
- Topics: array, functional, javascript, peek
- Language: JavaScript
- Size: 1.22 MB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# ![logomakr_5sisss](https://user-images.githubusercontent.com/3071208/46520471-66bd9300-c87c-11e8-855c-e38b28094435.png)
[![Build Status](https://travis-ci.org/kanekotic/array-peek.svg?branch=master)](https://travis-ci.org/kanekotic/array-peek)
[![codecov](https://codecov.io/gh/kanekotic/array-peek/branch/master/graph/badge.svg)](https://codecov.io/gh/kanekotic/array-peek)
[![npm](https://img.shields.io/npm/dy/array-peek.svg)](https://github.com/kanekotic/array-peek)
[![GitHub license](https://img.shields.io/github/license/kanekotic/array-peek.svg)](https://github.com/kanekotic/array-peek/blob/master/LICENSE)
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/kanekotic/array-peek/graphs/commit-activity)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/kanekotic/)extend array functionality to allow peek method.
## peek vs forEach
`peek` as `forEach` allows you to execute a callback on each of the elements of an array, not affecting the content of itself.
The difference is that `forEach` returns void so no further processing can be done, while `peek` will return the array so you can continue the transformations necesary for your processing
## Installation
add it to your project using `npm install array-peek --save` or `yarn add array-peek`
## Usage
to use this package just add it before the usage of any array to extend its prototype. From then on you will have access to the peek function as seen in the next example.
```
require('array-peek')[1,2,3]
.peek(console.log)
.map((value) => value * value)
.peek(console.log)
// Output:
//> 1
//> 2
//> 3
//> 1
//> 4
//> 9
```##### Created my free [logo](https://logomakr.com/5sISSS) at [LogoMakr.com](LogoMakr.com)