LoggerSerializers.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* eslint-disable
  2. no-return-assign,
  3. */
  4. // TODO: This file was created by bulk-decaffeinate.
  5. // Fix any style issues and re-enable lint.
  6. /*
  7. * decaffeinate suggestions:
  8. * DS102: Remove unnecessary code created because of implicit returns
  9. * DS103: Rewrite code to no longer use __guard__
  10. * DS207: Consider shorter variations of null checks
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. const _ = require('lodash')
  14. const showLength = function (thing) {
  15. if (thing != null ? thing.length : undefined) {
  16. return thing.length
  17. } else {
  18. return thing
  19. }
  20. }
  21. const showUpdateLength = function (update) {
  22. if ((update != null ? update.op : undefined) instanceof Array) {
  23. const copy = _.cloneDeep(update)
  24. copy.op.forEach(function (element, index) {
  25. if (
  26. __guard__(element != null ? element.i : undefined, x => x.length) !=
  27. null
  28. ) {
  29. copy.op[index].i = element.i.length
  30. }
  31. if (
  32. __guard__(element != null ? element.d : undefined, x1 => x1.length) !=
  33. null
  34. ) {
  35. copy.op[index].d = element.d.length
  36. }
  37. if (
  38. __guard__(element != null ? element.c : undefined, x2 => x2.length) !=
  39. null
  40. ) {
  41. return (copy.op[index].c = element.c.length)
  42. }
  43. })
  44. return copy
  45. } else {
  46. return update
  47. }
  48. }
  49. module.exports = {
  50. // replace long values with their length
  51. lines: showLength,
  52. oldLines: showLength,
  53. newLines: showLength,
  54. docLines: showLength,
  55. newDocLines: showLength,
  56. ranges: showLength,
  57. update: showUpdateLength,
  58. }
  59. function __guard__(value, transform) {
  60. return typeof value !== 'undefined' && value !== null
  61. ? transform(value)
  62. : undefined
  63. }