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

pure-upload

Package Overview
Dependencies
Maintainers
3
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 8.1.5 to 8.2.0

62

index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UploadStatus = exports.UploadQueue = exports.Uploader = exports.UploadCore = exports.UploadArea = exports.removeEventHandler = exports.ItemProcessor = exports.newGuid = exports.getValueOrResult = exports.getUploader = exports.getUploadCore = exports.decorateSimpleFunction = exports.castFiles = exports.isFileApi = exports.ErrorCode = exports.addEventHandler = void 0;
exports.Uploader = exports.UploadStatus = exports.UploadQueue = exports.UploadCore = exports.UploadArea = exports.removeEventHandler = exports.ItemProcessor = exports.newGuid = exports.getValueOrResult = exports.getUploader = exports.getUploadCore = exports.decorateSimpleFunction = exports.castFiles = exports.isFileApi = exports.ErrorCode = exports.addEventHandler = void 0;
function addEventHandler(el, event, handler, useCapture) {

@@ -770,32 +770,2 @@ if (el.addEventListener) {

exports.UploadCore = UploadCore;
var Uploader = /** @class */ (function () {
function Uploader(options, callbacks) {
if (options === void 0) { options = {}; }
if (callbacks === void 0) { callbacks = {}; }
this.options = options;
this.uploadAreas = [];
this.queue = new UploadQueue(options, callbacks);
}
Uploader.prototype.registerArea = function (element, options) {
var uploadArea = new UploadArea(element, options, this);
this.uploadAreas.push(uploadArea);
return uploadArea;
};
Uploader.prototype.unregisterArea = function (area) {
var areaIndex = this.uploadAreas.indexOf(area);
if (areaIndex >= 0) {
this.uploadAreas[areaIndex].destroy();
this.uploadAreas.splice(areaIndex, 1);
}
};
Object.defineProperty(Uploader.prototype, "firstUploadArea", {
get: function () {
return this.uploadAreas[0];
},
enumerable: false,
configurable: true
});
return Uploader;
}());
exports.Uploader = Uploader;
var UploadQueue = /** @class */ (function () {

@@ -978,1 +948,31 @@ function UploadQueue(options, callbacks) {

})(UploadStatus = exports.UploadStatus || (exports.UploadStatus = {}));
var Uploader = /** @class */ (function () {
function Uploader(options, callbacks) {
if (options === void 0) { options = {}; }
if (callbacks === void 0) { callbacks = {}; }
this.options = options;
this.uploadAreas = [];
this.queue = new UploadQueue(options, callbacks);
}
Uploader.prototype.registerArea = function (element, options) {
var uploadArea = new UploadArea(element, options, this);
this.uploadAreas.push(uploadArea);
return uploadArea;
};
Uploader.prototype.unregisterArea = function (area) {
var areaIndex = this.uploadAreas.indexOf(area);
if (areaIndex >= 0) {
this.uploadAreas[areaIndex].destroy();
this.uploadAreas.splice(areaIndex, 1);
}
};
Object.defineProperty(Uploader.prototype, "firstUploadArea", {
get: function () {
return this.uploadAreas[0];
},
enumerable: false,
configurable: true
});
return Uploader;
}());
exports.Uploader = Uploader;

@@ -0,1 +1,29 @@

export // See: https://wicg.github.io/entries-api
type FilesCallback = (file: File[]) => void;
interface FileSystemEntry {
readonly isDirectory: boolean;
readonly isFile: boolean;
readonly name: string;
}
interface FileSystemDirectoryEntry extends FileSystemEntry {
createReader(): FileSystemDirectoryReader;
}
interface FileSystemDirectoryReader {
readEntries(successCallback: FileSystemEntriesCallback, errorCallback?: ErrorCallback): void;
}
interface FileSystemFileEntry extends FileSystemEntry {
getAsFile(): File | null;
file(successCallback: FileCallback, errorCallback?: ErrorCallback): void;
}
interface IFileExt extends File {
fullPath: string;
kind: string;
}
export function addEventHandler(

@@ -43,3 +71,3 @@ el: Element | HTMLElement,

.filter(key => key !== "length")
.map(key => (<IFileOrObjectWithIndexer>fileList)[key]);
.map(key => (<IFileOrObjectWithIndexer>fileList)[key]!);
} else {

@@ -144,30 +172,2 @@ files = <IUploadFile[]>fileList;

export // See: https://wicg.github.io/entries-api
type FilesCallback = (file: File[]) => void;
interface FileSystemEntry {
readonly isDirectory: boolean;
readonly isFile: boolean;
readonly name: string;
}
interface FileSystemDirectoryEntry extends FileSystemEntry {
createReader(): FileSystemDirectoryReader;
}
interface FileSystemDirectoryReader {
readEntries(successCallback: FileSystemEntriesCallback, errorCallback?: ErrorCallback): void;
}
interface FileSystemFileEntry extends FileSystemEntry {
getAsFile(): File | null;
file(successCallback: FileCallback, errorCallback?: ErrorCallback): void;
}
interface IFileExt extends File {
fullPath: string;
kind: string;
}
export interface IFullUploadAreaOptions extends IUploadAreaOptions {

@@ -215,80 +215,2 @@ maxFileSize: number;

export class ItemProcessor {
errors: Error[] = [];
files: File[] = [];
private constructor() {}
static processItems(items: DataTransferItem[] | DataTransferItemList, callback?: FilesCallback): void {
const processor = new ItemProcessor();
processor.processItems(items, () => callback && callback(processor.files));
}
processItems(items: DataTransferItem[] | DataTransferItemList, callback?: () => void): void {
callback = this.callbackAfter(items.length, callback);
this.toValidItems(items).forEach((item) => this.processEntry(item.webkitGetAsEntry(), "", callback));
}
private processEntries(entries: FileSystemEntry[], path: string = "", callback?: () => void): void {
callback = this.callbackAfter(entries.length, callback);
entries.forEach((entry) => this.processEntry(entry, path, callback));
}
private processEntry(entry: FileSystemEntry | null, path: string = "", callback?: () => void): void {
if (!entry) return;
if (this.isFileSystemDirectoryEntry(entry)) this.processDirectoryEntry(entry, path, callback);
else if (this.isFileSystemFileEntry(entry)) this.processFileEntry(entry, path, callback);
else if (callback !== undefined) callback(); // this.errors.push(new Error('...'))?
}
private processDirectoryEntry(entry: FileSystemDirectoryEntry, path: string = "", callback?: () => void): void {
entry
.createReader()
.readEntries(
(entries) => this.processEntries(entries, path + "/" + entry.name, callback),
this.pushAndCallback(this.errors, callback)
);
}
private processFileEntry(entry: FileSystemFileEntry, path: string = "", callback?: () => void): void {
entry.file((file) => this.processFile(file, path, callback), this.pushAndCallback(this.errors, callback));
}
private processFile(file: File, path: string = "", callback?: () => void): void {
(file as IFileExt).fullPath = path + "/" + file.name;
this.pushAndCallback(this.files, callback)(file);
}
private callbackAfter(i: number, callback?: () => void) {
return () => (--i === 0 && callback !== undefined ? callback() : i);
}
private pushAndCallback<T>(array: T[], callback?: () => void) {
return (item: T) => {
array.push(item);
if (callback !== undefined) callback();
};
}
private toValidItems(items: DataTransferItem[] | DataTransferItemList): DataTransferItem[] {
const validItems = [];
for (let i = 0; i < items.length; ++i) {
if (items[i].webkitGetAsEntry !== undefined && items[i].webkitGetAsEntry !== null) {
validItems.push(items[i]);
}
}
return validItems;
}
private isFileSystemFileEntry(entry: FileSystemEntry | FileSystemFileEntry): entry is FileSystemFileEntry {
return entry.isFile;
}
private isFileSystemDirectoryEntry(entry: FileSystemEntry | FileSystemDirectoryEntry): entry is FileSystemDirectoryEntry {
return entry.isDirectory;
}
}
export interface IUploadAreaOptions extends IUploadOptions {

@@ -381,2 +303,80 @@ maxFileSize?: number;

export class ItemProcessor {
errors: Error[] = [];
files: File[] = [];
private constructor() {}
static processItems(items: DataTransferItem[] | DataTransferItemList, callback?: FilesCallback): void {
const processor = new ItemProcessor();
processor.processItems(items, () => callback && callback(processor.files));
}
processItems(items: DataTransferItem[] | DataTransferItemList, callback?: () => void): void {
callback = this.callbackAfter(items.length, callback);
this.toValidItems(items).forEach((item) => this.processEntry(item.webkitGetAsEntry(), "", callback));
}
private processEntries(entries: FileSystemEntry[], path: string = "", callback?: () => void): void {
callback = this.callbackAfter(entries.length, callback);
entries.forEach((entry) => this.processEntry(entry, path, callback));
}
private processEntry(entry: FileSystemEntry | null, path: string = "", callback?: () => void): void {
if (!entry) return;
if (this.isFileSystemDirectoryEntry(entry)) this.processDirectoryEntry(entry, path, callback);
else if (this.isFileSystemFileEntry(entry)) this.processFileEntry(entry, path, callback);
else if (callback !== undefined) callback(); // this.errors.push(new Error('...'))?
}
private processDirectoryEntry(entry: FileSystemDirectoryEntry, path: string = "", callback?: () => void): void {
entry
.createReader()
.readEntries(
(entries) => this.processEntries(entries, path + "/" + entry.name, callback),
this.pushAndCallback(this.errors, callback)
);
}
private processFileEntry(entry: FileSystemFileEntry, path: string = "", callback?: () => void): void {
entry.file((file) => this.processFile(file, path, callback), this.pushAndCallback(this.errors, callback));
}
private processFile(file: File, path: string = "", callback?: () => void): void {
(file as IFileExt).fullPath = path + "/" + file.name;
this.pushAndCallback(this.files, callback)(file);
}
private callbackAfter(i: number, callback?: () => void) {
return () => (--i === 0 && callback !== undefined ? callback() : i);
}
private pushAndCallback<T>(array: T[], callback?: () => void) {
return (item: T) => {
array.push(item);
if (callback !== undefined) callback();
};
}
private toValidItems(items: DataTransferItem[] | DataTransferItemList): DataTransferItem[] {
const validItems = [];
for (let i = 0; i < items.length; ++i) {
if (items[i]!.webkitGetAsEntry !== undefined && items[i]!.webkitGetAsEntry !== null) {
validItems.push(items[i]!);
}
}
return validItems;
}
private isFileSystemFileEntry(entry: FileSystemEntry | FileSystemFileEntry): entry is FileSystemFileEntry {
return entry.isFile;
}
private isFileSystemDirectoryEntry(entry: FileSystemEntry | FileSystemDirectoryEntry): entry is FileSystemDirectoryEntry {
return entry.isDirectory;
}
}
export function removeEventHandler(

@@ -713,7 +713,7 @@ el: HTMLInputElement | Element,

if (files.length) {
if (!this.options.multiple) files = [files[0]];
if (!this.options.multiple) files = [files[0]!];
let items = e.dataTransfer.items;
if (items && items.length && items[0].webkitGetAsEntry !== null) {
const itemsToProcess = this.options.multiple ? items : [items[0]];
if (items && items.length && items[0]!.webkitGetAsEntry !== null) {
const itemsToProcess = this.options.multiple ? items : [items[0]!];
ItemProcessor.processItems(itemsToProcess, (files) => this.selectFiles(files));

@@ -779,3 +779,3 @@ } else {

for (let i = 0; i < acceptedExtensions.length; i++) {
if (acceptedExtensions[i].toUpperCase().trim() === fileExtension.toUpperCase()) {
if (acceptedExtensions[i]!.toUpperCase().trim() === fileExtension.toUpperCase()) {
isFileExtensionExisted = false;

@@ -1035,32 +1035,2 @@ }

export class Uploader {
uploadAreas: UploadArea[];
queue: UploadQueue;
options: IUploadQueueOptions;
constructor(options: IUploadQueueOptions = {}, callbacks: IUploadQueueCallbacks = {}) {
this.options = options;
this.uploadAreas = [];
this.queue = new UploadQueue(options, callbacks);
}
registerArea(element: HTMLElement, options: IUploadAreaOptions): UploadArea {
const uploadArea = new UploadArea(element, options, this);
this.uploadAreas.push(uploadArea);
return uploadArea;
}
unregisterArea(area: UploadArea): void {
const areaIndex = this.uploadAreas.indexOf(area);
if (areaIndex >= 0) {
this.uploadAreas[areaIndex].destroy();
this.uploadAreas.splice(areaIndex, 1);
}
}
get firstUploadArea(): UploadArea | undefined {
return this.uploadAreas[0];
}
}
export class UploadQueue {

@@ -1294,1 +1264,31 @@ offset: IOffsetInfo = { fileCount: 0, running: false };

export class Uploader {
uploadAreas: UploadArea[];
queue: UploadQueue;
options: IUploadQueueOptions;
constructor(options: IUploadQueueOptions = {}, callbacks: IUploadQueueCallbacks = {}) {
this.options = options;
this.uploadAreas = [];
this.queue = new UploadQueue(options, callbacks);
}
registerArea(element: HTMLElement, options: IUploadAreaOptions): UploadArea {
const uploadArea = new UploadArea(element, options, this);
this.uploadAreas.push(uploadArea);
return uploadArea;
}
unregisterArea(area: UploadArea): void {
const areaIndex = this.uploadAreas.indexOf(area);
if (areaIndex >= 0) {
this.uploadAreas[areaIndex]!.destroy();
this.uploadAreas.splice(areaIndex, 1);
}
}
get firstUploadArea(): UploadArea | undefined {
return this.uploadAreas[0];
}
}
{
"name": "pure-upload",
"version": "8.1.5",
"version": "8.2.0",
"description": "The pure upload library without dependencies",

@@ -5,0 +5,0 @@ "author": {

declare module "pure-upload" {
export type FilesCallback = (file: File[]) => void;
export function addEventHandler(el: Element | HTMLElement, event: string, handler: EventListenerOrEventListenerObject, useCapture: boolean): void;

@@ -16,3 +17,2 @@ export enum ErrorCode {

export function newGuid(): string;
export type FilesCallback = (file: File[]) => void;
export interface IFullUploadAreaOptions extends IUploadAreaOptions {

@@ -49,19 +49,2 @@ maxFileSize: number;

}
export class ItemProcessor {
errors: Error[];
files: File[];
private constructor();
static processItems(items: DataTransferItem[] | DataTransferItemList, callback?: FilesCallback): void;
processItems(items: DataTransferItem[] | DataTransferItemList, callback?: () => void): void;
private processEntries;
private processEntry;
private processDirectoryEntry;
private processFileEntry;
private processFile;
private callbackAfter;
private pushAndCallback;
private toValidItems;
private isFileSystemFileEntry;
private isFileSystemDirectoryEntry;
}
export interface IUploadAreaOptions extends IUploadOptions {

@@ -146,2 +129,19 @@ maxFileSize?: number;

}
export class ItemProcessor {
errors: Error[];
files: File[];
private constructor();
static processItems(items: DataTransferItem[] | DataTransferItemList, callback?: FilesCallback): void;
processItems(items: DataTransferItem[] | DataTransferItemList, callback?: () => void): void;
private processEntries;
private processEntry;
private processDirectoryEntry;
private processFileEntry;
private processFile;
private callbackAfter;
private pushAndCallback;
private toValidItems;
private isFileSystemFileEntry;
private isFileSystemDirectoryEntry;
}
export function removeEventHandler(el: HTMLInputElement | Element, event: string, handler: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;

@@ -217,11 +217,2 @@ export class UploadArea {

}
export class Uploader {
uploadAreas: UploadArea[];
queue: UploadQueue;
options: IUploadQueueOptions;
constructor(options?: IUploadQueueOptions, callbacks?: IUploadQueueCallbacks);
registerArea(element: HTMLElement, options: IUploadAreaOptions): UploadArea;
unregisterArea(area: UploadArea): void;
get firstUploadArea(): UploadArea | undefined;
}
export class UploadQueue {

@@ -254,2 +245,11 @@ offset: IOffsetInfo;

}
export class Uploader {
uploadAreas: UploadArea[];
queue: UploadQueue;
options: IUploadQueueOptions;
constructor(options?: IUploadQueueOptions, callbacks?: IUploadQueueCallbacks);
registerArea(element: HTMLElement, options: IUploadAreaOptions): UploadArea;
unregisterArea(area: UploadArea): void;
get firstUploadArea(): UploadArea | undefined;
}
}

@@ -64,3 +64,3 @@ # Pure-upload

Upload area defines element registred in Uploader.
Upload area defines element registered in Uploader.

@@ -141,6 +141,8 @@ Registration:

File statuses accesible by `pu.uploadStatus`.
File statuses accessible by `pu.uploadStatus`.
## How to develop
Current gulp build tool requires node v16 or v17.
### Debug and watch

@@ -170,4 +172,4 @@

Library used by [Quadient](https://quadient.cz/.
Library used by [Quadient](https://quadient.cz/).
MIT, Copyright &copy; 2015 Tomáš Růt
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