Updates
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// @ts-check
|
||||
|
||||
const EJSON = require("./ejson");
|
||||
/**
|
||||
*
|
||||
* @param {string | Object<string,any>} query
|
||||
* @returns {Object<string,any>}
|
||||
*/
|
||||
function deserializeQuery(query) {
|
||||
/** @type {Object<string,any>} */
|
||||
let queryObject =
|
||||
typeof query == "object" ? query : Object(EJSON.parse(query));
|
||||
|
||||
const keys = Object.keys(queryObject);
|
||||
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const key = keys[i];
|
||||
const value = queryObject[key];
|
||||
|
||||
if (typeof value == "string") {
|
||||
if (value.match(/^\{|^\[/)) {
|
||||
queryObject[key] = EJSON.parse(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return queryObject;
|
||||
}
|
||||
|
||||
module.exports = deserializeQuery;
|
||||
Reference in New Issue
Block a user