Installations
npm install itrabble
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=6.11.1
Node Version
8.1.3
NPM Version
5.0.3
Score
73.3
Supply Chain
99.4
Quality
76.6
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (99.63%)
Shell (0.2%)
JavaScript (0.17%)
Developer
Download Statistics
Total Downloads
2,127
Last Day
1
Last Week
3
Last Month
14
Last Year
284
GitHub Statistics
6 Stars
158 Commits
1 Watching
7 Branches
1 Contributors
Package Meta Information
Latest Version
1.1.1
Package Id
itrabble@1.1.1
Unpacked Size
37.88 kB
Size
12.26 kB
File Count
34
NPM Version
5.0.3
Node Version
8.1.3
Total Downloads
Cumulative downloads
Total Downloads
2,127
Last day
0%
1
Compared to previous day
Last week
-50%
3
Compared to previous week
Last month
7.7%
14
Compared to previous month
Last year
42%
284
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
itrabble
Library to extend JavaScript ES6 iterables
Examples
API Documentation
Features
- small 920 bytes (ESM) with all dependencies, minified and brotlied.
- No dependencies.
- hand-crafted by single artisan developer - not mass produced by large corporation-backed open-source team.
- fun name to reference in your project dependencies
Why?
I know there are lots of other libraries that already do this kind of thing, and do it very well, providing the ability to extend ordinary JavaScript objects to be able to enjoy the breadth of functionality of say, a Ruby standard library object. For example Lodash.
The twist that interested me was to be able to incorporate the recent additions to the JavaScript language that make it possible to iterate through infinite sequences, evaluated lazily, with a handy range of methods. Plus having these methods work in a uniform way regardless of whether the source is an Array, a Map, a Set, a String or some form of TypedArray or stream. Or even a user-created object that has its own unique behaviour.
I wrote this mainly as a fun exercise for myself and a way to learn about the ES2015 features in more depth. I plan to add more utility functions as I see the need/think of them, or if people using the module request them.
Requirements
For a Node environment, you'll need a node version of at least 6.11.1 because this library uses a large number of the features introduced in ES2015 (iterators, generator functions, and rest/spread operators to name a few).
Changes from v1.0.1 -> v1.1.0
Usage
install with npm:
npm install --save itrabble
Examples
1// define some iterables 2const array = ['a', 'b', 'c', 'd', 'e', 'f']; 3 4const map = new Map([ 5 ['a', 'A'], 6 ['b', 'B'], 7 ['c', 'C'], 8 ['d', 'D'], 9 ['e', 'E'], 10 ['f', 'F'], 11]); 12 13const string = 'test string';
As of v1.1.0
there are now three ways to use the library.
Standard Usage
The easiest way is to use the imported module as a function to wrap the iterable object you wish to extend:
1const itrabble = require('itrabble'); 2 3itrabble(array).skipUntil((x) => x === 'd'); 4// => iterable sequence { d e f }
Alternative Usage
Another way is to import the object-prototype-decorator
nested module into scope and then call the itrabble
property on any entity that has the following:
Object
in its prototype- The
Symbol.iterator
property
In the previous version v1.0.1
this happened by default. It is now opt-in.
As the name suggests, this does modify the Object prototype. It's unlikely that the property itrabble
will clash with any existing namespace, but it's good to be aware of what this is doing if you are going to use it.
1require('itrabble/lib/object-prototype-decorator'); 2 3/* Array */ 4array.itrabble.skipUntil((x) => x === 'd'); 5// => iterable sequence { d e f } 6 7/* Map */ 8map.itrabble.takeUntil((xs) => xs.includes('e')); 9// => iterable sequence { [ 'a', 'A' ] [ 'b', 'B' ] [ 'c', 'C' ] [ 'd', 'D' ] } 10 11/* String */ 12string.itrabble.takeUntil((x) => x === 'i'); 13// => iterable sequence { test str } 14 15// All together now 16array.itrabble.zip(array, map, string).take(3); 17/* => iterable sequence { 18 * [ 'a', 'a', [ 'a', 'A' ], 't' ] [ 'b', 'b', [ 'b', 'B' ], 'e' ] [ 'c', 'c', [ 'c', 'C' ], 's' ] 19 * } 20 */
The methods called on an instance of itrabble
return an itrabble
iterator over the updated sequence, which means they can be chained.
1itrabble(array) 2 .skipUntil((x) => x === 'd') 3 .first(); // or array.itrabble.skipUntil(x => x === 'd').first() 4// => iterable sequence { d e f } => iterable sequence { d }
In order to consume the actual values of the returned iterator, you can use one of the following standard ES2015 calls:
1const skipped = itrabble(array).skipUntil((x) => x === 'd'); 2 3// ... operator 4console.log(...skipped); 5// => d e f 6 7// for of loop 8for (let value of skipped) { 9 console.log(value); 10} 11/* 12 * => d 13 * => e 14 * => f 15 */ 16 17// selected iteration through destructuring 18const [d, e, f] = skipped; 19/* 20 console.log(d) => d 21 console.log(e) => e 22 console.log(f) => f 23*/
or alternatively specify the format with the following methods:
1/* Array */ 2itrabble(array) 3 .takeUntil((x) => x === 'e') 4 .toArray(); 5// => ['a','b','c','d'] 6 7/* Map */ 8itrabble(map) 9 .takeUntil((x) => x.includes('e')) 10 .toMap(); 11// => Map { 'a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd' } 12 13/* Set */ 14itrabble(array) 15 .takeUntil((x) => x === 'e') 16 .toSet(); 17// => Set { 'a', 'b', 'c', 'd' }
v1.1.0
The main way of using the module hasn't changed, for example:
1const itrabble = require('itrabble'); 2 3itrabble(array).skipUntil((x) => x === 'd'); 4// => iterable sequence { d e f }
However if you were previously using the following syntax:
1require('itrabble'); 2 3array.itrabble.skipUntil((x) => x === 'd');
This has been updated to:
1require('itrabble/lib/object-prototype-decorator'); 2 3array.itrabble.skipUntil((x) => x === 'd');
As the name suggests more clearly now, this does modify the Object prototype. It's unlikely that the property itrabble
will clash with any existing namespace, but it's good to be aware of what this is doing if you are going to use it.
Individual Exports
itrabble
now provides a way to access the individual methods as separate exports which can be imported on a per-use basis, unattached to the rest of the itrabble
module.
An ideal way to use this would be with the (somewhat) proposed bind operator ::
. The proposal is on Github, and there is a Babel transform for this which describes the idea well. It hasn't progressed past stage 0 and seems to have lost momentum, so while it's probably not appropriate for production code I really like it. For example:
1import take from 'itrabble/lib/take'; 2 3const array = ['a', 'b', 'c']; 4const firstTwo = array::take(2); 5// => iterable sequence { a b }
Acknowledgements
Thanks to @wouterken for the interest and help with this!
Contributing
This project is open to contributions. Please read the Code of Conduct before doing anything else.
Please open an issue to point out anything broken, lacking or otherwise worth mentioning.
For development:
fork and clone the repo
Given the minimum required version of Node of 6.11.1
there's not a lot to set up to get going.
install dependencies
npm install
to run tests in watch mode
npm run test:watch
or for a coverage report
npm test
Related
You might find these related libraries & blog posts interesting
Dr Axel Rauschmayer explains ES6 iteration
IXJS - Interactive Extensions for JavaScript
License
MIT © Alex Revell
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/5 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:9: update your workflow using https://app.stepsecurity.io/secureworkflow/desnor/itrabble/main.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/desnor/itrabble/main.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/desnor/itrabble/main.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/desnor/itrabble/main.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/size.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/desnor/itrabble/size.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/size.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/desnor/itrabble/size.yml/master?enable=pin
- Info: 0 out of 3 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 3 third-party GitHubAction dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 28 are checked with a SAST tool
Reason
12 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-8jhw-289h-jh2g
- Warn: Project is vulnerable to: GHSA-64vr-g452-qvp3
- Warn: Project is vulnerable to: GHSA-9cwx-2883-4wfx
Score
2.8
/10
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More