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

@uppy/utils

Package Overview
Dependencies
Maintainers
6
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uppy/utils - npm Package Compare versions

Comparing version 5.5.2 to 5.6.0

lib/FileProgress.js

7

CHANGELOG.md
# @uppy/utils
## 5.6.0
Released: 2023-11-08
Included in: Uppy v3.19.0
- @uppy/utils: refactor to TS (Antoine du Hamel / #4699)
## 5.5.1

@@ -4,0 +11,0 @@

3

lib/AbortController.js

@@ -1,2 +0,2 @@

import hasOwnProperty from './hasProperty.js';
import hasOwnProperty from "./hasProperty.js";
/**

@@ -18,2 +18,3 @@ * Little AbortController proxy module so we can swap out the implementation easily later.

Object.defineProperty(err, 'cause', {
// @ts-expect-error TS is drunk
__proto__: null,

@@ -20,0 +21,0 @@ configurable: true,

@@ -9,4 +9,4 @@ const DATA_URL_PATTERN = /^data:([^/]+\/[^,;]+(?:[^,]*?))(;base64)?,([\s\S]*)$/;

const mimeType = (_ref = (_opts$mimeType = opts.mimeType) != null ? _opts$mimeType : dataURIData == null ? void 0 : dataURIData[1]) != null ? _ref : 'plain/text';
let data;
if (dataURIData[2] != null) {
let data; // We add `!` to tell TS we're OK with `data` being not defined when the dataURI is invalid.
if ((dataURIData == null ? void 0 : dataURIData[2]) != null) {
const binary = atob(decodeURIComponent(dataURIData[3]));

@@ -18,3 +18,3 @@ const bytes = new Uint8Array(binary.length);

data = [bytes];
} else {
} else if ((dataURIData == null ? void 0 : dataURIData[3]) != null) {
data = [decodeURIComponent(dataURIData[3])];

@@ -21,0 +21,0 @@ }

@@ -1,4 +0,4 @@

import dataURItoBlob from './dataURItoBlob.js';
import dataURItoBlob from "./dataURItoBlob.js";
export default function dataURItoFile(dataURI, opts) {
return dataURItoBlob(dataURI, opts, true);
}

@@ -1,9 +0,5 @@

import { createAbortError } from './AbortController.js';
import { createAbortError } from "./AbortController.js";
/**
* Return a Promise that resolves after `ms` milliseconds.
*
* @param {number} ms - Number of milliseconds to wait.
* @param {{ signal?: AbortSignal }} [opts] - An abort signal that can be used to cancel the delay early.
* @returns {Promise<void>} A Promise that resolves after the given amount of `ms`.
*/

@@ -10,0 +6,0 @@ export default function delay(ms, opts) {

@@ -6,6 +6,6 @@ /**

*
* @param {*} newValue the n-th value of the sequence
* @param {*} previousSmoothedValue the exponential average of the first n-1 values
* @param {*} halfLife value of `dt` to move the smoothed value halfway between `previousFilteredValue` and `newValue`
* @param {*} dt time elapsed between adding the (n-1)th and the n-th values
* @param newValue the n-th value of the sequence
* @param previousSmoothedValue the exponential average of the first n-1 values
* @param halfLife value of `dt` to move the smoothed value halfway between `previousFilteredValue` and `newValue`
* @param dt time elapsed between adding the (n-1)th and the n-th values
* @returns the exponential average of the first n values

@@ -12,0 +12,0 @@ */

@@ -1,11 +0,10 @@

import hasProperty from './hasProperty.js';
import hasProperty from "./hasProperty.js";
class ErrorWithCause extends Error {
constructor(message, options) {
if (options === void 0) {
options = {};
}
super(message);
this.cause = options.cause;
this.cause = options == null ? void 0 : options.cause;
if (this.cause && hasProperty(this.cause, 'isNetworkError')) {
this.isNetworkError = this.cause.isNetworkError;
} else {
this.isNetworkError = false;
}

@@ -12,0 +11,0 @@ }

@@ -1,2 +0,2 @@

import NetworkError from './NetworkError.js';
import NetworkError from "./NetworkError.js";

@@ -3,0 +3,0 @@ /**

export function filterNonFailedFiles(files) {
const hasError = file => 'error' in file && file.error;
const hasError = file => 'error' in file && !!file.error;
return files.filter(file => !hasError(file));

@@ -8,3 +8,6 @@ }

export function filterFilesToEmitUploadStarted(files) {
return files.filter(file => !file.progress.uploadStarted || !file.isRestored);
return files.filter(file => {
var _file$progress;
return !((_file$progress = file.progress) != null && _file$progress.uploadStarted) || !file.isRestored;
});
}

@@ -1,8 +0,5 @@

import isDOMElement from './isDOMElement.js';
import isDOMElement from "./isDOMElement.js";
/**
* Find one or more DOM elements.
*
* @param {string|Node} element
* @returns {Node[]|null}
*/

@@ -9,0 +6,0 @@ export default function findAllDOMElements(element) {

@@ -1,8 +0,5 @@

import isDOMElement from './isDOMElement.js';
import isDOMElement from "./isDOMElement.js";
/**
* Find a DOM element.
*
* @param {Node|string} element
* @returns {Node|null}
*/

@@ -9,0 +6,0 @@ export default function findDOMElement(element, context) {

@@ -1,2 +0,2 @@

import getFileType from './getFileType.js';
import getFileType from "./getFileType.js";
function encodeCharacter(character) {

@@ -7,3 +7,3 @@ return character.charCodeAt(0).toString(32);

let suffix = '';
return name.replace(/[^A-Z0-9]/ig, character => {
return name.replace(/[^A-Z0-9]/gi, character => {
suffix += `-${encodeCharacter(character)}`;

@@ -17,5 +17,2 @@ return '/';

* removing extra characters and adding type, size and lastModified
*
* @param {object} file
* @returns {string} the fileID
*/

@@ -22,0 +19,0 @@ export default function generateFileID(file) {

@@ -1,3 +0,3 @@

import webkitGetAsEntryApi from './utils/webkitGetAsEntryApi/index.js';
import fallbackApi from './utils/fallbackApi.js';
import webkitGetAsEntryApi from "./utils/webkitGetAsEntryApi/index.js";
import fallbackApi from "./utils/fallbackApi.js";

@@ -11,4 +11,5 @@ /**

*
* @param {DataTransfer} dataTransfer
* @param {Function} logDropError - a function that's called every time some
* @param dataTransfer
* @param options
* @param options.logDropError - a function that's called every time some
* folder or some file error out (e.g. because of the folder name being too long

@@ -19,7 +20,6 @@ * on Windows). Notice that resulting promise will always be resolved anyway.

*/
export default async function getDroppedFiles(dataTransfer, _temp) {
let {
logDropError = () => {}
} = _temp === void 0 ? {} : _temp;
export default async function getDroppedFiles(dataTransfer, options) {
var _options$logDropError;
// Get all files from all subdirs. Works (at least) in Chrome, Mozilla, and Safari
const logDropError = (_options$logDropError = options == null ? void 0 : options.logDropError) != null ? _options$logDropError : Function.prototype;
try {

@@ -26,0 +26,0 @@ const accumulator = [];

@@ -1,2 +0,2 @@

import toArray from '../../toArray.js';
import toArray from "../../toArray.js";

@@ -3,0 +3,0 @@ // .files fallback, should be implemented in any browser

/**
* Recursive function, calls the original callback() when the directory is entirely parsed.
*
* @param {FileSystemDirectoryReader} directoryReader
* @param {Array} oldEntries
* @param {Function} logDropError
* @param {Function} callback - called with ([ all files and directories in that directoryReader ])
*/

@@ -9,0 +4,0 @@ export default function getFilesAndDirectoriesFromDirectory(directoryReader, oldEntries, logDropError, _ref) {

@@ -1,3 +0,2 @@

import getFilesAndDirectoriesFromDirectory from './getFilesAndDirectoriesFromDirectory.js';
import getFilesAndDirectoriesFromDirectory from "./getFilesAndDirectoriesFromDirectory.js";
/**

@@ -21,7 +20,10 @@ * Polyfill for the new (experimental) getAsFileSystemHandle API (using the popular webkitGetAsEntry behind the scenes)

getFilesAndDirectoriesFromDirectory(directoryReader, [], logDropError, {
onSuccess: dirEntries => resolve(dirEntries.map(file => getAsFileSystemHandleFromEntry(file, logDropError)))
onSuccess: dirEntries => resolve(dirEntries.map(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
file => getAsFileSystemHandleFromEntry(file, logDropError)))
});
});
yield* entries;
}
},
isSameEntry: undefined
};

@@ -41,2 +43,3 @@ }

if (file != null) {
;
file.relativePath = relativePath ? getNextRelativePath() : null;

@@ -75,3 +78,4 @@ yield file;

// or else Chrome will crash when running in HTTP: https://github.com/transloadit/uppy/issues/4133
// if (window.isSecureContext && item.getAsFileSystemHandle != null) entry = await item.getAsFileSystemHandle()
// if (window.isSecureContext && item.getAsFileSystemHandle != null)
// fileSystemHandle = await item.getAsFileSystemHandle()

@@ -78,0 +82,0 @@ // `webkitGetAsEntry` exists in all popular browsers (including non-WebKit browsers),

@@ -1,3 +0,3 @@

import getSpeed from './getSpeed.js';
import getBytesRemaining from './getBytesRemaining.js';
import getSpeed from "./getSpeed.js";
import getBytesRemaining from "./getBytesRemaining.js";
export default function getETA(fileProgress) {

@@ -4,0 +4,0 @@ if (!fileProgress.bytesUploaded) return 0;

/**
* Takes a full filename string and returns an object {name, extension}
*
* @param {string} fullFileName
* @returns {object} {name, extension}
*/

@@ -7,0 +4,0 @@ export default function getFileNameAndExtension(fullFileName) {

@@ -1,3 +0,3 @@

import getFileNameAndExtension from './getFileNameAndExtension.js';
import mimeTypes from './mimeTypes.js';
import getFileNameAndExtension from "./getFileNameAndExtension.js";
import mimeTypes from "./mimeTypes.js";
export default function getFileType(file) {

@@ -4,0 +4,0 @@ var _getFileNameAndExtens;

const mimeToExtensions = {
__proto__: null,
'audio/mp3': 'mp3',

@@ -22,4 +23,5 @@ 'audio/mp4': 'mp4',

// eslint-disable-next-line no-param-reassign
;
[mimeType] = mimeType.split(';', 1);
return mimeToExtensions[mimeType] || null;
}
export default function getSocketHost(url) {
var _regex$exec;
// get the host domain
const regex = /^(?:https?:\/\/|\/\/)?(?:[^@\n]+@)?(?:www\.)?([^\n]+)/i;
const host = regex.exec(url)[1];
const host = (_regex$exec = regex.exec(url)) == null ? void 0 : _regex$exec[1];
const socketProtocol = /^http:\/\//i.test(url) ? 'ws' : 'wss';
return `${socketProtocol}://${host}`;
}
/**
* Get the declared text direction for an element.
*
* @param {Node} element
* @returns {string|undefined}
*/

@@ -7,0 +4,0 @@

/**
* Adds zero to strings shorter than two characters.
*
* @param {number} number
* @returns {string}
*/

@@ -7,0 +4,0 @@ function pad(number) {

/**
* Check if an object is a DOM element. Duck-typing based on `nodeType`.
*
* @param {*} obj
*/
export default function isDOMElement(obj) {
return (obj == null ? void 0 : obj.nodeType) === Node.ELEMENT_NODE;
if (typeof obj !== 'object' || obj === null) return false;
if (!('nodeType' in obj)) return false;
return obj.nodeType === Node.ELEMENT_NODE;
}
/**
* Checks if the browser supports Drag & Drop (not supported on mobile devices, for example).
*
* @returns {boolean}
*/

@@ -6,0 +4,0 @@ export default function isDragDropSupported() {

/**
* Checks if current device reports itself as “mobile”.
* Very simple, not very reliable.
*
* @returns {boolean}
*/

@@ -7,0 +5,0 @@ export default function isMobileDevice() {

/**
* Check if a URL string is an object URL from `URL.createObjectURL`.
*
* @param {string} url
* @returns {boolean}
*/

@@ -7,0 +4,0 @@ export default function isObjectURL(url) {

@@ -7,2 +7,3 @@ // ___Why not add the mime-types package?

export default {
__proto__: null,
md: 'text/markdown',

@@ -9,0 +10,0 @@ markdown: 'text/markdown',

@@ -1,2 +0,2 @@

import secondsToTime from './secondsToTime.js';
import secondsToTime from "./secondsToTime.js";
export default function prettyETA(seconds) {

@@ -3,0 +3,0 @@ const time = secondsToTime(seconds);

@@ -48,3 +48,3 @@ function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }

clearTimeout(_classPrivateFieldLooseBase(this, _aliveTimer)[_aliveTimer]);
_classPrivateFieldLooseBase(this, _aliveTimer)[_aliveTimer] = null;
_classPrivateFieldLooseBase(this, _aliveTimer)[_aliveTimer] = undefined;
_classPrivateFieldLooseBase(this, _isDone)[_isDone] = true;

@@ -51,0 +51,0 @@ }

@@ -241,3 +241,3 @@ function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }

_classPrivateFieldLooseBase(this, _activeRequests)[_activeRequests] -= 1;
cancelActive(cause);
cancelActive == null ? void 0 : cancelActive(cause);
_classPrivateFieldLooseBase(this, _queueNext)[_queueNext]();

@@ -244,0 +244,0 @@ },

@@ -1,2 +0,2 @@

import getFileNameAndExtension from './getFileNameAndExtension.js';
import getFileNameAndExtension from "./getFileNameAndExtension.js";
export default function remoteFileObjToLocal(file) {

@@ -3,0 +3,0 @@ return {

function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
var id = 0;
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
import has from './hasProperty.js';
import has from "./hasProperty.js";
// We're using a generic because languages have different plural rules.
function insertReplacement(source, rx, replacement) {

@@ -36,5 +39,4 @@ const newParts = [];

*
* @param {string} phrase that needs interpolation, with placeholders
* @param {object} options with values that will be used to replace placeholders
* @returns {any[]} interpolated
* @param phrase that needs interpolation, with placeholders
* @param options with values that will be used to replace placeholders
*/

@@ -77,5 +79,2 @@ function interpolate(phrase, options) {

export default class Translator {
/**
* @param {object|Array<object>} locales - locale or list of locales.
*/
constructor(locales) {

@@ -103,5 +102,5 @@ Object.defineProperty(this, _apply, {

*
* @param {string} key
* @param {object} options with values that will be used later to replace placeholders in string
* @returns {string} translated (and interpolated)
* @param key
* @param options with values that will be used later to replace placeholders in string
* @returns string translated (and interpolated)
*/

@@ -115,5 +114,3 @@ translate(key, options) {

*
* @param {string} key
* @param {object} options with values that will be used to replace placeholders
* @returns {Array} The translated and interpolated parts, in order.
* @returns The translated and interpolated parts, in order.
*/

@@ -120,0 +117,0 @@ translateArray(key, options) {

/**
* Truncates a string to the given number of chars (maxLength) by inserting '...' in the middle of that string.
* Partially taken from https://stackoverflow.com/a/5723274/3192470.
*
* @param {string} string - string to be truncated
* @param {number} maxLength - maximum size of the resulting string
* @returns {string}
*/

@@ -9,0 +5,0 @@ const separator = '...';

{
"name": "@uppy/utils",
"description": "Shared utility functions for Uppy Core and plugins maintained by the Uppy team.",
"version": "5.5.2",
"version": "5.6.0",
"license": "MIT",

@@ -75,4 +75,5 @@ "types": "types/index.d.ts",

"devDependencies": {
"@types/lodash": "^4.14.199",
"vitest": "^0.34.5"
}
}

@@ -6,8 +6,4 @@ import { describe, expect, it } from 'vitest'

it('should return index of an object in an array, that matches a predicate', () => {
const arr = [
{ name: 'foo' },
{ name: 'bar' },
{ name: '123' },
]
const index = findIndex(arr, item => item.name === 'bar')
const arr = [{ name: 'foo' }, { name: 'bar' }, { name: '123' }]
const index = findIndex(arr, (item) => item.name === 'bar')
expect(index).toEqual(1)

@@ -17,10 +13,6 @@ })

it('should return -1 when no object in an array matches a predicate', () => {
const arr = [
{ name: 'foo' },
{ name: 'bar' },
{ name: '123' },
]
const index = findIndex(arr, item => item.name === 'hello')
const arr = [{ name: 'foo' }, { name: 'bar' }, { name: '123' }]
const index = findIndex(arr, (item) => item.name === 'hello')
expect(index).toEqual(-1)
})
})
import { describe, expect, it } from 'vitest'
import generateFileID from './generateFileID.js'
import generateFileID from './generateFileID.ts'

@@ -4,0 +4,0 @@ describe('generateFileID', () => {

import { describe, expect, it } from 'vitest'
import getETA from './getETA.js'
import getETA from './getETA.ts'

@@ -4,0 +4,0 @@ describe('getETA', () => {

import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import isTouchDevice from './isTouchDevice.js'
import isTouchDevice from './isTouchDevice.ts'

@@ -4,0 +4,0 @@ describe('isTouchDevice', () => {

@@ -57,3 +57,3 @@ function createCancelError (cause) {

this.#activeRequests -= 1
cancelActive(cause)
cancelActive?.(cause)
this.#queueNext()

@@ -60,0 +60,0 @@ },

import { describe, expect, it } from 'vitest'
import { RateLimitedQueue } from './RateLimitedQueue.js'
import delay from './delay.ts'
const delay = ms => new Promise(resolve => setTimeout(resolve, ms))
describe('RateLimitedQueue', () => {
let pending = 0
function fn () {
function fn() {
pending++

@@ -18,5 +17,12 @@ return delay(15).then(() => pending--)

const result = Promise.all([
fn2(), fn2(), fn2(), fn2(),
fn2(), fn2(), fn2(), fn2(),
fn2(), fn2(),
fn2(),
fn2(),
fn2(),
fn2(),
fn2(),
fn2(),
fn2(),
fn2(),
fn2(),
fn2(),
])

@@ -38,5 +44,12 @@

const result = Promise.all([
fn2(), fn2(), fn2(), fn2(),
fn2(), fn2(), fn2(), fn2(),
fn2(), fn2(),
fn2(),
fn2(),
fn2(),
fn2(),
fn2(),
fn2(),
fn2(),
fn2(),
fn2(),
fn2(),
])

@@ -53,11 +66,20 @@

const queue = new RateLimitedQueue(1)
function syncFn () { return 1 }
function syncFn() {
return 1
}
const fn2 = queue.wrapPromiseFunction(syncFn)
return Promise.all([
fn2(), fn2(), fn2(), fn2(),
fn2(), fn2(), fn2(), fn2(),
fn2(), fn2(),
fn2(),
fn2(),
fn2(),
fn2(),
fn2(),
fn2(),
fn2(),
fn2(),
fn2(),
fn2(),
])
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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