@spenpai/tagscript
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

TagScript

A simple and safe template engine.

npm codecov npm

Description

TagScript is a drop in easy to use string interpreter that lets you provide users with ways of customizing their profiles or chat rooms with interactive text.

Read Full Documentation here.


Features

  • Written In Typescript
  • Offers CJS, ESM and UMD builds
  • Full TypeScript & JavaScript support
  • Faster than
  • Simple, expressive and safe template engine.
  • Supports your own parsers and transformers

Installation

# npm
npm i tagscript

# yarn
yarn add tagscript

Usage


Note: While examples uses import, it maps 1:1 with CommonJS' require syntax. For example,

import { Interpreter } from 'tagscript';

is the same as

const { Interpreter } = require('tagscript');

import { Interpreter, RandomParser, RangeParser, FiftyFiftyParser, IfStatementParser, SliceParser } from 'tagscript';
const ts = new Interpreter(new SliceParser(), new FiftyFiftyParser(), new RandomParser(), new IfStatementParser());

const result = await ts.run(
	`
    {random: Parbez,Rkn,Priyansh} attempts to pick the lock!,
    I pick {if({5050:.}!=):heads|tails}
    `
);

Parsers

Parsers are used to parse a tag and return a value based on the tag. You can use our builtin parsers or write your own parsers. Your own parser should implement IParser interface.

import { Interpreter, RandomParser, RangeParser, FiftyFiftyParser, IfStatementParser, SliceParser } from 'tagscript';
const ts = new Interpreter(new SliceParser(), new FiftyFiftyParser(), new RandomParser(), new IfStatementParser());

Transformers

Transformers are used to transform a value based on the tag at runtime. You can use our builtin transformers or write your own transformers. Your own transformer should implement ITransformer interface.

import { Interpreter, StringTransformer } from 'tagscript';
const ts = new Interpreter();

await ts.run(str, { args: new StringTransformer(args) });

Buy me some doughnuts

If you want to support me by donating, you can do so by using any of the following methods. Thank you very much in advance!

Buy Me A Coffee Buy Me a Coffee at ko-fi.com

Contributors

Thanks goes to these wonderful people (emoji key):


Parbez

💻 🚧 🤔

WhiteSource Renovate

🚧

Jeroen Claassens

🚧

This project follows the all-contributors specification. Contributions of any kind welcome!

Special Thanks

  • JonSnowbd for creating TagScript in python.

Package Sidebar

Install

npm i @spenpai/tagscript

Weekly Downloads

3

Version

1.0.2

License

none

Unpacked Size

276 kB

Total Files

10

Last publish

Collaborators

  • devspen