feat: jsonify, inspect, to_integer, normalize_whitespace filters

This commit is contained in:
Yang Jun
2024-05-06 21:10:27 +08:00
committed by Jun Yang
parent ea0eab93d1
commit 842b45c96a
19 changed files with 258 additions and 17 deletions
+42
View File
@@ -0,0 +1,42 @@
---
title: inspect
---
{% since %}v10.13.0{% endsince %}
类似于 `json`,但可以处理循环引用的情况。例如对于上下文:
```
const foo = {
bar: 'BAR'
}
foo.foo = foo
const scope = { foo }
```
输入
```liquid
{% foo | inspect %}
```
输出
```text
{"bar":"BAR","foo":"[Circular]"}
```
## 格式化
可以指定一个 `space` 参数来缩进长度。
输入
```liquid
{{ foo | inspect: 4 }}
```
输出
```text
{
"bar": "BAR",
"foo": "[Circular]"
}
```
+2 -2
View File
@@ -23,13 +23,13 @@ title: json
可以指定一个 `space` 参数来格式化 JSON。
Input
输入
```liquid
{% assign arr = "foo bar coo" | split: " " %}
{{ arr | json: 4 }}
```
Output
输出
```text
[
"foo",
+9
View File
@@ -0,0 +1,9 @@
---
title: jsonify
---
{% since %}v10.13.0{% endsince %}
见 [json][json]。
[json]: ./json.html
@@ -0,0 +1,17 @@
---
title: normalize_whitespace
---
{% since %}v10.13.0{% endsince %}
把连续的空白字符替换为单个空格。
输入
```liquid
{{ "a \n b" | normalize_whitespace }}
```
输出
```html
a b
```
+2 -2
View File
@@ -10,10 +10,10 @@ LiquidJS 共支持 40+ 个过滤器,可以分为如下几类:
类别 | 过滤器
--- | ---
数学 | plus, minus, modulo, times, floor, ceil, round, divided_by, abs, at_least, at_most
字符串 | append, prepend, capitalize, upcase, downcase, strip, lstrip, rstrip, strip_newlines, split, replace, replace_first, replace_last, remove, remove_first, remove_last, truncate, truncatewords
字符串 | append, prepend, capitalize, upcase, downcase, strip, lstrip, rstrip, strip_newlines, split, replace, replace_first, replace_last, remove, remove_first, remove_last, truncate, truncatewords, normalize_whitespace
HTML/URI | escape, escape_once, url_encode, url_decode, strip_html, newline_to_br
数组 | slice, map, sort, sort_natural, uniq, where, where_exp, group_by, group_by_exp, find, find_exp, first, last, join, reverse, concat, compact, size, push, pop, shift, unshift
日期 | date
其他 | default, json
其他 | default, json, jsonify, inspect, raw, to_integer
[shopify/liquid]: https://github.com/Shopify/liquid
+17
View File
@@ -0,0 +1,17 @@
---
title: to_integer
---
{% since %}v10.13.0{% endsince %}
转换为数字类型。
输入
```liquid
{{ "123" | to_integer | json }}
```
输出
```text
123
```