2014-09-30 18:56:33 +00:00
|
|
|
library angular.core.facade.lang;
|
2014-09-19 23:38:37 +00:00
|
|
|
|
2015-02-17 22:29:40 +00:00
|
|
|
export 'dart:core' show Type, RegExp, print, DateTime;
|
2014-10-28 21:46:09 +00:00
|
|
|
import 'dart:math' as math;
|
2015-02-11 18:13:49 +00:00
|
|
|
import 'dart:convert' as convert;
|
2015-06-11 17:32:55 +00:00
|
|
|
import 'dart:async' show Future;
|
2014-10-28 21:46:09 +00:00
|
|
|
|
2015-07-27 22:47:42 +00:00
|
|
|
bool isDart = true;
|
|
|
|
|
|
2015-07-13 21:22:43 +00:00
|
|
|
String getTypeNameForDebugging(Type type) => type.toString();
|
|
|
|
|
|
2014-10-28 21:46:09 +00:00
|
|
|
class Math {
|
|
|
|
|
static final _random = new math.Random();
|
|
|
|
|
static int floor(num n) => n.floor();
|
|
|
|
|
static double random() => _random.nextDouble();
|
|
|
|
|
}
|
2014-09-28 20:55:01 +00:00
|
|
|
|
2015-06-19 19:14:12 +00:00
|
|
|
int ENUM_INDEX(value) => value.index;
|
|
|
|
|
|
2014-10-02 19:27:01 +00:00
|
|
|
class CONST {
|
|
|
|
|
const CONST();
|
|
|
|
|
}
|
|
|
|
|
class ABSTRACT {
|
|
|
|
|
const ABSTRACT();
|
|
|
|
|
}
|
|
|
|
|
class IMPLEMENTS {
|
|
|
|
|
final interfaceClass;
|
|
|
|
|
const IMPLEMENTS(this.interfaceClass);
|
|
|
|
|
}
|
2014-09-26 20:52:12 +00:00
|
|
|
|
2014-09-30 18:56:33 +00:00
|
|
|
bool isPresent(obj) => obj != null;
|
|
|
|
|
bool isBlank(obj) => obj == null;
|
2015-01-21 20:05:52 +00:00
|
|
|
bool isString(obj) => obj is String;
|
2015-03-19 10:35:48 +00:00
|
|
|
bool isFunction(obj) => obj is Function;
|
2015-04-16 00:56:14 +00:00
|
|
|
bool isType(obj) => obj is Type;
|
2015-06-11 17:32:55 +00:00
|
|
|
bool isStringMap(obj) => obj is Map;
|
|
|
|
|
bool isArray(obj) => obj is List;
|
|
|
|
|
bool isPromise(obj) => obj is Future;
|
2015-07-04 17:55:43 +00:00
|
|
|
bool isNumber(obj) => obj is num;
|
2015-07-04 18:04:54 +00:00
|
|
|
bool isDate(obj) => obj is DateTime;
|
2014-10-31 06:47:22 +00:00
|
|
|
|
2014-10-03 20:29:59 +00:00
|
|
|
String stringify(obj) => obj.toString();
|
2014-09-26 20:52:12 +00:00
|
|
|
|
2015-07-10 23:09:18 +00:00
|
|
|
int serializeEnum(val) {
|
|
|
|
|
return val.index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Deserializes an enum
|
|
|
|
|
* val should be the indexed value of the enum (sa returned from @Link{serializeEnum})
|
|
|
|
|
* values should be a map from indexes to values for the enum that you want to deserialize.
|
|
|
|
|
*/
|
|
|
|
|
dynamic deserializeEnum(int val, Map<int, dynamic> values) {
|
|
|
|
|
return values[val];
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-26 20:52:12 +00:00
|
|
|
class StringWrapper {
|
|
|
|
|
static String fromCharCode(int code) {
|
|
|
|
|
return new String.fromCharCode(code);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-29 17:50:49 +00:00
|
|
|
static int charCodeAt(String s, int index) {
|
2014-09-26 20:52:12 +00:00
|
|
|
return s.codeUnitAt(index);
|
|
|
|
|
}
|
2014-11-12 01:33:47 +00:00
|
|
|
|
2015-01-29 17:50:49 +00:00
|
|
|
static List<String> split(String s, RegExp regExp) {
|
|
|
|
|
var parts = <String>[];
|
2014-11-12 01:33:47 +00:00
|
|
|
var lastEnd = 0;
|
|
|
|
|
regExp.allMatches(s).forEach((match) {
|
|
|
|
|
parts.add(s.substring(lastEnd, match.start));
|
|
|
|
|
lastEnd = match.end;
|
2015-01-29 17:50:49 +00:00
|
|
|
for (var i = 0; i < match.groupCount; i++) {
|
|
|
|
|
parts.add(match.group(i + 1));
|
2014-11-12 01:33:47 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
parts.add(s.substring(lastEnd));
|
|
|
|
|
return parts;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-10 04:51:27 +00:00
|
|
|
static bool equals(String s, String s2) {
|
2014-11-12 01:33:47 +00:00
|
|
|
return s == s2;
|
|
|
|
|
}
|
2014-11-14 22:18:23 +00:00
|
|
|
|
2015-02-18 09:06:31 +00:00
|
|
|
static String replace(String s, Pattern from, String replace) {
|
|
|
|
|
return s.replaceFirst(from, replace);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-14 22:18:23 +00:00
|
|
|
static String replaceAll(String s, RegExp from, String replace) {
|
|
|
|
|
return s.replaceAll(from, replace);
|
|
|
|
|
}
|
2015-02-04 22:35:10 +00:00
|
|
|
|
2015-05-14 16:17:44 +00:00
|
|
|
static String toUpperCase(String s) {
|
|
|
|
|
return s.toUpperCase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static String toLowerCase(String s) {
|
|
|
|
|
return s.toLowerCase();
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-05 22:03:58 +00:00
|
|
|
static startsWith(String s, String start) {
|
|
|
|
|
return s.startsWith(start);
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-04 22:35:10 +00:00
|
|
|
static String substring(String s, int start, [int end]) {
|
|
|
|
|
return s.substring(start, end);
|
|
|
|
|
}
|
2015-01-30 08:43:21 +00:00
|
|
|
|
|
|
|
|
static String replaceAllMapped(String s, RegExp from, Function cb) {
|
|
|
|
|
return s.replaceAllMapped(from, cb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool contains(String s, String substr) {
|
|
|
|
|
return s.contains(substr);
|
|
|
|
|
}
|
2015-07-20 20:37:50 +00:00
|
|
|
|
|
|
|
|
static int compare(String a, String b) => a.compareTo(b);
|
2014-09-26 20:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class StringJoiner {
|
2015-01-29 17:50:49 +00:00
|
|
|
final List<String> _parts = <String>[];
|
2014-09-26 20:52:12 +00:00
|
|
|
|
|
|
|
|
void add(String part) {
|
|
|
|
|
_parts.add(part);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String toString() => _parts.join("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class NumberWrapper {
|
2015-02-21 01:44:23 +00:00
|
|
|
static String toFixed(num n, int fractionDigits) {
|
|
|
|
|
return n.toStringAsFixed(fractionDigits);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool equal(num a, num b) {
|
|
|
|
|
return a == b;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-26 20:52:12 +00:00
|
|
|
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 17:56:15 +00:00
|
|
|
|
2015-01-29 17:50:49 +00:00
|
|
|
static double get NaN => double.NAN;
|
2014-10-28 17:56:15 +00:00
|
|
|
|
|
|
|
|
static bool isNaN(num value) => value.isNaN;
|
2014-12-02 12:14:07 +00:00
|
|
|
|
|
|
|
|
static bool isInteger(value) => value is int;
|
2014-09-26 20:52:12 +00:00
|
|
|
}
|
2014-10-11 03:44:55 +00:00
|
|
|
|
2014-10-28 21:46:09 +00:00
|
|
|
class RegExpWrapper {
|
2015-01-30 08:43:21 +00:00
|
|
|
static RegExp create(regExpStr, [String flags = '']) {
|
|
|
|
|
bool multiLine = flags.contains('m');
|
|
|
|
|
bool caseSensitive = !flags.contains('i');
|
2015-05-09 02:51:19 +00:00
|
|
|
return new RegExp(regExpStr,
|
|
|
|
|
multiLine: multiLine, caseSensitive: caseSensitive);
|
2014-10-28 21:46:09 +00:00
|
|
|
}
|
2015-01-29 17:50:49 +00:00
|
|
|
static Match firstMatch(RegExp regExp, String input) {
|
2014-11-12 01:33:47 +00:00
|
|
|
return regExp.firstMatch(input);
|
|
|
|
|
}
|
2015-05-26 11:34:11 +00:00
|
|
|
static bool test(RegExp regExp, String input) {
|
|
|
|
|
return regExp.hasMatch(input);
|
|
|
|
|
}
|
2015-01-29 17:50:49 +00:00
|
|
|
static Iterator<Match> matcher(RegExp regExp, String input) {
|
2014-10-28 21:46:09 +00:00
|
|
|
return regExp.allMatches(input).iterator;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class RegExpMatcherWrapper {
|
2015-02-26 15:31:56 +00:00
|
|
|
static _JSLikeMatch next(Iterator<Match> matcher) {
|
2014-10-28 21:46:09 +00:00
|
|
|
if (matcher.moveNext()) {
|
2015-02-26 15:31:56 +00:00
|
|
|
return new _JSLikeMatch(matcher.current);
|
2014-10-28 21:46:09 +00:00
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-26 15:31:56 +00:00
|
|
|
class _JSLikeMatch {
|
|
|
|
|
Match _m;
|
|
|
|
|
|
|
|
|
|
_JSLikeMatch(this._m);
|
|
|
|
|
|
2015-05-09 02:51:19 +00:00
|
|
|
String operator [](index) => _m[index];
|
2015-02-26 15:31:56 +00:00
|
|
|
int get index => _m.start;
|
|
|
|
|
int get length => _m.groupCount + 1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-04 18:19:37 +00:00
|
|
|
class FunctionWrapper {
|
|
|
|
|
static apply(Function fn, posArgs) {
|
|
|
|
|
return Function.apply(fn, posArgs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class BaseException extends Error {
|
2015-07-22 18:59:16 +00:00
|
|
|
final dynamic context;
|
2014-11-04 18:19:37 +00:00
|
|
|
final String message;
|
2015-06-28 03:00:11 +00:00
|
|
|
final originalException;
|
|
|
|
|
final originalStack;
|
2014-11-04 18:19:37 +00:00
|
|
|
|
2015-07-28 00:26:28 +00:00
|
|
|
BaseException(
|
|
|
|
|
[this.message, this.originalException, this.originalStack, this.context]);
|
2014-11-04 18:19:37 +00:00
|
|
|
|
|
|
|
|
String toString() {
|
|
|
|
|
return this.message;
|
|
|
|
|
}
|
2014-10-28 17:56:15 +00:00
|
|
|
}
|
|
|
|
|
|
2015-07-15 00:53:04 +00:00
|
|
|
Error makeTypeError([String message = ""]) {
|
|
|
|
|
return new BaseException(message);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-29 20:56:31 +00:00
|
|
|
const _NAN_KEY = const Object();
|
|
|
|
|
|
2015-07-14 23:04:49 +00:00
|
|
|
// Dart can have identical(str1, str2) == false while str1 == str2. Moreover,
|
|
|
|
|
// after compiling with dart2js identical(str1, str2) might return true.
|
|
|
|
|
// (see dartbug.com/22496 for details).
|
2015-01-29 17:50:49 +00:00
|
|
|
bool looseIdentical(a, b) =>
|
|
|
|
|
a is String && b is String ? a == b : identical(a, b);
|
2014-10-28 17:56:15 +00:00
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 23:25:47 +00:00
|
|
|
// TODO: remove with https://github.com/angular/angular/issues/3055
|
|
|
|
|
dynamic normalizeBlank(obj) => obj;
|
2014-11-24 17:42:53 +00:00
|
|
|
|
2015-05-27 17:14:37 +00:00
|
|
|
bool normalizeBool(bool obj) {
|
|
|
|
|
return isBlank(obj) ? false : obj;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-24 17:42:53 +00:00
|
|
|
bool isJsObject(o) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-24 20:46:39 +00:00
|
|
|
var _assertionsEnabled = null;
|
2015-01-10 04:51:27 +00:00
|
|
|
bool assertionsEnabled() {
|
2015-07-22 18:59:16 +00:00
|
|
|
if (_assertionsEnabled == null) {
|
2015-06-24 20:46:39 +00:00
|
|
|
try {
|
|
|
|
|
assert(false);
|
|
|
|
|
_assertionsEnabled = false;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
_assertionsEnabled = true;
|
|
|
|
|
}
|
2014-12-05 02:30:54 +00:00
|
|
|
}
|
2015-06-24 20:46:39 +00:00
|
|
|
return _assertionsEnabled;
|
2015-01-29 17:50:49 +00:00
|
|
|
}
|
2015-02-11 18:13:49 +00:00
|
|
|
|
|
|
|
|
// Can't be all uppercase as our transpiler would think it is a special directive...
|
|
|
|
|
class Json {
|
|
|
|
|
static parse(String s) => convert.JSON.decode(s);
|
2015-05-18 16:24:52 +00:00
|
|
|
static String stringify(data) {
|
|
|
|
|
var encoder = new convert.JsonEncoder.withIndent(" ");
|
|
|
|
|
return encoder.convert(data);
|
|
|
|
|
}
|
2015-02-11 18:13:49 +00:00
|
|
|
}
|
2015-02-17 22:29:40 +00:00
|
|
|
|
|
|
|
|
class DateWrapper {
|
2015-07-04 18:04:54 +00:00
|
|
|
static DateTime create(int year, [int month = 1, int day = 1, int hour = 0,
|
|
|
|
|
int minutes = 0, int seconds = 0, int milliseconds = 0]) {
|
|
|
|
|
return new DateTime(year, month, day, hour, minutes, seconds, milliseconds);
|
|
|
|
|
}
|
2015-02-23 19:44:59 +00:00
|
|
|
static DateTime fromMillis(int ms) {
|
2015-07-04 18:04:54 +00:00
|
|
|
return new DateTime.fromMillisecondsSinceEpoch(ms, isUtc: true);
|
2015-02-17 22:29:40 +00:00
|
|
|
}
|
2015-03-06 19:46:33 +00:00
|
|
|
static int toMillis(DateTime date) {
|
|
|
|
|
return date.millisecondsSinceEpoch;
|
|
|
|
|
}
|
2015-02-23 19:44:59 +00:00
|
|
|
static DateTime now() {
|
2015-02-17 22:29:40 +00:00
|
|
|
return new DateTime.now();
|
|
|
|
|
}
|
2015-07-04 18:04:54 +00:00
|
|
|
static String toJson(DateTime date) {
|
2015-03-06 19:46:33 +00:00
|
|
|
return date.toUtc().toIso8601String();
|
|
|
|
|
}
|
2015-02-17 22:29:40 +00:00
|
|
|
}
|
2015-04-29 23:22:38 +00:00
|
|
|
|
|
|
|
|
// needed to match the exports from lang.js
|
|
|
|
|
var global = null;
|