|
- import NodeBlob from 'node-blob'
- import isBrowser from './isBrowser'
-
- interface NodeFileConfig {
- type: string
- lastModified?: number
- }
-
- class File extends NodeBlob {
- public readonly name: string
- public readonly lastModified: number
- constructor(blobParts: unknown[], name: string, config: Partial<NodeFileConfig>) {
- super(blobParts, config)
- this.name = name
-
- switch (typeof config.lastModified!) {
- case 'number':
- if (isNaN(config.lastModified as number)) {
- break
- }
- this.lastModified = Math.floor(config.lastModified as number)
- return
- case 'object':
- // force native Date objects only!
- if (((config.lastModified as unknown) as Record<string, unknown>).constructor.name !== 'Date') {
- break
- }
- const tryDate = new Date(config.lastModified!).getTime()
- if (isNaN(tryDate)) {
- break
- }
- this.lastModified = tryDate
- return
- default:
- break
- }
- this.lastModified = 0
- }
- }
-
- export default isBrowser() ? window.File : File
|