No Description

sort.js 428B

123456789101112131415161718
  1. #!/usr/bin/env node
  2. var cli = require('cli');
  3. var options = cli.parse({
  4. numeric: ['n', 'Compare using a numeric sort'],
  5. reverse: ['r', 'Reverse the results']
  6. });
  7. cli.withStdinLines(function (lines, newline) {
  8. lines.sort(!options.numeric ? null : function (a, b) {
  9. return parseInt(a) > parseInt(b);
  10. });
  11. if (options.reverse) {
  12. lines.reverse();
  13. }
  14. this.output(lines.join(newline));
  15. });