regexp-support
Advanced tools
Comparing version
@@ -5,2 +5,3 @@ /** | ||
import lib from './lib'; | ||
import libPattern from './lib/pattern'; | ||
export declare const support: Readonly<{ | ||
@@ -35,2 +36,4 @@ flags: { | ||
namedCapturingGroups: boolean; | ||
namedCapturingGroupsUnicode: boolean; | ||
namedCapturingGroupsEmoji: boolean; | ||
}; | ||
@@ -40,2 +43,3 @@ }>; | ||
export import testFlag = lib.testFlag; | ||
export import testPattern = libPattern.testPattern; | ||
export default support; |
27
index.js
@@ -8,2 +8,3 @@ "use strict"; | ||
const flags_1 = require("./lib/flags"); | ||
const index_1 = require("./lib/index"); | ||
const pattern_1 = require("./lib/pattern"); | ||
@@ -33,27 +34,15 @@ const _support = { | ||
*/ | ||
flagsAll: {}, | ||
pattern: Object.keys(pattern_1.default).reduce(function (a, key) { | ||
flagsAll: index_1.testFlagsAll(), | ||
/** | ||
* pattern support | ||
*/ | ||
pattern: Object.keys(pattern_1.PatternSupport).reduce(function (a, key) { | ||
a[key] = pattern_1.testPattern(key); | ||
return a; | ||
}, pattern_1.default), | ||
}, {}), | ||
}; | ||
{ | ||
let flagsAll = {}; | ||
for (let i = 65; i <= 90; i++) { | ||
let k1 = String.fromCharCode(i); | ||
let k2 = String.fromCharCode(i + 32); | ||
flagsAll[k1] = lib_1.hasSupportFlag(k1); | ||
flagsAll[k2] = lib_1.hasSupportFlag(k2); | ||
} | ||
// @ts-ignore | ||
_support.flagsAll = Object.keys(flagsAll).sort().reduce(function (a, flag) { | ||
if (flagsAll[flag]) { | ||
a[flag] = flagsAll[flag]; | ||
} | ||
return a; | ||
}, {}); | ||
} | ||
exports.support = Object.freeze(_support); | ||
exports.hasSupportFlag = lib_1.default.hasSupportFlag; | ||
exports.testFlag = lib_1.default.testFlag; | ||
exports.testPattern = pattern_1.default.testPattern; | ||
exports.default = exports.support; |
43
index.ts
@@ -7,3 +7,4 @@ /** | ||
import FlagsName from './lib/flags'; | ||
import PatternSupport, { testPattern } from './lib/pattern'; | ||
import { testFlagsAll } from './lib/index'; | ||
import libPattern, { PatternSupport, testPattern } from './lib/pattern'; | ||
@@ -43,12 +44,7 @@ const _support = { | ||
*/ | ||
flagsAll: {} as { | ||
g: boolean, | ||
i: boolean, | ||
m: boolean, | ||
s: boolean, | ||
u: boolean, | ||
y: boolean, | ||
[key: string]: boolean | ||
}, | ||
flagsAll: testFlagsAll(), | ||
/** | ||
* pattern support | ||
*/ | ||
pattern: Object.keys(PatternSupport).reduce(function (a, key) | ||
@@ -58,29 +54,5 @@ { | ||
return a; | ||
}, PatternSupport), | ||
}, {} as typeof PatternSupport), | ||
}; | ||
{ | ||
let flagsAll = {}; | ||
for (let i = 65; i <= 90; i++) | ||
{ | ||
let k1 = String.fromCharCode(i); | ||
let k2 = String.fromCharCode(i + 32); | ||
flagsAll[k1] = hasSupportFlag(k1); | ||
flagsAll[k2] = hasSupportFlag(k2); | ||
} | ||
// @ts-ignore | ||
_support.flagsAll = Object.keys(flagsAll).sort().reduce(function (a, flag) | ||
{ | ||
if (flagsAll[flag]) | ||
{ | ||
a[flag] = flagsAll[flag]; | ||
} | ||
return a; | ||
}, {}); | ||
} | ||
export const support = Object.freeze(_support); | ||
@@ -90,2 +62,3 @@ | ||
export import testFlag = lib.testFlag | ||
export import testPattern = libPattern.testPattern | ||
@@ -92,0 +65,0 @@ type valueof<T> = T[keyof T]; |
@@ -104,1 +104,19 @@ /** | ||
export default self; | ||
export declare function testFlagsAll(RegExpClass?: typeof RegExp, skipPatternCheck?: boolean): { | ||
g: boolean; | ||
i: boolean; | ||
m: boolean; | ||
s: boolean; | ||
u: boolean; | ||
y: boolean; | ||
[key: string]: boolean; | ||
}; | ||
export interface IFlagsAll { | ||
g: boolean; | ||
i: boolean; | ||
m: boolean; | ||
s: boolean; | ||
u: boolean; | ||
y: boolean; | ||
[key: string]: boolean; | ||
} |
@@ -56,1 +56,26 @@ "use strict"; | ||
exports.default = self; | ||
function testFlagsAll(RegExpClass = RegExp, skipPatternCheck) { | ||
let flagsAll = {}; | ||
for (let i = 65; i <= 90; i++) { | ||
let k1 = String.fromCharCode(i); | ||
let k2 = String.fromCharCode(i + 32); | ||
flagsAll[k1] = hasSupportFlag(k1, RegExpClass, skipPatternCheck); | ||
flagsAll[k2] = hasSupportFlag(k2, RegExpClass, skipPatternCheck); | ||
} | ||
let def = [ | ||
'g', | ||
'i', | ||
'm', | ||
's', | ||
'u', | ||
'y', | ||
]; | ||
flagsAll = Object.keys(flagsAll).sort().reduce(function (a, flag) { | ||
if (flagsAll[flag] || def.includes(flag)) { | ||
a[flag] = flagsAll[flag]; | ||
} | ||
return a; | ||
}, {}); | ||
return flagsAll; | ||
} | ||
exports.testFlagsAll = testFlagsAll; |
@@ -74,2 +74,60 @@ /** | ||
import * as self from './index'; | ||
export default self; | ||
export function testFlagsAll(RegExpClass: typeof RegExp = RegExp, skipPatternCheck?: boolean): { | ||
g: boolean, | ||
i: boolean, | ||
m: boolean, | ||
s: boolean, | ||
u: boolean, | ||
y: boolean, | ||
[key: string]: boolean | ||
} | ||
{ | ||
let flagsAll = {} as IFlagsAll; | ||
for (let i = 65; i <= 90; i++) | ||
{ | ||
let k1 = String.fromCharCode(i); | ||
let k2 = String.fromCharCode(i + 32); | ||
flagsAll[k1] = hasSupportFlag(k1, RegExpClass, skipPatternCheck); | ||
flagsAll[k2] = hasSupportFlag(k2, RegExpClass, skipPatternCheck); | ||
} | ||
let def = [ | ||
'g', | ||
'i', | ||
'm', | ||
's', | ||
'u', | ||
'y', | ||
]; | ||
flagsAll = Object.keys(flagsAll).sort().reduce(function (a, flag) | ||
{ | ||
if (flagsAll[flag] || def.includes(flag)) | ||
{ | ||
a[flag] = flagsAll[flag]; | ||
} | ||
return a; | ||
}, {} as IFlagsAll); | ||
return flagsAll; | ||
} | ||
export interface IFlagsAll | ||
{ | ||
g: boolean, | ||
i: boolean, | ||
m: boolean, | ||
s: boolean, | ||
u: boolean, | ||
y: boolean, | ||
[key: string]: boolean | ||
} |
@@ -6,11 +6,7 @@ /** | ||
namedCapturingGroups: boolean; | ||
namedCapturingGroupsUnicode: boolean; | ||
namedCapturingGroupsEmoji: boolean; | ||
}; | ||
export declare const PatternTest: { | ||
[k in keyof typeof PatternSupport]?: { | ||
0: string; | ||
1: string; | ||
2: string; | ||
3: boolean | any; | ||
4?: string | IPatternTestFn; | ||
}[]; | ||
[k in keyof typeof PatternSupport]?: IPatternTestRow[]; | ||
}; | ||
@@ -21,10 +17,15 @@ export interface IPatternTestFn { | ||
export declare function testPattern(name: string, RegExpClass?: typeof RegExp, testPattern?: { | ||
namedCapturingGroups?: { | ||
0: string; | ||
1: string; | ||
2: string; | ||
3: any; | ||
4?: string | IPatternTestFn; | ||
}[]; | ||
namedCapturingGroups?: self.IPatternTestRow[]; | ||
namedCapturingGroupsUnicode?: self.IPatternTestRow[]; | ||
namedCapturingGroupsEmoji?: self.IPatternTestRow[]; | ||
}): boolean; | ||
export default PatternSupport; | ||
export declare function testNamedCapturingGroups(key: string, flags?: string): IPatternTestRow; | ||
export interface IPatternTestRow { | ||
0: string; | ||
1: string; | ||
2: string; | ||
3: boolean | any; | ||
4?: string | IPatternTestFn; | ||
} | ||
import * as self from './pattern'; | ||
export default self; |
@@ -8,19 +8,24 @@ "use strict"; | ||
namedCapturingGroups: false, | ||
namedCapturingGroupsUnicode: false, | ||
namedCapturingGroupsEmoji: false, | ||
}; | ||
exports.PatternTest = { | ||
/** | ||
* A-Z, a-z, 0-9, $, and _ | ||
*/ | ||
namedCapturingGroups: [ | ||
['U\\+(?<naïve嬢の日常>[0-9A-F]{4})', '', 'U+2620', { | ||
groups: { 'naïve嬢の日常': '2620' }, | ||
}, function (r, value, input) { | ||
let ret = r.exec(input); | ||
return ret.groups && Object | ||
.entries(ret.groups) | ||
.every(function (v) { | ||
let [key, v1] = v; | ||
let v2 = value.groups[key]; | ||
//console.log(key, v1, v2, v1 === v2); | ||
return v1 === v2; | ||
}); | ||
}], | ||
testNamedCapturingGroups('Az'), | ||
testNamedCapturingGroups('_09'), | ||
testNamedCapturingGroups('$'), | ||
], | ||
namedCapturingGroupsUnicode: [ | ||
testNamedCapturingGroups('naïve嬢の日常'), | ||
testNamedCapturingGroups('Русский'), | ||
testNamedCapturingGroups('naïve'), | ||
testNamedCapturingGroups('嬢の日常'), | ||
testNamedCapturingGroups('𠬠', 'u'), | ||
], | ||
namedCapturingGroupsEmoji: [ | ||
testNamedCapturingGroups('👩', 'u'), | ||
], | ||
}; | ||
@@ -59,2 +64,19 @@ function testPattern(name, RegExpClass = RegExp, testPattern = exports.PatternTest) { | ||
exports.testPattern = testPattern; | ||
exports.default = exports.PatternSupport; | ||
function testNamedCapturingGroups(key, flags) { | ||
return [`U\\+(?<${key}>[0-9A-F]{4})`, flags || '', 'U+2620', { | ||
groups: { [key]: '2620' }, | ||
}, function (r, value, input) { | ||
let ret = r.exec(input); | ||
return ret.groups && Object | ||
.entries(ret.groups) | ||
.every(function (v) { | ||
let [key, v1] = v; | ||
let v2 = value.groups[key]; | ||
//console.log(key, v1, v2, v1 === v2); | ||
return v1 === v2; | ||
}); | ||
}]; | ||
} | ||
exports.testNamedCapturingGroups = testNamedCapturingGroups; | ||
const self = require("./pattern"); | ||
exports.default = self; |
@@ -7,38 +7,27 @@ /** | ||
namedCapturingGroups: false, | ||
namedCapturingGroupsUnicode: false, | ||
namedCapturingGroupsEmoji: false, | ||
}; | ||
export const PatternTest: { | ||
[k in keyof typeof PatternSupport]?: { | ||
0: string, | ||
1: string, | ||
2: string, | ||
3: boolean | any, | ||
4?: string | IPatternTestFn, | ||
}[] | ||
[k in keyof typeof PatternSupport]?: IPatternTestRow[] | ||
} = { | ||
/** | ||
* A-Z, a-z, 0-9, $, and _ | ||
*/ | ||
namedCapturingGroups: [ | ||
['U\\+(?<naïve嬢の日常>[0-9A-F]{4})', '', 'U+2620', { | ||
groups: { 'naïve嬢の日常': '2620' }, | ||
}, function (r, value, input) | ||
{ | ||
let ret = r.exec(input) as RegExpExecArray & { | ||
groups: { | ||
[key: string]: string, | ||
} | ||
}; | ||
return ret.groups && Object | ||
.entries(ret.groups) | ||
.every(function (v) | ||
{ | ||
let [key, v1] = v; | ||
let v2 = value.groups[key]; | ||
//console.log(key, v1, v2, v1 === v2); | ||
return v1 === v2; | ||
}) | ||
; | ||
}], | ||
testNamedCapturingGroups('Az'), | ||
testNamedCapturingGroups('_09'), | ||
testNamedCapturingGroups('$'), | ||
], | ||
namedCapturingGroupsUnicode: [ | ||
testNamedCapturingGroups('naïve嬢の日常'), | ||
testNamedCapturingGroups('Русский'), | ||
testNamedCapturingGroups('naïve'), | ||
testNamedCapturingGroups('嬢の日常'), | ||
testNamedCapturingGroups('𠬠', 'u'), | ||
], | ||
namedCapturingGroupsEmoji: [ | ||
testNamedCapturingGroups('👩', 'u'), | ||
], | ||
}; | ||
@@ -100,2 +89,39 @@ | ||
export default PatternSupport; | ||
export function testNamedCapturingGroups(key: string, flags?: string): IPatternTestRow | ||
{ | ||
return [`U\\+(?<${key}>[0-9A-F]{4})`, flags || '', 'U+2620', { | ||
groups: { [key]: '2620' }, | ||
}, function (r, value, input) | ||
{ | ||
let ret = r.exec(input) as RegExpExecArray & { | ||
groups: { | ||
[key: string]: string, | ||
} | ||
}; | ||
return ret.groups && Object | ||
.entries(ret.groups) | ||
.every(function (v) | ||
{ | ||
let [key, v1] = v; | ||
let v2 = value.groups[key]; | ||
//console.log(key, v1, v2, v1 === v2); | ||
return v1 === v2; | ||
}) | ||
; | ||
}]; | ||
} | ||
export interface IPatternTestRow | ||
{ | ||
0: string, | ||
1: string, | ||
2: string, | ||
3: boolean | any, | ||
4?: string | IPatternTestFn, | ||
} | ||
import * as self from './pattern'; | ||
export default self; |
{ | ||
"name": "regexp-support", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "check RegExp ( regular expressions ) support", | ||
@@ -11,2 +11,3 @@ "keywords": [ | ||
"is", | ||
"pattern", | ||
"re", | ||
@@ -13,0 +14,0 @@ "regex", |
22080
16.58%822
14.97%