identifier.js 615 B

123456789101112131415161718192021222324252627
  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;