Gathering detailed insights and metrics for iterator-matcher
Gathering detailed insights and metrics for iterator-matcher
Gathering detailed insights and metrics for iterator-matcher
Gathering detailed insights and metrics for iterator-matcher
npm install iterator-matcher
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
7 Stars
56 Commits
1 Forks
2 Watching
1 Branches
2 Contributors
Updated on 25 Nov 2024
TypeScript (100%)
Cumulative downloads
Total Downloads
Last day
-33.3%
2
Compared to previous day
Last week
-6.7%
14
Compared to previous week
Last month
65.1%
71
Compared to previous month
Last year
169.8%
2,107
Compared to previous year
8
Easily found out if an ES6 Iterator match what you expected
This package is available in the Node Package Repository and can be easily installed with npm or yarn.
1$ npm i iterator-matcher 2# or 3$ yarn add iterator-matcher
1import { IteratorMatcher } from "iterator-matcher"; 2import assert from "node:assert"; 3 4function* dummyGen() { 5 yield "console"; 6 yield "trace"; 7 yield "error"; 8} 9 10const result = new IteratorMatcher() 11 .expect("console") 12 .expect(["trace", "error"], { occurence: 2 }) 13 .execute(dummyGen()); 14 15assert.ok(result.isMatching, true); 16assert.equal(result.elapsedSteps, 3);
[!NOTE] You can re-use the same IteratorMatcher multiple time.
No options are required.
The options payload is described by the following TypeScript interface:
1export interface IteratorMatcherExpectOptions { 2 /** 3 * When a value is not mandatory the Executor continue his job/execution. 4 * 5 * @default true 6 */ 7 mandatory?: boolean; 8 /** 9 * Number of occurences of the expected value 10 * 11 * @default 1 12 */ 13 occurence?: number; 14}
In usage the expectedValue can be an Array or a ES6 Set.
1new IteratorMatcher() 2 .expect("primitive", { mandatory: false }) 3 .expect([1, 2, 3]) 4 .expect(new Set(["oh", "hey", "oh"]), { occurence: 2 });
The options payload is described by the following TypeScript interface:
1interface DefaultIteratorMatcherExecutorOptions { 2 /** 3 * Stop the executor on the first matching value. 4 * 5 * @default false 6 */ 7 stopOnFirstMatch?: boolean; 8 9 /** 10 * When enabled it return isMatching: true if no value has been matched (like an empty Iterator for example). 11 * 12 * @default true 13 */ 14 allowNoMatchingValues?: boolean; 15} 16 17interface DefaultUnpreservedIteratorMatcherExecutorOptions 18 extends DefaultIteratorMatcherExecutorOptions { 19 /** 20 * Authorize unexpected value to appear 21 * 22 * @default false 23 */ 24 allowUnexpectedValue?: boolean; 25} 26 27export type IteratorMatcherExecutorOptions = { 28 /** 29 * When enabled it preserve the order of expectation 30 */ 31 preserveExpectationOrder?: true; 32} & DefaultIteratorMatcherExecutorOptions | { 33 /** 34 * When disabled it will iterate all expectations and try to match them all with no order. 35 */ 36 preserveExpectationOrder?: false; 37} & DefaultUnpreservedIteratorMatcherExecutorOptions;
The response is described by the following TypeScript type:
1export type IteratorMatcherExecutorResult = { 2 isMatching: boolean; 3 elapsedSteps: number; 4}
The IteratorMatcher expose an additional EventListener
helper class useful for testing purpose with Node.js EventEmitter.
Here a real world example extracted from the UT one of my package:
1import assert from "node:assert"; 2import { test } from "node:test"; 3 4import { TimeStore } from "@openally/timestore"; 5import { IteratorMatcher, EventListener } from "iterator-matcher"; 6 7test("Example with TimeStore, IteratorMatcher and EventListener", () => { 8 const store = new TimeStore({ ttl }) 9 .add("foo").add("bar"); 10 const eeListener = new EventListener(store, TimeStore.Expired); 11 12 // Doing some work with store 13 14 assert.equal(eeListener.listenerCount, 2); 15 const { isMatching } = new IteratorMatcher() 16 .expect("foo") 17 .expect("bar") 18 .execute(eeListener.names(), { allowNoMatchingValues: false }); 19 assert.ok(isMatching, true); 20});
Thanks goes to these wonderful people (emoji key):
Gentilhomme 💻 🐛 📖 🛡️ |
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
25 out of 25 merged PRs checked by a CI test -- score normalized to 10
Reason
project has 11 contributing companies or organizations
Details
Reason
no dangerous workflow patterns detected
Reason
update tool detected
Details
Reason
license file detected
Details
Reason
16 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
all dependencies are pinned
Details
Reason
security policy file detected
Details
Reason
GitHub workflow tokens follow principle of least privilege
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
1 existing vulnerabilities detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
Found 0/5 approved changesets -- score normalized to 0
Reason
project is not fuzzed
Details
Score
Last Scanned on 2024-11-26T07:32:40Z
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 Morejest-matcher-utils
A set of utility functions for expect and related packages
es-iterator-helpers
An ESnext spec-compliant iterator helpers shim/polyfill/replacement that works as far down as ES3.
es-get-iterator
Get an iterator for any JS language value. Works robustly across all environments, all versions.
stop-iteration-iterator
Firefox 17-26 iterators throw a StopIteration object to indicate "done". This normalizes it.