diff options
author | Florrie <towerofnix@gmail.com> | 2018-04-08 11:41:22 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-04-08 11:41:22 -0300 |
commit | 372cd36afdf6f489b00fb23893a480819883886a (patch) | |
tree | dd12c836c5f81780e5f06ca7e9663a6d2cd4a2c2 /src/general-util.js | |
parent | db7cd9742b271dad089b3fdffb099c05a599d0f5 (diff) |
Internal support for custom status lines
Diffstat (limited to 'src/general-util.js')
-rw-r--r-- | src/general-util.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/general-util.js b/src/general-util.js index b37f516..63f0312 100644 --- a/src/general-util.js +++ b/src/general-util.js @@ -313,3 +313,31 @@ module.exports.makePlaylistOptions = function() { } } } + +module.exports.processTemplateString = function(string, replacements) { + let outString = '' + let currentReplacement = null + for (let i = 0; i < string.length; i++) { + const char = string[i] + + if (char === '%') { + if (currentReplacement === null) { + currentReplacement = '' + } else { + if (Object.keys(replacements).includes(currentReplacement)) { + outString += replacements[currentReplacement].toString() + } else { + outString += '%UnknownKey:' + currentReplacement + '%' + } + currentReplacement = null + } + } else { + if (currentReplacement === null) { + outString += char + } else { + currentReplacement += char + } + } + } + return outString +} |