attr-accept
JavaScript implementation of the "accept" attribute for HTML5 <input type="file">
Last updated 2 years ago by rolandjitsu .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install attr-accept 
SYNC missed versions from official npm registry.

attr-accept

JavaScript implementation of the "accept" attribute for HTML5 <input type="file">

npm Tests

See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#attr-accept for more information.

Ships as both ES modules and CommonJS with bundled TypeScript type definitions.

Installation

npm install --save attr-accept

Usage

import accept from "attr-accept";

accept(
  {
    name: "my file.png",
    type: "image/png"
  },
  "image/*"
); // => true

accept(
  {
    name: "my file.json",
    type: "application/json"
  },
  "image/*"
); // => false

accept(
  {
    name: "my file.srt",
    type: ""
  },
  ".srt"
); // => true

You can also pass multiple mime types as a comma delimited string or array.

accept(
  {
    name: "my file.json",
    type: "application/json"
  },
  "application/json,video/*"
); // => true

accept(
  {
    name: "my file.json",
    type: "application/json"
  },
  ["application/json", "video/*"]
); // => true

In a CommonJS environment, use require instead:

const accept = require("attr-accept");

Contributing

Checkout the organization CONTRIBUTING.md.

Current Tags

  • 3.0.0-beta.1                                ...           beta (2 years ago)
  • 4.0.1                                ...           latest (2 months ago)

20 Versions

  • 4.0.1                                ...           2 months ago
  • 4.0.0                                ...           4 months ago
  • 3.0.0-beta.1                                ...           2 years ago
  • 3.0.0 [deprecated]           ...           2 years ago
  • 2.2.5                                ...           2 years ago
  • 2.2.4                                ...           2 years ago
  • 2.2.3                                ...           2 years ago
  • 2.2.2                                ...           6 years ago
  • 2.2.1                                ...           6 years ago
  • 2.2.0                                ...           6 years ago
  • 2.1.0                                ...           7 years ago
  • 2.0.0                                ...           7 years ago
  • 1.1.3                                ...           8 years ago
  • 1.1.2                                ...           9 years ago
  • 1.1.1                                ...           9 years ago
  • 1.1.0                                ...           10 years ago
  • 1.0.3                                ...           11 years ago
  • 1.0.2                                ...           11 years ago
  • 1.0.1                                ...           11 years ago
  • 1.0.0                                ...           11 years ago

© 2010 - cnpmjs.org x YWFE | Home | YWFE