feat(facade/lang): add math and regexp support

This commit is contained in:
Tobias Bosch 2014-10-28 14:46:09 -07:00
parent cc115d58ca
commit d4c099de8c
2 changed files with 48 additions and 1 deletions

View File

@ -1,6 +1,13 @@
library angular.core.facade.lang; library angular.core.facade.lang;
export 'dart:core' show Type; export 'dart:core' show Type, RegExp;
import 'dart:math' as math;
class Math {
static final _random = new math.Random();
static int floor(num n) => n.floor();
static double random() => _random.nextDouble();
}
class FIELD { class FIELD {
final String definition; final String definition;
@ -58,3 +65,21 @@ class NumberWrapper {
} }
} }
class RegExpWrapper {
static RegExp create(regExpStr) {
return new RegExp(regExpStr);
}
static matcher(regExp, input) {
return regExp.allMatches(input).iterator;
}
}
class RegExpMatcherWrapper {
static next(matcher) {
if (matcher.moveNext()) {
return matcher.current;
}
return null;
}
}

View File

@ -1,4 +1,5 @@
export var Type = Function; export var Type = Function;
export var Math = window.Math;
export class FIELD { export class FIELD {
constructor(definition) { constructor(definition) {
@ -107,3 +108,24 @@ export function int() {};
int.assert = function(value) { int.assert = function(value) {
return value == null || typeof value == 'number' && value === Math.floor(value); return value == null || typeof value == 'number' && value === Math.floor(value);
} }
export var RegExp = window.RegExp;
export class RegExpWrapper {
static create(regExpStr):RegExp {
return new RegExp(regExpStr, 'g');
}
static matcher(regExp, input) {
return {
re: regExp,
input: input
};
}
}
export class RegExpMatcherWrapper {
static next(matcher) {
return matcher.re.exec(matcher.input);
}
}