util.js 792 B

123456789101112131415161718192021222324252627282930313233
  1. exports.instanceOf = function (value, constructorName) {
  2. return Object.prototype.toString.apply(value) === '[object ' + constructorName + ']'
  3. }
  4. exports.elm = function (id) {
  5. return document.getElementById(id)
  6. }
  7. exports.generateId = function (prefix) {
  8. return prefix + Math.floor(Math.random() * 10000)
  9. }
  10. exports.isUndefined = function (value) {
  11. return typeof value === 'undefined'
  12. }
  13. exports.isDefined = function (value) {
  14. return !exports.isUndefined(value)
  15. }
  16. exports.parseQueryParams = function (locationSearch) {
  17. var params = {}
  18. var pairs = locationSearch.substr(1).split('&')
  19. var keyValue
  20. for (var i = 0; i < pairs.length; i++) {
  21. keyValue = pairs[i].split('=')
  22. params[decodeURIComponent(keyValue[0])] = decodeURIComponent(keyValue[1])
  23. }
  24. return params
  25. }