dehydrate.js 1.2 KB

1234567891011121314151617181920212223242526
  1. /**
  2. * Module dependencies
  3. */
  4. var rebuildSanitized = require('./helpers/sanitize');
  5. /**
  6. * Dehydrate/sanitize a value recursively:
  7. * • stringifying functions, dates, regexps, and errors, as well
  8. * • taking care of circular references
  9. * • normalizing -Infinity, Infinity, and NaN (to 0)
  10. * • stripping undefined (and potentially null) keys and values. If `allowNull` is set, `null` values will not be stripped from the encoded string.
  11. *
  12. * @param {===} value
  13. * @param {Boolean} allowNull [defaults to false]
  14. * @param {Boolean} dontStringifyFunctions [defaults to false]
  15. * @param {Boolean} allowNaNAndFriends [defaults to false]
  16. * @param {Boolean} doRunToJSONMethods [defaults to false]
  17. * ^^^^^^^^^^^^^^^^^^
  18. * (only applies to certain things -- see https://trello.com/c/5SkpUlhI/402-make-customtojson-work-with-actions2#comment-5a3b6e7b43107b7a2938e7bd)
  19. * @return {String}
  20. */
  21. module.exports = function dehydrate (value, allowNull, dontStringifyFunctions, allowNaNAndFriends, doRunToJSONMethods) {
  22. return rebuildSanitized(value, allowNull, dontStringifyFunctions, allowNaNAndFriends, doRunToJSONMethods);
  23. };