1.4.1 • Published 2 years ago

@ctrl/golang-template v1.4.1

Weekly downloads
28
License
MIT
Repository
github
Last release
2 years ago

golang-template npm CircleCI coverage status

Typescript library that handles basic functions of the golang template syntax.

Install

npm install @ctrl/golang-template

Use

import { parse } from '@ctrl/golang-template';

const keywords = '123';
parse('{{ if .keywords }}{{ .keywords }}!!{{else}}nothing{{end}}', { keywords });
// '123!!'

Supported template functions

variables

`{{ .foo }}`

if..else

`{{ if .keywords }}{{ .keywords }}{{else}}nothing{{end}}`

join

const categories = ['1', '2', '3'];
parse('{{ join .categories "," }}', { categories });
// 1,2,3

range

const categories = ['1', '2', '3'];
parse('{{ range .categories }}{{.}};{{end}}', { categories });
// 1;2;3;

re_replace

const categories = ['1', '2', '3'];
parse('{{ re_replace .category "[^a-zA-Z0-9]+" "%" }}', { categories });
// 1;2;3;

index

const data = {
  object: {
    value: 'foo'
  },
  array: [
    'bar'
  ]
}
parse('{{ index .object "value" }}', data);
//foo
parse('{{ index .array 0 }}', data);
//foo

Warnings

This is probably not safe for user input.

1.4.1

2 years ago

1.4.0

3 years ago

1.3.1

4 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago