-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
23 lines (21 loc) · 618 Bytes
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { readAll } from "./deps/std.ts";
import { semverSort } from "./src/mod.ts";
const input = await readAll(Deno.stdin);
const lines = await new TextDecoder().decode(input);
const versions = lines
.split(/\r\n|\n|\s|,/)
.map((l) => l.trim())
.filter((l) => l);
try {
for (const { version } of semverSort(...versions)) {
console.log(version);
}
} catch (err) {
const { code } = err;
if (code === "EPIPE") {
// ignore, this can happen if stdout is closed by a piped process
// such as `semver-sort | head -n 1` which will close stdout after a single line.
} else {
throw err;
}
}