From 98fd922915e77797f60c96d465abe5dab02ac92b Mon Sep 17 00:00:00 2001 From: Ellie Strejlau Date: Mon, 11 Mar 2019 12:12:19 -0400 Subject: [PATCH] Fix error when pasting an image into Slate image example. (#2592) * Fix error when pasting an image into Slate. * Change isImage to call getExtension, which uses the URL API. Additionally, make sure JSDocs are consistent. --- examples/images/index.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/examples/images/index.js b/examples/images/index.js index ec2e9c3b9..7f17e0db5 100644 --- a/examples/images/index.js +++ b/examples/images/index.js @@ -29,7 +29,7 @@ const Image = styled('img')` box-shadow: ${props => (props.selected ? '0 0 0 2px blue;' : 'none')}; ` -/* +/** * A function to determine whether a URL has an image extension. * * @param {String} url @@ -37,7 +37,18 @@ const Image = styled('img')` */ function isImage(url) { - return !!imageExtensions.find(url.endsWith) + return imageExtensions.includes(getExtension(url)) +} + +/** + * Get the extension of the URL, using the URL API. + * + * @param {String} url + * @return {String} + */ + +function getExtension(url) { + return new URL(url).pathname.split('.').pop() } /**