Created
May 21, 2019 15:37
-
-
Save calvinmetcalf/cc06feeffb0d05d0a6ad8694f189871d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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