My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Just rewrote JS template engine library - advice on syntax and publishing

Ben Gubler's photo
Ben Gubler
·Jan 24, 2020

Hi everyone! So, I just finished a major rewrite of my template engine library, Squirrelly (the new version can be found here).

Features include:

  • Super fast parsing times
  • Plugins
  • Filters
  • Filter parameters
  • Native code
  • Comments
  • Nice syntax
  • Configurable whitespace trimming
  • About 2.5 KB Gzipped, 6 KB minified
  • Custom Delimeters
  • Caching
  • Doesn't require ES6

Code examples:

Sqrl.Render("my favorite template engine is {{it.fav}}", {fav: "Squirrelly"})
// my favorite template engine is Squirrelly
Items: {{it.items | join (", ") | capitalize}}
var eachTemplate = `The Daugherty's have 8 kids. Their names are:
{{~each (it.kids) => val, index}}
{{~if(index < it.kids.length - 1_}}
  {{val}},
{{_#else_}}
  and {{val}}
{{_/if}}
{{_/each}}`

var res = Render(eachTemplate, { kids: ['Ben', 'Polly', 'Joel', 'Phronsie', 'Davie'] })
// The Daugherty's have 8 kids. Their names are:

// Ben,
// Polly,
// Joel,
// Phronsie,
// and Davie
{{~try}}
This won't work: {{ error }}
{{#catch => err}}
Uh-oh, error! Message was '{{err.message}}'
{{/try}}

Now, for the question parts of this post:

  1. First of all, I decided to go with doT-styled references to reference data (but without the =): {{it.someValue}}. This means that I allow what doT calls 'evaluate syntax' (just sticking in native code) like this: {{!whatever}}.

    • My question is whether I should switch, so you would reference variables like {{=it.name}} or {{=someLocallyDefinedVariable}} and use {{ whatever }} for evaluate syntax. The main convenience of this would be that comments would look nicer (ex. {{/comment/}} instead of {{!/comment/}}.
  2. My other question is about publishing. Should I publish as squirrelly-next on NPM, or publish it as version 8 of Squirrelly, or choose another name (like Gopher?)

    • Squirrelly has a bit of name recognition (220 stars on GitHub, 90 dependent packages) but is kind of hard to spell. I also don't want to break all the tutorials about how to use it