| 1 |
"use strict"; |
| 2 |
const {default:hasToStringTag} = require("has-to-string-tag-x"); |
| 3 |
const isObject = require("is-object"); |
| 4 |
const {LENIENT_PROPERTIES, STRICT_PROPERTIES} = require("./props"); |
| 5 |
|
| 6 |
const SEARCH_PARAMS_CLASS = "[object URLSearchParams]"; |
| 7 |
|
| 8 |
const toStringTag = Object.prototype.toString; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
const isURLSearchParams = (searchParams, supportIncomplete=false) => |
| 13 |
{ |
| 14 |
if (!isObject(searchParams)) |
| 15 |
{ |
| 16 |
return false; |
| 17 |
} |
| 18 |
else if (hasToStringTag && toStringTag.call(searchParams)!==SEARCH_PARAMS_CLASS) |
| 19 |
{ |
| 20 |
// Shimmed implementation with incorrect constructor name |
| 21 |
return false; |
| 22 |
} |
| 23 |
else if (!STRICT_PROPERTIES.every(prop => prop in searchParams)) |
| 24 |
{ |
| 25 |
return false; |
| 26 |
} |
| 27 |
else if (supportIncomplete) |
| 28 |
{ |
| 29 |
return true; |
| 30 |
} |
| 31 |
else |
| 32 |
{ |
| 33 |
return LENIENT_PROPERTIES.every(prop => prop in searchParams); |
| 34 |
} |
| 35 |
}; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
isURLSearchParams.lenient = searchParams => isURLSearchParams(searchParams, true); |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
module.exports = Object.freeze(isURLSearchParams); |