Skip to content

Instantly share code, notes, and snippets.

@calvinmetcalf
Created May 21, 2019 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calvinmetcalf/cc06feeffb0d05d0a6ad8694f189871d to your computer and use it in GitHub Desktop.
Save calvinmetcalf/cc06feeffb0d05d0a6ad8694f189871d to your computer and use it in GitHub Desktop.
// 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