regexp-support
Advanced tools
Comparing version
@@ -37,2 +37,4 @@ /** | ||
namedCapturingGroupsEmoji: boolean; | ||
namedCapturingGroupsBackreference: boolean; | ||
namedCapturingGroupsDuplicate: boolean; | ||
lookAheadPositive: boolean; | ||
@@ -43,2 +45,4 @@ lookAheadNegative: boolean; | ||
}; | ||
hasFlagsProp: boolean; | ||
nativeFlags: string; | ||
}>; | ||
@@ -45,0 +49,0 @@ export import hasSupportFlag = lib.hasSupportFlag; |
11
index.js
@@ -41,3 +41,14 @@ "use strict"; | ||
}, {}), | ||
hasFlagsProp: /x/g.flags === 'g', | ||
nativeFlags: '', | ||
}; | ||
_support.nativeFlags = Object | ||
.keys(_support.flagsAll) | ||
.reduce(function (a, f) { | ||
if (_support.flagsAll[f]) { | ||
a.push(f); | ||
} | ||
return a; | ||
}, []) | ||
.join(''); | ||
exports.support = Object.freeze(_support); | ||
@@ -44,0 +55,0 @@ exports.hasSupportFlag = lib_1.default.hasSupportFlag; |
18
index.ts
@@ -53,4 +53,22 @@ /** | ||
}, {} as typeof PatternSupport), | ||
hasFlagsProp: /x/g.flags === 'g', | ||
nativeFlags: '', | ||
}; | ||
_support.nativeFlags = Object | ||
.keys(_support.flagsAll) | ||
.reduce(function (a, f) | ||
{ | ||
if (_support.flagsAll[f]) | ||
{ | ||
a.push(f); | ||
} | ||
return a; | ||
}, [] as string[]) | ||
.join('') | ||
; | ||
export const support = Object.freeze(_support); | ||
@@ -57,0 +75,0 @@ |
@@ -38,1 +38,2 @@ /** | ||
export declare type ITypeCreateRegExp<T> = T extends typeof RegExp ? typeof RegExp : T extends ICreateRegExp ? ICreateRegExp : any; | ||
export declare function createRegExp<T>(pattern: string, flag?: string, RegExpClass?: ITypeCreateRegExp<T>): RegExp; |
@@ -31,4 +31,5 @@ "use strict"; | ||
exports.hasSupportFlag = hasSupportFlag; | ||
function testFlag(flag, | ||
// @ts-ignore | ||
function testFlag(flag, RegExpClass = RegExp, testPattern = flags_1.FlagsPattern) { | ||
RegExpClass = RegExp, testPattern = flags_1.FlagsPattern) { | ||
if (testPattern[flag] && testPattern[flag].length) { | ||
@@ -38,9 +39,3 @@ return testPattern[flag].every(function (v) { | ||
let bool; | ||
let r; | ||
if (typeof RegExpClass.create == 'function') { | ||
r = RegExpClass.create(pattern, flag); | ||
} | ||
else { | ||
r = new RegExpClass(pattern, flag); | ||
} | ||
let r = createRegExp(pattern, flag, RegExpClass); | ||
if (fn) { | ||
@@ -90,1 +85,13 @@ if (typeof fn == 'function') { | ||
exports.testFlagsAll = testFlagsAll; | ||
// @ts-ignore | ||
function createRegExp(pattern, flag, RegExpClass = RegExp) { | ||
let r; | ||
if (typeof RegExpClass.create == 'function') { | ||
r = RegExpClass.create(pattern, flag); | ||
} | ||
else { | ||
r = new RegExpClass(pattern, flag); | ||
} | ||
return r; | ||
} | ||
exports.createRegExp = createRegExp; |
@@ -41,4 +41,7 @@ /** | ||
export function testFlag(flag: string, RegExpClass?: ICreateRegExp, testPattern?: typeof FlagsPattern): boolean | ||
// @ts-ignore | ||
export function testFlag<T>(flag: string, RegExpClass: ITypeCreateRegExp<T> = RegExp, testPattern = FlagsPattern): boolean | ||
export function testFlag<T>(flag: string, | ||
// @ts-ignore | ||
RegExpClass: ITypeCreateRegExp<T> = RegExp, | ||
testPattern = FlagsPattern | ||
): boolean | ||
{ | ||
@@ -52,13 +55,4 @@ if (testPattern[flag] && testPattern[flag].length) | ||
let r: RegExp; | ||
let r = createRegExp(pattern, flag, RegExpClass); | ||
if (typeof (<ICreateRegExp>RegExpClass).create == 'function') | ||
{ | ||
r = (<ICreateRegExp>RegExpClass).create(pattern, flag); | ||
} | ||
else | ||
{ | ||
r = new (<typeof RegExp>RegExpClass)(pattern, flag); | ||
} | ||
if (fn) | ||
@@ -152,3 +146,5 @@ { | ||
create?(pattern, flag) | ||
create?(pattern, flag?) | ||
create?(pattern, flag?, ...argv) | ||
@@ -160,3 +156,21 @@ } | ||
T extends ICreateRegExp ? ICreateRegExp : | ||
//T extends RegExpConstructor ? RegExpConstructor : | ||
any | ||
; | ||
// @ts-ignore | ||
export function createRegExp<T>(pattern: string, flag?: string, RegExpClass: ITypeCreateRegExp<T> = RegExp) | ||
{ | ||
let r: RegExp; | ||
if (typeof (<ICreateRegExp>RegExpClass).create == 'function') | ||
{ | ||
r = (<ICreateRegExp>RegExpClass).create(pattern, flag); | ||
} | ||
else | ||
{ | ||
r = new (<typeof RegExp>RegExpClass)(pattern, flag); | ||
} | ||
return r; | ||
} |
@@ -9,2 +9,4 @@ /** | ||
namedCapturingGroupsEmoji: boolean; | ||
namedCapturingGroupsBackreference: boolean; | ||
namedCapturingGroupsDuplicate: boolean; | ||
lookAheadPositive: boolean; | ||
@@ -21,4 +23,4 @@ lookAheadNegative: boolean; | ||
} | ||
export declare function testPattern(name: string, RegExpClass?: typeof RegExp, testPattern?: typeof PatternTest): boolean; | ||
export declare function testPattern(name: string, RegExpClass?: ICreateRegExp, testPattern?: typeof PatternTest): boolean; | ||
export declare function testPattern(name: string, RegExpClass?: typeof RegExp, testPatterns?: typeof PatternTest): boolean; | ||
export declare function testPattern(name: string, RegExpClass?: ICreateRegExp, testPatterns?: typeof PatternTest): boolean; | ||
export declare function testNamedCapturingGroups(key: string, flags?: string): IPatternTestRow; | ||
@@ -25,0 +27,0 @@ export interface IPatternTestRow { |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const index_1 = require("./index"); | ||
exports.PatternSupport = { | ||
@@ -11,2 +12,4 @@ namedCapturingGroups: false, | ||
namedCapturingGroupsEmoji: false, | ||
namedCapturingGroupsBackreference: false, | ||
namedCapturingGroupsDuplicate: false, | ||
lookAheadPositive: false, | ||
@@ -36,2 +39,9 @@ lookAheadNegative: false, | ||
], | ||
namedCapturingGroupsBackreference: [ | ||
['^(?<half>.*).\\k<half>$', 'u', 'a*a', true, 'test'], | ||
['^(?<half>.*).\\k<half>$', 'u', 'a*b', false, 'test'], | ||
], | ||
namedCapturingGroupsDuplicate: [ | ||
['^(?:(?<half>b)|(?<half>a)).\\k<half>$', 'u', 'a*a', true, 'test'], | ||
], | ||
lookAheadPositive: [ | ||
@@ -57,16 +67,10 @@ ['aa(?=bb)', '', 'aabb', true, 'test'], | ||
// @ts-ignore | ||
function testPattern(name, RegExpClass = RegExp, testPattern = exports.PatternTest) { | ||
if (testPattern[name] && testPattern[name].length) { | ||
function testPattern(name, RegExpClass = RegExp, testPatterns = exports.PatternTest) { | ||
if (testPatterns[name] && testPatterns[name].length) { | ||
let bool = false; | ||
try { | ||
bool = testPattern[name].every(function (v) { | ||
bool = testPatterns[name].every(function (v) { | ||
let [pattern, flag, input, value, fn] = v; | ||
let bool; | ||
let r; | ||
if (typeof RegExpClass.create == 'function') { | ||
r = RegExpClass.create(pattern, flag); | ||
} | ||
else { | ||
r = new RegExpClass(pattern, flag); | ||
} | ||
let r = index_1.createRegExp(pattern, flag, RegExpClass); | ||
if (fn) { | ||
@@ -73,0 +77,0 @@ if (typeof fn == 'function') { |
@@ -5,3 +5,3 @@ /** | ||
import { ICreateRegExp, ITypeCreateRegExp } from './index'; | ||
import { createRegExp, ICreateRegExp, ITypeCreateRegExp } from './index'; | ||
@@ -13,2 +13,5 @@ export const PatternSupport = { | ||
namedCapturingGroupsBackreference: false, | ||
namedCapturingGroupsDuplicate: false, | ||
lookAheadPositive: false, | ||
@@ -43,2 +46,11 @@ lookAheadNegative: false, | ||
namedCapturingGroupsBackreference: [ | ||
['^(?<half>.*).\\k<half>$', 'u', 'a*a', true, 'test'], | ||
['^(?<half>.*).\\k<half>$', 'u', 'a*b', false, 'test'], | ||
], | ||
namedCapturingGroupsDuplicate: [ | ||
['^(?:(?<half>b)|(?<half>a)).\\k<half>$', 'u', 'a*a', true, 'test'], | ||
], | ||
lookAheadPositive: [ | ||
@@ -74,8 +86,8 @@ ['aa(?=bb)', '', 'aabb', true, 'test'], | ||
export function testPattern(name: string, RegExpClass?: typeof RegExp, testPattern?: typeof PatternTest): boolean | ||
export function testPattern(name: string, RegExpClass?: ICreateRegExp, testPattern?: typeof PatternTest): boolean | ||
export function testPattern(name: string, RegExpClass?: typeof RegExp, testPatterns?: typeof PatternTest): boolean | ||
export function testPattern(name: string, RegExpClass?: ICreateRegExp, testPatterns?: typeof PatternTest): boolean | ||
// @ts-ignore | ||
export function testPattern<T>(name: string, RegExpClass: ITypeCreateRegExp<T> = RegExp, testPattern = PatternTest): boolean | ||
export function testPattern<T>(name: string, RegExpClass: ITypeCreateRegExp<T> = RegExp, testPatterns = PatternTest): boolean | ||
{ | ||
if (testPattern[name] && testPattern[name].length) | ||
if (testPatterns[name] && testPatterns[name].length) | ||
{ | ||
@@ -86,3 +98,3 @@ let bool: boolean = false; | ||
{ | ||
bool = testPattern[name].every(function (v) | ||
bool = testPatterns[name].every(function (v) | ||
{ | ||
@@ -92,13 +104,4 @@ let [pattern, flag, input, value, fn] = v; | ||
let r: RegExp; | ||
let r = createRegExp(pattern, flag, RegExpClass); | ||
if (typeof (<ICreateRegExp>RegExpClass).create == 'function') | ||
{ | ||
r = (<ICreateRegExp>RegExpClass).create(pattern, flag); | ||
} | ||
else | ||
{ | ||
r = new (<typeof RegExp>RegExpClass)(pattern, flag); | ||
} | ||
if (fn) | ||
@@ -105,0 +108,0 @@ { |
{ | ||
"name": "regexp-support", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "check RegExp ( regular expressions ) support", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -86,6 +86,10 @@ # regexp-support | ||
namedCapturingGroupsEmoji: false, | ||
namedCapturingGroupsBackreference: true, | ||
namedCapturingGroupsDuplicate: false, | ||
lookAheadPositive: true, | ||
lookAheadNegative: true, | ||
lookBehindPositive: true, | ||
lookBehindNegative: true } } | ||
lookBehindNegative: true }, | ||
hasFlagsProp: true, | ||
nativeFlags: 'gimsuy' } | ||
``` | ||
@@ -92,0 +96,0 @@ |
32271
19.23%17
21.43%1034
20.23%156
2.63%