Commit 61984f01 authored by chaz's avatar chaz 👻

Use string match over regexp test/exec

parent 14dccc0f
......@@ -7,11 +7,11 @@ const ARCHIVE_URL = new URL('https://archive.org');
const DUMMY_CALLBACK_NAME = 'DUMMY';
const unwrapJsonp = (jsonp, wrapper = DUMMY_CALLBACK_NAME) => {
if (!/^[a-z0-9_]+$/i.test(wrapper))
if (!wrapper.match(/^[a-z0-9_]+$/i))
throw new Error(`Invalid jsonp wrapper '${wrapper}'`);
const unwrapRe = new RegExp(`^${wrapper}\\((.+)\\)$`);
const match = unwrapRe.exec(jsonp);
const match = jsonp.match(unwrapRe);
if (!match)
throw new Error(`Jsonp data didn't appear to be wrapped by '${wrapper}'`);
......@@ -63,7 +63,7 @@ const findEmailFromUsername = async (username) => {
const getItemsInCollection = async (collection, search = '',
{max = 0, page = 1, sort = 'createdate desc'} = {}) => {
let user;
const usernameMatch = /^@(.*)$/.exec(collection);
const usernameMatch = collection.match(/^@(.*)$/);
if (usernameMatch) user = await findEmailFromUsername(usernameMatch[1]);
const specifier = user ? `uploader:${user}` : `collection:${collection}`;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment