npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

huply

v0.3.1

Published

A dependency-free JavaScript-Tool for uploading files.

Downloads

102

Readme

Huply

A dependency-free file uploader

Table of contents

Installation

Installation via npm

Recommended step for projects with integrated module bundler (e.g. Webpack) or task-runner (e.g. Gulp).

  1. npm install huply --save
  2. Integrate it via the import statement import Huply from 'huply'
  3. Import [PATH_TO_NODE_MODULES]/huply/dist/style.css to your stylesheets / workflow

Usage

  1. Add lang - Attribute to html-Tag. Otherwise english or the defined fallback language is used as default language. <html lang="en">

  2. Add input field

 <input
   type="file"
   accept=".jpeg,.jpg,.png"
   multiple
   class="huply-test"
 />
  1. Execute init-function:
const el = document.querySelector('.huply-test');
new Huply(el).init();

Configuration

Every Huply-Instance can be modified by parameters:

| Parameter | Required | Type | |----------------------|----------|------------------------------| | dropzoneTheme | false | string | | maxConcurrentUploads | false | number | | maxFileSize | false | number | | uploadUrl | true | string | | deleteUrl | true | string |
| headers | false | object |
| withCredentials | false | boolean |
| preloadedFiles | false | PreloadedFileItemInterface[] |
| translations | false | object |
| allowedFileTypes | false | string[] | | chunkSize | false | number |

 const options = {
     dropzoneTheme: 'sm',
     maxConcurrentUploads: 3,
     maxFileSize: 3,
     uploadUrl: 'http://huply-be.loc/api/upload',
     deleteUrl: 'http://huply-be.loc/api/upload/{{filename}}',
     headers: {
      'X-API-Key': '123456789'
     },
     preloadedFiles: [
         {
             url: 'https://cdn.pixabay.com/photo/2022/03/06/05/30/clouds-7050884_960_720.jpg',
             name: 'test.jpg'
         },
         {
             url: 'https://cdn.pixabay.com/photo/2021/12/27/14/39/tulips-6897351_960_720.jpg',
             name: 'test2.jpg'
         },
         {
             url: 'data:application/octet-stream;base64, ...',
             name: 'url-as-data-url.jpg'
         },
     ],
     allowedFileTypes: ['.jpeg', '.png', '.jpg'],
     chunkSize: 5
 };
 new Huply(el, options).init();

dropzoneTheme

Values: 'sm' | 'lg'

const options = {
  ...
  dropzoneTheme: 'sm',
  ...
};
new Huply(el, options).init();

maxConcurrentUploads

Number of concurrent uploads.

const options = {
  ...
  maxConcurrentUploads: 3,
  ...
};
new Huply(el, options).init();

maxFileSize

Maximum file size in megabytes (MB)

const options = {
  ...
  maxFileSize: 3,
  ...
};
new Huply(el, options).init();

uploadUrl

Huply sends files to this url by POST-Method

const options = {
  ...
  uploadUrl: 'https://my-backend.url/upload',
  ...
};
new Huply(el, options).init();

deleteUrl

Huply sends a request to delete a temporary uploaded file. Request is sent by DELETE-Method. The placeholder {{filename}} is required and will be replaced with the filename.

const options = {
  ...
  deleteUrl: 'https://my-backend.url/upload/{{filename}},
  ...
};
new Huply(el, options).init();

headers

Add additional headers to request (e.g. CSRF-Token, API-Key).

const options = {
  ...
  headers: {
   'X-API-KEY' : '123456789'
  },
  ...
};
new Huply(el, options).init();

withCredentials

Add withCredentials to request.

const options = {
  ...
  withCredentials : true
  ...
};
new Huply(el, options).init();

preloadedFiles

Sets the preloaded files (e.g. from database). Size - Value in bytes.

const options = {
  ...
  preloadedFiles: [
      {
          url: 'https://cdn.pixabay.com/photo/2022/03/06/05/30/clouds-7050884_960_720.jpg',
          name: 'test.jpg',
          size: 20000000
      },
      {
          url: 'https://cdn.pixabay.com/photo/2021/12/27/14/39/tulips-6897351_960_720.jpg',
          name: 'test2.jpg',
          size: 10000000
      },
      {
          url: 'data:image/jpeg;base64, ...',
          name: 'url-as-data-url.jpg',
          size: 10000000
      },
  ],
  ...
};
new Huply(el, options).init();

allowedFileTypes

const options = {
  ...
  allowedFileTypes: ['.jpg', '.jpeg', '.png'],
  ...
};
new Huply(el, options).init();

chunkSize

