UNPKG

@vergiss/chooks

Version:
79 lines (62 loc) 1.51 kB
import "core-js/modules/es.array.for-each"; import "core-js/modules/es.object.to-string"; import "core-js/modules/es.promise"; import "core-js/modules/es.regexp.exec"; import "core-js/modules/es.string.split"; import "core-js/modules/web.dom-collections.for-each"; import "core-js/modules/web.timers"; function getUrlParams(name, location) { if (location === void 0) { location = window.location.href; } if (!location) { return null; } var query = location.split('?')[1]; if (!query) { return null; } var params = {}; query.split('&').forEach(function (pair) { var _a = pair.split('='), name = _a[0], val = _a[1]; params[name] = val; }); if (name) { return params[name]; } return params; } function parseJson(str, emptyValueType) { try { return JSON.parse(str); } catch (e) { if (!emptyValueType || emptyValueType === 'object') { return {}; } return ''; } } function debounce(fn, delay, thisValue) { var timer; return function debouncedFunction() { var _this = this; var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } if (timer) { window.clearTimeout(timer); } timer = window.setTimeout(function () { fn.apply(thisValue || _this, args); }, delay); }; } function sleep(delay) { return new Promise(function (r) { setTimeout(r, delay); }); } export { getUrlParams, parseJson, debounce, sleep };