+ queryObject to index router
This commit is contained in:
1 parent
c23f84ad76
commit
776485d3e5
1 file changed
+26
@@ -2,6 +2,32 @@ import path from 'path';
|
|||||||
import fs from 'mz/fs';
|
import fs from 'mz/fs';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
|
|
||||||
|
export function queryObject(){
|
||||||
|
let assign = (dict, key, value) => {
|
||||||
|
dict[key] = value;
|
||||||
|
return dict;
|
||||||
|
};
|
||||||
|
let map = (v, fn) =>
|
||||||
|
value => fn(value) ? v : value;
|
||||||
|
|
||||||
|
let toTrue = map(true, i => i === 'true');
|
||||||
|
let toFalse = map(false, i => i === 'false');
|
||||||
|
const processors = [toTrue, toFalse];
|
||||||
|
|
||||||
|
return function *(next) {
|
||||||
|
let query = this.query;
|
||||||
|
this.query = Object.keys(query)
|
||||||
|
.reduce((query, key) => assign(
|
||||||
|
query,
|
||||||
|
key,
|
||||||
|
processors
|
||||||
|
.reduce((value, fn) => fn(value), query[key])
|
||||||
|
), query);
|
||||||
|
|
||||||
|
yield next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function accepts(routes, def) {
|
export function accepts(routes, def) {
|
||||||
return function *() {
|
return function *() {
|
||||||
let req = this.request;
|
let req = this.request;
|
||||||
|
|||||||
Reference in new issue
Block a user