Installations
npm install tagged-templates-io
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
16.13.1
NPM Version
8.18.0
Score
70.2
Supply Chain
98.8
Quality
75.8
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
Download Statistics
Total Downloads
5,347
Last Day
1
Last Week
12
Last Month
49
Last Year
1,913
GitHub Statistics
1 Stars
14 Commits
1 Forks
2 Watching
1 Branches
1 Contributors
Bundle Size
2.55 kB
Minified
880.00 B
Minified + Gzipped
Package Meta Information
Latest Version
1.0.9
Package Id
tagged-templates-io@1.0.9
Unpacked Size
11.93 kB
Size
3.54 kB
File Count
4
NPM Version
8.18.0
Node Version
16.13.1
Total Downloads
Cumulative downloads
Total Downloads
5,347
Last day
0%
1
Compared to previous day
Last week
-25%
12
Compared to previous week
Last month
-54.2%
49
Compared to previous month
Last year
168.3%
1,913
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
No dependencies detected.
Read me
In most projects we use interpolations for several reasons. This could be simple html class-names, sql queries, or even more complicated strings that needs to be mutated on the fly. This is what this package is good for. You can easily create your own dynamic strings, with conditions, expressions or whatever you need.
API Reference
1taggedTemplate(pattern, values, conditions); // string
Pattern | Values | Conditions | Result |
---|---|---|---|
string | number, string, [number or string] | boolean, string, number, null, [boolean, string, number, null] | string |
text {0} | 'val 1' | null | 'text val 1' |
text {0} and {0} | 'val 1' | null | 'text val 1 and val 1' |
text {0} and {1} | 'val 1' | null | 'text val 1 and val 1' |
text {0} and {1} | ['val 1', 'val 2'] | null | 'text val 1 and val 2' |
text {0} and {1} | [ ['val 1.0', 'val 1.1'], ['val 2.0', 'val 2.1'] ] | [ true, false ] | 'text val 1.0 and val 2.1' |
text {0} and {1} | [ ['val 1.0', 'val 1.1'], ['val 2.0', 'val 2.1'] ] | [ true, null ] | 'text val 1.0 and val 2.0' |
text {key1} and {key2} | { key1: ['val 1.1', 'val 1.2'], key2: ['val 2.1', 'val 2.2'] } | null | 'text val 1.1,val 1.2 and val 2.1,val 2.2' |
text {key1} and {key2} | { key1: ['val 1.1', 'val 1.2'], key2: ['val 2.1', 'val 2.2'] } | { key1: true, key2: false } | 'text val 1.1 and val 2.2' |
text {key1} and {key2} | { key1: ['val 1.1', 'val 1.2'], key2: ['val 2.1', 'val 2.2'] } | { key1: 'true', key2: null } | 'text val 1.1 and val 2.2' |
(key) => `text ${key}` | 'val 1' | null | 'text val 1' |
(key) => `text ${key}` | ['val 1'] | null | 'text val 1' |
(key) => `text ${key}` | ['val 1'] | true | 'text val 1' |
(key) => `text ${key}` | ['val 1'] | [true] | 'text val 1' |
(key) => `text ${key}` | ['val 1'] | [false] or false | 'text val 1' |
(key1, key2) => `text ${key1} and ${key2}` | [['val 1.1','val 1.2'],['val 2.1', 'val 2.2']] | [true, false] | 'text val 1.1 and val 2.2' |
Examples
Html class names
1const isFirstNavItem = index === 0; 2 3const className = taggedTemplate( 4 `link__{1}--{0} link__type--{1}`, 5 [['active',''], 'nav'], 6 [isFirstNavItem, true] 7); 8 9<h1 :class="className">Title</h1> // VueJs Sample 10 11// Output 12 13// <h1 class="link__nav--active link__type--nav">Title</h1> 14
SQL
1const isClient = true; 2const as = 'age'; 3const from = ['clientTable', 'relationTable']; 4const fromCondition = isClient; 5const where = `${as} = ${42}`; 6const start = 0, end = 10; 7 8const a = taggedTemplate(` 9 SELECT {select} AS {as} 10 FROM {from} 11 WHERE {where} 12 LIMIT {start}, {end} 13`, 14 { select: 'age_col', as, from, where, start, end }, 15 { from: fromCondition }, 16) 17
Render HTML
1 2const classHandler = (id, activeIndex, classes) => { 3 if (!!classes) { 4 return taggedTemplate( 5 `class="{0}"`, 6 [[Array.from(new Set(classes)).join(' '), classes[0]]], 7 [id === activeIndex] 8 ); 9 } 10}; 11 12const activeIndex = 1; 13 14const result = taggedTemplate( 15 (listWrapper, listItems, activeClass, activeIndex) => ` 16 <ul class="${listWrapper}"> 17 ${listItems.reduce((ul, {id, label}) => { 18 return ul+`<li id="${id}" ${classHandler(id, activeIndex, activeClass)}>${label}</li>`; 19 }, '')} 20 </ul> 21 `, 22 [ 23 'list__wrapper', 24 [ 25 { id: 1, label: 'Item 1' }, 26 { id: 2, label: 'Item 2' } 27 ], 28 ['list__item','list__item--active'], 29 activeIndex 30 ] 31); 32 33/** 34 * Outputs 35 36<ul class="list__wrapper"> 37 <li id="1" class="list__item list__item--active"> 38 Item 1</li> 39 <li id="2" class="list__item"> 40 Item 2</li> 41</ul> 42 43*/
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE.md:0
- Info: FSF or OSI recognized license: MIT License: LICENSE.md:0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/14 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More