"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var isNum_1 = __importDefault(require("../number/isNum"));
var fromQueryString_1 = __importDefault(require("../network/fromQueryString"));
var getSearchParams_1 = __importDefault(require("./getSearchParams"));
/**
* Get single query parameter from location
*
* @param location
* @param key
* @param defaultValue
* @param isNumberExpected
* @param shouldFallbackWithWindow
* @category routing
* @module getSearchParam
*/
function getSearchParam(location, key, defaultValue, _a) {
if (location === void 0) { location = window.location; }
var _b = _a === void 0 ? {} : _a, isNumberExpected = _b.isNumberExpected, _c = _b.shouldFallbackWithWindow, shouldFallbackWithWindow = _c === void 0 ? true : _c;
var search = (0, getSearchParams_1.default)(location, shouldFallbackWithWindow);
if (search === null)
return defaultValue;
var _d = (0, fromQueryString_1.default)(search), _e = key, value = _d[_e];
if (isNumberExpected) {
// To ensure return number string
// If the value of searchObj[key] is number followed by any string
return ((0, isNum_1.default)(value, true) ? parseInt(value) : defaultValue);
}
return value;
}
exports.default = getSearchParam;
Source