Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/earthstar/src/entries/universal.ts>parseTemplate

Storage for private, distributed, offline-first applications.
Go to Latest
function parseTemplate
import { parseTemplate } from "https://deno.land/x/earthstar@v10.2.0/src/entries/universal.ts";

This is a low-level helper for the template matching code; probably don't use it directly.

Given a template, parse it and return:

  • a list of variable names
  • a glob for searching Earthstar using queryByGlob()
  • a regular expression with named capture groups which can extract the values of the variables from a path.

A variable in the template is any alphanumeric chars or underscores, in curly braces like {example} or {EXAMPLE} or {example_1}, starting with a non-number.

Templates can also contain * and ** according to the glob rules. Those wildcards are not counted as variables but are allowed to expand during the regex phase.

Rules for templates:

  • Variable names must only contain upper and lower letters, numbers, and underscore.
  • They cannot start with a number.
  • They cannot be empty {}.
  • Two variables cannot be directly touching {like}{this}.
  • A variable cannot be directly touching a star {likeThis}* or *{likeThis}.

If variable names don't match these rules, a ValidationError will be thrown.

Parameters

template: string

Returns

ParsedTemplate