Ein Projekt das es ermöglicht Beerpong über das Internet von zwei unabhängigen positionen aus zu spielen. Entstehung im Rahmen einer Praktikumsaufgabe im Fach Interaktion.
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.

stringify.js 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Load modules
  2. var Utils = require('./utils');
  3. // Declare internals
  4. var internals = {
  5. delimiter: '&'
  6. };
  7. internals.stringify = function (obj, prefix) {
  8. if (Utils.isBuffer(obj)) {
  9. obj = obj.toString();
  10. }
  11. else if (obj instanceof Date) {
  12. obj = obj.toISOString();
  13. }
  14. else if (obj === null) {
  15. obj = '';
  16. }
  17. if (typeof obj === 'string' ||
  18. typeof obj === 'number' ||
  19. typeof obj === 'boolean') {
  20. return [encodeURIComponent(prefix) + '=' + encodeURIComponent(obj)];
  21. }
  22. var values = [];
  23. for (var key in obj) {
  24. if (obj.hasOwnProperty(key)) {
  25. values = values.concat(internals.stringify(obj[key], prefix + '[' + key + ']'));
  26. }
  27. }
  28. return values;
  29. };
  30. module.exports = function (obj, options) {
  31. options = options || {};
  32. var delimiter = typeof options.delimiter === 'undefined' ? internals.delimiter : options.delimiter;
  33. var keys = [];
  34. for (var key in obj) {
  35. if (obj.hasOwnProperty(key)) {
  36. keys = keys.concat(internals.stringify(obj[key], key));
  37. }
  38. }
  39. return keys.join(delimiter);
  40. };