mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-19 22:40:48 -07:00
fix: remove spurious diff noise in filter files
Restore misc.ts from origin/next with LF line endings and re-apply only memoryLimit removal, avoiding CRLF and blank-line churn in the export block. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
+34
-28
@@ -1,42 +1,48 @@
|
|||||||
import { isFalsy } from '../render/boolean'
|
import { isFalsy } from '../render/boolean'
|
||||||
|
import { identify, isArray, isString, toValue } from '../util/underscore'
|
||||||
import { identify, isArray, isString, toValue } from '../util/underscore'
|
import { FilterImpl } from '../template'
|
||||||
|
|
||||||
function defaultFilter<T1 extends boolean, T2> (this: FilterImpl, value: T1, defaultValue: T2, ...args: Array<[string, any]>): T1 | T2 {
|
function defaultFilter<T1 extends boolean, T2> (this: FilterImpl, value: T1, defaultValue: T2, ...args: Array<[string, any]>): T1 | T2 {
|
||||||
import { FilterImpl } from '../template'
|
value = toValue(value)
|
||||||
|
if (isArray(value) || isString(value)) return value.length ? value : defaultValue
|
||||||
function defaultFilter<T1 extends boolean, T2> (this: FilterImpl, value: T1, defaultValue: T2, ...args: Array<[string, any]>): T1 | T2 {
|
if (value === false && (new Map(args)).get('allow_false')) return false as T1
|
||||||
return isFalsy(value, this.context) ? defaultValue : value
|
return isFalsy(value, this.context) ? defaultValue : value
|
||||||
|
}
|
||||||
|
|
||||||
function json (this: FilterImpl, value: any, space = 0) {
|
function json (this: FilterImpl, value: any, space = 0) {
|
||||||
return JSON.stringify(value, undefined, space)
|
return JSON.stringify(value, undefined, space)
|
||||||
if (value === false && (new Map(args)).get('allow_false')) return false as T1
|
}
|
||||||
|
|
||||||
function inspect (this: FilterImpl, value: any, space = 0) {
|
function inspect (this: FilterImpl, value: any, space = 0) {
|
||||||
return isFalsy(value, this.context) ? defaultValue : value
|
const ancestors: object[] = []
|
||||||
return JSON.stringify(value, function (this: unknown, _key: unknown, value: any) {
|
return JSON.stringify(value, function (this: unknown, _key: unknown, value: any) {
|
||||||
if (typeof value !== 'object' || value === null) {
|
if (typeof value !== 'object' || value === null) {
|
||||||
return value
|
return value
|
||||||
return JSON.stringify(value, undefined, space)
|
}
|
||||||
}
|
// `this` is the object that value is contained in, i.e., its direct parent.
|
||||||
|
while (ancestors.length > 0 && ancestors[ancestors.length - 1] !== this) ancestors.pop()
|
||||||
if (ancestors.includes(value)) {
|
if (ancestors.includes(value)) {
|
||||||
return '[Circular]'
|
return '[Circular]'
|
||||||
|
}
|
||||||
return JSON.stringify(value, function (this: unknown, _key: unknown, value: any) {
|
ancestors.push(value)
|
||||||
return value
|
return value
|
||||||
}, space)
|
}, space)
|
||||||
}
|
}
|
||||||
|
|
||||||
function to_integer (value: any) {
|
function to_integer (value: any) {
|
||||||
return Number(value)
|
return Number(value)
|
||||||
|
}
|
||||||
while (ancestors.length > 0 && ancestors[ancestors.length - 1] !== this) ancestors.pop()
|
|
||||||
|
const raw = {
|
||||||
if (ancestors.includes(value)) {
|
raw: true,
|
||||||
return '[Circular]'
|
handler: identify
|
||||||
}
|
}
|
||||||
|
|
||||||
ancestors.push(value)
|
export default {
|
||||||
|
default: defaultFilter,
|
||||||
return value
|
raw,
|
||||||
}, space)
|
jsonify: json,
|
||||||
}
|
to_integer,
|
||||||
|
json,
|
||||||
|
inspect
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user