mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-18 14:00:39 -07:00
fix: "filter is not a function" for uniq
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user