UNPKG

get-urls-host

Version:

Gets all URLs from a string from a particular host - uses https://npm.im/get-urls

16 lines (12 loc) 376 B
const url = require('url') const getUrls = require('get-urls') module.exports = function getUrlsHost(text, host) { let hostUrls = [] // get the URLs from the text (into the array) getUrls(text).forEach(thisUrl => hostUrls.push(thisUrl)) // now filter on the host return hostUrls.filter(thisUrl => { let u = url.parse(thisUrl) return u.host == host }) }