Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write # to be able to publish a GitHub release
issues: write # to be able to comment on released issues
contents: write # to be able to publish a GitHub release
issues: write # to be able to comment on released issues
pull-requests: write # to be able to comment on released pull requests
id-token: write # OIDC for npm trusted publishing (+ provenance)
id-token: write # OIDC for npm trusted publishing (+ provenance)
steps:
- name: Checkout repository
uses: actions/checkout@v7
Expand Down
62 changes: 41 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# attr-accept

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

[![npm](https://img.shields.io/npm/v/attr-accept.svg?style=flat-square)](https://www.npmjs.com/package/attr-accept)
Expand All @@ -9,44 +10,63 @@ See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#attr-ac
Ships as both ES modules and CommonJS with bundled TypeScript type definitions.

## Installation

```sh
npm install --save attr-accept
```

## Usage

```javascript
import accept from "attr-accept";

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

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

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

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

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

accept({
name: "my file.json",
type: "application/json"
}, ["application/json", "video/*"]); // => true
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:

```javascript
const accept = require("attr-accept");
```
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
"lint": "oxlint",
"lint:fix": "oxlint --fix",
"lint:type-aware": "oxlint --type-aware",
"format": "oxfmt \"src/**/*.ts\" \"*.ts\"",
"format:check": "oxfmt --check \"src/**/*.ts\" \"*.ts\"",
"format": "oxfmt .",
"format:check": "oxfmt --check .",
"pretest:cov": "npm run type-check && npm run lint && npm run format:check",
"test": "vitest",
"test:cov": "vitest run --coverage",
Expand Down