cli.js 549 B

123456789101112131415161718192021
  1. #!/usr/bin/env node
  2. 'use strict';
  3. const { parse } = require('..');
  4. const readline = require('readline');
  5. if (process.argv.length > 2) {
  6. // URL(s) was specified in the command arguments
  7. console.log(
  8. JSON.stringify(parse(process.argv[process.argv.length - 1]), null, 2),
  9. );
  10. } else {
  11. // No arguments were specified, read URLs from each line of STDIN
  12. const rlInterface = readline.createInterface({
  13. input: process.stdin,
  14. });
  15. rlInterface.on('line', function (line) {
  16. console.log(JSON.stringify(parse(line), null, 2));
  17. });
  18. }