/
githubmirror
/
angular.js
Обзор
Документация
Войти
/
githubmirror
/
angular.js
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
v1.7.5
src/stringify.js
37 строк
1 KB
Georgios Kalpakas
fix(angular-loader): do not depend on "closure" globals that may not be available
27 апр 2017, 22:46
27 апр 2017, 22:46
4a12ae7
Код
Авторство
О чём код?
'use strict'; /* exported toDebugString */ function serializeObject(obj, maxDepth) { var seen = []; // There is no direct way to stringify object until reaching a specific depth // and a very deep object can cause a performance issue, so we copy the object // based on this specific depth and then stringify it. if (isValidObjectMaxDepth(maxDepth)) { // This file is also included in `angular-loader`, so `copy()` might not always be available in // the closure. Therefore, it is lazily retrieved as `angular.copy()` when needed. obj = angular.copy(obj, null, maxDepth); } return JSON.stringify(obj, function(key, val) { val = toJsonReplacer(key, val); if (isObject(val)) { if (seen.indexOf(val) >= 0) return '...'; seen.push(val); } return val; }); } function toDebugString(obj, maxDepth) { if (typeof obj === 'function') { return obj.toString().replace(/ \{[\s\S]*$/, ''); } else if (isUndefined(obj)) { return 'undefined'; } else if (typeof obj !== 'string') { return serializeObject(obj, maxDepth); } return obj; }