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 🙏

© 2024 – Pkg Stats / Ryan Hefner

bureaucracy

v1.0.7

Published

Pull files from hidden file inputs into text inputs with ease

Downloads

172

Readme

bureaucracy

Pull files from hidden file inputs into text inputs with ease

If you want the hidden file inputs part, just absolutely position the file input behind a button skin. Many articles on the internet explain how to do this.

install

npm i bureaucracy -S

create(options?)

Creates a bureaucrat object that can submit files to an HTTP API endpoint. It takes a few options.

Option | Description -----------------------|--------------------------------------------------------------------------------------- validate | Function that receives a File object and should indicate whether that file is valid method | HTTP method to use when posting the files. Defaults to PUT endpoint | HTTP endpoint to post the files to. Defaults to /api/files fieldKey | String setting file upload field key. Defaults to uploads formData | Object containing additional form parameters. Defaults to an empty object: {}

There are "common" validate functions for your convenience. These can be referenced by name on the validate option

Validator | Description ----------|--------------- 'image' | Files are expected to have a MIME type of image/gif, image/png, image/jpg, or image/jpeg

bureaucrat.submit(files)

The files parameter expects an array of File or a FileList, like the ones you can pull from input.files, where input is an input element of type file.

The files are uploaded using a default uploads field key, but this can be customized using the fieldKey options parameter. Once your API has handled the uploaded files, a JSON response should be returned. The only requirement here is a results property that's an array describing the success of each file upload.

{
  "results": [
    "anything",
    { "can": "be_used"},
    ["as", "a", "result"]
  ]
}

This data can be useful for the front-end to react to successful file uploads on the success event.

var bureaucrat = create();
bureaucrat.on('success', uploadSuccess);
bureaucrat.submit(uploadInput.files);

function uploadSuccess (results) {
  console.log('so many files were uploaded!');
}

The submission process emits a variety of events on the bureaucrat object, using the contra emitter API.

Event | Arguments | Description ----------|----------------------|----------------------------------------------------------------------------- started | rawFiles | A submission attempt has started for rawFiles invalid | allFiles | Submitted files were invalid, a request won't be made valid | validFiles | At least one submitted file was valid, a request will be made error | err | An error err occurred during the HTTP API request success | results, body | The file API call succeeded and yielded some results ended | err, results, body | The HTTP API request process ended, emitted after both error and success

setup(fileinput, options?)

Reacts to change events on a file input by making a PUT /api/files request with the valid user-selected files as soon as the user is finished choosing their files.

license

mit