Comparing version 0.0.20 to 0.0.21
@@ -15,4 +15,4 @@ "use strict"; | ||
function lazy(other) { | ||
var set = new Set(other); | ||
return function (value) { | ||
var set = new Set(other); | ||
if (!set.has(value)) { | ||
@@ -19,0 +19,0 @@ return { |
@@ -18,2 +18,3 @@ import { LazyResult } from './_reduceLazy'; | ||
*/ | ||
export declare function filter<T, S extends T>(array: readonly T[], fn: (value: T) => value is S): S[]; | ||
export declare function filter<T>(array: readonly T[], fn: Pred<T, boolean>): T[]; | ||
@@ -34,6 +35,12 @@ /** | ||
*/ | ||
export declare function filter<T, S extends T>(fn: (input: T) => input is S): (array: readonly T[]) => S[]; | ||
export declare function filter<T>(fn: Pred<T, boolean>): (array: readonly T[]) => T[]; | ||
export declare namespace filter { | ||
function indexed<T, K>(array: readonly T[], fn: PredIndexed<T, boolean>): K[]; | ||
function indexed<T, K>(fn: PredIndexed<T, boolean>): (array: readonly T[]) => K[]; | ||
function indexed<T, S extends T>(array: readonly T[], fn: (input: T, index: number, array: T[]) => input is S): S[]; | ||
function indexed<T>(array: readonly T[], fn: PredIndexed<T, boolean>): T[]; | ||
/** | ||
* @data_last | ||
*/ | ||
function indexed<T, S extends T>(fn: (input: T, index: number, array: T[]) => input is S): (array: readonly T[]) => S[]; | ||
function indexed<T>(fn: PredIndexed<T, boolean>): (array: readonly T[]) => T[]; | ||
const lazy: <T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<T>; | ||
@@ -40,0 +47,0 @@ const lazyIndexed: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<T>) & { |
@@ -6,11 +6,30 @@ "use strict"; | ||
var _counter_1 = require("./_counter"); | ||
function assertType(data) { | ||
return data; | ||
} | ||
function isNumber(data) { | ||
return typeof data === 'number'; | ||
} // TODO Refactor to remeda function | ||
describe('data_first', function () { | ||
it('filter', function () { | ||
var result = filter_1.filter([1, 2, 3], function (x) { return x % 2 === 1; }); | ||
assertType(result); // Type test | ||
expect(result).toEqual([1, 3]); | ||
}); | ||
it('data_first with typescript guard', function () { | ||
var result = filter_1.filter([1, 2, 3, 'abc', true], isNumber); | ||
assertType(result); // Type test | ||
expect(result).toEqual([1, 2, 3]); | ||
}); | ||
it('filter.indexed', function () { | ||
var result = filter_1.filter.indexed([1, 2, 3], function (x, i) { return x % 2 === 1 && i !== 1; }); | ||
assertType(result); // Type test | ||
expect(result).toEqual([1, 3]); | ||
}); | ||
it('filter.indexed with typescript guard', function () { | ||
var result = filter_1.filter.indexed([1, 2, 3, false, "text"], // Type (1 | 2 | 3 | false | "text")[] | ||
isNumber); | ||
assertType(result); // Type test (1 | 2 | 3)[] | ||
expect(result).toEqual([1, 2, 3]); | ||
}); | ||
}); | ||
@@ -22,7 +41,32 @@ describe('data_last', function () { | ||
expect(counter.count).toHaveBeenCalledTimes(2); | ||
assertType(result); // Type test (1 | 2 | 3)[] | ||
expect(result).toEqual([1, 3]); | ||
}); | ||
it('filter', function () { | ||
var counter = _counter_1.createCounter(); | ||
var result = pipe_1.pipe([1, 2, 3], filter_1.filter(function (x) { return x % 2 === 1; }), counter.fn()); | ||
expect(counter.count).toHaveBeenCalledTimes(2); | ||
assertType(result); // Type test (1 | 2 | 3)[] | ||
expect(result).toEqual([1, 3]); | ||
}); | ||
it('filter with typescript guard', function () { | ||
var counter = _counter_1.createCounter(); | ||
var result = pipe_1.pipe([1, 2, 3, false, "text"], // Type (1 | 2 | 3 | false | "text")[] | ||
filter_1.filter(isNumber), counter.fn()); | ||
expect(counter.count).toHaveBeenCalledTimes(3); | ||
assertType(result); // Type test (1 | 2 | 3)[] | ||
expect(result).toEqual([1, 2, 3]); | ||
}); | ||
it('filter.indexed with typescript guard', function () { | ||
var counter = _counter_1.createCounter(); | ||
var result = pipe_1.pipe([1, 2, 3, false, "text"], // Type (1 | 2 | 3 | false | "text")[] | ||
filter_1.filter.indexed(isNumber), counter.fn()); | ||
assertType(result); // Type test (1 | 2 | 3)[] | ||
expect(counter.count).toHaveBeenCalledTimes(3); | ||
expect(result).toEqual([1, 2, 3]); | ||
}); | ||
it('filter.indexed', function () { | ||
var counter = _counter_1.createCounter(); | ||
var result = pipe_1.pipe([1, 2, 3], filter_1.filter.indexed(function (x, i) { return x % 2 === 1 && i !== 1; }), counter.fn()); | ||
assertType(result); // Type test (1 | 2 | 3)[] | ||
expect(counter.count).toHaveBeenCalledTimes(2); | ||
@@ -29,0 +73,0 @@ expect(result).toEqual([1, 3]); |
@@ -30,2 +30,3 @@ export * from './addProp'; | ||
export * from './mapKeys'; | ||
export * from './mapValues'; | ||
export * from './merge'; | ||
@@ -32,0 +33,0 @@ export * from './mergeAll'; |
@@ -35,2 +35,3 @@ "use strict"; | ||
__export(require("./mapKeys")); | ||
__export(require("./mapValues")); | ||
__export(require("./merge")); | ||
@@ -37,0 +38,0 @@ __export(require("./mergeAll")); |
@@ -12,5 +12,3 @@ /** | ||
*/ | ||
export declare function mapKeys<T, S>(object: T, fn: (key: keyof T, value: T[keyof T]) => any): { | ||
[x: string]: any; | ||
}; | ||
export declare function mapKeys<T, S extends string | number | symbol>(object: T, fn: (key: keyof T, value: T[keyof T]) => S): Record<S, T[keyof T]>; | ||
/** | ||
@@ -26,5 +24,3 @@ * Maps keys of `object` and keeps the same values. | ||
*/ | ||
export declare function mapKeys<T, S>(fn: (key: keyof T, value: T[keyof T]) => any): (object: T) => { | ||
[x: string]: any; | ||
}; | ||
export declare function mapKeys<T, S extends string | number | symbol>(fn: (key: keyof T, value: T[keyof T]) => S): (object: T) => Record<S, T[keyof T]>; | ||
//# sourceMappingURL=mapKeys.d.ts.map |
@@ -12,4 +12,4 @@ import { purry } from './purry'; | ||
function lazy(other) { | ||
var set = new Set(other); | ||
return function (value) { | ||
var set = new Set(other); | ||
if (!set.has(value)) { | ||
@@ -16,0 +16,0 @@ return { |
@@ -18,2 +18,3 @@ import { LazyResult } from './_reduceLazy'; | ||
*/ | ||
export declare function filter<T, S extends T>(array: readonly T[], fn: (value: T) => value is S): S[]; | ||
export declare function filter<T>(array: readonly T[], fn: Pred<T, boolean>): T[]; | ||
@@ -34,6 +35,12 @@ /** | ||
*/ | ||
export declare function filter<T, S extends T>(fn: (input: T) => input is S): (array: readonly T[]) => S[]; | ||
export declare function filter<T>(fn: Pred<T, boolean>): (array: readonly T[]) => T[]; | ||
export declare namespace filter { | ||
function indexed<T, K>(array: readonly T[], fn: PredIndexed<T, boolean>): K[]; | ||
function indexed<T, K>(fn: PredIndexed<T, boolean>): (array: readonly T[]) => K[]; | ||
function indexed<T, S extends T>(array: readonly T[], fn: (input: T, index: number, array: T[]) => input is S): S[]; | ||
function indexed<T>(array: readonly T[], fn: PredIndexed<T, boolean>): T[]; | ||
/** | ||
* @data_last | ||
*/ | ||
function indexed<T, S extends T>(fn: (input: T, index: number, array: T[]) => input is S): (array: readonly T[]) => S[]; | ||
function indexed<T>(fn: PredIndexed<T, boolean>): (array: readonly T[]) => T[]; | ||
const lazy: <T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<T>; | ||
@@ -40,0 +47,0 @@ const lazyIndexed: (<T>(fn: PredIndexedOptional<T, boolean>) => (value: T, index?: number | undefined, array?: T[] | undefined) => LazyResult<T>) & { |
import { pipe } from './pipe'; | ||
import { filter } from './filter'; | ||
import { createCounter } from './_counter'; | ||
function assertType(data) { | ||
return data; | ||
} | ||
function isNumber(data) { | ||
return typeof data === 'number'; | ||
} // TODO Refactor to remeda function | ||
describe('data_first', function () { | ||
it('filter', function () { | ||
var result = filter([1, 2, 3], function (x) { return x % 2 === 1; }); | ||
assertType(result); // Type test | ||
expect(result).toEqual([1, 3]); | ||
}); | ||
it('data_first with typescript guard', function () { | ||
var result = filter([1, 2, 3, 'abc', true], isNumber); | ||
assertType(result); // Type test | ||
expect(result).toEqual([1, 2, 3]); | ||
}); | ||
it('filter.indexed', function () { | ||
var result = filter.indexed([1, 2, 3], function (x, i) { return x % 2 === 1 && i !== 1; }); | ||
assertType(result); // Type test | ||
expect(result).toEqual([1, 3]); | ||
}); | ||
it('filter.indexed with typescript guard', function () { | ||
var result = filter.indexed([1, 2, 3, false, "text"], // Type (1 | 2 | 3 | false | "text")[] | ||
isNumber); | ||
assertType(result); // Type test (1 | 2 | 3)[] | ||
expect(result).toEqual([1, 2, 3]); | ||
}); | ||
}); | ||
@@ -19,7 +38,32 @@ describe('data_last', function () { | ||
expect(counter.count).toHaveBeenCalledTimes(2); | ||
assertType(result); // Type test (1 | 2 | 3)[] | ||
expect(result).toEqual([1, 3]); | ||
}); | ||
it('filter', function () { | ||
var counter = createCounter(); | ||
var result = pipe([1, 2, 3], filter(function (x) { return x % 2 === 1; }), counter.fn()); | ||
expect(counter.count).toHaveBeenCalledTimes(2); | ||
assertType(result); // Type test (1 | 2 | 3)[] | ||
expect(result).toEqual([1, 3]); | ||
}); | ||
it('filter with typescript guard', function () { | ||
var counter = createCounter(); | ||
var result = pipe([1, 2, 3, false, "text"], // Type (1 | 2 | 3 | false | "text")[] | ||
filter(isNumber), counter.fn()); | ||
expect(counter.count).toHaveBeenCalledTimes(3); | ||
assertType(result); // Type test (1 | 2 | 3)[] | ||
expect(result).toEqual([1, 2, 3]); | ||
}); | ||
it('filter.indexed with typescript guard', function () { | ||
var counter = createCounter(); | ||
var result = pipe([1, 2, 3, false, "text"], // Type (1 | 2 | 3 | false | "text")[] | ||
filter.indexed(isNumber), counter.fn()); | ||
assertType(result); // Type test (1 | 2 | 3)[] | ||
expect(counter.count).toHaveBeenCalledTimes(3); | ||
expect(result).toEqual([1, 2, 3]); | ||
}); | ||
it('filter.indexed', function () { | ||
var counter = createCounter(); | ||
var result = pipe([1, 2, 3], filter.indexed(function (x, i) { return x % 2 === 1 && i !== 1; }), counter.fn()); | ||
assertType(result); // Type test (1 | 2 | 3)[] | ||
expect(counter.count).toHaveBeenCalledTimes(2); | ||
@@ -26,0 +70,0 @@ expect(result).toEqual([1, 3]); |
@@ -30,2 +30,3 @@ export * from './addProp'; | ||
export * from './mapKeys'; | ||
export * from './mapValues'; | ||
export * from './merge'; | ||
@@ -32,0 +33,0 @@ export * from './mergeAll'; |
@@ -30,2 +30,3 @@ export * from './addProp'; | ||
export * from './mapKeys'; | ||
export * from './mapValues'; | ||
export * from './merge'; | ||
@@ -32,0 +33,0 @@ export * from './mergeAll'; |
@@ -12,5 +12,3 @@ /** | ||
*/ | ||
export declare function mapKeys<T, S>(object: T, fn: (key: keyof T, value: T[keyof T]) => any): { | ||
[x: string]: any; | ||
}; | ||
export declare function mapKeys<T, S extends string | number | symbol>(object: T, fn: (key: keyof T, value: T[keyof T]) => S): Record<S, T[keyof T]>; | ||
/** | ||
@@ -26,5 +24,3 @@ * Maps keys of `object` and keeps the same values. | ||
*/ | ||
export declare function mapKeys<T, S>(fn: (key: keyof T, value: T[keyof T]) => any): (object: T) => { | ||
[x: string]: any; | ||
}; | ||
export declare function mapKeys<T, S extends string | number | symbol>(fn: (key: keyof T, value: T[keyof T]) => S): (object: T) => Record<S, T[keyof T]>; | ||
//# sourceMappingURL=mapKeys.d.ts.map |
{ | ||
"name": "remeda", | ||
"version": "0.0.20", | ||
"version": "0.0.21", | ||
"description": "A utility library for JavaScript and Typescript.", | ||
@@ -5,0 +5,0 @@ "main": "dist/commonjs/index.js", |
@@ -49,4 +49,4 @@ import { purry } from './purry'; | ||
export function lazy<T>(other: T[]) { | ||
const set = new Set(other); | ||
return (value: T): LazyResult<T> => { | ||
const set = new Set(other); | ||
if (!set.has(value)) { | ||
@@ -53,0 +53,0 @@ return { |
@@ -5,8 +5,24 @@ import { pipe } from './pipe'; | ||
function assertType<T>(data: T): T { | ||
return data | ||
} | ||
function isNumber<T>(data: T): data is Extract<T, number> { | ||
return typeof data === 'number' | ||
} // TODO Refactor to remeda function | ||
describe('data_first', () => { | ||
it('filter', () => { | ||
const result = filter([1, 2, 3] as const, x => x % 2 === 1); | ||
assertType<(1 | 2 | 3)[]>(result) // Type test | ||
expect(result).toEqual([1, 3]); | ||
}); | ||
it('data_first with typescript guard', () => { | ||
const result = filter([1, 2, 3, 'abc', true] as const, isNumber); | ||
assertType<(1 | 2 | 3)[]>(result) // Type test | ||
expect(result).toEqual([1, 2, 3]); | ||
}); | ||
it('filter.indexed', () => { | ||
@@ -17,4 +33,14 @@ const result = filter.indexed( | ||
); | ||
assertType<(1 | 2 | 3)[]>(result) // Type test | ||
expect(result).toEqual([1, 3]); | ||
}); | ||
it('filter.indexed with typescript guard', () => { | ||
const result = filter.indexed( | ||
[1, 2, 3, false, "text"] as const, // Type (1 | 2 | 3 | false | "text")[] | ||
isNumber | ||
); | ||
assertType<(1 | 2 | 3)[]>(result) // Type test (1 | 2 | 3)[] | ||
expect(result).toEqual([1, 2, 3]); | ||
}); | ||
}); | ||
@@ -31,4 +57,40 @@ | ||
expect(counter.count).toHaveBeenCalledTimes(2); | ||
assertType<(1 | 2 | 3)[]>(result) // Type test (1 | 2 | 3)[] | ||
expect(result).toEqual([1, 3]); | ||
}); | ||
it('filter', () => { | ||
const counter = createCounter(); | ||
const result = pipe( | ||
[1, 2, 3] as const, | ||
filter(x => x % 2 === 1), | ||
counter.fn() | ||
); | ||
expect(counter.count).toHaveBeenCalledTimes(2); | ||
assertType<(1 | 2 | 3)[]>(result) // Type test (1 | 2 | 3)[] | ||
expect(result).toEqual([1, 3]); | ||
}); | ||
it('filter with typescript guard', () => { | ||
const counter = createCounter(); | ||
const result = pipe( | ||
[1, 2, 3, false, "text"] as const, // Type (1 | 2 | 3 | false | "text")[] | ||
filter(isNumber), | ||
counter.fn() | ||
); | ||
expect(counter.count).toHaveBeenCalledTimes(3); | ||
assertType<(1 | 2 | 3)[]>(result) // Type test (1 | 2 | 3)[] | ||
expect(result).toEqual([1, 2, 3]); | ||
}); | ||
it('filter.indexed with typescript guard', () => { | ||
const counter = createCounter(); | ||
const result = pipe( | ||
[1, 2, 3, false, "text"] as const, // Type (1 | 2 | 3 | false | "text")[] | ||
filter.indexed(isNumber), | ||
counter.fn() | ||
); | ||
assertType<(1 | 2 | 3)[]>(result) // Type test (1 | 2 | 3)[] | ||
expect(counter.count).toHaveBeenCalledTimes(3); | ||
expect(result).toEqual([1, 2, 3]); | ||
}); | ||
it('filter.indexed', () => { | ||
@@ -41,2 +103,3 @@ const counter = createCounter(); | ||
); | ||
assertType<(1 | 2 | 3)[]>(result) // Type test (1 | 2 | 3)[] | ||
expect(counter.count).toHaveBeenCalledTimes(2); | ||
@@ -43,0 +106,0 @@ expect(result).toEqual([1, 3]); |
@@ -21,2 +21,3 @@ import { purry } from './purry'; | ||
*/ | ||
export function filter<T, S extends T>(array: readonly T[], fn: (value: T) => value is S): S[]; | ||
export function filter<T>(array: readonly T[], fn: Pred<T, boolean>): T[]; | ||
@@ -38,2 +39,3 @@ | ||
*/ | ||
export function filter<T, S extends T>(fn: (input: T) => input is S): (array: readonly T[]) => S[]; | ||
export function filter<T>(fn: Pred<T, boolean>): (array: readonly T[]) => T[]; | ||
@@ -76,9 +78,19 @@ | ||
export namespace filter { | ||
export function indexed<T, K>( | ||
export function indexed<T, S extends T>( | ||
array: readonly T[], | ||
fn: (input: T, index: number, array: T[]) => input is S | ||
): S[]; | ||
export function indexed<T>( | ||
array: readonly T[], | ||
fn: PredIndexed<T, boolean> | ||
): K[]; | ||
export function indexed<T, K>( | ||
): T[]; | ||
/** | ||
* @data_last | ||
*/ | ||
export function indexed<T, S extends T>( | ||
fn: (input: T, index: number, array: T[]) => input is S | ||
): (array: readonly T[]) => S[]; | ||
export function indexed<T>( | ||
fn: PredIndexed<T, boolean> | ||
): (array: readonly T[]) => K[]; | ||
): (array: readonly T[]) => T[]; | ||
export function indexed() { | ||
@@ -85,0 +97,0 @@ return purry(_filter(true), arguments, filter.lazyIndexed); |
@@ -30,2 +30,3 @@ export * from './addProp'; | ||
export * from './mapKeys'; | ||
export * from './mapValues'; | ||
export * from './merge'; | ||
@@ -32,0 +33,0 @@ export * from './mergeAll'; |
@@ -12,6 +12,6 @@ /** | ||
*/ | ||
export function mapKeys<T, S>( | ||
export function mapKeys<T, S extends string | number | symbol>( | ||
object: T, | ||
fn: (key: keyof T, value: T[keyof T]) => any | ||
): { [x: string]: any }; | ||
fn: (key: keyof T, value: T[keyof T]) => S | ||
): Record<S, T[keyof T]>; | ||
@@ -28,5 +28,5 @@ /** | ||
*/ | ||
export function mapKeys<T, S>( | ||
fn: (key: keyof T, value: T[keyof T]) => any | ||
): (object: T) => { [x: string]: any }; | ||
export function mapKeys<T, S extends string | number | symbol>( | ||
fn: (key: keyof T, value: T[keyof T]) => S | ||
): (object: T) => Record<S, T[keyof T]>; | ||
@@ -33,0 +33,0 @@ export function mapKeys(arg1: any, arg2?: any): any { |
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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1239232
856
42978