diff --git a/src/helpers.js b/src/helpers.js index 902ffa7..d1c03ec 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -5,7 +5,8 @@ export const slugifyString = (str) => { .trim() .replace(/[^\w\s-]/g, '') .replace(/[\s_-]+/g, '-') - .replace(/^-+|-+$/g, ''); + .replace(/^-+/g, '') + .replace(/-+$/g, ''); }; export const convertDateToSeconds = (date, onChangeFunction) => { diff --git a/src/helpers.test.js b/src/helpers.test.js new file mode 100644 index 0000000..5062997 --- /dev/null +++ b/src/helpers.test.js @@ -0,0 +1,5 @@ +import { slugifyString } from './helpers'; + +test('it can slugify a string', () => { + expect(slugifyString("hello-world_ and then Some such-")).toEqual('hello-world-and-then-some-such'); +});