diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-05-28 00:38:50 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-05-28 00:40:43 +0200 |
commit | 7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027 (patch) | |
tree | 6de9a1aebd150a23b7f8c273ec657a5d0a18fe3e /node_modules/code-excerpt | |
parent | 963b7a41feb29cc4be090a2446bdfe0c1f1bcd81 (diff) | |
download | wallet-core-7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027.tar.xz |
add linting (and some initial fixes)
Diffstat (limited to 'node_modules/code-excerpt')
-rw-r--r-- | node_modules/code-excerpt/index.js | 38 | ||||
-rw-r--r-- | node_modules/code-excerpt/license | 21 | ||||
-rw-r--r-- | node_modules/code-excerpt/package.json | 31 | ||||
-rw-r--r-- | node_modules/code-excerpt/readme.md | 73 |
4 files changed, 163 insertions, 0 deletions
diff --git a/node_modules/code-excerpt/index.js b/node_modules/code-excerpt/index.js new file mode 100644 index 000000000..f9a2d51b3 --- /dev/null +++ b/node_modules/code-excerpt/index.js @@ -0,0 +1,38 @@ +'use strict'; + +const tabsToSpaces = require('convert-to-spaces'); + +const generateLineNumbers = (line, around) => { + const lineNumbers = []; + + const min = line - around; + const max = line + around; + + for (let lineNumber = min; lineNumber <= max; lineNumber++) { + lineNumbers.push(lineNumber); + } + + return lineNumbers; +}; + +module.exports = (source, line, options) => { + if (typeof source !== 'string') { + throw new TypeError('Source code is missing.'); + } + + if (!line || line < 1) { + throw new TypeError('Line number must start from `1`.'); + } + + source = tabsToSpaces(source).split('\n'); + + if (line > source.length) { + return null; + } + + options = Object.assign({around: 3}, options); + + return generateLineNumbers(line, options.around) + .filter(line => source[line - 1] !== undefined) + .map(line => ({line, value: source[line - 1]})); +}; diff --git a/node_modules/code-excerpt/license b/node_modules/code-excerpt/license new file mode 100644 index 000000000..3e03f3e75 --- /dev/null +++ b/node_modules/code-excerpt/license @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) vdemedes <vdemedes@gmail.com> (github.com/vdemedes) + +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/code-excerpt/package.json b/node_modules/code-excerpt/package.json new file mode 100644 index 000000000..8c8917268 --- /dev/null +++ b/node_modules/code-excerpt/package.json @@ -0,0 +1,31 @@ +{ + "name": "code-excerpt", + "version": "2.1.0", + "description": "Extract code excerpts", + "license": "MIT", + "repository": "vadimdemedes/code-excerpt", + "author": { + "name": "vdemedes", + "email": "vdemedes@gmail.com", + "url": "github.com/vadimdemedes" + }, + "engines": { + "node": ">=4" + }, + "scripts": { + "test": "xo && ava" + }, + "files": [ + "index.js" + ], + "dependencies": { + "convert-to-spaces": "^1.0.1" + }, + "devDependencies": { + "ava": "^0.16.0", + "xo": "^0.17.1" + }, + "xo": { + "esnext": true + } +} diff --git a/node_modules/code-excerpt/readme.md b/node_modules/code-excerpt/readme.md new file mode 100644 index 000000000..216b6b3d5 --- /dev/null +++ b/node_modules/code-excerpt/readme.md @@ -0,0 +1,73 @@ +# code-excerpt [![Build Status](https://travis-ci.org/vadimdemedes/code-excerpt.svg?branch=master)](https://travis-ci.org/vadimdemedes/code-excerpt) + +> Extract code excerpts + + +## Install + +``` +$ npm install --save code-excerpt +``` + + +## Usage + +```js +const codeExcerpt = require('code-excerpt'); + +const source = ` +'use strict'; + +function someFunc() {} + +module.exports = () => { + const a = 1; + const b = 2; + const c = 3; + + someFunc(); +}; +`.trim(); + +const excerpt = codeExcerpt(source, 5); +//=> [ +// {line: 2, value: ''}, +// {line: 3, value: 'function someFunc() {}'}, +// {line: 4, value: ''}, +// {line: 5, value: 'module.exports = () => {'}, +// {line: 6, value: ' const a = 1;'}, +// {line: 7, value: ' const b = 2;'}, +// {line: 8, value: ' const c = 3;'} +// ] +``` + + +## API + +### codeExcerpt(source, line, [options]) + +#### source + +Type: `string` + +Source code. + +#### line + +Type: `number` + +Line number to extract excerpt for. + +#### options + +##### around + +Type: `number`<br> +Default: `3` + +Number of surrounding lines to extract. + + +## License + +MIT © [Vadim Demedes](https://github.com/vadimdemedes) |