url.js 611 B

12345678910111213141516171819202122232425262728293031
  1. 'use strict'
  2. const path = require('path')
  3. const { URL } = require('url')
  4. /**
  5. * Url object used for tracking files in `file-list.js`.
  6. */
  7. class Url {
  8. constructor (path, type, integrity) {
  9. this.path = path
  10. this.originalPath = path
  11. this.type = type
  12. this.integrity = integrity
  13. this.isUrl = true
  14. }
  15. /**
  16. * Detect type from the file extension in the path part of the URL.
  17. * @returns {string} detected file type or empty string
  18. */
  19. detectType () {
  20. return path.extname(new URL(this.path).pathname).slice(1)
  21. }
  22. toString () {
  23. return this.path
  24. }
  25. }
  26. module.exports = Url