From eaaa1309dbbc3882173e1b6cdb9ff8d1628ea986 Mon Sep 17 00:00:00 2001 From: Jan Kuri Date: Sat, 29 Apr 2017 03:26:17 +0200 Subject: [PATCH] chore(bundle): bundle for version 3 --- index.ts | 3 + ngx-uploader.ts | 1 + package.json | 2 + src/ngx-uploader/classes/index.ts | 3 - .../classes/ng-uploader-options.class.ts | 79 ------------------ .../classes/upload-rejected.class.ts | 8 -- .../classes/uploaded-file.class.ts | 80 ------------------- src/ngx-uploader/services/ngx-uploader.ts | 2 - 8 files changed, 6 insertions(+), 172 deletions(-) create mode 100644 index.ts create mode 100644 ngx-uploader.ts delete mode 100644 src/ngx-uploader/classes/index.ts delete mode 100644 src/ngx-uploader/classes/ng-uploader-options.class.ts delete mode 100644 src/ngx-uploader/classes/upload-rejected.class.ts delete mode 100644 src/ngx-uploader/classes/uploaded-file.class.ts diff --git a/index.ts b/index.ts new file mode 100644 index 00000000..f588cc36 --- /dev/null +++ b/index.ts @@ -0,0 +1,3 @@ +export * from './src/ngx-uploader/module/ngx-uploader.module'; +export * from './src/ngx-uploader/services/ngx-uploader'; +export * from './src/ngx-uploader/directives/ng-file-select'; diff --git a/ngx-uploader.ts b/ngx-uploader.ts new file mode 100644 index 00000000..ea465c2a --- /dev/null +++ b/ngx-uploader.ts @@ -0,0 +1 @@ +export * from './index'; diff --git a/package.json b/package.json index 9ddcf018..6a9662bf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,8 @@ { "name": "ngx-uploader", "version": "3.0.0", + "main": "bundles/ngx-uploader.umd.js", + "module": "index.ts", "scripts": { "start": "webpack-dev-server --env.client --env.serve --progress", "start:aot": "webpack-dev-server --env.client --env.serve --env.aot --progress", diff --git a/src/ngx-uploader/classes/index.ts b/src/ngx-uploader/classes/index.ts deleted file mode 100644 index 31f9969c..00000000 --- a/src/ngx-uploader/classes/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './ng-uploader-options.class'; -export * from './uploaded-file.class'; -export * from './upload-rejected.class'; diff --git a/src/ngx-uploader/classes/ng-uploader-options.class.ts b/src/ngx-uploader/classes/ng-uploader-options.class.ts deleted file mode 100644 index 1661bba6..00000000 --- a/src/ngx-uploader/classes/ng-uploader-options.class.ts +++ /dev/null @@ -1,79 +0,0 @@ -export interface INgUploaderOptions { - url: string; - cors?: boolean; - withCredentials?: boolean; - multiple?: boolean; - maxUploads?: number; - data?: any; - autoUpload?: boolean; - multipart?: boolean; - method?: string; - customHeaders?: any; - encodeHeaders?: boolean; - filenameHeader?: string; - authTokenPrefix?: string; - authToken?: string; - fieldName?: string; - fieldReset?: boolean; - previewUrl?: boolean; - calculateSpeed?: boolean; - filterExtensions?: boolean; - allowedExtensions?: string[]; - maxSize?: number; - plainJson?: boolean; -} - -export class NgUploaderOptions implements INgUploaderOptions { - url: string; - cors?: boolean; - withCredentials?: boolean; - multiple?: boolean; - maxUploads?: number; - data?: any; - autoUpload?: boolean; - multipart?: boolean; - method?: string; - customHeaders?: any; - encodeHeaders?: boolean; - filenameHeader?: string; - authTokenPrefix?: string; - authToken?: string; - fieldName?: string; - fieldReset?: boolean; - previewUrl?: boolean; - calculateSpeed?: boolean; - filterExtensions?: boolean; - allowedExtensions?: string[]; - maxSize?: number; - plainJson?: boolean; - - constructor(obj: INgUploaderOptions) { - function use(source: T, defaultValue: T): T { - return obj && source !== undefined ? source : defaultValue; - } - - this.url = use(obj.url, ''); - this.cors = use(obj.cors, true); - this.withCredentials = use(obj.withCredentials, false); - this.multiple = use(obj.multiple, true); - this.maxUploads = use(obj.maxUploads, 10); - this.data = use(obj.data, {}); - this.autoUpload = use(obj.autoUpload, true); - this.multipart = use(obj.multipart, true); - this.method = use(obj.method, 'POST'); - this.customHeaders = use(obj.customHeaders, {}); - this.encodeHeaders = use(obj.encodeHeaders, false); - this.filenameHeader = use(obj.filenameHeader, undefined); - this.authTokenPrefix = use(obj.authTokenPrefix, 'Bearer'); - this.authToken = use(obj.authToken, undefined); - this.fieldName = use(obj.fieldName, 'file'); - this.fieldReset = use(obj.fieldReset, true); - this.previewUrl = use(obj.previewUrl, false); - this.calculateSpeed = use(obj.calculateSpeed, true); - this.filterExtensions = use(obj.filterExtensions, false); - this.allowedExtensions = use(obj.allowedExtensions, []); - this.maxSize = use(obj.maxSize, undefined); - this.plainJson = use(obj.plainJson, false); - } - -} diff --git a/src/ngx-uploader/classes/upload-rejected.class.ts b/src/ngx-uploader/classes/upload-rejected.class.ts deleted file mode 100644 index dc40f801..00000000 --- a/src/ngx-uploader/classes/upload-rejected.class.ts +++ /dev/null @@ -1,8 +0,0 @@ -export class UploadRejected { - public static get EXTENSION_NOT_ALLOWED(): string { return 'ExtensionNotAllowed'; } - public static get MAX_SIZE_EXCEEDED(): string { return 'MaxSizeExceeded'; } - public static get MAX_UPLOADS_EXCEEDED(): string { return 'MaxUploadsExceeded'; } - - file: any; - reason: string; -} diff --git a/src/ngx-uploader/classes/uploaded-file.class.ts b/src/ngx-uploader/classes/uploaded-file.class.ts deleted file mode 100644 index af0ef817..00000000 --- a/src/ngx-uploader/classes/uploaded-file.class.ts +++ /dev/null @@ -1,80 +0,0 @@ -export class UploadedFile { - xhr: XMLHttpRequest | undefined; - id: string; - status: number; - statusText: string; - progress: Object; - originalName: string; - size: number; - response: string; - done: boolean; - error: boolean; - abort: boolean; - startTime: number; - endTime: number; - speedAverage: number; - speedAverageHumanized: string|null; - - constructor(id: string, originalName: string, size: number, xhr?: XMLHttpRequest) { - this.xhr = xhr; - this.id = id; - this.originalName = originalName; - this.size = size; - this.progress = { - loaded: 0, - total: 0, - percent: 0, - speed: 0, - speedHumanized: null - }; - this.done = false; - this.error = false; - this.abort = false; - this.startTime = new Date().getTime(); - this.endTime = 0; - this.speedAverage = 0; - this.speedAverageHumanized = null; - } - - abortUpload(){ - if (this.xhr) { - this.xhr.abort(); - } - } - - setProgress(progress: Object): void { - this.progress = progress; - } - - setError(): void { - this.error = true; - this.done = true; - } - - setAbort(): void { - this.abort = true; - this.done = true; - } - - onFinished(status: number, statusText: string, response: string): void { - this.endTime = new Date().getTime(); - this.speedAverage = this.size / (this.endTime - this.startTime) * 1000; - this.speedAverage = parseInt(this.speedAverage, 10); - this.speedAverageHumanized = this.humanizeBytes(this.speedAverage); - this.status = status; - this.statusText = statusText; - this.response = response; - this.done = true; - } - - humanizeBytes(bytes: number): string { - if (bytes === 0) { - return '0 Byte'; - } - let k = 1024; - const sizes: string[] = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB']; - let i: number = Math.floor(Math.log(bytes) / Math.log(k)); - - return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i] + '/s'; - } -} diff --git a/src/ngx-uploader/services/ngx-uploader.ts b/src/ngx-uploader/services/ngx-uploader.ts index 514d8a1e..6f01b9d2 100644 --- a/src/ngx-uploader/services/ngx-uploader.ts +++ b/src/ngx-uploader/services/ngx-uploader.ts @@ -1,6 +1,4 @@ import { EventEmitter, Injectable, Provider } from '@angular/core'; -import { NgUploaderOptions } from '../classes/ng-uploader-options.class'; -import { UploadedFile } from '../classes/uploaded-file.class'; import { Observable } from 'rxjs/Observable'; import { Subscription } from 'rxjs/Subscription'; import { Subscriber } from 'rxjs/Subscriber';