Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pure-upload

Package Overview
Dependencies
Maintainers
2
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pure-upload - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

87

index.js

@@ -52,4 +52,12 @@ function castFiles(fileList, status) {

this.uploadCore = exports.getUploadCore(this.options, this.uploader.queue.callbacks);
this.setFullOptions(options);
this.setupHiddenInput();
}
UploadArea.prototype.setFullOptions = function (options) {
this.options.maxFileSize = options.maxFileSize || 1024;
this.options.allowDragDrop = options.allowDragDrop == undefined ? true : options.allowDragDrop;
this.options.clickable = options.clickable == undefined ? true : options.clickable;
this.options.accept = options.accept || '*';
this.options.multiple = options.multiple == undefined ? true : options.multiple;
};
UploadArea.prototype.putFilesToQueue = function (fileList) {

@@ -59,2 +67,3 @@ var _this = this;

uploadFiles.forEach(function (file) {
file.progress = 0;
file.start = function () {

@@ -67,2 +76,13 @@ _this.uploadCore.upload([file]);

};
UploadArea.prototype.putFileToQueue = function (file) {
var _this = this;
var uploadFile;
uploadFile = file;
uploadFile.progress = 0;
uploadFile.start = function () {
_this.uploadCore.upload([file]);
uploadFile.start = function () { };
};
this.uploader.queue.addFiles([uploadFile]);
};
UploadArea.prototype.setupHiddenInput = function () {

@@ -72,4 +92,4 @@ var _this = this;

this.fileInput.setAttribute("type", "file");
this.fileInput.setAttribute("accept", this.options.accept);
this.fileInput.style.display = "none";
this.fileInput.accept = this.options.accept;
var onChange = function (e) { return _this.onChange(e); };

@@ -110,2 +130,3 @@ this.fileInput.addEventListener("change", onChange);

UploadArea.prototype.onDrop = function (e) {
this.stopEventPropagation(e);
if (!e.dataTransfer) {

@@ -116,6 +137,10 @@ return;

if (files.length) {
var items = e.dataTransfer.files;
this.putFilesToQueue(items);
var items = e.dataTransfer.items;
if (items && items.length && (items[0].webkitGetAsEntry != null)) {
this.addFilesFromItems(items);
}
else {
this.handleFiles(files);
}
}
this.stopEventPropagation(e);
};

@@ -126,2 +151,50 @@ UploadArea.prototype.onClick = function () {

};
UploadArea.prototype.addFilesFromItems = function (items) {
var entry;
for (var i = 0; i < items.length; i++) {
var item = items[i];
if ((item.webkitGetAsEntry) && (entry = item.webkitGetAsEntry())) {
if (entry.isFile) {
this.putFileToQueue(item.getAsFile());
}
else if (entry.isDirectory) {
this.processDirectory(entry, entry.name);
}
}
else if (item.getAsFile) {
if ((item.kind == null) || item.kind === "file") {
this.putFileToQueue(item.getAsFile());
}
}
}
};
UploadArea.prototype.processDirectory = function (directory, path) {
var dirReader = directory.createReader();
var _class = this;
var entryReader = function (entries) {
for (var i = 0; i < entries.length; i++) {
var entry = entries[i];
if (entry.isFile) {
entry.file(function (file) {
if (file.name.substring(0, 1) === '.') {
return;
}
file.fullPath = "" + path + "/" + file.name;
_class.putFileToQueue(file);
});
}
else if (entry.isDirectory) {
_class.processDirectory(entry, "" + path + "/" + entry.name);
}
}
};
return dirReader.readEntries(entryReader, function (error) {
return typeof console !== "undefined" && console !== null ? typeof console.log === "function" ? console.log(error) : void 0 : void 0;
});
};
UploadArea.prototype.handleFiles = function (files) {
for (var i = 0; i < files.length; i++) {
this.putFileToQueue(files[i]);
}
};
UploadArea.prototype.stopEventPropagation = function (e) {

@@ -132,2 +205,5 @@ e.stopPropagation();

}
else {
return e.returnValue = false;
}
};

@@ -283,3 +359,3 @@ UploadArea.prototype.destroy = function () {

Uploader.prototype.setOptions = function (options) {
this.uploaderOptions = options;
this.options = options;
};

@@ -375,3 +451,2 @@ Uploader.prototype.registerArea = function (element, options) {

exports.uploadStatus.uploaded,
exports.uploadStatus.failed,
exports.uploadStatus.canceled

@@ -378,0 +453,0 @@ ].indexOf(file.uploadStatus) >= 0; })

121

index.ts

@@ -49,8 +49,18 @@ export function castFiles(fileList: File[]| Object, status?:IUploadStatus): IUploadFile[] {

export interface FileExt extends File {
kind: string;
webkitGetAsEntry: () => File;
getAsFile: () => File;
file: (file: any) => void;
isFile: boolean;
isDirectory: boolean;
}
export interface IUploadAreaOptions extends IUploadOptions {
maxFileSize: number;
allowDragDrop: boolean;
clickable: boolean;
accept: string;
multiple: boolean;
maxFileSize?: number;
allowDragDrop?: boolean;
clickable?: boolean;
accept?: string;
multiple?: boolean;
}

@@ -128,8 +138,18 @@

this.uploadCore = getUploadCore(this.options, this.uploader.queue.callbacks);
this.setFullOptions(options);
this.setupHiddenInput();
}
private setFullOptions(options: IUploadAreaOptions): void {
this.options.maxFileSize = options.maxFileSize || 1024;
this.options.allowDragDrop = options.allowDragDrop == undefined ? true : options.allowDragDrop;
this.options.clickable = options.clickable == undefined ? true : options.clickable;
this.options.accept = options.accept || '*';
this.options.multiple = options.multiple == undefined ? true : options.multiple;
}
private putFilesToQueue(fileList: FileList): void {
var uploadFiles = castFiles(fileList);
uploadFiles.forEach((file: IUploadFile) => {
file.progress = 0;
file.start = () => {

@@ -143,7 +163,18 @@ this.uploadCore.upload([file]);

private putFileToQueue(file: File): void {
let uploadFile: IUploadFile;
uploadFile = <IUploadFile>file;
uploadFile.progress = 0;
uploadFile.start = () => {
this.uploadCore.upload([file]);
uploadFile.start = () => { };
};
this.uploader.queue.addFiles([uploadFile]);
}
private setupHiddenInput(): void {
this.fileInput = document.createElement("input");
this.fileInput.setAttribute("type", "file");
this.fileInput.setAttribute("accept", this.options.accept);
this.fileInput.style.display = "none";
this.fileInput.accept = this.options.accept;

@@ -170,15 +201,2 @@ var onChange = (e) => this.onChange(e);

this.unregisterOnDrop = () => this.targetElement.removeEventListener("drop", onDrop);
// this.targetElement.addEventListener("dragenter", (e) => {
// console.log("dragenter");
// console.log(e);
// });
// this.targetElement.addEventListener("dragstart", (e) => {
// console.log("dragstart");
// console.log(e);
// });
// this.targetElement.addEventListener("dragend", (e) => {
// console.log("dragend");
// console.log(e);
// });
}

@@ -203,2 +221,3 @@ // attach to body

private onDrop(e: DragEvent): void {
this.stopEventPropagation(e);
if (!e.dataTransfer) {

@@ -209,6 +228,9 @@ return;

if (files.length) {
var items = e.dataTransfer.files;
this.putFilesToQueue(items);
var items = e.dataTransfer.items;
if (items && items.length && ((<any>items[0]).webkitGetAsEntry != null)) {
this.addFilesFromItems(items);
} else {
this.handleFiles(files);
}
}
this.stopEventPropagation(e);
}

@@ -221,2 +243,50 @@

private addFilesFromItems(items: FileList): void {
var entry;
for (var i = 0; i < items.length; i++) {
let item: FileExt = <FileExt>items[i];
if ((item.webkitGetAsEntry) && (entry = item.webkitGetAsEntry())) {
if (entry.isFile) {
this.putFileToQueue(item.getAsFile());
} else if (entry.isDirectory) {
this.processDirectory(entry, entry.name);
}
} else if (item.getAsFile) {
if ((item.kind == null) || item.kind === "file") {
this.putFileToQueue(item.getAsFile());
}
}
}
}
private processDirectory(directory: any, path: string): void {
var dirReader = directory.createReader();
var _class = this;
var entryReader = (entries: FileExt[]) => {
for (var i = 0; i < entries.length; i++) {
var entry = entries[i];
if (entry.isFile) {
entry.file((file) => {
if (file.name.substring(0, 1) === '.') {
return;
}
file.fullPath = "" + path + "/" + file.name;
_class.putFileToQueue(file);
});
} else if (entry.isDirectory) {
_class.processDirectory(entry, "" + path + "/" + entry.name)
}
}
};
return dirReader.readEntries(entryReader, function(error) {
return typeof console !== "undefined" && console !== null ? typeof console.log === "function" ? console.log(error) : void 0 : void 0;
});
}
private handleFiles(files: FileList): void {
for (var i = 0; i < files.length; i++) {
this.putFileToQueue(files[i]);
}
}
private stopEventPropagation(e) {

@@ -226,2 +296,4 @@ e.stopPropagation();

e.preventDefault();
} else {
return e.returnValue = false;
}

@@ -392,3 +464,3 @@ }

queue: UploadQueue;
uploaderOptions: IUploadQueueOptions;
options: IUploadQueueOptions;

@@ -402,3 +474,3 @@ constructor(options: IUploadQueueOptions, callbacks: IUploadQueueCallbacks) {

setOptions(options: IUploadQueueOptions) : void {
this.uploaderOptions = options;
this.options = options;
}

@@ -511,3 +583,2 @@

uploadStatus.uploaded,
uploadStatus.failed,
uploadStatus.canceled

@@ -514,0 +585,0 @@ ].indexOf(file.uploadStatus) >= 0)

{
"name": "pure-upload",
"version": "1.0.4",
"version": "1.0.5",
"description": "The pure upload library without dependencies",

@@ -5,0 +5,0 @@ "contributors": [

@@ -7,8 +7,16 @@ declare module "pure-upload" {

export function newGuid(): string;
export interface FileExt extends File {
kind: string;
webkitGetAsEntry: () => File;
getAsFile: () => File;
file: (file: any) => void;
isFile: boolean;
isDirectory: boolean;
}
export interface IUploadAreaOptions extends IUploadOptions {
maxFileSize: number;
allowDragDrop: boolean;
clickable: boolean;
accept: string;
multiple: boolean;
maxFileSize?: number;
allowDragDrop?: boolean;
clickable?: boolean;
accept?: string;
multiple?: boolean;
}

@@ -80,3 +88,5 @@ export interface IUploadCallbacks {

constructor(targetElement: Element, options: IUploadAreaOptions, uploader: Uploader);
private setFullOptions(options);
private putFilesToQueue(fileList);
private putFileToQueue(file);
private setupHiddenInput();

@@ -87,2 +97,5 @@ private onChange(e);

private onClick();
private addFilesFromItems(items);
private processDirectory(directory, path);
private handleFiles(files);
private stopEventPropagation(e);

@@ -113,3 +126,3 @@ destroy(): void;

queue: UploadQueue;
uploaderOptions: IUploadQueueOptions;
options: IUploadQueueOptions;
constructor(options: IUploadQueueOptions, callbacks: IUploadQueueCallbacks);

@@ -116,0 +129,0 @@ setOptions(options: IUploadQueueOptions): void;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc