Source

routing/getSearchParams.js

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var isObj_1 = __importDefault(require("../object/isObj"));
/**
 * Get query string from location
 *
 * @param location
 * @param useWindowLocationAsFallback
 * @category routing
 * @module getSearchParams
 */
var getSearchParams = function (location, 
/**
  Since argument 'location' can be string pathname,
  it might not necessarily contains search parameters.
  If this argument equals true,
  That means window.location.search will be used
  as the last fallback of deriving search parameters.
  Default to true.
 */
shouldFallbackWithWindow) {
    if (location === void 0) { location = window.location; }
    if (shouldFallbackWithWindow === void 0) { shouldFallbackWithWindow = true; }
    // Return search from location object
    if ((0, isObj_1.default)(location))
        return location.search || null;
    // Return search from location string
    var search = location.split('?')[0];
    if (search)
        return search || null;
    // Return search from window.location object
    if (shouldFallbackWithWindow)
        return window.location.search || null;
    // Return null
    return null;
};
exports.default = getSearchParams;