Gathering detailed insights and metrics for @brdu/expand-template
Gathering detailed insights and metrics for @brdu/expand-template
Gathering detailed insights and metrics for @brdu/expand-template
Gathering detailed insights and metrics for @brdu/expand-template
Expands placeholders in a string template based on named or positional arguments. It's also possible to use complex templates including lists and conditionals.
npm install @brdu/expand-template
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1 Stars
4 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Mar 05, 2023
Latest Version
1.0.2
Package Id
@brdu/expand-template@1.0.2
Unpacked Size
22.02 kB
Size
6.43 kB
File Count
11
NPM Version
6.14.6
Node Version
12.18.3
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
4
Expands placeholders in a string template based on named or positional arguments. It's also possible to use complex templates including lists and conditionals.
$ npm install --save @brdu/expand-template
Simple templates accept both named and positional arguments, as well as nested named arguments.
The placeholder format for this template is %(key)
. Simple templates are also used within conditional templates and list templates.
const expand = require('@brdu/expand-template')
let template = 'Hello %(name). How are you doing today?'
let args = { name: 'Buffolander' }
console.info(expand({ template, args }))
// 'Hello Buffolander. How are you doing today?'
template = 'Hello %(1) and %(0). How are you doing?'
args = ['Buffolander', 'Kelly']
console.info(expand({ template, args }))
// 'Hello Kelly and Buffolander. How are you doing?'
template = '...schedule an appointment with Dr. %(md.last_name)'
args = {
patient: 'any',
md: {
first_name: 'John',
last_name: 'Smith',
},
}
console.info(expand({ template, args }))
// '...schedule an appointment with Dr. Smith'
Conditional templates use one or more keys to validate wether to expand variables within that section or to remove the section altogether.
The placeholder format for this template is [?(keyA, keyB) <simpleTemplate>]
.
template = 'Hello world! [?(weather, city) It\'s a %(weather) day in %(city).]'
args = { weather: 'sunny' }
console.info(expand({ template, args }))
// 'Hello world!' // city missing in args; conditional section removed
args = { ...args, city: 'Miami' }
console.info(expand({ template, args }))
// 'Hello world! It\'s a sunny day in Miami.'
Finally, list templates take an array as input for repeating text sections. The placeholder format for this template is [[%(key) <simpleTemplate>]]
. On this template index
is a reserved key, used to print out the position in the array.
template = 'Hello there, please [[%(directory) press %(index) for %(department)]].'
args = {
company: 'Acme',
directory: [{
department: 'Sales',
}, {
department: 'Support',
}],
}
console.info(expand({ template, args }))
// 'Hello there, please press 0 for Sales, press 1 for Support.'
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/4 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
28 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
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