appolo-utils
Advanced tools
Comparing version 0.0.48 to 0.0.50
@@ -24,3 +24,3 @@ "use strict"; | ||
} | ||
static remove(list, item) { | ||
static removeBy(list, criteria) { | ||
if (!list || !list.length) { | ||
@@ -30,3 +30,3 @@ return; | ||
for (let i = list.length - 1; i >= 0; i--) { | ||
if (list[i] === item) { | ||
if (criteria(list[i], i)) { | ||
list.splice(i, 1); | ||
@@ -36,2 +36,8 @@ } | ||
} | ||
static remove(list, item) { | ||
Arrays.removeBy(list, current => current === item); | ||
} | ||
static chunk(array, chunkSize) { | ||
return Arrays.splitToChunks(array, chunkSize); | ||
} | ||
static splitToChunks(array, chunkSize) { | ||
@@ -98,2 +104,21 @@ return [].concat.apply([], array.map(function (elem, i) { | ||
} | ||
static map(arr, criteria) { | ||
if (!arr) { | ||
return []; | ||
} | ||
if (!Array.isArray(arr)) { | ||
return Object.keys(arr).map(key => criteria(arr[key], key)); | ||
} | ||
return arr.map(criteria); | ||
} | ||
static forEach(arr, criteria) { | ||
if (!arr) { | ||
return; | ||
} | ||
if (!Array.isArray(arr)) { | ||
Object.keys(arr).forEach(key => criteria(arr[key], key)); | ||
return; | ||
} | ||
arr.forEach(criteria); | ||
} | ||
static uniqBy(arr, criteria) { | ||
@@ -100,0 +125,0 @@ let dic = new Map(), out = []; |
@@ -31,4 +31,4 @@ import {Classes} from "./classes"; | ||
public static remove<T>(list: T[], item: T): void { | ||
public static removeBy<T>(list: T[], criteria: (value: T, i?: number) => boolean): void { | ||
if (!list || !list.length) { | ||
@@ -39,3 +39,3 @@ return; | ||
for (let i = list.length - 1; i >= 0; i--) { | ||
if (list[i] === item) { | ||
if (criteria(list[i], i)) { | ||
list.splice(i, 1); | ||
@@ -46,2 +46,10 @@ } | ||
public static remove<T>(list: T[], item: T): void { | ||
Arrays.removeBy(list, current => current === item) | ||
} | ||
public static chunk(array: any[], chunkSize: number): any[] { | ||
return Arrays.splitToChunks(array, chunkSize) | ||
} | ||
public static splitToChunks(array: any[], chunkSize: number): any[] { | ||
@@ -144,2 +152,27 @@ | ||
public static map<T, K>(arr: T[] | { [index: string]: T }, criteria: (value: T, i?: number | string) => K): K[] { | ||
if (!arr) { | ||
return [] | ||
} | ||
if (!Array.isArray(arr)) { | ||
return Object.keys(arr).map(key => criteria(arr[key], key)) | ||
} | ||
return arr.map(criteria) | ||
} | ||
public static forEach<T>(arr: T[] | { [index: string]: T }, criteria: (value: T, i?: number | string) => void): void { | ||
if (!arr) { | ||
return; | ||
} | ||
if (!Array.isArray(arr)) { | ||
Object.keys(arr).forEach(key => criteria(arr[key], key)); | ||
return; | ||
} | ||
arr.forEach(criteria); | ||
} | ||
public static uniqBy<T>(arr: T[], criteria: (value: T, i?: number) => any): T[] { | ||
@@ -146,0 +179,0 @@ let dic = new Map<any, 1>(), out = []; |
@@ -17,3 +17,3 @@ { | ||
"main": "./index.js", | ||
"version": "0.0.48", | ||
"version": "0.0.50", | ||
"license": "MIT", | ||
@@ -20,0 +20,0 @@ "repository": { |
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
107222
1939