Skip to content

Conversation

@jg-rp
Copy link
Contributor

@jg-rp jg-rp commented May 8, 2025

This PR adds a sort_numeric filter. See also #1028 and #980.

sort_numeric sorts an array by numerical values extracted from runs of digits within the string representation of each item.

require "liquid"

template = Liquid::Template.parse("{{ array | sort_numeric | join }}")

puts template.render({ "array" => ["v1.2", "v1.9", "v10.0", "v0.1", "v1.10", "v1.1.0"] })
# v0.1 v1.1.0 v1.2 v1.9 v1.10 v10.0

puts template.render({ "array" => ["107", "042", "0001", "02", "17"] })
# 0001 02 17 042 107

puts template.render({ "array" => ["10.1", "3.5", "2.3", "1.1", "1.01"] })
# 1.01 1.1 2.3 3.5 10.1

@juanlncf
Copy link

juanlncf commented Jun 9, 2025

Please somebody push this please god

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants