Socket
Book a DemoInstallSign in
Socket

js-native-template

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-native-template

## Installation

1.0.3
latest
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

JS Native Template

Installation

yarn add js-native-template

Examples

Basic

const createParser = require('js-native-template');

const parse = createParser();

(async () => {
  const result = await parse('Sum: 1 + 1 = ${1+1}');
  // result === 'Sum: 1 + 1 = 2'
})();

With custom methods

const createParser = require('js-native-template');

const methods = {
  echo: (x) => x,
  asyncEcho: async (x) => x
}

const parse = createParser(methods);

(async () => {
  const result = await parse('Echoes: ${echo("foo").toUpperCase()} ${asyncEcho("bar")}');
  // result === 'Echoes: FOO bar'
)();

Catch errors

const createParser = require('js-native-template');

const parse = createParser();

(async () => {
  try {
  const result = await parse('Throw error: ${nonExisting}');
  } catch(err){
    // err.message === 'nonExisting is not defined at 1:16' - position of occured error is relative in parsed string
  }
})();

FAQs

Package last updated on 17 Aug 2017

Did you know?

Socket

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.