Shopify / Shopify/liquid

Additional string filters

Open
#778 2 comments 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
11.9k
Forks
1.5k
Avg merge
17h 55m
Merged PRs (30d)
3

Description

I found myself needing to remove the last character of a string without knowing the length of the string in advance. At first, I thought I could use slice, but ran into the behavior mentioned in https://github.com/Shopify/liquid/issues/522. I then tried a few other things, including reversing the string, removing the first character, then reversing again. However, I didn't get the behavior I was looking for.

I think a few new filters would have made my issue easier to solve, as well as be good complementary filters to the ones which already exist.

clip (or some other name): Similar to slice, but allow for negative indices for people who want a Python-style method.
str_reverse: Reverses a string
replace_last, remove_last: Perform the same as their counterparts, replace_first and remove_first, except they obviously start at the end of the string and read backwards.

Merely having the str_reverse filter would make all the others above achievable (though a bit cumbersome) with existing filters, but I think all four of the filters would be great additions to the toolbox.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing slice, replace_first, and remove_first filters, then read issue #522 for the slice behavior that motivated this request. Done requires a settled API and semantics for the proposed filters, with the requested string operations covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.