Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

iterable-to-string.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. "use strict";
  2. var slice = require("@sinonjs/commons").prototypes.string.slice;
  3. var typeOf = require("@sinonjs/commons").typeOf;
  4. var valueToString = require("@sinonjs/commons").valueToString;
  5. /**
  6. * Creates a string represenation of an iterable object
  7. *
  8. * @private
  9. * @param {object} obj The iterable object to stringify
  10. * @returns {string} A string representation
  11. */
  12. function iterableToString(obj) {
  13. if (typeOf(obj) === "map") {
  14. return mapToString(obj);
  15. }
  16. return genericIterableToString(obj);
  17. }
  18. /**
  19. * Creates a string representation of a Map
  20. *
  21. * @private
  22. * @param {Map} map The map to stringify
  23. * @returns {string} A string representation
  24. */
  25. function mapToString(map) {
  26. var representation = "";
  27. // eslint-disable-next-line @sinonjs/no-prototype-methods/no-prototype-methods
  28. map.forEach(function (value, key) {
  29. representation += `[${stringify(key)},${stringify(value)}],`;
  30. });
  31. representation = slice(representation, 0, -1);
  32. return representation;
  33. }
  34. /**
  35. * Create a string represenation for an iterable
  36. *
  37. * @private
  38. * @param {object} iterable The iterable to stringify
  39. * @returns {string} A string representation
  40. */
  41. function genericIterableToString(iterable) {
  42. var representation = "";
  43. // eslint-disable-next-line @sinonjs/no-prototype-methods/no-prototype-methods
  44. iterable.forEach(function (value) {
  45. representation += `${stringify(value)},`;
  46. });
  47. representation = slice(representation, 0, -1);
  48. return representation;
  49. }
  50. /**
  51. * Creates a string representation of the passed `item`
  52. *
  53. * @private
  54. * @param {object} item The item to stringify
  55. * @returns {string} A string representation of `item`
  56. */
  57. function stringify(item) {
  58. return typeof item === "string" ? `'${item}'` : valueToString(item);
  59. }
  60. module.exports = iterableToString;