Skip to content

feat(filters): add squish filter - #943

Merged
harttle merged 2 commits into
harttle:masterfrom
MildlyMeticulous:feat/squish-filter
Aug 11, 2026
Merged

feat(filters): add squish filter#943
harttle merged 2 commits into
harttle:masterfrom
MildlyMeticulous:feat/squish-filter

Conversation

@MildlyMeticulous

Copy link
Copy Markdown
Contributor

squish is a standard Shopify/liquid string filter and LiquidJS doesn't have it, so {{ "Hello World!" | squish }} currently renders unchanged rather than Hello World!.

engine.parseAndRenderSync('{{ "  Hello   World!  " | squish }}')
// before: "  Hello   World!  "
// after:  "Hello World!"

Strips leading and trailing whitespace and collapses each internal run to a single space, matching Shopify/liquid 5.12.0. Added alongside strip_newlines in src/filters/string.ts, with docs and a sidebar entry.

Verified against all 17 squish cases in golden-liquid, which tests against Shopify/liquid as the reference implementation. All pass. 1588 tests pass here; the new tests fail on revert.

Comment thread src/filters/string.ts
export function squish (this: FilterImpl, v: string) {
const str = stringify(v)
this.context.memoryLimit.use(str.length)
return str.replace(/\s+/g, ' ').trim()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the spaces trimed by .trim() is same with those \s matches, and whether the order of replace and trim matters (it's different with shopify).

Anyway this is good enough to merge. Will handle it when discrepancies arise.

@harttle
harttle merged commit 875513f into harttle:master Aug 11, 2026
13 checks passed
github-actions Bot pushed a commit that referenced this pull request Aug 11, 2026
# [10.29.0](v10.28.0...v10.29.0) (2026-08-11)

### Features

* add unregisterFilter method ([#946](#946)) ([69b2c58](69b2c58))
* **filters:** add squish filter ([#943](#943)) ([875513f](875513f))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 10.29.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@MildlyMeticulous
MildlyMeticulous deleted the feat/squish-filter branch August 11, 2026 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants