@vergiss/chooks
Version:
React hooks library
92 lines (71 loc) • 1.79 kB
JavaScript
;
import "core-js/modules/es.array.for-each";
import "core-js/modules/es.object.define-property";
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";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.sleep = exports.debounce = exports.parseJson = exports.getUrlParams = void 0;
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;
}
exports.getUrlParams = getUrlParams;
function parseJson(str, emptyValueType) {
try {
return JSON.parse(str);
} catch (e) {
if (!emptyValueType || emptyValueType === 'object') {
return {};
}
return '';
}
}
exports.parseJson = parseJson;
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);
};
}
exports.debounce = debounce;
function sleep(delay) {
return new Promise(function (r) {
setTimeout(r, delay);
});
}
exports.sleep = sleep;