Skip to content

Commit

Permalink
Remove extract-domain dependency (#105)
Browse files Browse the repository at this point in the history
do the same using native `URL` and strip www
  • Loading branch information
Kikobeats authored May 9, 2018
1 parent 7e44352 commit 03a28a5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 0 additions & 1 deletion packages/react-microlink/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"previsualization"
],
"dependencies": {
"extract-domain": "~2.0.3",
"nanoclamp": "~1.2.6"
},
"devDependencies": {
Expand Down
12 changes: 10 additions & 2 deletions packages/react-microlink/src/components/Card/CardContent.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
/* global URL */

import React from 'react'
import styled, { css } from 'styled-components'
import extractDomain from 'extract-domain'
import CardText from './CardText'

import { media } from '../../utils'

const REGEX_STRIP_WWW = /^www\./

const getHostname = href => {
const { hostname } = new URL(href)
return hostname.replace(REGEX_STRIP_WWW, '')
}

const isLarge = cardSize => cardSize === 'large'

const largeContentStyle = css`
Expand Down Expand Up @@ -68,7 +76,7 @@ export default ({ title, description, url, cardSize, className }) => (
<CardText lines={2}>{description}</CardText>
</Description>
<Url className='microlink_card__content_url'>
<CardText lines={1}>{extractDomain(url)}</CardText>
<CardText lines={1}>{getHostname(url)}</CardText>
</Url>
</Content>
)
4 changes: 3 additions & 1 deletion packages/react-microlink/stories/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export const urls = [
'http://es.engadget.com/2017/10/23/meizu-m6-note-analisis-review-fotos',
'https://www.nytimes.com/2017/09/19/learning/whats-going-on-in-this-graph-sept-19-2017.html',
'https://gizmodo.com/drone-video-of-border-wall-prototypes-accidentally-show-1819710328',
'https://www.bbc.com/news/technology-40762328'
'https://www.bbc.com/news/technology-40762328',
'https://browserless.js.org',
'https://xn--vi8hl0c.ws/'
]

export const urlsVideo = [
Expand Down

0 comments on commit 03a28a5

Please sign in to comment.