Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

array-fp-utils

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-fp-utils - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

20

dist/cjs/uniqueBy/uniqueBy.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.uniqueBy = void 0;
const uniqueBy = (getUniqueKey, reduceValue = (prevValue) => prevValue) => (arr) => {
const map = arr.reduce((acc, value) => {
exports.uniqueBy = exports._uniqueBy = void 0;
function _uniqueBy(arr, getUniqueKey, reduceValue = (prevValue) => prevValue) {
const map = new Map();
for (const value of arr) {
const key = getUniqueKey(value);
const existingValue = acc.get(key);
const existingValue = map.get(key);
if (!existingValue) {
acc.set(key, value);
map.set(key, value);
}
else {
acc.set(key, reduceValue(existingValue, value));
map.set(key, reduceValue(existingValue, value));
}
return acc;
}, new Map());
}
return Array.from(map.values());
};
}
exports._uniqueBy = _uniqueBy;
const uniqueBy = (getUniqueKey, reduceValue = (prevValue) => prevValue) => (arr) => _uniqueBy(arr, getUniqueKey, reduceValue);
exports.uniqueBy = uniqueBy;

@@ -1,14 +0,15 @@

export const uniqueBy = (getUniqueKey, reduceValue = (prevValue) => prevValue) => (arr) => {
const map = arr.reduce((acc, value) => {
export function _uniqueBy(arr, getUniqueKey, reduceValue = (prevValue) => prevValue) {
const map = new Map();
for (const value of arr) {
const key = getUniqueKey(value);
const existingValue = acc.get(key);
const existingValue = map.get(key);
if (!existingValue) {
acc.set(key, value);
map.set(key, value);
}
else {
acc.set(key, reduceValue(existingValue, value));
map.set(key, reduceValue(existingValue, value));
}
return acc;
}, new Map());
}
return Array.from(map.values());
};
}
export const uniqueBy = (getUniqueKey, reduceValue = (prevValue) => prevValue) => (arr) => _uniqueBy(arr, getUniqueKey, reduceValue);
import { Primitive } from '../types';
export declare function isDistinctArray(arr: Readonly<Array<Primitive>>): boolean;
export declare function isDistinctArray(arr: ReadonlyArray<Primitive>): boolean;
//# sourceMappingURL=isDistinctArray.d.ts.map
export type NonEmptyArray<T> = [T, ...T[]];
export type NonEmptyArrayAlt<A> = Array<A> & {
0: A;
export type NonEmptyArrayAlt<T> = Array<T> & {
0: T;
};
export type Primitive = string | number | boolean | bigint | symbol | null | undefined;
//# sourceMappingURL=types.d.ts.map

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

export declare const uniqueBy: <ValueType, KeyType_1>(getUniqueKey: (value: ValueType) => KeyType_1, reduceValue?: (prevValue: ValueType, nextValue: ValueType) => ValueType) => (arr: readonly ValueType[]) => ValueType[];
import { NonEmptyArray, NonEmptyArrayAlt } from '../types';
export declare function _uniqueBy<T extends ReadonlyArray<unknown> | Readonly<NonEmptyArray<unknown>> | Readonly<NonEmptyArrayAlt<unknown>>, K>(arr: T, getUniqueKey: (value: T[number]) => K, reduceValue?: (prevValue: T[number], nextValue: T[number]) => T[number]): T;
export declare const uniqueBy: <T extends readonly unknown[] | readonly [unknown, ...unknown[]] | Readonly<NonEmptyArrayAlt<unknown>>, K>(getUniqueKey: (value: T[number]) => K, reduceValue?: (prevValue: T[number], nextValue: T[number]) => T[number]) => (arr: T) => T;
//# sourceMappingURL=uniqueBy.d.ts.map
{
"name": "array-fp-utils",
"version": "0.4.0",
"version": "0.5.0",
"description": "Array utilities for functional programming in TypeScript.",

@@ -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

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