Skip to content

Commit

Permalink
bumped to v2.0.0-dev, moved legacy to backcompat.js
Browse files Browse the repository at this point in the history
  • Loading branch information
slevithan committed Mar 6, 2012
1 parent 6b19484 commit 80d1243
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[XRegExp](http://xregexp.com/) (v1.6.0-dev)
[XRegExp](http://xregexp.com/) (v2.0.0-dev)
=============================================

XRegExp provides augmented, extensible JavaScript regular expressions. You get new syntax, flags, and methods beyond what browsers support natively. XRegExp is also a regular expression utility belt with tools to make your client-side grepping simpler and more powerful, while freeing you from worrying about pesky cross-browser inconsistencies and the dubious `lastIndex` property.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xregexp",
"version": "1.6.0-dev",
"version": "2.0.0-dev",
"url": "http://xregexp.com/",
"author": "Steven Levithan <steves_list@hotmail.com>",
"license": "MIT",
Expand Down
19 changes: 17 additions & 2 deletions src/backcompat.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,25 @@
;(function () {
"use strict";

// overriding natives, adding RegExp.prototype methods, and allowing syntax extensions became
// optional features in XRegExp v1.6.0
// XRegExp v2.0.0 no longer automatically overrides natives, extends
// RegExp.prototype, or allows syntax extensions
XRegExp.install("natives methods extensibility");

// renamed in XRegExp v2.0.0
XRegExp.copyAsGlobal = XRegExp.globalize;

// renamed in XRegExp v2.0.0
XRegExp.execAt = XRegExp.exec;

// renamed in XRegExp v2.0.0
XRegExp.iterate = XRegExp.forEach;

// removed in XRegExp v2.0.0. If you want this functionality to be
// permanent, `delete XRegExp.install` afterward
XRegExp.freezeTokens = function () {
XRegExp.uninstall("extensibility");
};

// renamed in XRegExp v1.5.0
XRegExp.matchWithinChain = XRegExp.matchChain;

Expand Down
35 changes: 14 additions & 21 deletions src/xregexp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* XRegExp v1.6.0-dev
* XRegExp v2.0.0-dev
* Copyright 2007-2012 Steven Levithan <http://xregexp.com/>
* Available under the MIT License
* Augmented, extensible, cross-browser regular expressions
Expand Down Expand Up @@ -71,7 +71,7 @@
// Public properties
//---------------------------------

XRegExp.version = "1.6.0-dev";
XRegExp.version = "2.0.0-dev";

// Token scope bitflags
// Create private copies to protect core operations
Expand Down Expand Up @@ -182,9 +182,8 @@
// Accepts a string to search, regex to search with, position to start the search within the
// string (default: 0), and an optional Boolean indicating whether matches must start at-or-
// after the position or at the specified position only. This function ignores the `lastIndex`
// of the provided regex in its own handling, but updates the property for compatibility.
// The alias `XRegExp.execAt` was deprecated in v1.6.0
XRegExp.exec = XRegExp.execAt = function (str, regex, pos, sticky) {
// of the provided regex in its own handling, but updates the property for compatibility
XRegExp.exec = function (str, regex, pos, sticky) {
var r2 = copy(regex, "g" + ((sticky && hasNativeY) ? "y" : "")),
match;
r2.lastIndex = pos = pos || 0;
Expand All @@ -198,9 +197,8 @@

// Executes `callback` once per match within `str`; returns `context`. Provides a simpler and
// cleaner way to iterate over regex matches compared to the traditional approaches of
// subverting `String.prototype.replace` or repeatedly calling `exec` within a `while` loop.
// The alias `XRegExp.iterate` was deprecated in v1.6.0
XRegExp.forEach = XRegExp.iterate = function (str, regex, callback, context) {
// subverting `String.prototype.replace` or repeatedly calling `exec` within a `while` loop
XRegExp.forEach = function (str, regex, callback, context) {
var r2 = XRegExp.globalize(regex),
i = -1, match;
while ((match = r2.exec(str))) { // Run the altered `exec` (required for `lastIndex` fix, etc.)
Expand All @@ -215,18 +213,11 @@
return context;
};

// Deprecated in v1.6.0. If you want this functionality to be permanent,
// `delete XRegExp.install` afterward
XRegExp.freezeTokens = function () {
XRegExp.uninstall("extensibility");
};

// Accepts a `RegExp` instance; returns a copy with the `/g` flag set. The copy has a fresh
// `lastIndex` (set to zero). If you want to copy a regex without forcing the `global`
// property, use `XRegExp(regex)`. Do not use `RegExp(regex)` because it will not preserve
// special properties required for named capture.
// The alias `XRegExp.copyAsGlobal` was deprecated in v1.6.0
XRegExp.globalize = XRegExp.copyAsGlobal = function (regex) {
// special properties required for named capture
XRegExp.globalize = function (regex) {
return copy(regex, "g");
};

Expand Down Expand Up @@ -300,6 +291,11 @@
return result;
};

// Fixes browser bugs in the native `String.prototype.split`
XRegExp.split = function (str, separator, limit) {
return fixed.split.call(str, separator, limit);
};

// Accepts an object or space-delimited string specifying optional features to uninstall
XRegExp.uninstall = function (options) {
options = prepareOptions(options);
Expand Down Expand Up @@ -762,16 +758,13 @@
function () {return this.hasFlag("s");}
);

//XRegExp.uninstall("extensibility");
XRegExp.uninstall("extensibility");


//---------------------------------
// Expose XRegExp
//---------------------------------

// Automatically install optional features
XRegExp.install("all");

if (typeof exports === "undefined")
root.XRegExp = XRegExp; // Create global varable
else // For CommonJS enviroments
Expand Down
9 changes: 7 additions & 2 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ test("Basic availability", function () {
ok(XRegExp.escape, "XRegExp.escape exists");
ok(XRegExp.exec, "XRegExp.exec exists");
ok(XRegExp.forEach, "XRegExp.forEach exists");
//ok(XRegExp.freezeTokens, "XRegExp.freezeTokens exists"); // Deprecated in v1.6.0
//ok(XRegExp.freezeTokens, "XRegExp.freezeTokens exists"); // Deprecated in v2.0.0
ok(XRegExp.globalize, "XRegExp.globalize exists");
ok(XRegExp.install, "XRegExp.install exists");
ok(XRegExp.isInstalled, "XRegExp.isInstalled exists");
ok(XRegExp.isRegExp, "XRegExp.isRegExp exists");
ok(XRegExp.matchChain, "XRegExp.matchChain exists");
ok(XRegExp.replace, "XRegExp.replace exists");
ok(XRegExp.split, "XRegExp.split exists");
ok(XRegExp.uninstall, "XRegExp.uninstall exists");
ok(XRegExp.version, "XRegExp.version exists");
ok(XRegExp.INSIDE_CLASS, "XRegExp.INSIDE_CLASS exists");
Expand Down Expand Up @@ -177,7 +178,7 @@ test("XRegExp.forEach", function () {
equal(regexG.lastIndex, 0, "lastIndex of global regex reset to 0 after iteration");
});

// Deprecated in v1.6.0
// Deprecated in v2.0.0
/*test("XRegExp.freezeTokens", function () {
XRegExp.freezeTokens();
Expand Down Expand Up @@ -256,6 +257,10 @@ test("XRegExp.replace", function () {
// TODO: Add tests
});

test("XRegExp.split", function () {
// TODO: Add tests
});

test("XRegExp.uninstall", function () {
// TODO: Add tests
});
Expand Down

0 comments on commit 80d1243

Please sign in to comment.