diff options
| author | ruki <waruqi@gmail.com> | 2018-11-08 00:38:48 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2018-11-07 21:53:09 +0800 |
| commit | 26105034da4fcce7ac883c899d781f016559310d (patch) | |
| tree | c459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/strip-comments | |
| parent | 2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff) | |
| download | xmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip | |
switch to vuepress
Diffstat (limited to 'node_modules/strip-comments')
| -rw-r--r-- | node_modules/strip-comments/LICENSE | 21 | ||||
| -rw-r--r-- | node_modules/strip-comments/README.md | 185 | ||||
| -rw-r--r-- | node_modules/strip-comments/index.js | 186 | ||||
| -rw-r--r-- | node_modules/strip-comments/package.json | 69 |
4 files changed, 461 insertions, 0 deletions
diff --git a/node_modules/strip-comments/LICENSE b/node_modules/strip-comments/LICENSE new file mode 100644 index 00000000..f8de0630 --- /dev/null +++ b/node_modules/strip-comments/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015-2018, Jon Schlinkert. + +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/strip-comments/README.md b/node_modules/strip-comments/README.md new file mode 100644 index 00000000..1022deef --- /dev/null +++ b/node_modules/strip-comments/README.md @@ -0,0 +1,185 @@ +# strip-comments [](https://www.npmjs.com/package/strip-comments) [](https://npmjs.org/package/strip-comments) [](https://npmjs.org/package/strip-comments) [](https://travis-ci.org/jonschlinkert/strip-comments) + +> Strip comments from code. Removes line comments, block comments, the first comment only, or all comments. Optionally leave protected comments unharmed. + +Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. + +- [Install](#install) +- [Usage](#usage) +- [API](#api) +- [About](#about) + +_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_ + +## Install + +Install with [npm](https://www.npmjs.com/): + +```sh +$ npm install --save strip-comments +``` + +## Usage + +By default all comments are stripped. + +```js +const strip = require('strip-comments'); +const str = strip('const foo = "bar";// this is a comment\n /* me too *\/'); +console.log(str); +// => 'const foo = "bar";\n' +``` + +For more use-cases see the [tests](./test/test.js) + +## API + +### [strip](index.js#L34) + +Strip all code comments from the given `input`, including protected comments that start with `!`, unless disabled by setting `options.keepProtected` to true. + +**Params** + +* `input` **{String}**: string from which to strip comments +* `options` **{Object}**: optional options, passed to [extract-comments](https://github.com/jonschlinkert/extract-comments) +* `returns` **{String}**: modified input + +**Options** + +- `line` **{Boolean}**: if `false` strip only block comments, default `true` +- `block` **{Boolean}**: if `false` strip only line comments, default `true` +- `keepProtected` **{Boolean}**: Keep ignored comments (e.g. `/*!`, `/**!` and `//!`) +- `preserveNewlines` **{Boolean}**: Preserve newlines after comments are stripped + +**Example** + +```js +const str = strip('const foo = "bar";// this is a comment\n /* me too */'); +console.log(str); +// => 'const foo = "bar";' +``` + +### [.block](index.js#L54) + +Strip only block comments. + +**Params** + +* `input` **{String}**: string from which to strip comments +* `options` **{Object}**: pass `opts.keepProtected: true` to keep ignored comments (e.g. `/*!`) +* `returns` **{String}**: modified string + +**Example** + +```js +const strip = require('..'); +const str = strip.block('const foo = "bar";// this is a comment\n /* me too */'); +console.log(str); +// => 'const foo = "bar";// this is a comment' +``` + +### [.line](index.js#L73) + +Strip only line comments. + +**Params** + +* `input` **{String}**: string from which to strip comments +* `options` **{Object}**: pass `opts.keepProtected: true` to keep ignored comments (e.g. `//!`) +* `returns` **{String}**: modified string + +**Example** + +```js +const str = strip.line('const foo = "bar";// this is a comment\n /* me too */'); +console.log(str); +// => 'const foo = "bar";\n/* me too */' +``` + +### [.first](index.js#L93) + +Strip the first comment from the given `input`. Or, if `opts.keepProtected` is true, the first non-protected comment will be stripped. + +**Params** + +* `input` **{String}** +* `options` **{Object}**: pass `opts.keepProtected: true` to keep comments with `!` +* `returns` **{String}** + +**Example** + +```js +const output = strip.first(input, { keepProtected: true }); +console.log(output); +// => '//! first comment\nfoo; ' +``` + +## About + +<details> +<summary><strong>Contributing</strong></summary> + +Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). + +</details> + +<details> +<summary><strong>Running Tests</strong></summary> + +Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: + +```sh +$ npm install && npm test +``` + +</details> + +<details> +<summary><strong>Building docs</strong></summary> + +_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ + +To generate the readme, run the following command: + +```sh +$ npm install -g verbose/verb#dev verb-generate-readme && verb +``` + +</details> + +### Related projects + +You might also be interested in these projects: + +* [babel-extract-comments](https://www.npmjs.com/package/babel-extract-comments): Uses babel (babylon) to extract JavaScript code comments from a JavaScript string or file. | [homepage](https://github.com/jonschlinkert/babel-extract-comments "Uses babel (babylon) to extract JavaScript code comments from a JavaScript string or file.") +* [code-context](https://www.npmjs.com/package/code-context): Parse a string of javascript to determine the context for functions, variables and comments based… [more](https://github.com/jonschlinkert/code-context) | [homepage](https://github.com/jonschlinkert/code-context "Parse a string of javascript to determine the context for functions, variables and comments based on the code that follows.") +* [extract-comments](https://www.npmjs.com/package/extract-comments): Uses esprima to extract line and block comments from a string of JavaScript. Also optionally… [more](https://github.com/jonschlinkert/extract-comments) | [homepage](https://github.com/jonschlinkert/extract-comments "Uses esprima to extract line and block comments from a string of JavaScript. Also optionally parses code context (the next line of code after a comment).") +* [parse-code-context](https://www.npmjs.com/package/parse-code-context): Parse code context in a single line of javascript, for functions, variable declarations, methods, prototype… [more](https://github.com/jonschlinkert/parse-code-context) | [homepage](https://github.com/jonschlinkert/parse-code-context "Parse code context in a single line of javascript, for functions, variable declarations, methods, prototype properties, prototype methods etc.") +* [parse-comments](https://www.npmjs.com/package/parse-comments): Parse code comments from JavaScript or any language that uses the same format. | [homepage](https://github.com/jonschlinkert/parse-comments "Parse code comments from JavaScript or any language that uses the same format.") + +### Contributors + +| **Commits** | **Contributor** | +| --- | --- | +| 59 | [jonschlinkert](https://github.com/jonschlinkert) | +| 4 | [charlike-old](https://github.com/charlike-old) | +| 2 | [mk-pmb](https://github.com/mk-pmb) | +| 1 | [kgryte](https://github.com/kgryte) | +| 1 | [epicoxymoron](https://github.com/epicoxymoron) | + +### Author + +**Jon Schlinkert** + +* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) +* [GitHub Profile](https://github.com/jonschlinkert) +* [Twitter Profile](https://twitter.com/jonschlinkert) + +### License + +Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert). +Released under the [MIT License](LICENSE). + +*** + +_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on March 24, 2018._
\ No newline at end of file diff --git a/node_modules/strip-comments/index.js b/node_modules/strip-comments/index.js new file mode 100644 index 00000000..517fb5ba --- /dev/null +++ b/node_modules/strip-comments/index.js @@ -0,0 +1,186 @@ +/*! + * strip-comments <https://github.com/jonschlinkert/strip-comments> + * + * Copyright (c) 2014-2016, 2018, Jon Schlinkert. + * Released under the MIT License. + */ + +'use strict'; + +const assign = Object.assign; +const extract = require('babel-extract-comments'); + +/** + * Strip all code comments from the given `input`, including protected + * comments that start with `!`, unless disabled by setting `options.keepProtected` + * to true. + * + * ```js + * const str = strip('const foo = "bar";// this is a comment\n /* me too *\/'); + * console.log(str); + * // => 'const foo = "bar";' + * ``` + * @name strip + * @param {String} `input` string from which to strip comments + * @param {Object} `options` optional options, passed to [extract-comments][extract-comments] + * @option {Boolean} [options] `line` if `false` strip only block comments, default `true` + * @option {Boolean} [options] `block` if `false` strip only line comments, default `true` + * @option {Boolean} [options] `keepProtected` Keep ignored comments (e.g. `/*!` and `//!`) + * @option {Boolean} [options] `preserveNewlines` Preserve newlines after comments are stripped + * @return {String} modified input + * @api public + */ + +function strip(input, options) { + return stripComments(input, assign({ block: true, line: true }, options)); +} + +/** + * Strip only block comments. + * + * ```js + * const strip = require('..'); + * const str = strip.block('const foo = "bar";// this is a comment\n /* me too *\/'); + * console.log(str); + * // => 'const foo = "bar";// this is a comment' + * ``` + * @name .block + * @param {String} `input` string from which to strip comments + * @param {Object} `options` pass `opts.keepProtected: true` to keep ignored comments (e.g. `/*!`) + * @return {String} modified string + * @api public + */ + +strip.block = function(input, options) { + return stripComments(input, assign({ block: true }, options)); +}; + +/** + * Strip only line comments. + * + * ```js + * const str = strip.line('const foo = "bar";// this is a comment\n /* me too *\/'); + * console.log(str); + * // => 'const foo = "bar";\n/* me too *\/' + * ``` + * @name .line + * @param {String} `input` string from which to strip comments + * @param {Object} `options` pass `opts.keepProtected: true` to keep ignored comments (e.g. `//!`) + * @return {String} modified string + * @api public + */ + +strip.line = function(input, options) { + return stripComments(input, assign({ line: true }, options)); +}; + +/** + * Strip the first comment from the given `input`. Or, if `opts.keepProtected` is true, + * the first non-protected comment will be stripped. + * + * ```js + * const output = strip.first(input, { keepProtected: true }); + * console.log(output); + * // => '//! first comment\nfoo; ' + * ``` + * @name .first + * @param {String} `input` + * @param {Object} `options` pass `opts.keepProtected: true` to keep comments with `!` + * @return {String} + * @api public + */ + +strip.first = function(input, options) { + const opts = assign({ block: true, line: true, first: true }, options); + return stripComments(input, opts); +}; + +/** + * Strip comments + */ + +function stripComments(input, options) { + if (typeof input !== 'string') { + throw new TypeError('expected a string'); + } + + // strip all by default, including `ingored` comments. + const defaults = { + // we shouldn't care about this here since our goal is to strip comments, + // not transpiling, and this has been a common cause of parsing issues + allowReturnOutsideFunction: true, + block: false, + line: false, + safe: false, + first: false, + plugins: [] + }; + + const opts = assign({}, defaults, options); + opts.plugins.push('objectRestSpread'); + + if (typeof opts.keepProtected !== 'boolean') { + opts.keepProtected = opts.safe; + } + + try { + const comments = extract(input, opts); + let pos = { start: 0, end: 0, removed: 0 }; + if (!comments) return input; + + for (const comment of comments) { + if (typeof opts.filter === 'function' && opts.filter(comment, opts) === false) { + continue; + } + + input = remove(input, comment, opts, pos); + + if (opts.first === true && !isProtected(comment, opts)) { + break; + } + } + } catch (err) { + if (options.silent !== true) { + throw err; + } + } + return input; +} + +/** + * Remove a single comment from the given string. + */ + +function remove(str, comment, options, pos) { + let nl = ''; + + if (isProtected(comment, options)) { + return str; + } + + if (options && options.preserveNewlines) { + nl = comment.value.replace(/[^\r\n]/g, ''); + } + + if (comment.type === 'CommentLine' && options.line === true) { + const before = str.slice(0, comment.start - pos.removed); + const after = str.slice(comment.end - pos.removed); + pos.removed += comment.end - comment.start - nl.length; + return before + nl + after; + } + + if (comment.type === 'CommentBlock' && options.block === true) { + const before = str.slice(0, comment.start - pos.removed); + const after = str.slice(comment.end - pos.removed); + pos.removed += comment.end - comment.start - nl.length; + return before + nl + after; + } + + return str; +} + +function isProtected(comment, options) { + return options && options.keepProtected === true && /^\*?!/.test(comment.value); +} + +module.exports = strip; diff --git a/node_modules/strip-comments/package.json b/node_modules/strip-comments/package.json new file mode 100644 index 00000000..4a972d3d --- /dev/null +++ b/node_modules/strip-comments/package.json @@ -0,0 +1,69 @@ +{ + "name": "strip-comments", + "description": "Strip comments from code. Removes line comments, block comments, the first comment only, or all comments. Optionally leave protected comments unharmed.", + "version": "1.0.2", + "homepage": "https://github.com/jonschlinkert/strip-comments", + "author": "Jon Schlinkert (https://github.com/jonschlinkert)", + "repository": "jonschlinkert/strip-comments", + "bugs": { + "url": "https://github.com/jonschlinkert/strip-comments/issues" + }, + "license": "MIT", + "files": [ + "index.js" + ], + "main": "index.js", + "engines": { + "node": ">=4" + }, + "scripts": { + "test": "mocha" + }, + "dependencies": { + "babel-extract-comments": "^1.0.0", + "babel-plugin-transform-object-rest-spread": "^6.26.0" + }, + "devDependencies": { + "gulp-format-md": "^1.0.0", + "mocha": "^3.5.3" + }, + "keywords": [ + "babel", + "babylon", + "block", + "block comment", + "code comment", + "comment", + "comments", + "javascript", + "line", + "line comment", + "remove", + "strip" + ], + "verb": { + "toc": true, + "layout": "default", + "tasks": [ + "readme" + ], + "plugins": [ + "gulp-format-md" + ], + "helpers": [ + "./examples/support/helpers.js" + ], + "related": { + "list": [ + "babel-extract-comments", + "code-context", + "extract-comments", + "parse-code-context", + "parse-comments" + ] + }, + "lint": { + "reflinks": true + } + } +} |
