Created
May 28, 2021 02:30
-
-
Save erwinv/af582183aa0e1c6cd8e3a594b2d22e5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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