Socket
Socket
Sign inDemoInstall

regex-not

Package Overview
Dependencies
2
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.2 to 1.0.0

67

index.js
'use strict';
function toRegex(str, options) {
options = options || {};
var extend = require('extend-shallow');
if (options && options.contains === true) {
options.strictNegate = false;
}
/**
* The main export is a function that takes a `pattern` string and an `options` object.
*
* ```js
& var not = require('regex-not');
& console.log(not('foo'));
& //=> /^(?:(?!^(?:foo)$).)*$/
* ```
*
* @param {String} `pattern`
* @param {Object} `options`
* @return {RegExp} Converts the given `pattern` to a regex using the specified `options`.
* @api public
*/
var open = options.strictOpen !== false ? '^' : '';
var close = options.strictClose !== false ? '$' : '';
return new RegExp(open + toRegex.create(str, options) + close);
function toRegex(pattern, options) {
return new RegExp(toRegex.create(pattern, options));
}
toRegex.create = function(str, options) {
if (typeof str !== 'string') {
/**
* Create a regex-compatible string from the given `pattern` and `options`.
*
* ```js
& var not = require('regex-not');
& console.log(not.create('foo'));
& //=> '^(?:(?!^(?:foo)$).)*$'
* ```
* @param {String} `pattern`
* @param {Object} `options`
* @return {String}
* @api public
*/
toRegex.create = function(pattern, options) {
if (typeof pattern !== 'string') {
throw new TypeError('expected a string');
}
if (options && options.strictNegate === false) {
return '(?:(?!(?:' + str + ')).)*';
var opts = extend({}, options);
if (opts && opts.contains === true) {
opts.strictNegate = false;
}
return '(?:(?!^(?:' + str + ')$).)*';
var open = opts.strictOpen !== false ? '^' : '';
var close = opts.strictClose !== false ? '$' : '';
var endChar = opts.endChar ? opts.endChar : '+';
var str = pattern;
if (opts && opts.strictNegate === false) {
str = '(?:(?!(?:' + pattern + ')).)' + endChar;
} else {
str = '(?:(?!^(?:' + pattern + ')$).)' + endChar;
}
return open + str + close;
};
/**
* Expose `toRegex`
*/
module.exports = toRegex;

5

package.json
{
"name": "regex-not",
"description": "Create a javascript regular expression for matching everything except for the given string.",
"version": "0.1.2",
"version": "1.0.0",
"homepage": "https://github.com/jonschlinkert/regex-not",

@@ -22,2 +22,5 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

},
"dependencies": {
"extend-shallow": "^2.0.1"
},
"devDependencies": {

@@ -24,0 +27,0 @@ "gulp-format-md": "^0.1.10",

@@ -47,3 +47,3 @@ # regex-not [![NPM version](https://img.shields.io/npm/v/regex-not.svg?style=flat)](https://www.npmjs.com/package/regex-not) [![NPM downloads](https://img.shields.io/npm/dm/regex-not.svg?style=flat)](https://npmjs.org/package/regex-not) [![Build Status](https://img.shields.io/travis/jonschlinkert/regex-not.svg?style=flat)](https://travis-ci.org/jonschlinkert/regex-not)

Get a string, so you can create your own regex:
Returns a string to allow you to create your own regex:

@@ -112,2 +112,2 @@ ```js

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.1.31, on September 26, 2016._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.1.31, on October 07, 2016._
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc