Socket
Socket
Sign inDemoInstall

@ctrl/golang-template

Package Overview
Dependencies
0
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @ctrl/golang-template

Basic golang template parsing in js


Version published
Weekly downloads
1K
decreased by-21.49%
Maintainers
1
Install size
20.3 kB
Created
Weekly downloads
 

Readme

Source

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.

Keywords

FAQs

Last updated on 05 Sep 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc