diff --git a/client/dom/events/index.js b/client/dom/events/index.js index 195987da..85c24a3d 100644 --- a/client/dom/events/index.js +++ b/client/dom/events/index.js @@ -32,7 +32,7 @@ function EventsProto() { switch(type) { default: - if (!/element$/.test(type)) + if (!type.endsWith('element')) throw Error('unknown eventName: ' + type); parseArgs( diff --git a/client/dom/files.js b/client/dom/files.js index dce0ac39..6d9627d4 100644 --- a/client/dom/files.js +++ b/client/dom/files.js @@ -36,8 +36,8 @@ function check(name) { } function getModule(name) { - const regExpHTML = new RegExp(FILES_HTML + '|' + FILES_HTML_ROOT); - const regExpJSON = new RegExp(FILES_JSON); + const regExpHTML = RegExp(FILES_HTML + '|' + FILES_HTML_ROOT); + const regExpJSON = RegExp(FILES_JSON); const isHTML = regExpHTML.test(name); const isJSON = regExpJSON.test(name); @@ -54,7 +54,7 @@ function getModule(name) { function getPath(name, isHTML, isJSON) { let path; - const regExp = new RegExp(FILES_HTML_ROOT); + const regExp = RegExp(FILES_HTML_ROOT); const isRoot = regExp.test(name); if (isHTML) { diff --git a/client/modules/user-menu/parse-user-menu.js b/client/modules/user-menu/parse-user-menu.js index 78ce016f..d4013405 100644 --- a/client/modules/user-menu/parse-user-menu.js +++ b/client/modules/user-menu/parse-user-menu.js @@ -14,7 +14,7 @@ module.exports = (userMenu) => { continue; } - if (/^_/.test(str)) { + if (str.startsWith('_')) { continue; } diff --git a/client/sw/sw.js b/client/sw/sw.js index 3c849bd8..ff9a23fe 100644 --- a/client/sw/sw.js +++ b/client/sw/sw.js @@ -15,7 +15,7 @@ const respondWith = currify((f, e) => { const {url} = request; const pathname = getPathName(url); - if (/\/$/.test(url) || /\^\/fs/.test(pathname)) + if (url.endsWith('/') || /\^\/fs/.test(pathname)) return; if (!isGet(request)) @@ -24,7 +24,7 @@ const respondWith = currify((f, e) => { if (!isBasic(request)) return; - if (/^\/api/.test(pathname)) + if (pathname.startsWith('/api')) return; if (/^socket.io/.test(pathname)) diff --git a/server/markdown/index.spec.js b/server/markdown/index.spec.js index d6e9c338..bc736bef 100644 --- a/server/markdown/index.spec.js +++ b/server/markdown/index.spec.js @@ -27,14 +27,14 @@ const {request} = require('serve-once')(cloudcmd, { test('cloudcmd: markdown: error', async (t) => { const {body} = await request.get('/api/v1/markdown/not-found'); - t.ok(/ENOENT/.test(body), 'should not found'); + t.match(body, 'ENOENT', 'should not found'); t.end(); }); test('cloudcmd: markdown: relative: error', async (t) => { const {body} = await request.get('/api/v1/markdown/not-found?relative'); - t.ok(/ENOENT/.test(body), 'should not found'); + t.match(body, 'ENOENT', 'should not found'); t.end(); }); diff --git a/server/rest/index.js b/server/rest/index.js index cbd65d44..b3989191 100644 --- a/server/rest/index.js +++ b/server/rest/index.js @@ -87,7 +87,7 @@ function rest(config, request, response) { */ function sendData(params, config, callback) { const p = params; - const isMD = /^\/markdown/.test(p.name); + const isMD = p.name.startsWith('/markdown'); const rootDir = config('root'); if (isMD) @@ -122,7 +122,7 @@ function onGET(params, config, callback) { if (p.name[0] === '/') cmd = p.name.replace('/', ''); - if (/^pack/.test(cmd)) { + if (cmd.startsWith('pack')) { cmd = cmd.replace(/^pack/, ''); streamPack(root(cmd, rootDir), p.response, packer); return; diff --git a/test/rest/pack.js b/test/rest/pack.js index aff32c61..8ad25b7a 100644 --- a/test/rest/pack.js +++ b/test/rest/pack.js @@ -137,7 +137,7 @@ test('cloudcmd: rest: pack: tar: put: error', async (t) => { ]), }); - t.ok(/^ENOENT: no such file or directory/.test(body), 'should return error'); + t.match(body, /^ENOENT: no such file or directory/, 'should return error'); t.end(); }); @@ -219,7 +219,7 @@ test('cloudcmd: rest: pack: zip: put: error', async (t) => { ]), }); - t.ok(/^ENOENT: no such file or directory/.test(body), 'should return error'); + t.match(body, /^ENOENT: no such file or directory/, 'should return error'); t.end(); });