提交 ca733287 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

use plain javascript for phantomjs #60

上级 8dce2d5d
......@@ -176,10 +176,10 @@ export class Contact implements Sayable {
}
log.verbose('Cotnact', 'findAll({ name: %s })', query.name)
const name = query.name
const nameFilter = query.name
if (!name) {
throw new Error('name not found')
if (!nameFilter) {
throw new Error('nameFilter not found')
}
/**
......@@ -188,10 +188,10 @@ export class Contact implements Sayable {
*/
let filterFunction: string
if (name instanceof RegExp) {
filterFunction = `c => ${name.toString()}.test(c)`
} else if (typeof name === 'string') {
filterFunction = `c => c === '${name}'`
if (nameFilter instanceof RegExp) {
filterFunction = `function (c) { return ${nameFilter.toString()}.test(c) }`
} else if (typeof nameFilter === 'string') {
filterFunction = `function (c) { return c === '${nameFilter}' }`
} else {
throw new Error('unsupport name type')
}
......
......@@ -399,18 +399,18 @@ export class Room extends EventEmitter implements Sayable {
public static async findAll(query: RoomQueryFilter): Promise<Room[]> {
log.verbose('Room', 'findAll({ topic: %s })', query.topic)
const topic = query.topic
const topicFilter = query.topic
if (!topic) {
throw new Error('topic not found')
if (!topicFilter) {
throw new Error('topicFilter not found')
}
let filterFunction: string
if (topic instanceof RegExp) {
filterFunction = `c => ${topic.toString()}.test(c)`
} else if (typeof topic === 'string') {
filterFunction = `c => c === '${topic}'`
if (topicFilter instanceof RegExp) {
filterFunction = `function (c) { return ${topicFilter.toString()}.test(c) }`
} else if (typeof topicFilter === 'string') {
filterFunction = `function (c) { return c === '${topicFilter}' }`
} else {
throw new Error('unsupport topic type')
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册