-
-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: jsonify, inspect, to_integer, normalize_whitespace filters
- Loading branch information
Showing
19 changed files
with
258 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: inspect | ||
--- | ||
|
||
{% since %}v10.13.0{% endsince %} | ||
|
||
Similar with `json`, but `inspect` allows cyclic structure. For the scope below: | ||
|
||
``` | ||
const foo = { | ||
bar: 'BAR' | ||
} | ||
foo.foo = foo | ||
const scope = { foo } | ||
``` | ||
|
||
Input | ||
```liquid | ||
{% foo | inspect %} | ||
``` | ||
|
||
Output | ||
```text | ||
{"bar":"BAR","foo":"[Circular]"} | ||
``` | ||
|
||
## Formatting | ||
|
||
An additional `space` argument can be specified for the indent width. | ||
|
||
Input | ||
```liquid | ||
{{ foo | inspect: 4 }} | ||
``` | ||
|
||
Output | ||
```text | ||
{ | ||
"bar": "BAR", | ||
"foo": "[Circular]" | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
title: jsonify | ||
--- | ||
|
||
{% since %}v10.13.0{% endsince %} | ||
|
||
See [json][json]. | ||
|
||
[json]: /filters/json.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
title: normalize_whitespace | ||
--- | ||
|
||
{% since %}v10.13.0{% endsince %} | ||
|
||
Replace any occurrence of whitespace with a single space. | ||
|
||
Input | ||
```liquid | ||
{{ "a \n b" | normalize_whitespace }} | ||
``` | ||
|
||
Output | ||
```html | ||
a b | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
title: to_integer | ||
--- | ||
|
||
{% since %}v10.13.0{% endsince %} | ||
|
||
Convert values to number. | ||
|
||
Input | ||
```liquid | ||
{{ "123" | to_integer | json }} | ||
``` | ||
|
||
Output | ||
```text | ||
123 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]" | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
title: jsonify | ||
--- | ||
|
||
{% since %}v10.13.0{% endsince %} | ||
|
||
见 [json][json]。 | ||
|
||
[json]: ./json.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
title: normalize_whitespace | ||
--- | ||
|
||
{% since %}v10.13.0{% endsince %} | ||
|
||
把连续的空白字符替换为单个空格。 | ||
|
||
输入 | ||
```liquid | ||
{{ "a \n b" | normalize_whitespace }} | ||
``` | ||
|
||
输出 | ||
```html | ||
a b | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
title: to_integer | ||
--- | ||
|
||
{% since %}v10.13.0{% endsince %} | ||
|
||
转换为数字类型。 | ||
|
||
输入 | ||
```liquid | ||
{{ "123" | to_integer | json }} | ||
``` | ||
|
||
输出 | ||
```text | ||
123 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.