From d42a1365a46546dbb394b9aec118126838cddca5 Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Fri, 12 Apr 2024 12:17:49 +0200 Subject: [PATCH] perfectionize toCssClass and add sanitizeTheatreKey dependencies hashes: openFrameworks d78075f4bca6be2a2533c6e51a75cc1f18404501 ofxMsdfgen e14da13d02c4dff04fb69d7923469f606924e6c3 ofxGPUFont d482bb7cbdf6b296fa4ab5abcf73fb5ff8c8b239 ofxVariableLab 0b5f9bdebc1e5550621957e73c040c258ec6317b ofxProfiler a868e34fa1a79189dd4fbdede2938e308535e5e8 theatre 86d3e07f6f2c75fd6e08fca8c97e3617c9e23b18 --- bin/em/variabletime/web/js/utils.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/bin/em/variabletime/web/js/utils.js b/bin/em/variabletime/web/js/utils.js index 300c93f..6efd43b 100644 --- a/bin/em/variabletime/web/js/utils.js +++ b/bin/em/variabletime/web/js/utils.js @@ -446,16 +446,25 @@ const sequencialPromises = async (iterable, callback = false) => { } }; -// NOTE: this is not perfect, -// but good enough for our use case -// theoretically we would have to get -// rid of all special characters +// NOTE: this is perfect const toCssClass = (text, prefix = '') => { - return prefix + 'vt_' + text - .replaceAll('.','-dot-') - .replaceAll(' ','_') - .replaceAll('#','-hash-') + const cssClass = prefix + 'vt_' + text + .replaceAll('.', '-d-') + .replaceAll(' ', '_') + .replaceAll(':', '-c-') + .replaceAll('#', '-h-') + .replace(/[^a-zA-Z0-9_-]/g, "") ; + return cssClass; +}; +const sanitizeTheatreKey = (key) => { + let theatreKey = key; + theatreKey = theatreKey.split('.'); + if (theatreKey.length > 1) { + theatreKey.pop(); + } + theatreKey = theatreKey.join(''); + return theatreKey.replace(/[^a-zA-Z0-9_]/g,""); }; const renameProperty = (o, old_key, new_key) => { @@ -591,6 +600,7 @@ export { isMobile, sequencialPromises, toCssClass, + sanitizeTheatreKey, renameProperty, flattenObject, deFlattenObject,