Browse Source

twigFunction 'matches': accept a 2nd parameter flags

master
parent
commit
019fba2e40
  1. 2
      doc/TwigJS.md
  2. 3
      src/twigFunctions.js

2
doc/TwigJS.md

@ -67,7 +67,7 @@ There are several extra functions defined for the TwigJS language:
Extra filters:
* filter websiteUrl: return a valid http link. Example: `{{ "www.google.com"|websiteUrl }}` -> "http://www.google.com"; `{{ "https://google.com"|websiteUrl }}` -> "https://google.com"
* filter `matches`: regular expression match. e.g. `{{ "test"|matches("e(st)$") }}` returns `[ "est", "st" ]`. Returns null if it does not match.
* filter `matches`: regular expression match. e.g. `{{ "test"|matches("e(st)$") }}` returns `[ "est", "st" ]`. You can pass a second parameter with [RegExp flags](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/RegExp). Returns null if it does not match.
* filter `osmParseDate`: returns an array with the lower and upper boundary of the year of a `start_date` tag. See [openstreetmap-date-parser](https://github.com/plepe/openstreetmap-date-parser) for details.
* filter `osmFormatDate`: returns the date as localized strings. Accept an object for options, e.g. `{{ tags.start_date|osmFormatDate({ format: 'short' }) }}`. See [openstreetmap-date-format](https://github.com/plepe/openstreetmap-date-format) for details.
* filter `natsort`: Sort an array naturally, see [natsort](https://www.npmjs.com/package/natsort) for details.

3
src/twigFunctions.js

@ -53,7 +53,8 @@ OverpassLayer.twig.extendFilter('matches', function (value, param) {
throw new Error("Filter 'matches' needs a parameter!")
}
return value.toString().match(param[0])
const r = new RegExp(...param)
return value.toString().match(r)
})
OverpassLayer.twig.extendFilter('natsort', function (values, options) {
return values.sort(natsort(options))

Loading…
Cancel
Save