@qubejs/cms
Advanced tools
Comparing version 0.5.0-beta.9 to 0.5.0-beta.10
{ | ||
"name": "@qubejs/core", | ||
"version": "0.5.0-beta.9", | ||
"version": "0.5.0-beta.10", | ||
"main": "./src/index.js", | ||
"type": "commonjs" | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const common_1 = tslib_1.__importDefault(require("./common")); | ||
class QueryString { | ||
@@ -13,4 +15,14 @@ constructor(params = {}) { | ||
Object.keys(this.input).forEach((key) => { | ||
if (this.input[key]) { | ||
if (Array.isArray(this.input[key])) { | ||
this.input[key].forEach((itemVal) => { | ||
str += | ||
(str ? '&' : '') + key + '=' + encodeURIComponent(itemVal); | ||
}); | ||
} | ||
else if (typeof this.input[key] === 'object' && this.input[key] !== null) { | ||
str += | ||
(str ? '&' : '') + key + '=' + encodeURIComponent('o:' + JSON.stringify(this.input[key])); | ||
} | ||
else if (!common_1.default.isNullOrUndefinedBlank(this.input[key])) { | ||
str += | ||
(str ? '&' : '') + key + '=' + encodeURIComponent(this.input[key]); | ||
@@ -25,6 +37,20 @@ } | ||
if (this.isString) { | ||
const runInput = this.input.substr(this.input.indexOf('?')) ? this.input.substr(this.input.indexOf('?') + 1) : ''; | ||
const runInput = this.input.substr(this.input.indexOf('?') + 1); | ||
runInput.split('&').forEach((keyValue) => { | ||
const split = keyValue.split('='); | ||
obj[split[0]] = decodeURIComponent(split[1]); | ||
const actualVal = decodeURIComponent(split[1]); | ||
if (actualVal.substr(0, 2) === 'o:') { | ||
obj[split[0]] = JSON.parse(decodeURIComponent(actualVal.substr(2))); | ||
} | ||
else { | ||
if (Array.isArray(obj[split[0]])) { | ||
obj[split[0]].push(decodeURIComponent(split[1])); | ||
} | ||
else if (obj[split[0]]) { | ||
obj[split[0]] = [obj[split[0]], decodeURIComponent(split[1])]; | ||
} | ||
else { | ||
obj[split[0]] = decodeURIComponent(split[1]); | ||
} | ||
} | ||
}); | ||
@@ -36,1 +62,29 @@ } | ||
exports.default = QueryString; | ||
// class QueryString { | ||
// constructor(params) { | ||
// this.input = params; | ||
// this.isString = !!params && typeof params === 'string'; | ||
// this.isObject = !!params && typeof params === 'object'; | ||
// } | ||
// toObject() { | ||
// var obj = {}; | ||
// if (this.isString) { | ||
// const runInput = this.input.substr(this.input.indexOf('?') + 1); | ||
// runInput.split('&').forEach((keyValue) => { | ||
// const split = keyValue.split('='); | ||
// if (split[1].substr(0,2) === 'o:') { | ||
// obj[split[0]] = JSON.parse(decodeURIComponent(split[1].substr(2))); | ||
// } else { | ||
// if (Array.isArray(obj[split[0]])) { | ||
// obj[split[0]].push(decodeURIComponent(split[1])) | ||
// } else if (obj[split[0]]) { | ||
// obj[split[0]] = [obj[split[0]], decodeURIComponent(split[1])]; | ||
// } else { | ||
// obj[split[0]] = decodeURIComponent(split[1]); | ||
// } | ||
// } | ||
// }); | ||
// } | ||
// return obj; | ||
// } | ||
// } |
{ | ||
"name": "@qubejs/cms", | ||
"version": "0.5.0-beta.9", | ||
"version": "0.5.0-beta.10", | ||
"dependencies": { | ||
@@ -5,0 +5,0 @@ "tslib": "^2.3.0" |
10707392
115859