Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Dollar-Quoted String Constants: see 4.1.2.4 https://www.postgresql.org/docs/9.0/static/sql-syntax-lexical.html
function tagRegex(tag) {
return new RegExp('\\$' + tag + '\\$');
}
function getBase(input) {
var tagBase = 'cartodb';
if (!input.toString().match(tagRegex(tagBase))) {
return tagBase;
}
var i = 0;
while(input.toString().match(tagRegex(tagBase + i))) {
i++;
}
return tagBase + i;
}
export default string => {
const rand = getBase(string);
return `$${rand}$${string}$${rand}$`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment