eemeli/fluent-compiler

Use @fluent/dedent

Closed this issue ยท 1 comments

stasm commented

Hi @eemeli ๐Ÿ‘‹ I noticed that you implemented a dedentation helper in:

export function ftl(strings) {
const [code] = strings
const lines = code.split('\n').slice(1, -1)
const indents = lines.filter(nonBlank).map(countIndent)
const common = Math.min(...indents)
const indent = new RegExp(`^\\s{${common}}`)
const dedented = lines.map(line => line.replace(indent, ''))
return `${dedented.join('\n')}\n`
}

Not too long ago I extracted and refactored the ftl helper into its own package: https://github.com/projectfluent/fluent.js/tree/master/fluent-dedent

Perhaps you'd like to switch to it? I can create a pull request, if you wish.

Sure, I'm fine with switching, and would welcome a PR.

FYI, the dedenter is only used in the tests, and it probably cleans up leading & trailing empty lines a bit differently than @fluent/dedent. I also just pushed a bunch of changes that bring the implementation in line with projectfluent/fluent.js#380, in case you start working on this.