dmnd/dedent

Expose a util function

jimthedev opened this issue · 5 comments

Hi there. Thanks for the package. It works really well.

One small piece of feedback: as someone who is using this in my own library and not as a template writer, I don't actually have any templates in my own code. Instead, users pass templates to my library. I just need to know that the templates passed to my package methods have been dedented. So, really I just want to call a simple function that returns a new, dedented template.

Here is the function that I'm currently using to do do this:

var dedent = require('dedent');

function dd(str) {
    return dedent`${str}`;
}

Then calling dd(template); will obviously return a dedented version of template. It would be nice if this method was accessible somewhere.

Cheers.

Shameless plug — you can use my version for this purpose: https://github.com/surganov/dedent.

Also, there's an interesting use case of dedent as a higher-order template tag as seen in another version of dedent:

deindent(String.raw)`
    this
    is
  the ${ "end" }
      my only
      friend
    the end
`;
dmnd commented

@jimthedev Thanks for the suggestion! It's in 0.4.0. 🎉

@dmnd Thanks! Good work.

@surganov Good to see another variety. I'd imagine that there will be an increased need for these kinds of utils as ES6 adoption moves forward. It'd be nice to see some consolidation under a common organization/library similar to lodash. I guess it is still early. :)

@jimthedev do you have any ideas on missing utlity functions for ES6?

@surganov Good q. Specifically there are some dsls where indentation matters and it would be handy to be able to take a string literal and ensure that indentation is applied correctly.

Take the case of indented code in markdown. You might want to dedent but then pad each line with 4 spaces. This is probably too specific a use case to warrant being included in a library. I'm pretty sure there are other cases like this that I'm not thinking of, but for now, this illustrates the type of thing you might want to do using new es6 features that previously you might have done differently.