tscommons-core
Advanced tools
Comparing version 1.21.3 to 1.22.0
@@ -0,1 +1,2 @@ | ||
import { TArrayWithErrors } from '../types/tarray-with-errors'; | ||
export declare abstract class CommonsArray { | ||
@@ -15,2 +16,4 @@ static remove<T>(array: T[], item: T): boolean; | ||
static shuffle<T>(array: T[], minDistance?: number): boolean; | ||
static splitMapErrors<T>(array: (T | Error)[]): TArrayWithErrors<T>; | ||
static mapWithErrors<S, D>(src: S[], callback: (item: S) => D | Error): TArrayWithErrors<D>; | ||
} |
@@ -186,4 +186,42 @@ "use strict"; | ||
} | ||
static splitMapErrors(array) { | ||
const errors = []; | ||
const items = []; | ||
for (const item of array) { | ||
try { | ||
if (item instanceof Error) { | ||
errors.push(item); | ||
continue; | ||
} | ||
} | ||
catch (e) { | ||
// ignore, probably a Javascript dislike of (e ! class object) instanceof Error | ||
} | ||
items.push(item); | ||
} | ||
return { | ||
errors: errors, | ||
array: items | ||
}; | ||
} | ||
static mapWithErrors(src, callback) { | ||
const results = []; | ||
for (const item of src) { | ||
try { | ||
const result = callback(item); | ||
results.push(result); | ||
} | ||
catch (e) { | ||
if (commons_type_1.CommonsType.isError(e)) { | ||
results.push(e); | ||
} | ||
else { | ||
results.push(new Error(e)); | ||
} | ||
} | ||
} | ||
return CommonsArray.splitMapErrors(results); | ||
} | ||
} | ||
exports.CommonsArray = CommonsArray; | ||
//# sourceMappingURL=commons-array.js.map |
@@ -0,1 +1,2 @@ | ||
export * from './tarray-with-errors'; | ||
export * from './tdate-range'; | ||
@@ -2,0 +3,0 @@ export * from './tdefined'; |
{ | ||
"name": "tscommons-core", | ||
"version": "1.21.3", | ||
"version": "1.22.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
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
243719
73
3266