From fd7a9bd01d5c82d5fd4dd794101bb89b2db28ba1 Mon Sep 17 00:00:00 2001 From: Ben Matheson Date: Mon, 21 Mar 2016 13:00:51 -0600 Subject: [PATCH 1/3] Give empty string in place of undefined --- slug.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slug.js b/slug.js index 010c89f..c803fd1 100644 --- a/slug.js +++ b/slug.js @@ -10,7 +10,7 @@ function symbols(code) { } function slug(string, opts) { - string = string.toString(); + string = (string || '').toString(); if ('string' === typeof opts) opts = {replacement:opts}; opts = opts || {}; From 288b8829f2982b91b19e075cf6490ab89c34179c Mon Sep 17 00:00:00 2001 From: Ben Matheson Date: Tue, 31 May 2016 13:22:41 -0600 Subject: [PATCH 2/3] Throws error if null or undefined --- slug.js | 4 +++- test.js | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/slug.js b/slug.js index c803fd1..55ac07b 100644 --- a/slug.js +++ b/slug.js @@ -10,7 +10,9 @@ function symbols(code) { } function slug(string, opts) { - string = (string || '').toString(); + if (string === null || string === undefined) + throw new Error('Slug input must be castable to string') + string = string.toString(); if ('string' === typeof opts) opts = {replacement:opts}; opts = opts || {}; diff --git a/test.js b/test.js index dbef81a..f77a9d3 100644 --- a/test.js +++ b/test.js @@ -1 +1,3 @@ console.log(require('./slug')('😹')); +console.log(require('./slug')('Test')); +console.log(require('./slug')(null)); From 6e2948d9a2e9e52aec7aea49dca36e0ee1a41768 Mon Sep 17 00:00:00 2001 From: Ben Matheson Date: Tue, 31 May 2016 13:27:50 -0600 Subject: [PATCH 3/3] Removed changes to test --- test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test.js b/test.js index f77a9d3..dbef81a 100644 --- a/test.js +++ b/test.js @@ -1,3 +1 @@ console.log(require('./slug')('😹')); -console.log(require('./slug')('Test')); -console.log(require('./slug')(null));