mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-20 12:00:53 +08:00
added definitions for XRegExp
This commit is contained in:
@@ -287,6 +287,7 @@ List of Definitions
|
||||
* [WinJS](http://msdn.microsoft.com/en-us/library/windows/apps/br229773.aspx) (from TypeScript samples)
|
||||
* [WinRT](http://msdn.microsoft.com/en-us/library/windows/apps/br211377.aspx) (from TypeScript samples)
|
||||
* [ws](http://einaros.github.io/ws/) (by [Paul Loyd](https://github.com/loyd))
|
||||
* [XRegExp](http://xregexp.com/) (by [Bart van der Schoor](https://github.com/Bartvds))
|
||||
* [YouTube](https://developers.google.com/youtube/) (by [Daz Wilkin](https://github.com/DazWilkin/))
|
||||
* [YouTube Analytics API](https://developers.google.com/youtube/analytics/) (by [Frank M](https://github.com/sgtfrankieboy))
|
||||
* [YouTube Data API](https://developers.google.com/youtube/v3/) (by [Frank M](https://github.com/sgtfrankieboy/))
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
/// <reference path="xregexp.d.ts" />
|
||||
|
||||
import X = require('xregexp');
|
||||
import XRegExp = X.XRegExp;
|
||||
import TokenOpts = X.TokenOpts;
|
||||
|
||||
// -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
|
||||
var exp: RegExp;
|
||||
var expArr: RegExp[];
|
||||
var chain: RegExp[];
|
||||
var regex: RegExp;
|
||||
var value: any;
|
||||
var str: string;
|
||||
var scope: string;
|
||||
var search: string;
|
||||
var searchEx: RegExp;
|
||||
var bool: boolean;
|
||||
var strArr: string[];
|
||||
var pattern: string;
|
||||
var flags: string;
|
||||
var right: string;
|
||||
var left: string;
|
||||
var sticky: boolean;
|
||||
var pos: number;
|
||||
var num: number;
|
||||
var limit: number;
|
||||
var obj: Object;
|
||||
var matchArr: RegExpExecArray;
|
||||
var options: TokenOpts;
|
||||
var replacer: Function;
|
||||
|
||||
// -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
|
||||
regex = XRegExp(str);
|
||||
regex = XRegExp(str, flags);
|
||||
regex = XRegExp(regex);
|
||||
|
||||
str = XRegExp.version;
|
||||
|
||||
// -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
|
||||
XRegExp.addToken(regex, (arr, scope) => {
|
||||
matchArr = arr;
|
||||
str = scope;
|
||||
return str;
|
||||
});
|
||||
|
||||
XRegExp.addToken(regex, (arr, scope) => {
|
||||
matchArr = arr;
|
||||
str = scope;
|
||||
return str;
|
||||
}, options);
|
||||
|
||||
// -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
|
||||
regex = XRegExp.build(pattern, strArr, flags);
|
||||
regex = XRegExp.build(pattern, strArr);
|
||||
regex = XRegExp.cache(pattern);
|
||||
regex = XRegExp.cache(pattern, flags);
|
||||
|
||||
str = XRegExp.escape(str);
|
||||
|
||||
matchArr = XRegExp.exec(str, regex, pos, sticky);
|
||||
matchArr = XRegExp.exec(str, regex, pos);
|
||||
matchArr = XRegExp.exec(str, regex);
|
||||
|
||||
// -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
|
||||
matchArr = XRegExp.forEach(str, regex, (match, index, input, regexp) => {
|
||||
exp = regexp;
|
||||
str = input;
|
||||
num = index;
|
||||
matchArr = match;
|
||||
}, obj);
|
||||
|
||||
matchArr = XRegExp.forEach(str, regex, (match, index, input, regexp) => {
|
||||
exp = regexp;
|
||||
str = input;
|
||||
num = index;
|
||||
matchArr = match;
|
||||
});
|
||||
|
||||
// -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
|
||||
regex = XRegExp.globalize(regex);
|
||||
|
||||
XRegExp.install(str);
|
||||
XRegExp.install(obj);
|
||||
|
||||
bool = XRegExp.isInstalled(str);
|
||||
bool = XRegExp.isRegExp(value);
|
||||
strArr = XRegExp.matchChain(str, chain);
|
||||
|
||||
// -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
|
||||
strArr = XRegExp.matchRecursive(str, left, right, flags, options);
|
||||
strArr = XRegExp.matchRecursive(str, left, right, flags);
|
||||
strArr = XRegExp.matchRecursive(str, left, right);
|
||||
|
||||
// -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
str = XRegExp.replace(str, search, str, scope);
|
||||
str = XRegExp.replace(str, search, str);
|
||||
str = XRegExp.replace(str, search, replacer, scope);
|
||||
str = XRegExp.replace(str, search, replacer);
|
||||
|
||||
str = XRegExp.replace(str, searchEx, str, scope);
|
||||
str = XRegExp.replace(str, searchEx, str);
|
||||
str = XRegExp.replace(str, searchEx, replacer, scope);
|
||||
str = XRegExp.replace(str, searchEx, replacer);
|
||||
|
||||
// -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
|
||||
strArr = XRegExp.split(str, search, limit);
|
||||
strArr = XRegExp.split(str, search);
|
||||
strArr = XRegExp.split(str, searchEx, limit);
|
||||
strArr = XRegExp.split(str, searchEx);
|
||||
|
||||
// -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
|
||||
bool = XRegExp.test(str, regex, pos, bool);
|
||||
bool = XRegExp.test(str, regex, pos);
|
||||
bool = XRegExp.test(str, regex);
|
||||
|
||||
// -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
|
||||
XRegExp.uninstall(obj);
|
||||
XRegExp.uninstall(str);
|
||||
|
||||
regex = XRegExp.union(strArr, flags);
|
||||
regex = XRegExp.union(strArr);
|
||||
|
||||
// -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
|
||||
Vendored
+62
@@ -0,0 +1,62 @@
|
||||
// Type definitions for XRegExp 2.0.0
|
||||
// Project: http://xregexp.com
|
||||
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module 'xregexp' {
|
||||
// scopes: 'default', 'class', or 'all'
|
||||
/*
|
||||
Native flags:
|
||||
g - global
|
||||
i - ignore case
|
||||
m - multiline anchors
|
||||
y - sticky (Firefox 3+)
|
||||
Additional XRegExp flags:
|
||||
n - explicit capture
|
||||
s - dot matches all (aka singleline)
|
||||
x - free-spacing and line comments (aka extended)
|
||||
*/
|
||||
export interface TokenOpts {
|
||||
scope?: string;
|
||||
trigger?: () => boolean;
|
||||
customFlags?: string;
|
||||
}
|
||||
|
||||
export function XRegExp(pattern: string, flags?: string): RegExp;
|
||||
export function XRegExp(pattern: RegExp): RegExp;
|
||||
|
||||
export module XRegExp {
|
||||
function addToken(regex: RegExp, handler: (matchArr: RegExpExecArray, scope: string) => string, options?: TokenOpts): void;
|
||||
|
||||
function build(pattern: string, subs: string[], flags?: string): RegExp;
|
||||
function cache(pattern: string, flags?: string): RegExp;
|
||||
function escape(str: string): string;
|
||||
function exec(str: string, regex: RegExp, pos?: number, sticky?: boolean): RegExpExecArray;
|
||||
function forEach(str: string, regex: RegExp, callback: (matchArr: RegExpExecArray, index: number, input: string, regexp: RegExp) => void, context?: Object): any;
|
||||
function globalize(regex: RegExp): RegExp;
|
||||
|
||||
function install(options: string): void;
|
||||
function install(options: Object): void;
|
||||
|
||||
function isInstalled(feature: string): boolean;
|
||||
function isRegExp(value: any): boolean;
|
||||
function matchChain(str: string, chain: RegExp[]): string[];
|
||||
function matchRecursive(str: string, left: string, right: string, flags?: string, options?: Object): string[];
|
||||
|
||||
function replace(str: string, search: string, replacement: string, scope?: string): string;
|
||||
function replace(str: string, search: string, replacement: Function, scope?: string): string;
|
||||
function replace(str: string, search: RegExp, replacement: string, scope?: string): string;
|
||||
function replace(str: string, search: RegExp, replacement: Function, scope?: string): string;
|
||||
|
||||
function split(str: string, separator: string, limit?: number): string[];
|
||||
function split(str: string, separator: RegExp, limit?: number): string[];
|
||||
|
||||
function test(str: string, regex: RegExp, pos?: number, sticky?: boolean): boolean;
|
||||
|
||||
function uninstall(options: Object): void;
|
||||
function uninstall(options: string): void;
|
||||
|
||||
function union(patterns: string[], flags?: string): RegExp;
|
||||
var version: string;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user