Skip to content

Commit d4c099d

Browse files
committed
feat(facade/lang): add math and regexp support
1 parent cc115d5 commit d4c099d

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

modules/facade/src/lang.dart

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
library angular.core.facade.lang;
22

3-
export 'dart:core' show Type;
3+
export 'dart:core' show Type, RegExp;
4+
import 'dart:math' as math;
5+
6+
class Math {
7+
static final _random = new math.Random();
8+
static int floor(num n) => n.floor();
9+
static double random() => _random.nextDouble();
10+
}
411

512
class FIELD {
613
final String definition;
@@ -58,3 +65,21 @@ class NumberWrapper {
5865
}
5966
}
6067

68+
class RegExpWrapper {
69+
static RegExp create(regExpStr) {
70+
return new RegExp(regExpStr);
71+
}
72+
static matcher(regExp, input) {
73+
return regExp.allMatches(input).iterator;
74+
}
75+
}
76+
77+
class RegExpMatcherWrapper {
78+
static next(matcher) {
79+
if (matcher.moveNext()) {
80+
return matcher.current;
81+
}
82+
return null;
83+
}
84+
}
85+

modules/facade/src/lang.es6

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export var Type = Function;
2+
export var Math = window.Math;
23

34
export class FIELD {
45
constructor(definition) {
@@ -107,3 +108,24 @@ export function int() {};
107108
int.assert = function(value) {
108109
return value == null || typeof value == 'number' && value === Math.floor(value);
109110
}
111+
112+
export var RegExp = window.RegExp;
113+
114+
export class RegExpWrapper {
115+
static create(regExpStr):RegExp {
116+
return new RegExp(regExpStr, 'g');
117+
}
118+
static matcher(regExp, input) {
119+
return {
120+
re: regExp,
121+
input: input
122+
};
123+
}
124+
}
125+
126+
export class RegExpMatcherWrapper {
127+
static next(matcher) {
128+
return matcher.re.exec(matcher.input);
129+
}
130+
}
131+

0 commit comments

Comments
 (0)