From 874998dcd80fa9d61780012866549dc9eb73660c Mon Sep 17 00:00:00 2001 From: Adam Trager Date: Fri, 3 Sep 2021 11:38:35 -0400 Subject: [PATCH] Add option to split on digit strings Had a need for this use case, thought it might be valuable to others --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index a9826e2..d7b570b 100644 --- a/index.js +++ b/index.js @@ -11,6 +11,7 @@ module.exports = (str, options) => { if (typeof str !== 'string') throw new TypeError('expected a string'); return str.trim() .replace(/([a-z])([A-Z])/g, '$1-$2') + .replace(/(\d+)/g, m => options && options.splitOnDigits ? `-${m}-` : m) .replace(/\W/g, m => /[À-ž]/.test(m) ? m : '-') .replace(/^-+|-+$/g, '') .replace(/-{2,}/g, m => options && options.condense ? '-' : m)