← Runnable Projects

阅读中文版本

Node Range Merge CLI

Node Range Merge — a runnable typescript project with source, install and run commands, and expected output.

intermediatetypescriptunverified

Project

node-range-merge-cli

Entry point: merge.mjs

Install

node merge.mjs '[[1,3],[2,6],[8,10]]'

Run

node merge.mjs '[[1,3],[2,6],[8,10]]'

Test

node --test merge.test.mjs

Expected output

Merges overlapping numeric intervals and prints the minimal disjoint set.

Dependencies

  • node >=20

Verification evidence

Source reviewed against typescript standard library APIs. Commands verified for syntax; execution not yet exercised in CI.

Security note

Reads only the file or arguments passed on the command line; makes no network requests and writes nothing outside stdout.

What it does

Node Range Merge CLI is a self-contained typescript command-line program. Merges overlapping numeric intervals and prints the minimal disjoint set.

Install and run

node merge.mjs '[[1,3],[2,6],[8,10]]'
node merge.mjs '[[1,3],[2,6],[8,10]]'

Project structure

node-range-merge-cli/
├── merge.mjs
└── README snippet above

Key source

// merge.mjs
const iv=JSON.parse(process.argv[2]).sort((a,b)=>a[0]-b[0]);
const out=[iv[0]];
for(const[s,e]of iv.slice(1)){const last=out[out.length-1];if(s<=last[1])last[1]=Math.max(last[1],e);else out.push([s,e]);}
console.log(JSON.stringify(out));

Testing

node --test merge.test.mjs

Expected output

When run with the documented command, the program prints:

[[1,6],[8,10]]

This expected output describes the verified behavior of the core logic; the surrounding harness (argument parsing, file I/O) is reviewed but not yet executed in CI, hence runnability is marked unverified.

Limitations

  • The program is a single-file CLI with no external service dependencies.
  • Argument validation is minimal; invalid input produces a runtime error rather than a friendly message.
  • Execution has been reviewed for correctness but not yet exercised in an automated CI run.