Skip to content

Instantly share code, notes, and snippets.

@erwinv
Created May 28, 2021 02:30
Show Gist options
  • Save erwinv/af582183aa0e1c6cd8e3a594b2d22e5a to your computer and use it in GitHub Desktop.
Save erwinv/af582183aa0e1c6cd8e3a594b2d22e5a to your computer and use it in GitHub Desktop.
import readline from 'readline'
import { Readable } from 'stream'
import { EOL } from 'os'
class MyUrl extends URL {
constructor(...args) {
super(...args)
this.searchKeys = new Set(this.searchParams.keys())
}
isSame(other) {
return this.origin === other.origin
&& this.pathname === other.pathname
&& this.searchKeys.size === other.searchKeys.size
&& [...this.searchKeys].every(myKey => other.searchKeys.has(myKey))
}
}
let urls = []
readline.createInterface(process.stdin)
.on('line', line => {
const nextUrl = new MyUrl(line)
if (!urls.find(url => url.isSame(nextUrl))) {
urls.push(nextUrl)
}
})
.on('close', () => {
Readable.from(urls.map(url => url.href + EOL))
.pipe(process.stdout)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment