perfectionize toCssClass and add sanitizeTheatreKey

dependencies hashes:
openFrameworks d78075f4bca6be2a2533c6e51a75cc1f18404501
ofxMsdfgen e14da13d02c4dff04fb69d7923469f606924e6c3
ofxGPUFont d482bb7cbdf6b296fa4ab5abcf73fb5ff8c8b239
ofxVariableLab 0b5f9bdebc1e5550621957e73c040c258ec6317b
ofxProfiler a868e34fa1a79189dd4fbdede2938e308535e5e8
theatre 86d3e07f6f2c75fd6e08fca8c97e3617c9e23b18
This commit is contained in:
themancalledjakob 2024-04-12 12:17:49 +02:00
parent d050789d77
commit d42a1365a4

View file

@ -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-')
const cssClass = prefix + 'vt_' + text
.replaceAll('.', '-d-')
.replaceAll(' ', '_')
.replaceAll('#','-hash-')
.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,