From cc97a4dd2a967e1c2273bd5f4c5f49a5bf2e2585 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 27 Mar 2019 21:01:33 +0100 Subject: remove node_modules --- node_modules/shelljs/src/uniq.js | 91 ---------------------------------------- 1 file changed, 91 deletions(-) delete mode 100644 node_modules/shelljs/src/uniq.js (limited to 'node_modules/shelljs/src/uniq.js') diff --git a/node_modules/shelljs/src/uniq.js b/node_modules/shelljs/src/uniq.js deleted file mode 100644 index 30121616a..000000000 --- a/node_modules/shelljs/src/uniq.js +++ /dev/null @@ -1,91 +0,0 @@ -var common = require('./common'); -var fs = require('fs'); - -// add c spaces to the left of str -function lpad(c, str) { - var res = '' + str; - if (res.length < c) { - res = Array((c - res.length) + 1).join(' ') + res; - } - return res; -} - -common.register('uniq', _uniq, { - canReceivePipe: true, - cmdOptions: { - 'i': 'ignoreCase', - 'c': 'count', - 'd': 'duplicates', - }, -}); - -//@ -//@ ### uniq([options,] [input, [output]]) -//@ Available options: -//@ -//@ + `-i`: Ignore case while comparing -//@ + `-c`: Prefix lines by the number of occurrences -//@ + `-d`: Only print duplicate lines, one for each group of identical lines -//@ -//@ Examples: -//@ -//@ ```javascript -//@ uniq('foo.txt'); -//@ uniq('-i', 'foo.txt'); -//@ uniq('-cd', 'foo.txt', 'bar.txt'); -//@ ``` -//@ -//@ Filter adjacent matching lines from input -function _uniq(options, input, output) { - // Check if this is coming from a pipe - var pipe = common.readFromPipe(); - - if (!pipe) { - if (!input) common.error('no input given'); - - if (!fs.existsSync(input)) { - common.error(input + ': No such file or directory'); - } else if (fs.statSync(input).isDirectory()) { - common.error("error reading '" + input + "'"); - } - } - if (output && fs.existsSync(output) && fs.statSync(output).isDirectory()) { - common.error(output + ': Is a directory'); - } - - var lines = (input ? fs.readFileSync(input, 'utf8') : pipe). - trimRight(). - split(/\r*\n/); - - var compare = function (a, b) { - return options.ignoreCase ? - a.toLocaleLowerCase().localeCompare(b.toLocaleLowerCase()) : - a.localeCompare(b); - }; - var uniqed = lines.reduceRight(function (res, e) { - // Perform uniq -c on the input - if (res.length === 0) { - return [{ count: 1, ln: e }]; - } else if (compare(res[0].ln, e) === 0) { - return [{ count: res[0].count + 1, ln: e }].concat(res.slice(1)); - } else { - return [{ count: 1, ln: e }].concat(res); - } - }, []).filter(function (obj) { - // Do we want only duplicated objects? - return options.duplicates ? obj.count > 1 : true; - }).map(function (obj) { - // Are we tracking the counts of each line? - return (options.count ? (lpad(7, obj.count) + ' ') : '') + obj.ln; - }).join('\n') + '\n'; - - if (output) { - (new common.ShellString(uniqed)).to(output); - // if uniq writes to output, nothing is passed to the next command in the pipeline (if any) - return ''; - } else { - return uniqed; - } -} - -module.exports = _uniq; -- cgit v1.2.3