This repository has been archived by the owner on Jul 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlib.js
70 lines (61 loc) · 1.47 KB
/
lib.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// @ts-check
"use strict"
import { Blob } from "./package.js"
const WebFile = class File extends Blob {
/**
*
* @param {BlobPart[]} init
* @param {string} name - A USVString representing the file name or the path
* to the file.
* @param {FilePropertyBag} [options]
*/
constructor(
init,
name = panic(new TypeError("File constructor requires name argument")),
options = {}
) {
super(init, options)
// Per File API spec https://w3c.github.io/FileAPI/#file-constructor
// Every "/" character of file name must be replaced with a ":".
/** @private */
this._name = String(name).replace(/\//g, ":")
/** @private */
this._lastModified = options.lastModified || Date.now()
}
/**
* The name of the file referenced by the File object.
* @type {string}
*/
get name() {
return this._name
}
/**
* The path the URL of the File is relative to.
* @type {string}
*/
get webkitRelativePath() {
return ""
}
/**
* Returns the last modified time of the file, in millisecond since the UNIX
* epoch (January 1st, 1970 at Midnight).
* @returns {number}
*/
get lastModified() {
return this._lastModified
}
get [Symbol.toStringTag]() {
return "File"
}
}
/**
* @param {*} error
* @returns {never}
*/
const panic = (error) => {
throw error
}
// Marking export as a DOM File object instead of custom class.
/** @type {typeof window.File} */
const File = WebFile
export { File, Blob }