版博士V2.0程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

94 řádky
2.3 KiB

  1. /**
  2. * The `Show` type class represents those types which can be converted into
  3. * a human-readable `string` representation.
  4. *
  5. * While not required, it is recommended that for any expression `x`, the
  6. * string `show(x)` be executable TypeScript code which evaluates to the same
  7. * value as the expression `x`.
  8. *
  9. * @since 2.0.0
  10. */
  11. import * as _ from './internal';
  12. // -------------------------------------------------------------------------------------
  13. // combinators
  14. // -------------------------------------------------------------------------------------
  15. /**
  16. * @since 2.10.0
  17. */
  18. export var struct = function (shows) { return ({
  19. show: function (a) {
  20. var s = '{';
  21. for (var k in shows) {
  22. if (_.has.call(shows, k)) {
  23. s += " ".concat(k, ": ").concat(shows[k].show(a[k]), ",");
  24. }
  25. }
  26. if (s.length > 1) {
  27. s = s.slice(0, -1) + ' ';
  28. }
  29. s += '}';
  30. return s;
  31. }
  32. }); };
  33. /**
  34. * @since 2.10.0
  35. */
  36. export var tuple = function () {
  37. var shows = [];
  38. for (var _i = 0; _i < arguments.length; _i++) {
  39. shows[_i] = arguments[_i];
  40. }
  41. return ({
  42. show: function (t) { return "[".concat(t.map(function (a, i) { return shows[i].show(a); }).join(', '), "]"); }
  43. });
  44. };
  45. // -------------------------------------------------------------------------------------
  46. // deprecated
  47. // -------------------------------------------------------------------------------------
  48. /**
  49. * Use [`tuple`](#tuple) instead.
  50. *
  51. * @category zone of death
  52. * @since 2.0.0
  53. * @deprecated
  54. */
  55. export var getTupleShow = tuple;
  56. /**
  57. * Use [`struct`](#struct) instead.
  58. *
  59. * @category zone of death
  60. * @since 2.0.0
  61. * @deprecated
  62. */
  63. export var getStructShow = struct;
  64. /**
  65. * Use [`Show`](./boolean.ts.html#show) instead.
  66. *
  67. * @category zone of death
  68. * @since 2.0.0
  69. * @deprecated
  70. */
  71. export var showBoolean = {
  72. show: function (a) { return JSON.stringify(a); }
  73. };
  74. /**
  75. * Use [`Show`](./string.ts.html#show) instead.
  76. *
  77. * @category zone of death
  78. * @since 2.0.0
  79. * @deprecated
  80. */
  81. export var showString = {
  82. show: function (a) { return JSON.stringify(a); }
  83. };
  84. /**
  85. * Use [`Show`](./number.ts.html#show) instead.
  86. *
  87. * @category zone of death
  88. * @since 2.0.0
  89. * @deprecated
  90. */
  91. export var showNumber = {
  92. show: function (a) { return JSON.stringify(a); }
  93. };