util.js 678 B

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. require("../common/vendor.js");
  3. const urlEncode = (obj = {}) => {
  4. const result = [];
  5. for (const key in obj) {
  6. const item = obj[key];
  7. if (!item) {
  8. continue;
  9. }
  10. if (isArray(item)) {
  11. item.forEach((val) => {
  12. result.push(key + "=" + val);
  13. });
  14. } else {
  15. result.push(key + "=" + item);
  16. }
  17. }
  18. return result.join("&");
  19. };
  20. const inArray = (search, array) => {
  21. for (var i in array) {
  22. if (array[i] == search)
  23. return true;
  24. }
  25. return false;
  26. };
  27. const isArray = (array) => {
  28. return Object.prototype.toString.call(array) === "[object Array]";
  29. };
  30. exports.inArray = inArray;
  31. exports.urlEncode = urlEncode;