diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-10-10 03:43:44 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-10-10 03:43:44 +0200 |
commit | abd94a7f5a50f43c797a11b53549ae48fff667c3 (patch) | |
tree | ab8ed457f65cdd72e13e0571d2975729428f1551 /node_modules/detect-indent | |
parent | a0247c6a3fd6a09a41a7e35a3441324c4dcb58be (diff) | |
download | wallet-core-abd94a7f5a50f43c797a11b53549ae48fff667c3.tar.xz |
add node_modules to address #4364
Diffstat (limited to 'node_modules/detect-indent')
-rwxr-xr-x | node_modules/detect-indent/cli.js | 55 | ||||
-rw-r--r-- | node_modules/detect-indent/index.js | 119 | ||||
-rw-r--r-- | node_modules/detect-indent/license | 21 | ||||
l--------- | node_modules/detect-indent/node_modules/.bin/repeating | 1 | ||||
-rwxr-xr-x | node_modules/detect-indent/node_modules/repeating/cli.js | 36 | ||||
-rw-r--r-- | node_modules/detect-indent/node_modules/repeating/index.js | 24 | ||||
-rw-r--r-- | node_modules/detect-indent/node_modules/repeating/license | 21 | ||||
-rw-r--r-- | node_modules/detect-indent/node_modules/repeating/package.json | 105 | ||||
-rw-r--r-- | node_modules/detect-indent/node_modules/repeating/readme.md | 40 | ||||
-rw-r--r-- | node_modules/detect-indent/package.json | 113 | ||||
-rw-r--r-- | node_modules/detect-indent/readme.md | 120 |
11 files changed, 655 insertions, 0 deletions
diff --git a/node_modules/detect-indent/cli.js b/node_modules/detect-indent/cli.js new file mode 100755 index 000000000..0fb804e1a --- /dev/null +++ b/node_modules/detect-indent/cli.js @@ -0,0 +1,55 @@ +#!/usr/bin/env node +'use strict'; +var fs = require('fs'); +var stdin = require('get-stdin'); +var argv = require('minimist')(process.argv.slice(2)); +var pkg = require('./package.json'); +var detectIndent = require('./'); +var input = argv._[0]; + +function help() { + console.log([ + '', + ' ' + pkg.description, + '', + ' Usage', + ' detect-indent <file>', + ' echo <string> | detect-indent', + '', + ' Example', + ' echo \' foo\\n bar\' | detect-indent | wc --chars', + ' 2' + ].join('\n')); +} + +function init(data) { + var indent = detectIndent(data).indent; + + if (indent !== null) { + process.stdout.write(indent); + } else { + console.error('Indentation could not be detected'); + process.exit(2); + } +} + +if (argv.help) { + help(); + return; +} + +if (argv.version) { + console.log(pkg.version); + return; +} + +if (process.stdin.isTTY) { + if (!input) { + help(); + return; + } + + init(fs.readFileSync(input, 'utf8')); +} else { + stdin(init); +} diff --git a/node_modules/detect-indent/index.js b/node_modules/detect-indent/index.js new file mode 100644 index 000000000..e9b91424c --- /dev/null +++ b/node_modules/detect-indent/index.js @@ -0,0 +1,119 @@ +'use strict'; +var repeating = require('repeating'); + +// detect either spaces or tabs but not both to properly handle tabs +// for indentation and spaces for alignment +var INDENT_RE = /^(?:( )+|\t+)/; + +function getMostUsed(indents) { + var result = 0; + var maxUsed = 0; + var maxWeight = 0; + + for (var n in indents) { + var indent = indents[n]; + var u = indent[0]; + var w = indent[1]; + + if (u > maxUsed || u === maxUsed && w > maxWeight) { + maxUsed = u; + maxWeight = w; + result = +n; + } + } + + return result; +} + +module.exports = function (str) { + if (typeof str !== 'string') { + throw new TypeError('Expected a string'); + } + + // used to see if tabs or spaces are the most used + var tabs = 0; + var spaces = 0; + + // remember the size of previous line's indentation + var prev = 0; + + // remember how many indents/unindents as occurred for a given size + // and how much lines follow a given indentation + // + // indents = { + // 3: [1, 0], + // 4: [1, 5], + // 5: [1, 0], + // 12: [1, 0], + // } + var indents = {}; + + // pointer to the array of last used indent + var current; + + // whether the last action was an indent (opposed to an unindent) + var isIndent; + + str.split(/\n/g).forEach(function (line) { + if (!line) { + // ignore empty lines + return; + } + + var indent; + var matches = line.match(INDENT_RE); + + if (!matches) { + indent = 0; + } else { + indent = matches[0].length; + + if (matches[1]) { + spaces++; + } else { + tabs++; + } + } + + var diff = indent - prev; + prev = indent; + + if (diff) { + // an indent or unindent has been detected + + isIndent = diff > 0; + + current = indents[isIndent ? diff : -diff]; + + if (current) { + current[0]++; + } else { + current = indents[diff] = [1, 0]; + } + } else if (current) { + // if the last action was an indent, increment the weight + current[1] += +isIndent; + } + }); + + var amount = getMostUsed(indents); + + var type; + var actual; + if (!amount) { + type = null; + actual = ''; + } else if (spaces >= tabs) { + type = 'space'; + actual = repeating(' ', amount); + } else { + type = 'tab'; + actual = repeating('\t', amount); + } + + return { + amount: amount, + type: type, + indent: actual + }; +}; diff --git a/node_modules/detect-indent/license b/node_modules/detect-indent/license new file mode 100644 index 000000000..654d0bfe9 --- /dev/null +++ b/node_modules/detect-indent/license @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/node_modules/detect-indent/node_modules/.bin/repeating b/node_modules/detect-indent/node_modules/.bin/repeating new file mode 120000 index 000000000..cdedec32e --- /dev/null +++ b/node_modules/detect-indent/node_modules/.bin/repeating @@ -0,0 +1 @@ +../repeating/cli.js
\ No newline at end of file diff --git a/node_modules/detect-indent/node_modules/repeating/cli.js b/node_modules/detect-indent/node_modules/repeating/cli.js new file mode 100755 index 000000000..9bb87d4a7 --- /dev/null +++ b/node_modules/detect-indent/node_modules/repeating/cli.js @@ -0,0 +1,36 @@ +#!/usr/bin/env node +'use strict'; +var pkg = require('./package.json'); +var repeating = require('./'); +var argv = process.argv.slice(2); + +function help() { + console.log([ + '', + ' ' + pkg.description, + '', + ' Usage', + ' $ repeating <string> <count>', + '', + ' Example', + ' $ repeating \'unicorn \' 2', + ' unicorn unicorn' + ].join('\n')); +} + +if (process.argv.indexOf('--help') !== -1) { + help(); + return; +} + +if (process.argv.indexOf('--version') !== -1) { + console.log(pkg.version); + return; +} + +if (!argv[1]) { + console.error('You have to define how many times to repeat the string.'); + process.exit(1); +} + +console.log(repeating(argv[0], Number(argv[1]))); diff --git a/node_modules/detect-indent/node_modules/repeating/index.js b/node_modules/detect-indent/node_modules/repeating/index.js new file mode 100644 index 000000000..2d000a8af --- /dev/null +++ b/node_modules/detect-indent/node_modules/repeating/index.js @@ -0,0 +1,24 @@ +'use strict'; +var isFinite = require('is-finite'); + +module.exports = function (str, n) { + if (typeof str !== 'string') { + throw new TypeError('Expected a string as the first argument'); + } + + if (n < 0 || !isFinite(n)) { + throw new TypeError('Expected a finite positive number'); + } + + var ret = ''; + + do { + if (n & 1) { + ret += str; + } + + str += str; + } while (n = n >> 1); + + return ret; +}; diff --git a/node_modules/detect-indent/node_modules/repeating/license b/node_modules/detect-indent/node_modules/repeating/license new file mode 100644 index 000000000..654d0bfe9 --- /dev/null +++ b/node_modules/detect-indent/node_modules/repeating/license @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/node_modules/detect-indent/node_modules/repeating/package.json b/node_modules/detect-indent/node_modules/repeating/package.json new file mode 100644 index 000000000..b8fc1695b --- /dev/null +++ b/node_modules/detect-indent/node_modules/repeating/package.json @@ -0,0 +1,105 @@ +{ + "_args": [ + [ + { + "raw": "repeating@^1.1.0", + "scope": null, + "escapedName": "repeating", + "name": "repeating", + "rawSpec": "^1.1.0", + "spec": ">=1.1.0 <2.0.0", + "type": "range" + }, + "/home/dold/repos/taler/wallet-webex/node_modules/detect-indent" + ] + ], + "_from": "repeating@>=1.1.0 <2.0.0", + "_id": "repeating@1.1.3", + "_inCache": true, + "_location": "/detect-indent/repeating", + "_nodeVersion": "0.12.4", + "_npmUser": { + "name": "sindresorhus", + "email": "sindresorhus@gmail.com" + }, + "_npmVersion": "2.10.1", + "_phantomChildren": {}, + "_requested": { + "raw": "repeating@^1.1.0", + "scope": null, + "escapedName": "repeating", + "name": "repeating", + "rawSpec": "^1.1.0", + "spec": ">=1.1.0 <2.0.0", + "type": "range" + }, + "_requiredBy": [ + "/detect-indent" + ], + "_resolved": "https://registry.npmjs.org/repeating/-/repeating-1.1.3.tgz", + "_shasum": "3d4114218877537494f97f77f9785fab810fa4ac", + "_shrinkwrap": null, + "_spec": "repeating@^1.1.0", + "_where": "/home/dold/repos/taler/wallet-webex/node_modules/detect-indent", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "sindresorhus.com" + }, + "bin": { + "repeating": "cli.js" + }, + "bugs": { + "url": "https://github.com/sindresorhus/repeating/issues" + }, + "dependencies": { + "is-finite": "^1.0.0" + }, + "description": "Repeat a string - fast", + "devDependencies": { + "ava": "0.0.4" + }, + "directories": {}, + "dist": { + "shasum": "3d4114218877537494f97f77f9785fab810fa4ac", + "tarball": "https://registry.npmjs.org/repeating/-/repeating-1.1.3.tgz" + }, + "engines": { + "node": ">=0.10.0" + }, + "files": [ + "index.js", + "cli.js" + ], + "gitHead": "23e93be864952600940d29c8d67f2b9a09d48d81", + "homepage": "https://github.com/sindresorhus/repeating", + "keywords": [ + "cli-app", + "cli", + "bin", + "repeat", + "repeating", + "string", + "str", + "text", + "fill" + ], + "license": "MIT", + "maintainers": [ + { + "name": "sindresorhus", + "email": "sindresorhus@gmail.com" + } + ], + "name": "repeating", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git+https://github.com/sindresorhus/repeating.git" + }, + "scripts": { + "test": "node test.js" + }, + "version": "1.1.3" +} diff --git a/node_modules/detect-indent/node_modules/repeating/readme.md b/node_modules/detect-indent/node_modules/repeating/readme.md new file mode 100644 index 000000000..4cd86671b --- /dev/null +++ b/node_modules/detect-indent/node_modules/repeating/readme.md @@ -0,0 +1,40 @@ +# repeating [![Build Status](https://travis-ci.org/sindresorhus/repeating.svg?branch=master)](https://travis-ci.org/sindresorhus/repeating) + +> Repeat a string - fast + + +## Usage + +```sh +$ npm install --save repeating +``` + +```js +var repeating = require('repeating'); + +repeating('unicorn ', 100); +//=> unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn unicorn +``` + + +## CLI + +```sh +$ npm install --global repeating +``` + +``` +$ repeating --help + + Usage + repeating <string> <count> + + Example + repeating 'unicorn ' 2 + unicorn unicorn +``` + + +## License + +MIT © [Sindre Sorhus](http://sindresorhus.com) diff --git a/node_modules/detect-indent/package.json b/node_modules/detect-indent/package.json new file mode 100644 index 000000000..d8dfce443 --- /dev/null +++ b/node_modules/detect-indent/package.json @@ -0,0 +1,113 @@ +{ + "_args": [ + [ + { + "raw": "detect-indent@^3.0.1", + "scope": null, + "escapedName": "detect-indent", + "name": "detect-indent", + "rawSpec": "^3.0.1", + "spec": ">=3.0.1 <4.0.0", + "type": "range" + }, + "/home/dold/repos/taler/wallet-webex/node_modules/babel-generator" + ] + ], + "_from": "detect-indent@>=3.0.1 <4.0.0", + "_id": "detect-indent@3.0.1", + "_inCache": true, + "_location": "/detect-indent", + "_nodeVersion": "0.12.0", + "_npmUser": { + "name": "sindresorhus", + "email": "sindresorhus@gmail.com" + }, + "_npmVersion": "2.5.1", + "_phantomChildren": { + "is-finite": "1.0.2" + }, + "_requested": { + "raw": "detect-indent@^3.0.1", + "scope": null, + "escapedName": "detect-indent", + "name": "detect-indent", + "rawSpec": "^3.0.1", + "spec": ">=3.0.1 <4.0.0", + "type": "range" + }, + "_requiredBy": [ + "/babel-generator" + ], + "_resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-3.0.1.tgz", + "_shasum": "9dc5e5ddbceef8325764b9451b02bc6d54084f75", + "_shrinkwrap": null, + "_spec": "detect-indent@^3.0.1", + "_where": "/home/dold/repos/taler/wallet-webex/node_modules/babel-generator", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "http://sindresorhus.com" + }, + "bin": { + "detect-indent": "cli.js" + }, + "bugs": { + "url": "https://github.com/sindresorhus/detect-indent/issues" + }, + "dependencies": { + "get-stdin": "^4.0.1", + "minimist": "^1.1.0", + "repeating": "^1.1.0" + }, + "description": "Detect the indentation of code", + "devDependencies": { + "mocha": "*" + }, + "directories": {}, + "dist": { + "shasum": "9dc5e5ddbceef8325764b9451b02bc6d54084f75", + "tarball": "https://registry.npmjs.org/detect-indent/-/detect-indent-3.0.1.tgz" + }, + "engines": { + "node": ">=0.10.0" + }, + "files": [ + "index.js", + "cli.js" + ], + "gitHead": "c046bec94ac5eefeb67ae4501d556c8dcec2914e", + "homepage": "https://github.com/sindresorhus/detect-indent", + "keywords": [ + "cli", + "bin", + "indent", + "indentation", + "detect", + "infer", + "identify", + "code", + "string", + "text", + "source", + "space", + "tab" + ], + "license": "MIT", + "maintainers": [ + { + "name": "sindresorhus", + "email": "sindresorhus@gmail.com" + } + ], + "name": "detect-indent", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git+https://github.com/sindresorhus/detect-indent.git" + }, + "scripts": { + "test": "mocha" + }, + "version": "3.0.1" +} diff --git a/node_modules/detect-indent/readme.md b/node_modules/detect-indent/readme.md new file mode 100644 index 000000000..c09ffddcd --- /dev/null +++ b/node_modules/detect-indent/readme.md @@ -0,0 +1,120 @@ +# detect-indent [![Build Status](https://travis-ci.org/sindresorhus/detect-indent.svg?branch=master)](https://travis-ci.org/sindresorhus/detect-indent) + +> Detect the indentation of code + +Pass in a string of any kind of text and get the indentation. + + +## Use cases + +- Persisting the indentation when modifying a file. +- Have new content match the existing indentation. +- Setting the right indentation in your editor. + + +## Install + +```sh +$ npm install --save detect-indent +``` + + +## Usage + +```js +// modify a JSON file while persisting the indentation in Node +var fs = require('fs'); +var detectIndent = require('detect-indent'); +/* +{ + "ilove": "pizza" +} +*/ +var file = fs.readFileSync('foo.json', 'utf8'); +// tries to detect the indentation and falls back to a default if it can't +var indent = detectIndent(file).indent || ' '; +var json = JSON.parse(file); + +json.ilove = 'unicorns'; + +fs.writeFileSync('foo.json', JSON.stringify(json, null, indent)); +/* +{ + "ilove": "unicorns" +} +*/ +``` + + +## API + +Accepts a string and returns an object with stats about the indentation: + +* `amount`: {Number} the amount of indentation, e.g. `2` +* `type`: {String|Null} the type of indentation. Possible values are `tab`, `space` or `null` if no indentation is detected +* `indent`: {String} the actual indentation + + +## CLI + +```sh +$ npm install --global detect-indent +``` + +``` +$ detect-indent --help + + Usage + detect-indent <file> + echo <string> | detect-indent + + Example + echo ' foo\n bar' | detect-indent | wc --chars + 2 +``` + + +## Algorithm + +The current algorithm looks for the most common difference between two consecutive non-empty lines. + +In the following example, even if the 4-space indentation is used 3 times whereas the 2-space one is used 2 times, it is detected as less used because there were only 2 differences with this value instead of 4 for the 2-space indentation: + +```css +html { + box-sizing: border-box; +} + +body { + background: grey; +} + +p { + line-height: 1.3em; + margin-top: 1em; + text-indent: 2em; +} +``` + +[Source](https://medium.com/@heatherarthur/detecting-code-indentation-eff3ed0fb56b#3918). + +Furthermore, if there are more than one most used difference, the indentation with the most lines is selected. + +In the following example, the indentation is detected as 4-spaces: + +```css +body { + background: grey; +} + +p { + line-height: 1.3em; + margin-top: 1em; + text-indent: 2em; +} +``` + + +## License + +MIT © [Sindre Sorhus](http://sindresorhus.com) |