MCPcopy
hub / github.com/thinkjs/thinkjs / param

Function param

lib/extend/context.js:167–196  ·  view source on GitHub ↗

* get or set query data * `query` or `get` is already used in koa * @param {String} name * @param {Mixed} value

(name, value)

Source from the content-addressed store, hash-verified

165 * @param {Mixed} value
166 */
167 param(name, value) {
168 if (!this[PARAM]) {
169 this[PARAM] = Object.assign({}, this.request._query || this.request.query);
170 this.app.emit('filterParam', this[PARAM]);
171 }
172 if (!name) return this[PARAM];
173 if (helper.isObject(name)) {
174 this[PARAM] = Object.assign(this[PARAM], name);
175 return this;
176 }
177 if (value === undefined) {
178 // this.param('a,b')
179 if (helper.isString(name) && name.indexOf(',') > -1) {
180 name = name.split(/\s*,\s*/);
181 }
182 if (helper.isArray(name)) {
183 const value = {};
184 name.forEach(item => {
185 const val = this[PARAM][item];
186 if (val !== undefined) {
187 value[item] = val;
188 }
189 });
190 return value;
191 }
192 return this[PARAM][name];
193 }
194 this[PARAM][name] = value;
195 return this;
196 },
197 /**
198 * get or set post data
199 * @param {String} name

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected