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

@appolo/utils

Package Overview
Dependencies
Maintainers
2
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@appolo/utils - npm Package Compare versions

Comparing version 8.0.48 to 8.0.49

46

lib/arrays.js

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

found = true;
break;
}

@@ -243,2 +244,47 @@ }

}
static intersection(arr, arr2) {
return Arrays.intersectionBy(arr, arr2, item => item);
}
static intersectionBy(arr, arr2, criteria) {
let out = [], index = new Set;
if (!arr || !arr.length || !arr2 || !arr2.length) {
return [];
}
for (let i = 0; i < arr.length; i++) {
let item1 = arr[i], key1 = criteria(item1, i);
if (index.has(key1)) {
continue;
}
for (let j = 0; j < arr2.length; j++) {
let item2 = arr2[j], key2 = criteria(item2, j);
if (key1 === key2) {
out.push(item1);
index.add(key1);
break;
}
}
}
return out;
}
static union(arr, arr2) {
return Arrays.unionBy(arr, arr2, item => item);
}
static unionBy(arr, arr2, criteria) {
let out = [], index = new Set();
for (let i = 0; i < (arr || []).length; i++) {
let item1 = arr[i], key1 = criteria(item1, i);
if (!index.has(key1)) {
out.push(item1);
index.add(key1);
}
}
for (let j = 0; j < (arr2 || []).length; j++) {
let item2 = arr2[j], key2 = criteria(item2, j);
if (!index.has(key2)) {
out.push(item2);
index.add(key2);
}
}
return out;
}
static countBy(arr, criteria) {

@@ -245,0 +291,0 @@ if (!arr || !arr.length) {

74

lib/arrays.ts

@@ -118,3 +118,5 @@ import {Classes} from "./classes";

public static groupBy<T>(arr: T[], key: string | number | ((item: T) => string | number)): { [index: string]: T[] } {
public static groupBy<T>(arr: T[], key: string | number | ((item: T) => string | number)): {
[index: string]: T[]
} {

@@ -134,3 +136,5 @@ let output: { [index: string]: T[] } = {};

public static keyBy<T extends any>(arr: T[], key?: string | ((item: T, index: number) => string)): { [index: string]: T } {
public static keyBy<T extends any>(arr: T[], key?: string | ((item: T, index: number) => string)): {
[index: string]: T
} {

@@ -255,3 +259,5 @@ if (!key) {

public static forEach<T>(arr: T[] | { [index: string]: T }, criteria: (value: T, i?: number | string) => void): void {
public static forEach<T>(arr: T[] | {
[index: string]: T
}, criteria: (value: T, i?: number | string) => void): void {
if (!arr) {

@@ -311,3 +317,3 @@ return;

public static differenceBy<T>(arr: T[], arr2: T[], criteria: (value: T, i?: number) => any): T[] {
let out = [];
let out: T[] = [];
if (!arr || !arr.length) {

@@ -328,2 +334,3 @@ return []

found = true;
break;
}

@@ -340,4 +347,61 @@ }

public static countBy<T>(arr: T[], criteria: (value: T, i?: number) => string | number): { [index: string]: number } {
public static intersection<T>(arr: T[], arr2: T[]): T[] {
return Arrays.intersectionBy(arr, arr2, item => item);
}
public static intersectionBy<T>(arr: T[], arr2: T[], criteria: (value: T, i?: number) => any): T[] {
let out: T[] = [], index = new Set<string>
if (!arr || !arr.length || !arr2 || !arr2.length) {
return []
}
for (let i = 0; i < arr.length; i++) {
let item1 = arr[i], key1 = criteria(item1, i);
if (index.has(key1)) {
continue;
}
for (let j = 0; j < arr2.length; j++) {
let item2 = arr2[j], key2 = criteria(item2, j);
if (key1 === key2) {
out.push(item1);
index.add(key1);
break;
}
}
}
return out;
}
public static union<T>(arr: T[], arr2: T[]): T[] {
return Arrays.unionBy(arr, arr2, item => item);
}
public static unionBy<T>(arr: T[], arr2: T[], criteria: (value: T, i?: number) => any): T[] {
let out: T[] = [], index = new Set<string>();
for (let i = 0; i < (arr || []).length; i++) {
let item1 = arr[i], key1 = criteria(item1, i);
if (!index.has(key1)) {
out.push(item1);
index.add(key1);
}
}
for (let j = 0; j < (arr2 || []).length; j++) {
let item2 = arr2[j], key2 = criteria(item2, j);
if (!index.has(key2)) {
out.push(item2);
index.add(key2);
}
}
return out;
}
public static countBy<T>(arr: T[], criteria: (value: T, i?: number) => string | number): {
[index: string]: number
} {
if (!arr || !arr.length) {

@@ -344,0 +408,0 @@ return {};

@@ -72,2 +72,10 @@ "use strict";

}
intersection(arr2) {
this._value = arrays_1.Arrays.intersection(this._value, arr2);
return this;
}
union(arr2) {
this._value = arrays_1.Arrays.union(this._value, arr2);
return this;
}
differenceBy(arr2, criteria) {

@@ -77,2 +85,10 @@ this._value = arrays_1.Arrays.differenceBy(this._value, arr2, criteria);

}
intersectionBy(arr2, criteria) {
this._value = arrays_1.Arrays.intersectionBy(this._value, arr2, criteria);
return this;
}
unionBy(arr2, criteria) {
this._value = arrays_1.Arrays.unionBy(this._value, arr2, criteria);
return this;
}
map(predicate) {

@@ -79,0 +95,0 @@ this._value = this._value.map(predicate);

@@ -89,2 +89,12 @@ import {Arrays} from "./arrays";

public intersection<S = K>(arr2: S[]): this {
this._value = Arrays.intersection(this._value, arr2);
return this
}
public union<S = K>(arr2: S[]): this {
this._value = Arrays.union(this._value, arr2);
return this
}
public differenceBy<S = K>(arr2: S[], criteria: (value: S, i?: number) => any): this {

@@ -95,2 +105,12 @@ this._value = Arrays.differenceBy(this._value, arr2, criteria);

public intersectionBy<S = K>(arr2: S[], criteria: (value: S, i?: number) => any): this {
this._value = Arrays.intersectionBy(this._value, arr2, criteria);
return this
}
public unionBy<S = K>(arr2: S[], criteria: (value: S, i?: number) => any): this {
this._value = Arrays.unionBy(this._value, arr2, criteria);
return this
}
public map<U, S = K>(predicate: (value: S, index: number, array: S[]) => U): Chain<U> {

@@ -97,0 +117,0 @@ this._value = this._value.map(predicate);

2

package.json

@@ -20,3 +20,3 @@ {

"main": "./index.js",
"version": "8.0.48",
"version": "8.0.49",
"license": "MIT",

@@ -23,0 +23,0 @@ "repository": {

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