This page is part of a static HTML representation of TriTarget.org at https://tritarget.org

examples/state-machines-work-for-logic-too

Sukima14th May 2020 at 2:30pm

Example of using generator functions, finite state machine, and op code parsing for a simplistic URI Template like utility.

Read the full article about this.

function uriTemplate(template) {
  return compileTemplate(parseTemplate(template));
}

let template = uriTemplate('foo.com{/bar,baz}');
let result = template({ bar: 'BAR', baz: 'BAZ' });
console.log(result);