url.js 569 B

123456789101112131415161718192021222324252627282930
  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) {
  9. this.path = path
  10. this.originalPath = path
  11. this.type = type
  12. this.isUrl = true
  13. }
  14. /**
  15. * Detect type from the file extension in the path part of the URL.
  16. * @returns {string} detected file type or empty string
  17. */
  18. detectType () {
  19. return path.extname(new URL(this.path).pathname).slice(1)
  20. }
  21. toString () {
  22. return this.path
  23. }
  24. }
  25. module.exports = Url