Gathering detailed insights and metrics for text-template-forked
Gathering detailed insights and metrics for text-template-forked
Gathering detailed insights and metrics for text-template-forked
Gathering detailed insights and metrics for text-template-forked
npm install text-template-forked
Typescript
Module System
Node Version
NPM Version
64
Supply Chain
95.9
Quality
75.2
Maintenance
100
Vulnerability
100
License
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
180
Last Day
1
Last Week
2
Last Month
13
Last Year
54
MIT License
10 Commits
2 Watchers
1 Branches
1 Contributors
Updated on Feb 10, 2023
Minified
Minified + Gzipped
Latest Version
1.0.7
Package Id
text-template-forked@1.0.7
Unpacked Size
9.57 kB
Size
4.01 kB
File Count
6
NPM Version
6.14.17
Node Version
14.20.0
Published on
Feb 10, 2023
Cumulative downloads
Total Downloads
Last Day
-50%
1
Compared to previous day
Last Week
-75%
2
Compared to previous week
Last Month
333.3%
13
Compared to previous month
Last Year
-57.1%
54
Compared to previous year
No dependencies detected.
On this page
start
and end
token1npm install @master/text-template
1import { TextTemplate } from '@master/text-template';
1const template = new TextTemplate(text);
equal to
1const template = new TextTemplate(text, { 2 start: '{{', 3 end: '}}', 4 behavior: '', // replace 5 language: '', // /* data */ /* */, 6 removeOnError: false, 7 delimiter: ' ', 8});
1const template = new TextTemplate('Hi {{ username }}'); 2const renderedText = template.render({ username: 'Aron' });
output renderedText
:
1Hi Aron
1const html = ` 2 <title> 3 <!-- title --><!-- --> 4 <title> 5`; 6const template = new TextTemplate(html, { 7 behavior: 'slot', 8 language: 'html' 9}); 10const renderedHtml = template.render({ title: 'Hello World' });
output renderedHtml
:
1<title> 2 <!-- title -->Hello World<!-- --> 3<title>
The slot token isn't removed, which means you can keep result and render multiple times.
1const readmeText = ` 2 # Hi {{ username }} 3 <!-- description --><!-- --> 4`; 5 6const data = { 7 username: 'Aron', 8 description: 'Hello World {{ username }}' 9} 10 11// 1. Insert 12const slotTemplate = new TextTemplate(readmeText, { 13 behavior: 'slot', 14 language: 'readme' 15}); 16 17// 2. Replace 18const template = new TextTemplate(slotTemplate.render(data)); 19 20const renderedReadmeText = template.render(data);
output renderedReadmeText
:
1# Hi Aron 2<!-- description -->Hello World Aron<!-- -->
start
and end
token1const template = new TextTemplate('Hi ${ username }', { 2 start: '${', 3 end: '}' 4});
1const data = { 2 people: ['Aron', 'Joy'] 3} 4const text = `/* people.join(' ❤️ ') */ /* */`; 5const template = new TextTemplate(text); 6const renderedText = template.render(data);
output renderedText
1/* people.join(' ❤️ ') */ Aron ❤️ Joy /* */
removeOnError: true
1const text = 'Hi {{ username }}, welcome.'; 2const data = {}; 3const t1 = new TextTemplate(text); 4const t2 = new TextTemplate(text, { removeOnError: true }); 5const r1 = t1.render(data); 6const r2 = t2.render(data);
output r1
Hi {{ username }}, welcome.
output r2
Hi , welcome.
default
1const template = new TextTemplate(html, {
2 behavior: 'slot',
3 language: 'html'
4});
1<title><!-- name -->text-template<!----></title>
custom
1const template = new TextTemplate(html, {
2 behavior: 'slot',
3 language: 'html',
4 delimiter: ' / '
5});
1<title><!-- name --><!-- / --></title>
The default values of all options are undefined
, and each has a default behavior.
start
Default {{
. Replace or slot start tokenend
Default }}
. Replace or slot end tokenbehavior
Default replace. Specify render behaviorlanguage
Required behavior: 'slot'
. Specify using comment language to set start
and end
quickly.
''
relative to /* data */ /* */
as default'html'
, readme
relative to <!-- data --> <!-- -->
'pascal'
relative to (* data *) (* *)
or { data } { }
'forth'
relative to ( data ) ()
'haskell'
relative to {- data -} {- -}
delimiter
Default
. Required behavior: 'slot'
. Specify middle delimiter for identifying endremoveOnError
Default false
. If true
, the token will be removed when the data doesn't match or js syntax go wrong.No vulnerabilities found.
No security vulnerabilities found.