Public
Edited
Feb 22, 2023
Insert cell
Insert cell
function normalize_index_name(s, search_provider='Algolia') {
if (search_provider != "Meilisearch") {
// Replace non-alphanumeric characters with underscore except for !@#%^()-:<>? and whitespace
s = s.replace(/[^!\w\s@#%^()\-\:<>\?]+/g, '_');
}
else {
// Replace non-alphanumeric characters with underscore except for whitespace
s = s.replace(/[^\w\s]+/g, '_');
}
// Replace consecutive underscores with one underscore
s = s.replace(/_+/g, '_');
// Replace consecutive spaces with one space
s = s.replace(/\s+/g, ' ');
// Remove leading and trailing spaces
s = s.trim();
// Remove leading and trailing underscores
s = s.replace(/^_+|_+$/g, '');
return s;
}
Insert cell
tests = [
"Purchase Order Line Item",
"Content3",
" GlobalVariabletoTrackXLSXUploads ",
"_ForCatSearch ",
"FU Attachment?",
"FSA (First Site Activation____)",
"Submission #",
"BS: SqFootage__",
"#",
"Signed By Real Equity?",
"Flag-exRole",
"~!@#$%^&*())_/*-+}\{\'",
"~`!@#$%^&*()=-~!@#$%^&*())_/*-+}\{\'",
]
Insert cell
console.log(tests.map(item => normalize_index_name(item,"Algolia")))
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more