mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-12 19:00:39 -07:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39233ba9f2 | ||
|
|
8f57d9fed8 | ||
|
|
9af92f5d8c | ||
|
|
747bdbdbee | ||
|
|
875513f4c5 | ||
|
|
f88a528e27 |
@@ -847,6 +847,24 @@
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "YacovGold",
|
||||
"name": "YacovGold",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/8984042?v=4",
|
||||
"profile": "https://github.com/YacovGold",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "sarathfrancis90",
|
||||
"name": "Sarath Francis",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/9289498?v=4",
|
||||
"profile": "https://github.com/sarathfrancis90",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
}
|
||||
],
|
||||
"contributorsPerLine": 7,
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
# [10.29.0](https://github.com/harttle/liquidjs/compare/v10.28.0...v10.29.0) (2026-08-11)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add unregisterFilter method ([#946](https://github.com/harttle/liquidjs/issues/946)) ([69b2c58](https://github.com/harttle/liquidjs/commit/69b2c589f9b69a34427cb8533ddb938bd997914f))
|
||||
* **filters:** add squish filter ([#943](https://github.com/harttle/liquidjs/issues/943)) ([875513f](https://github.com/harttle/liquidjs/commit/875513f4c5136bed0c64562cccabb21a7db8d36c))
|
||||
|
||||
# [10.28.0](https://github.com/harttle/liquidjs/compare/v10.27.2...v10.28.0) (2026-08-01)
|
||||
|
||||
|
||||
|
||||
@@ -242,6 +242,8 @@ Want to contribute? see [Contribution Guidelines][contribution]. Thanks goes to
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/spokodev"><img src="https://avatars.githubusercontent.com/u/239690017?v=4?s=100" width="100px;" alt="spokodev"/><br /><sub><b>spokodev</b></sub></a><br /><a href="https://github.com/harttle/liquidjs/commits?author=spokodev" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/YacovGold"><img src="https://avatars.githubusercontent.com/u/8984042?v=4?s=100" width="100px;" alt="YacovGold"/><br /><sub><b>YacovGold</b></sub></a><br /><a href="https://github.com/harttle/liquidjs/commits?author=YacovGold" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/sarathfrancis90"><img src="https://avatars.githubusercontent.com/u/9289498?v=4?s=100" width="100px;" alt="Sarath Francis"/><br /><sub><b>Sarath Francis</b></sub></a><br /><a href="https://github.com/harttle/liquidjs/commits?author=sarathfrancis90" title="Code">💻</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -94,6 +94,7 @@ filters:
|
||||
sort: sort.html
|
||||
sort_natural: sort_natural.html
|
||||
split: split.html
|
||||
squish: squish.html
|
||||
strip: strip.html
|
||||
strip_html: strip_html.html
|
||||
strip_newlines: strip_newlines.html
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
title: squish
|
||||
---
|
||||
|
||||
{% since %}v10.28.0{% endsince %}
|
||||
|
||||
Removes leading and trailing whitespace from a string, and replaces every run of whitespace inside it with a single space.
|
||||
|
||||
Input
|
||||
```liquid
|
||||
{{ " Hello there,
|
||||
Major Tom. " | squish }}
|
||||
```
|
||||
|
||||
Output
|
||||
```text
|
||||
Hello there, Major Tom.
|
||||
```
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "liquidjs",
|
||||
"version": "10.28.0",
|
||||
"version": "10.29.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "liquidjs",
|
||||
"version": "10.28.0",
|
||||
"version": "10.29.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"commander": "^10.0.0"
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "liquidjs",
|
||||
"version": "10.28.0",
|
||||
"version": "10.29.0",
|
||||
"sideEffects": false,
|
||||
"description": "A simple, expressive, extensible Liquid template engine for JavaScript — Shopify, Jekyll and GitHub Pages compatible, for Node.js, browsers, and the CLI, with TypeScript support.",
|
||||
"main": "dist/liquid.node.js",
|
||||
@@ -35,7 +35,7 @@
|
||||
"build:contributors": "node bin/build-contributors.js",
|
||||
"build:apidoc": "shx rm -rf docs/source/api && typedoc --plugin typedoc-plugin-missing-exports ./src --gitRevision master --out docs/source/api",
|
||||
"build:changelog": "node bin/build-changelog.js",
|
||||
"build:docs-hexo": "cd docs && npm ci && npm run build && shx cp CNAME public/",
|
||||
"build:docs-hexo": "cd docs && npm ci && npm run build && shx cp CNAME .nojekyll public/",
|
||||
"serve:docs": "cd docs && npm run start",
|
||||
"dev:docs": "run-s prepare:docs serve:docs"
|
||||
},
|
||||
|
||||
@@ -128,6 +128,12 @@ export function strip_newlines (this: FilterImpl, v: string) {
|
||||
return str.replace(/\r?\n/gm, '')
|
||||
}
|
||||
|
||||
export function squish (this: FilterImpl, v: string) {
|
||||
const str = stringify(v)
|
||||
this.context.memoryLimit.use(str.length)
|
||||
return str.replace(/\s+/g, ' ').trim()
|
||||
}
|
||||
|
||||
export function capitalize (this: FilterImpl, str: string) {
|
||||
str = stringify(str)
|
||||
this.context.memoryLimit.use(str.length)
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { stringify } from '../util/underscore'
|
||||
|
||||
export const url_decode = (x: string) => decodeURIComponent(stringify(x)).replace(/\+/g, ' ')
|
||||
export const url_decode = (x: string) => decodeURIComponent(stringify(x).replace(/\+/g, ' '))
|
||||
export const url_encode = (x: string) => encodeURIComponent(stringify(x)).replace(/%20/g, '+')
|
||||
export const cgi_escape = (x: string) => encodeURIComponent(stringify(x))
|
||||
.replace(/%20/g, '+')
|
||||
|
||||
@@ -153,6 +153,26 @@ describe('filters/string', function () {
|
||||
'{{ string_with_newlines | strip_newlines }}',
|
||||
'Hellothere')
|
||||
})
|
||||
describe('squish', function () {
|
||||
it('should collapse whitespace between words', function () {
|
||||
return test('{{ "Hello World!" | squish }}', 'Hello World!')
|
||||
})
|
||||
it('should strip leading and trailing whitespace', function () {
|
||||
return test('{{ " HelloWorld! " | squish }}', 'HelloWorld!')
|
||||
})
|
||||
it('should treat newlines and tabs as whitespace', function () {
|
||||
return test('{{ " \n\t\r\nHello \n\t World! \n" | squish }}', 'Hello World!')
|
||||
})
|
||||
it('should return empty string for whitespace only', function () {
|
||||
return test('{{ " \n\t " | squish }}', '')
|
||||
})
|
||||
it('should stringify a number', function () {
|
||||
return test('{{ 5 | squish }}', '5')
|
||||
})
|
||||
it('should return empty string for undefined', function () {
|
||||
return test('{{ nosuchthing | squish }}', '')
|
||||
})
|
||||
})
|
||||
describe('truncate', function () {
|
||||
it('should truncate when string too long', function () {
|
||||
return test('{{ "Ground control to Major Tom." | truncate: 20 }}',
|
||||
|
||||
@@ -7,6 +7,14 @@ describe('filters/url', () => {
|
||||
const html = liquid.parseAndRenderSync('{{ "%27Stop%21%27+said+Fred" | url_decode }}')
|
||||
expect(html).toEqual("'Stop!' said Fred")
|
||||
})
|
||||
it('should decode %2B to a literal plus', () => {
|
||||
const html = liquid.parseAndRenderSync('{{ "1%2B1" | url_decode }}')
|
||||
expect(html).toEqual('1+1')
|
||||
})
|
||||
it('should keep a literal plus when round-tripped through url_encode', () => {
|
||||
const html = liquid.parseAndRenderSync('{{ "a+b c" | url_encode | url_decode }}')
|
||||
expect(html).toEqual('a+b c')
|
||||
})
|
||||
})
|
||||
|
||||
describe('url_encode', () => {
|
||||
|
||||
Reference in New Issue
Block a user