identifier.js 614 B

1234567891011121314151617181920212223242526
  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 = /^(#?(?:\0.|[^?#\0])*)(\?(?:\0.|[^#\0])*)?(#.*)?$/;
  7. /**
  8. * @param {string} identifier identifier
  9. * @returns {[string, string, string]|null} parsed identifier
  10. */
  11. function parseIdentifier(identifier) {
  12. const match = PATH_QUERY_FRAGMENT_REGEXP.exec(identifier);
  13. if (!match) return null;
  14. return [
  15. match[1].replace(/\0(.)/g, "$1"),
  16. match[2] ? match[2].replace(/\0(.)/g, "$1") : "",
  17. match[3] || ""
  18. ];
  19. }
  20. module.exports.parseIdentifier = parseIdentifier;