extractUrlAndGlobal.js 570 B

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