@simplism/core
Advanced tools
Comparing version 0.2.13 to 0.2.14
@@ -6,2 +6,3 @@ import { GroupedArray } from "../type/GroupedArray"; | ||
groupBy<K, V>(keyPredicate: (item: T, index: number) => K, valuePredicate: (item: T, index: number) => V): GroupedArray<K, V>[]; | ||
toMap<V>(keyPredicate: (item: T, index: number) => string, valuePredicate: (item: T, index: number) => V): Map<string, V>; | ||
mapMany<R>(predicate: (item: T, index: number) => R[]): R[]; | ||
@@ -8,0 +9,0 @@ first(predicate?: (item: T, index: number) => boolean): T; |
@@ -24,2 +24,15 @@ "use strict"; | ||
}; | ||
Array.prototype.toMap = function (keyPredicate, valuePredicate) { | ||
var result = new Map(); | ||
for (var i = 0; i < this.length; i++) { | ||
var item = this[i]; | ||
var key = keyPredicate(item, i); | ||
var value = valuePredicate(item, i); | ||
if (result.has(key)) { | ||
throw Error("키[" + key + "]가 복수 존재합니다."); | ||
} | ||
result.set(key, value); | ||
} | ||
return result; | ||
}; | ||
Array.prototype.mapMany = function (predicate) { | ||
@@ -26,0 +39,0 @@ return this.length > 0 ? this.map(predicate).reduce(function (p, n) { return p.concat(n); }) : []; |
{ | ||
"name": "@simplism/core", | ||
"version": "0.2.13", | ||
"version": "0.2.14", | ||
"description": "Simplism - 코어 라이브러리", | ||
@@ -5,0 +5,0 @@ "repository": "bitbucket:kslhunter/simplism", |
@@ -7,29 +7,45 @@ import {GroupedArray} from "../type/GroupedArray"; | ||
groupBy<K>(keyPredicate: (item: T, index: number) => K): GroupedArray<K, T>[]; | ||
groupBy<K, V>(keyPredicate: (item: T, index: number) => K, valuePredicate: (item: T, index: number) => V): GroupedArray<K, V>[]; | ||
toMap<V>(keyPredicate: (item: T, index: number) => string, valuePredicate: (item: T, index: number) => V): Map<string, V>; | ||
mapMany<R>(predicate: (item: T, index: number) => R[]): R[]; | ||
first(predicate?: (item: T, index: number) => boolean): T; | ||
single(predicate?: (item: T, index: number) => boolean): T; | ||
last(predicate?: (item: T, index: number) => boolean): T; | ||
sum(): T; | ||
max(): T; | ||
min(): T; | ||
sum<U>(predicate: (item: T) => U): U; | ||
max<U>(predicate: (item: T) => U): U; | ||
min<U>(predicate: (item: T) => U): U; | ||
distinct(predicate?: (item: T, index: number) => boolean): T[]; | ||
distinct(predicate?: (item: T, index: number) => boolean): T[]; | ||
orderBy(predicate?: (item: T) => any): T[]; | ||
orderByDesc(predicate?: (item: T) => any): T[]; | ||
pushRange(items: T[]): void; | ||
insert(index: number, item: T): void; | ||
remove(item: T): void; | ||
removeRange(items: T[]): void; | ||
removeRange(predicate: (item: T, index: number) => boolean): void; | ||
clear(): void; | ||
replaceAll(arr: any[]): void; | ||
@@ -60,2 +76,19 @@ } | ||
Array.prototype.toMap = function (keyPredicate: (item: any, index: number) => string, valuePredicate: (item: any, index: number) => any): Map<string, any> { | ||
let result = new Map<string, any>(); | ||
for (let i = 0; i < this.length; i++) { | ||
let item = this[i]; | ||
let key = keyPredicate(item, i); | ||
let value = valuePredicate(item, i); | ||
if (result.has(key)) { | ||
throw Error("키[" + key + "]가 복수 존재합니다.") | ||
} | ||
result.set(key, value); | ||
} | ||
return result; | ||
}; | ||
Array.prototype.mapMany = function (predicate: (item: any, index: number) => any[]): any[] { | ||
@@ -62,0 +95,0 @@ return this.length > 0 ? this.map(predicate).reduce((p: any, n: any) => p.concat(n)) : []; |
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
167881
2151