UNPKG

531 BJavaScriptView Raw
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Sam Chen @chenxsan
4*/
5
6"use strict";
7
8/**
9 * @param {string} urlAndGlobal the script request
10 * @returns {string[]} script url and its global variable
11 */
12module.exports = function extractUrlAndGlobal(urlAndGlobal) {
13 const index = urlAndGlobal.indexOf("@");
14 if (index <= 0 || index === urlAndGlobal.length - 1) {
15 throw new Error(`Invalid request "${urlAndGlobal}"`);
16 }
17 return [urlAndGlobal.substring(index + 1), urlAndGlobal.substring(0, index)];
18};