diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Angular.js | 53 | ||||
| -rw-r--r-- | src/JSON.js | 49 | 
2 files changed, 53 insertions, 49 deletions
diff --git a/src/Angular.js b/src/Angular.js index b174a54c..0f66d99c 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -727,6 +727,59 @@ function bind(self, fn) {    }  } + +function toJsonReplacer(key, value) { +  var val = value; + +  if (/^\$+/.test(key)) { +    val = undefined; +  } else if (isWindow(value)) { +    val = '$WINDOW'; +  } else if (value &&  document === value) { +    val = '$DOCUMENT'; +  } else if (isScope(value)) { +    val = '$SCOPE'; +  } + +  return val; +}; + + +/** + * @ngdoc function + * @name angular.toJson + * @function + * + * @description + * Serializes input into a JSON-formatted string. + * + * @param {Object|Array|Date|string|number} obj Input to be serialized into JSON. + * @param {boolean=} pretty If set to true, the JSON output will contain newlines and whitespace. + * @returns {string} Jsonified string representing `obj`. + */ +function toJson(obj, pretty) { +  return JSON.stringify(obj, toJsonReplacer, pretty ? '  ' : null); +} + + +/** + * @ngdoc function + * @name angular.fromJson + * @function + * + * @description + * Deserializes a JSON string. + * + * @param {string} json JSON string to deserialize. + * @returns {Object|Array|Date|string|number} Deserialized thingy. + */ +function fromJson(json) { +  return isString(json) +      ? JSON.parse(json) +      : json; +} + +  function toBoolean(value) {    if (value && value.length !== 0) {      var v = lowercase("" + value); diff --git a/src/JSON.js b/src/JSON.js deleted file mode 100644 index e6d48c86..00000000 --- a/src/JSON.js +++ /dev/null @@ -1,49 +0,0 @@ -'use strict'; - -var jsonReplacer = function(key, value) { -  var val = value; -  if (/^\$+/.test(key)) { -    val = undefined; -  } else if (isWindow(value)) { -    val = '$WINDOW'; -  } else if (value &&  document === value) { -    val = '$DOCUMENT'; -  } else if (isScope(value)) { -    val = '$SCOPE'; -  } - -  return val; -}; - -/** - * @ngdoc function - * @name angular.toJson - * @function - * - * @description - * Serializes input into a JSON-formatted string. - * - * @param {Object|Array|Date|string|number} obj Input to be serialized into JSON. - * @param {boolean=} pretty If set to true, the JSON output will contain newlines and whitespace. - * @returns {string} Jsonified string representing `obj`. - */ -function toJson(obj, pretty) { -  return JSON.stringify(obj, jsonReplacer, pretty ? '  ' : null); -} - -/** - * @ngdoc function - * @name angular.fromJson - * @function - * - * @description - * Deserializes a JSON string. - * - * @param {string} json JSON string to deserialize. - * @returns {Object|Array|Date|string|number} Deserialized thingy. - */ -function fromJson(json) { -  return isString(json) -      ? JSON.parse(json) -      : json; -}  | 