If you need large file size uploads, huply slices the file into chunks. Chunk size in Megabytes (MB). An additional header (Content-Range) will be sent by file upload.

const options = {
  ...
  chunkSize: 3,
  ...
};
new Huply(el, options).init();

Data-attributes

Add parameters as data-attributes:

 <input
   accept=".jpeg,.jpg,.png"
   multiple
   class="huply-test"
   name="huply-test"
   type="file"
   data-dropzone-theme="sm"
   data-max-concurrent-uploads="2"
   data-max-file-size="5"
   data-max-files="3"
   data-upload-url="http://huply-be.loc/api/upload"
   data-delete-url="http://huply-be.loc/api/upload/{{filename}}"
   data-preloaded-files='base64-encoded string (Decoded: [{"url":"https://cdn.pixabay.com/photo/2022/03/06/05/30/clouds-7050884_960_720.jpg","name":"test.jpg"},{"url":"https://cdn.pixabay.com/photo/2021/12/27/14/39/tulips-6897351_960_720.jpg","name":"test2.jpg"},{"url":"https://cdn.pixabay.com/photo/2020/03/26/10/58/norway-4970080_960_720.jpg","name":"test3.jpg"}])'
   data-chunk-size="3"
 />

and initialize it:

new Huply(el).init();

Translation

You can choose between english (en) and german (de) as default translations. Add a lang-attribute to HTML-Tag: <html lang="en">. If you need an individual translation you can use a global variable:

window.huplyTranslations {
   chooseFiles: 'Choose files',
   chooseFile: 'Choose file',
   allowedFileTypes: 'Allowed file types: {{allowedFileTypes}}',
   maxFileSize: 'Maximum file size: {{maxFileSize}} MB',
   fileItemStatusWaiting: "In queue",
   fileItemStatusUploading: "Uploading ...",
   fileItemStatusUploaded: "Uploaded",
   fileItemStatusPreloaded: "Already uploaded",
   fileItemStatusError: "An error occured.",
   fileItemStatusErrorFileSize: "The file size exceeds the maximum size: {{maxFileSize}} MB",
   fileItemStatusErrorFileType: "The file type is not allowed. Allowed file types: {{allowedFileTypes}}",
   delete: "Delete"
}

Events

If you need additional functionality, you can subscribe to events published by huply.

fileAdded

A file was added.

const huply = new Huply(el).init();
huply.on('fileAdded', function(fileItem) {
   
});

fileUploaded

A file was uploaded.

const huply = new Huply(el).init();
huply.on('fileUploaded', function(fileItem) {
   
});

filesUploaded

All files were uploaded.

const huply = new Huply(el).init();
huply.on('filesUploaded', function() {
   
});

fileDeleted

A file was deleted.

const huply = new Huply(el).init();
huply.on('fileDeleted', function(fileItem) {
   
});

fileItemUpdate

Status of added file changed.

const huply = new Huply(el).init();
huply.on('fileDeleted', function(fileItem) {
   
});

Methods

addFileItem

Adds a file item to the preloaded file list.

const huply = new Huply(el).init();
const fileItem = {
   name: 'test123.jpg',
   size: 200000,
   // https://test.xyz OR Data url (data:image/jpeg;base64,....) OR empty string
   url: '' 
}
huply.addFileItem(fileItem);

Backends

The backend needs two endpoints:

  • Processing the file upload (default and chunked)
  • Delete temporary uploaded files

Processing the file upload

You need to fill the uploadUrl - Parameter.

Every new upload will be placed in a temporary upload folder, because the huply upload input is only a part of a form. After submission of the form the temporary upload folder will be processed by the backend and will be placed in a persistent storage.

Request

If it is a chunked upload, the HTTP-Header Content-Range will be added.

HTTP-Method: POST

HTTP-Body (JSON):

{
 file: FILE-CONTENT
}

Response

The response includes the filename generated by the backend. It is possible that the backend renames the filename because of special characters in the filename or duplicate filenames. The frontend needs to know this the new filename. Every successful upload returns the HTTP-Status Code 200.

HTTP-Status Code: 200

HTTP-Body (JSON):

{
 filename: "test.jpg"
}

Delete temporary uploaded files

You need to fill the deleteUrl - Parameter.

Uploaded files will be stored in a temporary folder. If they are deleted by the frontend, the backend needs to know it. Every successful deletions returns the HTTP-Status Code 200.

Request

HTTP-Method: DELETE

HTTP-Parameter: The filename will be sent as GET-Parameter. The {{filename}} placeholder will be replaced by huply. (e.g. https://my-url.com/upload/{{filename}})

Response

HTTP-Status Code: 200

Examples

License

This project is available under the MIT license.