Socket
Socket
Sign inDemoInstall

gensequence

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gensequence - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

lib/src/GenSequence.perf.d.ts

3

CHANGELOG.md
# Release Notes
# 1.1.0
* Added `all` and `any` - thanks to @sea1jxr
# 1.0.0

@@ -4,0 +7,0 @@ * Added full test coverage

@@ -23,2 +23,4 @@ export declare type Maybe<T> = T | undefined;

take(n: number): Sequence<T>;
all(fnFilter: (t: T) => boolean): boolean;
any(fnFilter: (t: T) => boolean): boolean;
first(fnFilter?: (t: T) => boolean, defaultValue?: T): Maybe<T>;

@@ -69,2 +71,4 @@ first(fnFilter: (t: T) => boolean, defaultValue: T): T;

export declare function concatMap<T, U>(fn: (t: T) => Iterable<U>, i: Iterable<T>): IterableIterator<U>;
export declare function any<T>(fn: (t: T) => boolean, i: Iterable<T>): boolean;
export declare function all<T>(fn: (t: T) => boolean, i: Iterable<T>): boolean;
export declare function first<T>(fn: Maybe<(t: T) => boolean>, defaultValue: Maybe<T>, i: Iterable<T>): Maybe<T>;

@@ -71,0 +75,0 @@ export declare function toIterator<T>(i: Iterable<T>): IterableIterator<T>;

@@ -41,2 +41,8 @@ "use strict";

},
all: (fnFilter) => {
return all(fnFilter, i);
},
any: (fnFilter) => {
return any(fnFilter, i);
},
first: (fnFilter, defaultValue) => {

@@ -194,2 +200,20 @@ return first(fnFilter, defaultValue, i);

exports.concatMap = concatMap;
function any(fn, i) {
for (const t of i) {
if (fn(t)) {
return true;
}
}
return false;
}
exports.any = any;
function all(fn, i) {
for (const t of i) {
if (!fn(t)) {
return false;
}
}
return true;
}
exports.all = all;
function first(fn, defaultValue, i) {

@@ -196,0 +220,0 @@ fn = fn || (() => true);

12

package.json
{
"name": "gensequence",
"version": "1.0.0",
"version": "1.1.0",
"description": "Small library to simplify working with Generators and Iterators in Javascript / Typescript",

@@ -10,10 +10,11 @@ "main": "lib/index.js",

"@types/chai": "^3.4.34",
"@types/mocha": "^2.2.33",
"@types/mocha": "^2.2.39",
"@types/node": "^7.0.5",
"chai": "^3.5.0",
"coveralls": "^2.11.15",
"coveralls": "^2.11.16",
"mocha": "^3.2.0",
"nyc": "^10.1.2",
"rimraf": "^2.5.4",
"ts-node": "^2.0.0",
"typescript": "^2.1.5"
"ts-node": "^2.1.0",
"typescript": "^2.1.6"
},

@@ -25,2 +26,3 @@ "scripts": {

"test": "mocha lib/**/*.test.js",
"perf": "mocha lib/**/*.perf.js",
"build": "tsc -p .",

@@ -27,0 +29,0 @@ "watch": "tsc -w -p .",

@@ -124,2 +124,4 @@ # GenSequence

- `.take(n)` -- take the next *n* entries in the sequence.
- `.all()` -- true if all values in the sequence return true for *fn(value)* or the sequence is empty.
- `.any()` -- true if any value in the sequence exists where *fn(value)* returns true.
- `.first()` -- return the next value in the sequence.

@@ -126,0 +128,0 @@ - `.first(fn)` -- return the next value in the sequence where *fn(value)* return true.

@@ -250,2 +250,52 @@ import { genSequence, sequenceFromObject, sequenceFromRegExpMatch } from './GenSequence';

});
it('test any with match', () => {
const values = [1, 2, 3, 4];
expect(genSequence(values).any(a => a > 3)).to.be.true;
});
it('test any with no match', () => {
const values = [0, 1, 2, 3];
expect(genSequence(values).any(a => a > 3)).to.be.false;
});
it('test any with empty set', () => {
const values = [];
expect(genSequence(values).any(a => a > 3)).to.be.false;
});
it('test any exits early', () => {
const values = [1, 2, 3, 4];
let count: number = 0;
genSequence(values).any(a => {
count++;
return a == 3;
});
expect(count).to.be.equal(3);
});
it('test all where all values match', () => {
const values = [1, 2, 3, 4];
expect(genSequence(values).all(a => a >= 0)).to.be.true;
});
it('test all with one value that does not match', () => {
const values = [0, 1];
expect(genSequence(values).all(a => a != 1)).to.be.false;
});
it('test all with empty set', () => {
const values = [];
expect(genSequence(values).all(a => a > 3)).to.be.true;
});
it('test all exits early', () => {
const values = [1, 2, 3, 4];
let count: number = 0;
genSequence(values).all(a => {
count++;
return a < 3;
});
expect(count).to.be.equal(3);
});
});

@@ -26,2 +26,4 @@

take(n: number): Sequence<T>;
all(fnFilter: (t: T)=> boolean): boolean;
any(fnFilter: (t: T)=> boolean): boolean;
first(fnFilter?: (t: T)=> boolean, defaultValue?: T): Maybe<T>;

@@ -80,2 +82,8 @@ first(fnFilter: (t: T)=> boolean, defaultValue: T): T;

},
all: (fnFilter: (t: T) => boolean): boolean => {
return all(fnFilter, i);
},
any: (fnFilter: (t: T) => boolean): boolean => {
return any(fnFilter, i);
},
first: (fnFilter: (t: T) => boolean, defaultValue: T): T => {

@@ -250,2 +258,20 @@ return first(fnFilter, defaultValue, i) as T;

export function any<T>(fn: (t: T) => boolean, i: Iterable<T>): boolean {
for (const t of i) {
if (fn(t)) {
return true;
}
}
return false;
}
export function all<T>(fn: (t: T) => boolean, i: Iterable<T>): boolean {
for (const t of i) {
if (!fn(t)) {
return false;
}
}
return true;
}
export function first<T>(fn: Maybe<(t: T) => boolean>, defaultValue: Maybe<T>, i: Iterable<T>): Maybe<T>;

@@ -252,0 +278,0 @@ export function first<T>(fn: (t: T) => boolean, defaultValue: T, i: Iterable<T>): T {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc