use module to escape regexp special characters

This commit is contained in:
Jeff Williams 2014-07-07 16:49:11 -07:00
parent cae3cce8c1
commit 333ac90968
7 changed files with 114 additions and 8 deletions

View File

@ -96,6 +96,16 @@ Copyright (c) 2013 Dominic Tarr.
The source code for crypto-browserify is available at:
https://github.com/dominictarr/crypto-browserify
## escape-string-regexp ##
escape-string-regexp is distributed under the MIT License, which is reproduced
above.
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com>.
The source code for escape-string-regexp is available at:
https://github.com/sindresorhus/escape-string-regexp
## Esprima ##
Esprima is distributed under the BSD 2-clause license:

View File

@ -7,6 +7,7 @@
'use strict';
var _ = require('underscore');
var escape = require('escape-string-regexp');
/**
* Longnames that have a special meaning in JSDoc.
@ -183,12 +184,6 @@ exports.resolve = function(doclet) {
}
};
// TODO: also used by jsdoc/src/handlers; extract into a utility module
RegExp.escape = RegExp.escape || function(str) {
var specials = new RegExp('[.*+?|()\\[\\]{}\\\\]', 'g'); // .*+?|()[]{}\
return str.replace(specials, '\\$&');
};
/**
@method module:jsdoc/name.applyNamespace
@param {string} longname The full longname of the symbol.
@ -201,7 +196,7 @@ exports.applyNamespace = function(longname, ns) {
longname = nameParts.longname;
if ( !/^[a-zA-Z]+?:.+$/i.test(name) ) {
longname = longname.replace( new RegExp(RegExp.escape(name) + '$'), ns + ':' + name );
longname = longname.replace( new RegExp(escape(name) + '$'), ns + ':' + name );
}
return longname;

View File

@ -3,6 +3,7 @@
*/
'use strict';
var escape = require('escape-string-regexp');
var jsdoc = {
doclet: require('jsdoc/doclet'),
name: require('jsdoc/name'),
@ -177,7 +178,7 @@ exports.attachTo = function(parser) {
newDoclet.addTag('memberof', memberofName);
if (basename) {
newDoclet.name = (newDoclet.name || '')
.replace(new RegExp('^' + RegExp.escape(basename) + '.'), '');
.replace(new RegExp('^' + escape(basename) + '.'), '');
}
}
else {

8
node_modules/escape-string-regexp/index.js generated vendored Normal file
View File

@ -0,0 +1,8 @@
'use strict';
module.exports = function (str) {
if (typeof str !== 'string') {
throw new TypeError('Expected a string');
}
return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&');
};

64
node_modules/escape-string-regexp/package.json generated vendored Normal file
View File

@ -0,0 +1,64 @@
{
"name": "escape-string-regexp",
"version": "1.0.0",
"description": "Escape RegExp special characters",
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/sindresorhus/escape-string-regexp"
},
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "http://sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "mocha"
},
"files": [
"index.js"
],
"keywords": [
"regex",
"regexp",
"re",
"regular",
"expression",
"escape",
"string",
"str",
"special",
"characters"
],
"devDependencies": {
"mocha": "*"
},
"bugs": {
"url": "https://github.com/sindresorhus/escape-string-regexp/issues"
},
"homepage": "https://github.com/sindresorhus/escape-string-regexp",
"_id": "escape-string-regexp@1.0.0",
"_shasum": "0ca42ef5f3d8499fbc239fa0409ea849857d74c4",
"_from": "escape-string-regexp@*",
"_npmVersion": "1.4.9",
"_npmUser": {
"name": "sindresorhus",
"email": "sindresorhus@gmail.com"
},
"maintainers": [
{
"name": "sindresorhus",
"email": "sindresorhus@gmail.com"
}
],
"dist": {
"shasum": "0ca42ef5f3d8499fbc239fa0409ea849857d74c4",
"tarball": "http://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.0.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.0.tgz",
"readme": "ERROR: No README data found!"
}

27
node_modules/escape-string-regexp/readme.md generated vendored Normal file
View File

@ -0,0 +1,27 @@
# escape-string-regexp [![Build Status](https://travis-ci.org/sindresorhus/escape-string-regexp.svg?branch=master)](https://travis-ci.org/sindresorhus/escape-string-regexp)
> Escape RegExp special characters
## Install
```sh
$ npm install --save escape-string-regexp
```
## Usage
```js
var escapeStringRegexp = require('escape-string-regexp');
var escapedString = escapeStringRegexp('how much $ for a unicorn?');
//=> how much \$ for a unicorn\?
new RegExp(escapedString);
```
## License
MIT © [Sindre Sorhus](http://sindresorhus.com)

View File

@ -20,6 +20,7 @@
"dependencies": {
"async": "~0.1.22",
"catharsis": "~0.8.2",
"escape-string-regexp": "~1.0.0",
"esprima": "https://github.com/ariya/esprima/tarball/49a2eccb243f29bd653b11e9419241a9d726af7c",
"js2xmlparser": "~0.1.0",
"marked": "~0.3.1",