Skip to content

Commit

Permalink
Remove xregexp from dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Semigradsky committed Jan 9, 2019
1 parent c552cec commit 626e0ee
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 21 deletions.
30 changes: 26 additions & 4 deletions lib/index.js
@@ -1,10 +1,32 @@
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
var XRegExp = require("xregexp");
var value = '[-+]?(?:Infinity|[[0-9]*\\.?\\d*(?:[eE][-+]?\\d+)?)';
var mathInterval = XRegExp("(?<leftBrace> [\\(\\]\\[] ) (?<fromValue> " + value + " )? (?<delimeter> , )? (?<toValue> " + value + " )? (?<rightBrace> [\\)\\]\\[] )", 'x');
var patternParts = {
value: '[-+]?(?:Infinity|[[0-9]*\\.?\\d*(?:[eE][-+]?\\d+)?)',
leftBrace: '[\\(\\]\\[]',
delimeter: ',',
rightBrace: '[\\)\\]\\[]',
};
var PATTERN = new RegExp("(" + patternParts.leftBrace + ")" +
("(" + patternParts.value + ")?") +
("(" + patternParts.delimeter + ")?") +
("(" + patternParts.value + ")?") +
("(" + patternParts.rightBrace + ")"));
function execPattern(str) {
var match = PATTERN.exec(str);
if (!match) {
return null;
}
var _ = match[0], leftBrace = match[1], fromValue = match[2], delimeter = match[3], toValue = match[4], rightBrace = match[5];
return {
leftBrace: leftBrace,
fromValue: fromValue,
delimeter: delimeter,
toValue: toValue,
rightBrace: rightBrace,
};
}
function parse(str) {
var match = XRegExp.exec(str, mathInterval);
var match = execPattern(str);
if (!match) {
return null;
}
Expand Down
13 changes: 5 additions & 8 deletions package.json
Expand Up @@ -30,16 +30,13 @@
"parse",
"parsing"
],
"dependencies": {
"xregexp": "^3.2.0"
},
"devDependencies": {
"coveralls": "^2.11.2",
"dts-bundle": "~0.2.0",
"coveralls": "^3.0.2",
"dts-bundle": "~0.7",
"istanbul": "^0.3.13",
"mocha": "2.*",
"mocha-lcov-reporter": "0.0.2",
"tslint": "2.*",
"mocha": "^5.2.0",
"mocha-lcov-reporter": "^1.3.0",
"tslint": "^5.11.0",
"typescript": "2.*"
}
}
40 changes: 31 additions & 9 deletions src/index.ts
@@ -1,7 +1,5 @@
'use strict';

import * as XRegExp from 'xregexp';

export interface MathInterval {
from: {
value: number,
Expand All @@ -21,17 +19,41 @@ interface RegexParts {
rightBrace: ')' | ']' | '['
}

const patternParts = {
value: '[-+]?(?:Infinity|[[0-9]*\\.?\\d*(?:[eE][-+]?\\d+)?)',
leftBrace: '[\\(\\]\\[]',
delimeter: ',',
rightBrace: '[\\)\\]\\[]',
};

const PATTERN = new RegExp(
`(${patternParts.leftBrace})` +
`(${patternParts.value})?` +
`(${patternParts.delimeter})?` +
`(${patternParts.value})?` +
`(${patternParts.rightBrace})`
);

function execPattern(str: string): RegexParts | null {
const match = PATTERN.exec(str);

const value = '[-+]?(?:Infinity|[[0-9]*\\.?\\d*(?:[eE][-+]?\\d+)?)';
if (!match) {
return null;
}

const mathInterval = XRegExp(`(?<leftBrace> [\\(\\]\\[] ) \
(?<fromValue> ${value} )? \
(?<delimeter> , )? \
(?<toValue> ${value} )? \
(?<rightBrace> [\\)\\]\\[] )`, 'x');
const [_, leftBrace, fromValue, delimeter, toValue, rightBrace] = match;

return {
leftBrace,
fromValue,
delimeter,
toValue,
rightBrace,
} as RegexParts;
}

function parse(str: string): (MathInterval | null) {
const match = XRegExp.exec(str, mathInterval) as RegexParts;
const match = execPattern(str) as RegexParts;
if (!match) {
return null;
}
Expand Down

0 comments on commit 626e0ee

Please sign in to comment.