This repository has been archived on 2024-07-27. You can view files and clone it, but cannot push or open issues or pull requests.
keksAccountGUI/node_modulesOLD/eslint/lib/util/interpolate.js

29 lines
764 B
JavaScript
Raw Normal View History

2019-08-11 18:48:02 +00:00
/**
* @fileoverview Interpolate keys from an object into a string with {{ }} markers.
* @author Jed Fox
*/
"use strict";
//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------
module.exports = (text, data) => {
if (!data) {
return text;
}
// Substitution content for any {{ }} markers.
return text.replace(/\{\{([^{}]+?)\}\}/gu, (fullMatch, termWithWhitespace) => {
const term = termWithWhitespace.trim();
if (term in data) {
return data[term];
}
// Preserve old behavior: If parameter name not provided, don't replace it.
return fullMatch;
});
};