@simplism/core
Advanced tools
Comparing version 10.1.48 to 10.2.2
@@ -42,2 +42,3 @@ import { Type } from "../type/Type"; | ||
single(predicate?: (item: T, index: number) => boolean): T | undefined; | ||
single(key: keyof T, checkValue: T): T | undefined; | ||
last(predicate?: (item: T, index: number) => boolean): T | undefined; | ||
@@ -44,0 +45,0 @@ sum(): T | undefined; |
@@ -826,8 +826,20 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
}; | ||
Array.prototype.single = function (predicate) { | ||
var filtered = predicate ? this.filter(predicate.bind(this)) : this; | ||
if (filtered.length > 1) { | ||
throw new Error("복수의 결과물이 있습니다."); | ||
Array.prototype.single = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return filtered[0]; | ||
if (args.length === 1) { | ||
var predicate = args[0]; | ||
var filtered = predicate ? this.filter(predicate.bind(this)) : this; | ||
if (filtered.length > 1) { | ||
throw new Error("복수의 결과물이 있습니다."); | ||
} | ||
return filtered[0]; | ||
} | ||
else { | ||
var key_1 = args[0]; | ||
var checkValue_1 = args[1]; | ||
return this.single(function (item) { return item[key_1] === checkValue_1; }); | ||
} | ||
}; | ||
@@ -834,0 +846,0 @@ Array.prototype.last = function (predicate) { |
{ | ||
"name": "@simplism/core", | ||
"version": "10.1.48", | ||
"version": "10.2.2", | ||
"description": "Simplism Core Package", | ||
@@ -5,0 +5,0 @@ "repository": "github:kslhunter/simplism", |
@@ -27,2 +27,4 @@ import {Type} from "../type/Type"; | ||
single(key: keyof T, checkValue: T): T | undefined; | ||
last(predicate?: (item: T, index: number) => boolean): T | undefined; | ||
@@ -134,8 +136,17 @@ | ||
Array.prototype.single = function (predicate?: (item: any, index: number) => boolean): any { | ||
const filtered = predicate ? this.filter(predicate.bind(this)) : this; | ||
if (filtered.length > 1) { | ||
throw new Error("복수의 결과물이 있습니다."); | ||
Array.prototype.single = function (...args: any[]): any { | ||
if (args.length === 1) { | ||
const predicate: ((item: any, index: number) => boolean) = args[0]; | ||
const filtered = predicate ? this.filter(predicate.bind(this)) : this; | ||
if (filtered.length > 1) { | ||
throw new Error("복수의 결과물이 있습니다."); | ||
} | ||
return filtered[0]; | ||
} | ||
return filtered[0]; | ||
else { | ||
const key = args[0]; | ||
const checkValue = args[1]; | ||
return this.single(item => item[key] === checkValue); | ||
} | ||
}; | ||
@@ -142,0 +153,0 @@ |
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
226274
3218