UNPKG

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