@homebound/activesupport
Advanced tools
Comparing version 1.8.0 to 1.9.0
@@ -308,2 +308,5 @@ import { Temporal } from 'temporal-polyfill'; | ||
sum(f: CallbackFn<T, Promise<number | undefined>>): Promise<number>; | ||
sum(this: (bigint | undefined)[]): bigint; | ||
sum(f: CallbackFn<T, bigint | undefined>): bigint; | ||
sum(f: CallbackFn<T, Promise<bigint | undefined>>): Promise<bigint>; | ||
/** | ||
@@ -320,7 +323,13 @@ * Sums numbers but will return `undefined` if either a) there are no numbers or b) they are all | ||
maybeSum(f: CallbackFn<T, Promise<number | undefined>>): Promise<number | undefined>; | ||
maybeSum(this: (bigint | undefined)[]): bigint | undefined; | ||
maybeSum(f: CallbackFn<T, bigint | undefined>): bigint | undefined; | ||
maybeSum(f: CallbackFn<T, Promise<bigint | undefined>>): Promise<bigint | undefined>; | ||
} | ||
interface ReadonlyArray<T> { | ||
sum(this: (number | undefined)[]): number; | ||
sum(this: readonly (number | undefined)[]): number; | ||
sum(f: CallbackFnRO<T, number | undefined>): number; | ||
sum(f: CallbackFnRO<T, Promise<number | undefined>>): Promise<number>; | ||
sum(this: (bigint | undefined)[]): bigint; | ||
sum(f: CallbackFn<T, bigint | undefined>): bigint; | ||
sum(f: CallbackFn<T, Promise<bigint | undefined>>): Promise<bigint>; | ||
/** | ||
@@ -334,5 +343,8 @@ * Sums numbers but will return `undefined` if either a) there are no numbers or b) they are all | ||
*/ | ||
maybeSum(this: (number | undefined)[]): number | undefined; | ||
maybeSum(this: readonly (number | undefined)[]): number | undefined; | ||
maybeSum(f: CallbackFnRO<T, number | undefined>): number | undefined; | ||
maybeSum(f: CallbackFnRO<T, Promise<number | undefined>>): Promise<number | undefined>; | ||
maybeSum(this: readonly (bigint | undefined)[]): bigint | undefined; | ||
maybeSum(f: CallbackFn<T, bigint | undefined>): bigint | undefined; | ||
maybeSum(f: CallbackFn<T, Promise<bigint | undefined>>): Promise<bigint | undefined>; | ||
} | ||
@@ -339,0 +351,0 @@ } |
@@ -234,4 +234,5 @@ "use strict"; | ||
const values = fn ? this.map(fn) : this; | ||
let max = values.shift(); | ||
for (const value of values) { | ||
let max = values.first; | ||
for (let i = 1; i < values.length; i++) { | ||
const value = values[i]; | ||
if (compare(value, max) > 0) | ||
@@ -246,4 +247,5 @@ max = value; | ||
const values = fn ? this.map(fn) : this; | ||
let min = values.shift(); | ||
for (const value of values) { | ||
let min = values.first; | ||
for (let i = 1; i < values.length; i++) { | ||
const value = values[i]; | ||
if (compare(value, min) < 0) | ||
@@ -301,6 +303,12 @@ min = value; | ||
const promisesOrNumbers = fn ? this.map(fn) : this; | ||
return maybePromiseAllThen( | ||
promisesOrNumbers, | ||
(numbers) => numbers.reduce((result, number) => result + (number ?? 0), 0) | ||
); | ||
return maybePromiseAllThen(promisesOrNumbers, (numbers) => { | ||
let sum2 = numbers[0]; | ||
for (let i = 1; i < numbers.length; i++) { | ||
const number = numbers[i]; | ||
if (number !== void 0) { | ||
sum2 = (sum2 ?? (typeof number === "bigint" ? 0n : 0)) + number; | ||
} | ||
} | ||
return sum2 ?? 0; | ||
}); | ||
} | ||
@@ -310,6 +318,12 @@ Array.prototype.sum = sum; | ||
const promisesOrNumbers = fn ? this.map(fn) : this; | ||
return maybePromiseAllThen( | ||
promisesOrNumbers, | ||
(numbers) => numbers.every((n) => n === void 0) ? void 0 : numbers.reduce((result, number) => result + (number ?? 0), 0) | ||
); | ||
return maybePromiseAllThen(promisesOrNumbers, (numbers) => { | ||
let sum2 = numbers[0]; | ||
for (let i = 1; i < numbers.length; i++) { | ||
const number = numbers[i]; | ||
if (number !== void 0) { | ||
sum2 = (sum2 ?? (typeof number === "bigint" ? 0n : 0)) + number; | ||
} | ||
} | ||
return sum2; | ||
}); | ||
} | ||
@@ -316,0 +330,0 @@ Array.prototype.maybeSum = maybeSum; |
{ | ||
"name": "@homebound/activesupport", | ||
"version": "1.8.0", | ||
"version": "1.9.0", | ||
"main": "./dist/index.js", | ||
@@ -5,0 +5,0 @@ "module": "./dist/index.mjs", |
@@ -18,4 +18,5 @@ import { Comparable, compare } from "../utils"; | ||
const values = fn ? ((this as T[]).map(fn) as R[]) : (this as R[]); | ||
let max = values.shift(); | ||
for (const value of values) { | ||
let max = values.first; | ||
for (let i = 1; i < values.length; i++) { | ||
const value = values[i]; | ||
if (compare(value, max!) > 0) max = value; | ||
@@ -22,0 +23,0 @@ } |
@@ -18,4 +18,5 @@ import { Comparable, compare } from "../utils"; | ||
const values = fn ? ((this as T[]).map(fn) as R[]) : (this as R[]); | ||
let min = values.shift(); | ||
for (const value of values) { | ||
let min = values.first; | ||
for (let i = 1; i < values.length; i++) { | ||
const value = values[i]; | ||
if (compare(value, min!) < 0) min = value; | ||
@@ -22,0 +23,0 @@ } |
@@ -9,2 +9,5 @@ import { MaybePromise, maybePromiseAllThen } from "../utils"; | ||
sum(f: CallbackFn<T, Promise<number | undefined>>): Promise<number>; | ||
sum(this: (bigint | undefined)[]): bigint; | ||
sum(f: CallbackFn<T, bigint | undefined>): bigint; | ||
sum(f: CallbackFn<T, Promise<bigint | undefined>>): Promise<bigint>; | ||
/** | ||
@@ -21,8 +24,14 @@ * Sums numbers but will return `undefined` if either a) there are no numbers or b) they are all | ||
maybeSum(f: CallbackFn<T, Promise<number | undefined>>): Promise<number | undefined>; | ||
maybeSum(this: (bigint | undefined)[]): bigint | undefined; | ||
maybeSum(f: CallbackFn<T, bigint | undefined>): bigint | undefined; | ||
maybeSum(f: CallbackFn<T, Promise<bigint | undefined>>): Promise<bigint | undefined>; | ||
} | ||
interface ReadonlyArray<T> { | ||
sum(this: (number | undefined)[]): number; | ||
sum(this: readonly (number | undefined)[]): number; | ||
sum(f: CallbackFnRO<T, number | undefined>): number; | ||
sum(f: CallbackFnRO<T, Promise<number | undefined>>): Promise<number>; | ||
sum(this: (bigint | undefined)[]): bigint; | ||
sum(f: CallbackFn<T, bigint | undefined>): bigint; | ||
sum(f: CallbackFn<T, Promise<bigint | undefined>>): Promise<bigint>; | ||
/** | ||
@@ -36,5 +45,8 @@ * Sums numbers but will return `undefined` if either a) there are no numbers or b) they are all | ||
*/ | ||
maybeSum(this: (number | undefined)[]): number | undefined; | ||
maybeSum(this: readonly (number | undefined)[]): number | undefined; | ||
maybeSum(f: CallbackFnRO<T, number | undefined>): number | undefined; | ||
maybeSum(f: CallbackFnRO<T, Promise<number | undefined>>): Promise<number | undefined>; | ||
maybeSum(this: readonly (bigint | undefined)[]): bigint | undefined; | ||
maybeSum(f: CallbackFn<T, bigint | undefined>): bigint | undefined; | ||
maybeSum(f: CallbackFn<T, Promise<bigint | undefined>>): Promise<bigint | undefined>; | ||
} | ||
@@ -46,10 +58,20 @@ } | ||
function sum<T, R extends number | undefined>(f: CallbackFn<T, Promise<R>>): Promise<number>; | ||
function sum<T, R extends number | undefined>( | ||
function sum<T, R extends bigint | undefined>(this: R[]): bigint; | ||
function sum<T, R extends bigint | undefined>(f: CallbackFn<T, R>): bigint; | ||
function sum<T, R extends bigint | undefined>(f: CallbackFn<T, Promise<R>>): Promise<bigint>; | ||
function sum<T, R extends number | bigint | undefined>( | ||
this: T[] | R[], | ||
fn?: CallbackFn<T, MaybePromise<R>>, | ||
): MaybePromise<number> { | ||
): MaybePromise<number | bigint> { | ||
const promisesOrNumbers = fn ? (this.map(fn as any) as R[] | Promise<R>[]) : (this as R[]); | ||
return maybePromiseAllThen(promisesOrNumbers, (numbers) => | ||
numbers.reduce((result: number, number) => result + (number ?? 0), 0), | ||
); | ||
return maybePromiseAllThen(promisesOrNumbers, (numbers) => { | ||
let sum: bigint | number | undefined = numbers[0]; | ||
for (let i = 1; i < numbers.length; i++) { | ||
const number = numbers[i]; | ||
if (number !== undefined) { | ||
sum = (((sum ?? (typeof number === "bigint" ? 0n : 0)) as any) + number) as any; | ||
} | ||
} | ||
return sum ?? 0; | ||
}); | ||
} | ||
@@ -62,14 +84,22 @@ | ||
function maybeSum<T, R extends number | undefined>(f: CallbackFn<T, Promise<R>>): Promise<R>; | ||
function maybeSum<T, R extends number | undefined>( | ||
function maybeSum<T, R extends bigint | undefined>(this: R[]): R; | ||
function maybeSum<T, R extends bigint | undefined>(f: CallbackFn<T, R>): R; | ||
function maybeSum<T, R extends bigint | undefined>(f: CallbackFn<T, Promise<R>>): Promise<R>; | ||
function maybeSum<T, R extends number | bigint | undefined>( | ||
this: T[] | R[], | ||
fn?: CallbackFn<T, MaybePromise<R>>, | ||
): MaybePromise<number | undefined> { | ||
): MaybePromise<number | bigint | undefined> { | ||
const promisesOrNumbers = fn ? (this.map(fn as any) as R[] | Promise<R>[]) : (this as R[]); | ||
return maybePromiseAllThen(promisesOrNumbers, (numbers) => | ||
numbers.every((n) => n === undefined) | ||
? undefined | ||
: numbers.reduce((result: number, number) => result + (number ?? 0), 0), | ||
); | ||
return maybePromiseAllThen(promisesOrNumbers, (numbers) => { | ||
let sum: bigint | number | undefined = numbers[0]; | ||
for (let i = 1; i < numbers.length; i++) { | ||
const number = numbers[i]; | ||
if (number !== undefined) { | ||
sum = (((sum ?? (typeof number === "bigint" ? 0n : 0)) as any) + number) as any; | ||
} | ||
} | ||
return sum; | ||
}); | ||
} | ||
Array.prototype.maybeSum = maybeSum; |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
390176
5170
0