d3-view
Version:
View-model d3 plugin for building interactive data-driven web interfaces
14 lines (12 loc) • 362 B
JavaScript
export default (str, options) => {
if (typeof str !== "string") {
throw new TypeError("expected a string");
}
return str
.trim()
.replace(/([a-z])([A-Z])/g, "$1-$2")
.replace(/\W/g, m => (/[À-ž]/.test(m) ? m : "-"))
.replace(/^-+|-+$/g, "")
.replace(/-{2,}/g, m => (options && options.condense ? "-" : m))
.toLowerCase();
};