2014-09-30 14:56:33 -04:00
|
|
|
library angular.core.facade.lang;
|
2014-09-19 16:38:37 -07:00
|
|
|
|
2014-10-28 14:46:09 -07:00
|
|
|
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();
|
|
|
|
}
|
2014-09-28 13:55:01 -07:00
|
|
|
|
|
|
|
class FIELD {
|
2014-10-02 12:27:01 -07:00
|
|
|
final String definition;
|
|
|
|
const FIELD(this.definition);
|
2014-09-28 13:55:01 -07:00
|
|
|
}
|
|
|
|
|
2014-10-02 12:27:01 -07:00
|
|
|
class CONST {
|
|
|
|
const CONST();
|
|
|
|
}
|
|
|
|
class ABSTRACT {
|
|
|
|
const ABSTRACT();
|
|
|
|
}
|
|
|
|
class IMPLEMENTS {
|
|
|
|
final interfaceClass;
|
|
|
|
const IMPLEMENTS(this.interfaceClass);
|
|
|
|
}
|
2014-09-26 13:52:12 -07:00
|
|
|
|
2014-09-30 14:56:33 -04:00
|
|
|
bool isPresent(obj) => obj != null;
|
|
|
|
bool isBlank(obj) => obj == null;
|
2015-01-21 12:05:52 -08:00
|
|
|
bool isString(obj) => obj is String;
|
2014-10-30 23:47:22 -07:00
|
|
|
|
2014-10-03 16:29:59 -04:00
|
|
|
String stringify(obj) => obj.toString();
|
2014-09-26 13:52:12 -07:00
|
|
|
|
|
|
|
class StringWrapper {
|
|
|
|
static String fromCharCode(int code) {
|
|
|
|
return new String.fromCharCode(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
static charCodeAt(String s, int index) {
|
|
|
|
return s.codeUnitAt(index);
|
|
|
|
}
|
2014-11-11 17:33:47 -08:00
|
|
|
|
|
|
|
static split(String s, RegExp regExp) {
|
|
|
|
var parts = [];
|
|
|
|
var lastEnd = 0;
|
|
|
|
regExp.allMatches(s).forEach((match) {
|
|
|
|
parts.add(s.substring(lastEnd, match.start));
|
|
|
|
lastEnd = match.end;
|
|
|
|
for (var i=0; i<match.groupCount; i++) {
|
|
|
|
parts.add(match.group(i+1));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
parts.add(s.substring(lastEnd));
|
|
|
|
return parts;
|
|
|
|
}
|
|
|
|
|
2015-01-09 20:51:27 -08:00
|
|
|
static bool equals(String s, String s2) {
|
2014-11-11 17:33:47 -08:00
|
|
|
return s == s2;
|
|
|
|
}
|
2014-11-14 14:18:23 -08:00
|
|
|
|
|
|
|
static String replaceAll(String s, RegExp from, String replace) {
|
|
|
|
return s.replaceAll(from, replace);
|
|
|
|
}
|
2014-09-26 13:52:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
class StringJoiner {
|
|
|
|
List<String> _parts = <String>[];
|
|
|
|
|
|
|
|
void add(String part) {
|
|
|
|
_parts.add(part);
|
|
|
|
}
|
|
|
|
|
|
|
|
String toString() => _parts.join("");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class NumberWrapper {
|
|
|
|
static int parseIntAutoRadix(String text) {
|
|
|
|
return int.parse(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parseInt(String text, int radix) {
|
|
|
|
return int.parse(text, radix: radix);
|
|
|
|
}
|
|
|
|
|
|
|
|
static double parseFloat(String text) {
|
|
|
|
return double.parse(text);
|
|
|
|
}
|
2014-10-28 18:56:15 +01:00
|
|
|
|
|
|
|
static get NaN => double.NAN;
|
|
|
|
|
|
|
|
static bool isNaN(num value) => value.isNaN;
|
2014-12-02 13:14:07 +01:00
|
|
|
|
|
|
|
static bool isInteger(value) => value is int;
|
2014-09-26 13:52:12 -07:00
|
|
|
}
|
2014-10-10 20:44:55 -07:00
|
|
|
|
2014-10-28 14:46:09 -07:00
|
|
|
class RegExpWrapper {
|
|
|
|
static RegExp create(regExpStr) {
|
|
|
|
return new RegExp(regExpStr);
|
|
|
|
}
|
2014-11-11 17:33:47 -08:00
|
|
|
static firstMatch(regExp, input) {
|
|
|
|
return regExp.firstMatch(input);
|
|
|
|
}
|
2014-10-28 14:46:09 -07:00
|
|
|
static matcher(regExp, input) {
|
|
|
|
return regExp.allMatches(input).iterator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class RegExpMatcherWrapper {
|
|
|
|
static next(matcher) {
|
|
|
|
if (matcher.moveNext()) {
|
|
|
|
return matcher.current;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-04 10:19:37 -08:00
|
|
|
class FunctionWrapper {
|
|
|
|
static apply(Function fn, posArgs) {
|
|
|
|
return Function.apply(fn, posArgs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class BaseException extends Error {
|
|
|
|
final String message;
|
|
|
|
|
|
|
|
BaseException(this.message);
|
|
|
|
|
|
|
|
String toString() {
|
|
|
|
return this.message;
|
|
|
|
}
|
2014-10-28 18:56:15 +01:00
|
|
|
}
|
|
|
|
|
2014-10-29 21:56:31 +01:00
|
|
|
const _NAN_KEY = const Object();
|
|
|
|
|
2014-10-28 18:56:15 +01:00
|
|
|
// Dart can have identical(str1, str2) == false while str1 == str2
|
|
|
|
bool looseIdentical(a, b) => a is String && b is String ? a == b : identical(a, b);
|
|
|
|
|
|
|
|
// Dart compare map keys by equality and we can have NaN != NaN
|
|
|
|
dynamic getMapKey(value) {
|
|
|
|
if (value is! num) return value;
|
|
|
|
return value.isNaN ? _NAN_KEY : value;
|
|
|
|
}
|
|
|
|
|
2014-11-24 18:42:53 +01:00
|
|
|
dynamic normalizeBlank(obj) {
|
2014-11-21 21:19:23 -08:00
|
|
|
return isBlank(obj) ? null : obj;
|
2014-12-02 13:14:07 +01:00
|
|
|
}
|
2014-11-24 18:42:53 +01:00
|
|
|
|
|
|
|
bool isJsObject(o) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-04 18:30:54 -08:00
|
|
|
|
2015-01-09 20:51:27 -08:00
|
|
|
bool assertionsEnabled() {
|
2014-12-04 18:30:54 -08:00
|
|
|
try {
|
|
|
|
assert(false);
|
|
|
|
return false;
|
|
|
|
} catch (e) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|