What is @uppy/utils?
@uppy/utils is a utility library that provides a set of helper functions for working with files, URLs, and other common tasks in JavaScript. It is part of the Uppy file uploader ecosystem and is designed to simplify various operations related to file handling and manipulation.
What are @uppy/utils's main functionalities?
getFileNameAndExtension
This function extracts the file name and extension from a given file path or URL.
const { getFileNameAndExtension } = require('@uppy/utils');
const { name, extension } = getFileNameAndExtension('example.txt');
console.log(name); // 'example'
console.log(extension); // 'txt'
getSafeFileName
This function sanitizes a file name by replacing unsafe characters with safe ones.
const { getSafeFileName } = require('@uppy/utils');
const safeName = getSafeFileName('example file.txt');
console.log(safeName); // 'example-file.txt'
generateFileID
This function generates a unique ID for a file based on its properties such as name, type, and size.
const { generateFileID } = require('@uppy/utils');
const fileID = generateFileID({ name: 'example.txt', type: 'text/plain', size: 1024 });
console.log(fileID); // A unique file ID based on the file's properties
isPreviewSupported
This function checks if a given MIME type is supported for preview.
const { isPreviewSupported } = require('@uppy/utils');
const supported = isPreviewSupported('image/jpeg');
console.log(supported); // true
Other packages similar to @uppy/utils
file-type
The 'file-type' package is used to detect the file type of a Buffer/Uint8Array/ArrayBuffer. It is similar to @uppy/utils in that it helps with file handling, but it focuses specifically on detecting file types rather than providing a broader set of utilities.
mime
The 'mime' package is used to look up the MIME type of a file based on its extension. It is similar to @uppy/utils in that it deals with file types and extensions, but it does not provide the same range of utilities for file manipulation.
sanitize-filename
The 'sanitize-filename' package is used to sanitize file names by removing or replacing unsafe characters. It is similar to the getSafeFileName function in @uppy/utils, but it is focused solely on sanitizing file names.
@uppy/utils
Shared utility functions for Uppy Core and the "official" plugins maintained by the Uppy team.
Uppy is being developed by the folks at Transloadit, a versatile file encoding service.
Installation
Unless you are creating a custom plugin, you should not need to install this manually.
$ npm install @uppy/utils --save
License
The MIT License.
0.28.0
| Package | Version | Package | Version |
|-|-|-|-|
| uppy | 0.28.0 | @uppy/xhr-upload | 0.28.0 |
| @uppy/core | 0.28.0 | @uppy/react | 0.28.0 |
| @uppy/dashboard | 0.28.0 | @uppy/transloadit | 0.28.0 |
| @uppy/dropbox | 0.28.0 | @uppy/tus | 0.28.0 |
| @uppy/form | 0.28.0 | @uppy/url | 0.28.0 |
| @uppy/informer | 0.28.0 | @uppy/webcam | 0.28.0 |
| @uppy/utils | 0.28.0 | @uppy/url | 0.28.0 |
| @uppy/thumbnail-generator | 0.28.0 | @uppy/status-bar | 0.28.0 |
| @uppy/redux-dev-tools | 0.28.0 | @uppy/react | 0.28.0 |
| @uppy/provider-views | 0.28.0 | @uppy/progress-bar | 0.28.0 |
| @uppy/instagram | 0.28.0 | @uppy/informer | 0.28.0 |
| @uppy/google-drive | 0.28.0 | @uppy/golden-retriever | 0.28.0 |
| @uppy/form | 0.28.0 | @uppy/file-input | 0.28.0 |
| @uppy/dropbox | 0.28.0 | @uppy/drag-drop | 0.28.0 |
| @uppy/dashboard | 0.28.0 | @uppy/companion | 0.15.0 |
| @uppy/aws-s3 | 0.28.0 | @uppy/aws-s3-multipart | 0.28.0 |
- @uppy/core: bring back i18n locale packs (#1114 / @goto-bus-stop, @arturi)
- @uppy/companion: option validation (can use https://npm.im/ajv + JSON schema)
- @uppy/companion: Remove duplicate typescript dependency (#1119 / @goto-bus-stop)
- @uppy/companion: ⚠️ breaking Migrate provider adapter to Companion: saves 5KB on the frontend, all heavy lifting moved to the server side (#1093 / @ifedapoolarewaju)
- @uppy/core: single-use Uppy instance: adds an
allowMultipleUploads
option to @uppy/core. If set to false, uppy.upload() can only be called once. Afterward, no new files can be added and no new uploads can be started. This is intended to serve the <form>
-like use case. (#1064 / @goto-bus-stop) - @uppy/dashboard: Auto close after finish using
closeAfterFinish: true
(#1106 / @goto-bus-stop) - @uppy/dashboard: call
hideAllPanels
after a file is added in Dashboard, instead of toggleAddFilesPanel(false)
that didn’t hide some panels - @uppy/status-bar: ⚠️ breaking Add spinner, pause/resume as small round buttons, different color for encoding; Added separate options for hiding pause/resume and cancel button; Added more statuses to the Dashboard, like “Upload complete”, “Upload paused” and “Uploading 5 files” (#1097 / @arturi)
- @uppy/url: add end2end test for Url plugin (#1120 / @ifedapoolarewaju)
- @uppy/transloadit: add end2end test for @uppy/transloadit (#1086 / @arturi)
- @uppy/thumbnail-generator: Add thumbnail generation integration test (#970 / @goto-bus-stop)
- @uppy/thumbnail-generator: Allow to constrain thumbnail height, fixes #979 (@richartkeil / #1096)
- @uppy/thumbnail-generator: Fix JPG previews on Edge (#1092 / @goto-bus-stop)
- @uppy/aws-s3: use RequestClient, it contains the Uppy Companion specific stuff, so we don't have to think about that when working on the S3 plugin. (#1091 / @goto-bus-stop)
- @uppy/transloadit: Add
COMPANION_PATTERN
constant (#1104 / @goto-bus-stop) - @uppy/transloadit: Error tweaks (#1103 / @goto-bus-stop)
- @uppy/webcam: Fix getting data from Webcam recording if mime type includes codec metadata (#1094 / @goto-bus-stop)
- @uppy/core: remove upload-cancel event, file-removed should be enough (#1069 / @arutri)
- meta: document events, deprecate unused (#1069 / @arturi)
- meta: New demo video/gif and website frontpage code sample (#1099 / @arturi)
- meta: Update react.md (#1110 / @asmt3)
- meta: Add missing addMoreFiles string to locale (#1111 / @FWirtz)
- meta: Release script improvements: generate nicer releases and a nicer commit history. (#1122 / @goto-bus-stop)
- meta: Add release documentation. eg: test on transloadit website, check examples on the uppy.io website (@goto-bus-stop)