Public
Edited
May 10, 2023
1 fork
Importers
3 stars
Insert cell
Insert cell
normalize = str =>
String(str)
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "")
.replace("œ", "oe")
Insert cell
Insert cell
viewof mots = Search(
["été", "tête", "bête", "île", "ÉTÉ", "BETE", "Ile", "œil"],
{
placeholder: "try 'ile'"
}
)
Insert cell
mots
Insert cell
Insert cell
viewof mots_std = inputsMain.search(
["été", "tête", "bête", "île", "ÉTÉ", "BETE", "Ile", "œil"],
{
placeholder: "try 'ile'"
}
)
Insert cell
mots_std
Insert cell
Insert cell
import { Search as _Search } from "@observablehq/inputs"
Insert cell
Insert cell
function columnFilter(columns) {
return query => {
const filters = normalize(query + "")
.split(/\s+/gu)
.filter(t => t)
.map(termFilter);

console.warn(filters);

return d => {
out: for (const filter of filters) {
for (const column of columns) {
if (filter.test(normalize(d[column]))) {
continue out;
}
}
return false;
}
return true;
};
};
}
Insert cell
function searchFilter(query) {
const filters = normalize(query + "")
.split(/\s+/g)
.filter(t => t)
.map(termFilter);
return d => {
if (d == null) return false;
if (typeof d === "object") {
out: for (const filter of filters) {
for (const value of valuesof(d)) {
if (filter.test(normalize(value))) {
continue out;
}
}
return false;
}
} else {
for (const filter of filters) {
if (!filter.test(normalize(d))) {
return false;
}
}
}
return true;
};
}
Insert cell
function termFilter(term) {
return new RegExp(`\\b${escapeRegExp(term)}`, "iu"); // FIX THIS: \b limited to ascii
}
Insert cell
function escapeRegExp(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/gu, "\\$&");
}
Insert cell
function* valuesof(d) {
for (const key in d) {
yield d[key];
}
}
Insert cell
inputsMain = FileAttachment("inputs.js").url().then(require)
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