You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
615 B

3 months ago
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Ivan Kopeykin @vankop
  4. */
  5. "use strict";
  6. const PATH_QUERY_FRAGMENT_REGEXP =
  7. /^(#?(?:\0.|[^?#\0])*)(\?(?:\0.|[^#\0])*)?(#.*)?$/;
  8. /**
  9. * @param {string} identifier identifier
  10. * @returns {[string, string, string]|null} parsed identifier
  11. */
  12. function parseIdentifier(identifier) {
  13. const match = PATH_QUERY_FRAGMENT_REGEXP.exec(identifier);
  14. if (!match) return null;
  15. return [
  16. match[1].replace(/\0(.)/g, "$1"),
  17. match[2] ? match[2].replace(/\0(.)/g, "$1") : "",
  18. match[3] || ""
  19. ];
  20. }
  21. module.exports.parseIdentifier = parseIdentifier;