fix: "filter is not a function" for uniq

This commit is contained in:
Yang Jun
2024-08-23 21:27:53 +08:00
committed by Jun Yang
parent 2d59cff0a6
commit 68387c31ea
5 changed files with 22 additions and 14 deletions
+3
View File
@@ -1,4 +1,5 @@
import { assert } from './assert'
import { toNumber } from './underscore'
export class Limiter {
private message: string
@@ -9,10 +10,12 @@ export class Limiter {
this.limit = limit
}
use (count: number) {
count = toNumber(count)
assert(this.base + count <= this.limit, this.message)
this.base += count
}
check (count: number) {
count = toNumber(count)
assert(count <= this.limit, this.message)
}
}
+5
View File
@@ -66,6 +66,11 @@ export function toValue (value: any): any {
return (value instanceof Drop && isFunction(value.valueOf)) ? value.valueOf() : value
}
export function toNumber (value: any): number {
value = Number(value)
return isNaN(value) ? 0 : value
}
export function isNumber (value: any): value is number {
return typeof value === 'number'
}