🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

fromfrom

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fromfrom - npm Package Compare versions

Comparing version

to
1.2.0

dist/lib/test.js

52

dist/fromfrom.es5.js

@@ -136,2 +136,32 @@ /**

const createWithoutIterable = (iterator, withoutItems, comparePredicate) => {
if (!comparePredicate) {
const withoutSet = new Set(withoutItems);
// fast path, create a filter iterable with the `Set.prototype.has` function call
return createFilterIterable(iterator, item => !withoutSet.has(item));
}
else {
// Must compare each item for equality for each item
return new IterableCreatorIterable(function* filter() {
// cache already found results
const cache = new Set();
outer: for (const item of iterator) {
// fast path, this item was already found, don't loop
if (cache.has(item))
continue;
// slow path, loop over each item in the set, determine if it matches the ComparePredicate
for (const withoutItem of withoutItems) {
// if the item is found, add it to the cache and skip the item
if (comparePredicate(item, withoutItem)) {
cache.add(item);
continue outer;
}
}
// we can safely yield the item
yield item;
}
});
}
};
const identityPredicateFn = (x) => x;

@@ -431,2 +461,24 @@ const defaultComparer = (a, b) => {

/**
* Returns elements from a sequence as long as they don't exist in the specified iterable items.
*
* @param items The provided set of items that should not be in the returned Sequence.
* @param predicate The optional predicate that determines if two TItem items are equal.
*
* @example
* ```ts
* // returns [2, 4, 6]
* from([1, 2, 3, 4, 5, 6])
* .without([1, 3, 5])
* .toArray();
*
* // returns [{ id: 1 }, { id: 3 }]
* from([{ id: 1 }, { id: 2 }, { id: 3 }])
* .without([{ id: 2 }], (a, b) => a.id === b.id)
* .toArray();
* ```
*/
without(items, predicate) {
return new Sequence(createWithoutIterable(this._iterable, items, predicate));
}
/**
* Converts the sequence to an array

@@ -433,0 +485,0 @@ *

@@ -142,2 +142,32 @@ (function (global, factory) {

const createWithoutIterable = (iterator, withoutItems, comparePredicate) => {
if (!comparePredicate) {
const withoutSet = new Set(withoutItems);
// fast path, create a filter iterable with the `Set.prototype.has` function call
return createFilterIterable(iterator, item => !withoutSet.has(item));
}
else {
// Must compare each item for equality for each item
return new IterableCreatorIterable(function* filter() {
// cache already found results
const cache = new Set();
outer: for (const item of iterator) {
// fast path, this item was already found, don't loop
if (cache.has(item))
continue;
// slow path, loop over each item in the set, determine if it matches the ComparePredicate
for (const withoutItem of withoutItems) {
// if the item is found, add it to the cache and skip the item
if (comparePredicate(item, withoutItem)) {
cache.add(item);
continue outer;
}
}
// we can safely yield the item
yield item;
}
});
}
};
const identityPredicateFn = (x) => x;

@@ -437,2 +467,24 @@ const defaultComparer = (a, b) => {

/**
* Returns elements from a sequence as long as they don't exist in the specified iterable items.
*
* @param items The provided set of items that should not be in the returned Sequence.
* @param predicate The optional predicate that determines if two TItem items are equal.
*
* @example
* ```ts
* // returns [2, 4, 6]
* from([1, 2, 3, 4, 5, 6])
* .without([1, 3, 5])
* .toArray();
*
* // returns [{ id: 1 }, { id: 3 }]
* from([{ id: 1 }, { id: 2 }, { id: 3 }])
* .without([{ id: 2 }], (a, b) => a.id === b.id)
* .toArray();
* ```
*/
without(items, predicate) {
return new Sequence(createWithoutIterable(this._iterable, items, predicate));
}
/**
* Converts the sequence to an array

@@ -439,0 +491,0 @@ *

@@ -15,2 +15,3 @@ "use strict";

const skipWhile_1 = require("./transforms/skipWhile");
const without_1 = require("./transforms/without");
const identityPredicateFn = (x) => x;

@@ -310,2 +311,24 @@ const defaultComparer = (a, b) => {

/**
* Returns elements from a sequence as long as they don't exist in the specified iterable items.
*
* @param items The provided set of items that should not be in the returned Sequence.
* @param predicate The optional predicate that determines if two TItem items are equal.
*
* @example
* ```ts
* // returns [2, 4, 6]
* from([1, 2, 3, 4, 5, 6])
* .without([1, 3, 5])
* .toArray();
*
* // returns [{ id: 1 }, { id: 3 }]
* from([{ id: 1 }, { id: 2 }, { id: 3 }])
* .without([{ id: 2 }], (a, b) => a.id === b.id)
* .toArray();
* ```
*/
without(items, predicate) {
return new Sequence(without_1.createWithoutIterable(this._iterable, items, predicate));
}
/**
* Converts the sequence to an array

@@ -312,0 +335,0 @@ *

22

dist/types/Sequence.d.ts

@@ -1,2 +0,2 @@

import { KeySelectorFn, ComparerFn, PredicateFn, MapFn, CallbackFn, Grouping, ReduceCallbackFn, NumberKeyedObject, StringKeyedObject } from "./types";
import { KeySelectorFn, ComparerFn, PredicateFn, MapFn, CallbackFn, Grouping, ReduceCallbackFn, NumberKeyedObject, StringKeyedObject, ComparePredicate } from "./types";
/**

@@ -317,2 +317,22 @@ * A sequence of items

/**
* Returns elements from a sequence as long as they don't exist in the specified iterable items.
*
* @param items The provided set of items that should not be in the returned Sequence.
* @param predicate The optional predicate that determines if two TItem items are equal.
*
* @example
* ```ts
* // returns [2, 4, 6]
* from([1, 2, 3, 4, 5, 6])
* .without([1, 3, 5])
* .toArray();
*
* // returns [{ id: 1 }, { id: 3 }]
* from([{ id: 1 }, { id: 2 }, { id: 3 }])
* .without([{ id: 2 }], (a, b) => a.id === b.id)
* .toArray();
* ```
*/
without(items: Iterable<TItem>, predicate?: ComparePredicate<TItem>): Sequence<TItem>;
/**
* Converts the sequence to an array

@@ -319,0 +339,0 @@ *

@@ -8,2 +8,3 @@ export declare type MapFn<TItem, TResult> = (item: TItem) => TResult;

export declare type IteratorCreatorFn<TResult> = () => Iterator<TResult>;
export declare type ComparePredicate<TItem> = (a: TItem, b: TItem) => boolean;
export interface Grouping<TKey, TElement> {

@@ -10,0 +11,0 @@ key: TKey;

2

package.json
{
"name": "fromfrom",
"version": "1.1.1",
"version": "1.2.0",
"description": "LINQ inspired library to transform sequences of data",

@@ -5,0 +5,0 @@ "keywords": [

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