Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

file-select-dialog

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file-select-dialog - npm Package Compare versions

Comparing version 1.4.1 to 1.5.0

7

CHANGELOG.md

@@ -0,1 +1,8 @@

# [1.5.0](https://github.com/TomokiMiyauci/file-select-dialog/compare/v1.4.1...v1.5.0) (2020-11-29)
### Features
* **file-dialog:** add strict parameter and change default return types ([b9754e2](https://github.com/TomokiMiyauci/file-select-dialog/commit/b9754e28ec14686a223856cb04500a2bc8aa651e))
## [1.4.1](https://github.com/TomokiMiyauci/file-select-dialog/compare/v1.4.0...v1.4.1) (2020-11-28)

@@ -2,0 +9,0 @@

13

dist/file-dialog.d.ts

@@ -1,16 +0,17 @@

export interface Parameters<T extends boolean = false> {
export interface Parameters<T extends boolean = false, U extends boolean = false> {
accept: string | string[];
multiple: T;
strict: U;
}
declare type PickFile<T extends boolean = false> = T extends true ? FileList : File;
declare type PickFile<T extends boolean = false, U extends boolean = false> = T extends false ? (U extends true ? File : FileList) : FileList;
/**
* Call file select dialog programmatically.
* @param {object} [parameters] optional
* @returns {Promise} Promise <File | FileList> if multiple is true, return FileList object, if false return File object
* @returns {Promise} Promise <File | FileList> if strict is false, return FileList object, if multiple is false and strict is true return File object
*/
export declare const fileDialog: <T extends boolean = false>(parameters?: Partial<Parameters<T>> | undefined) => Promise<PickFile<T>>;
export declare const resolver: <T extends boolean>(fileList: HTMLInputElement['files'], multiple: T) => Promise<PickFile<T>>;
export declare const getFileListObj: <T extends boolean>(files: NonNullable<HTMLInputElement['files']>, multiple: T) => PickFile<T> | null;
export declare const fileDialog: <T extends boolean = false, U extends boolean = false>(parameters?: Partial<Parameters<T, U>> | undefined) => Promise<PickFile<T, U>>;
export declare const resolver: <T extends boolean, U extends boolean>(fileList: HTMLInputElement['files'], multiple: T, strict: U) => Promise<PickFile<T, U>>;
export declare const getFileListObj: <T extends boolean, U extends boolean>(files: NonNullable<HTMLInputElement['files']>, multiple: T, strict: U) => PickFile<T, U> | null;
export declare const createFileInputElement: ({ accept, multiple }: Pick<HTMLInputElement, 'accept' | 'multiple'>) => HTMLInputElement;
export {};
//# sourceMappingURL=file-dialog.d.ts.map

@@ -1,2 +0,2 @@

class e extends Error{}class t extends e{}class n extends e{}const c=(e,t=",")=>e.join(t),l={accept:"*",multiple:!1},r=e=>{const{accept:t,multiple:n}={...l,...e},r=p({multiple:n,accept:Array.isArray(t)?c(t):t});return new Promise((e=>{r.onchange=()=>{e(s(r.files,n)),r.remove()},r.click()}))},s=(e,c)=>new Promise(((l,r)=>{if(!e)return r(new t);const s=i(e,c);if(!s)return r(new n);l(s)})),i=(e,t)=>t?e:1===e.length?e[0]:null,p=({accept:e,multiple:t})=>{const n=document.createElement("input");return n.type="file",n.multiple=t,n.accept=e,n};export{r as fileDialog};
class e extends Error{}class t extends e{}class n extends e{}const c=(e,t=",")=>e.join(t),l={accept:"*",multiple:!1,strict:!1},r=e=>{const{accept:t,multiple:n,strict:r}={...l,...e},i=p({multiple:n,accept:Array.isArray(t)?c(t):t});return new Promise((e=>{i.onchange=()=>{e(s(i.files,n,r)),i.remove()},i.click()}))},s=(e,c,l)=>new Promise(((r,s)=>{if(!e)return s(new t);const p=i(e,c,l);if(!p)return s(new n);r(p)})),i=(e,t,n)=>!t&&n?1===e.length?e[0]:null:e.length?e:null,p=({accept:e,multiple:t})=>{const n=document.createElement("input");return n.type="file",n.multiple=t,n.accept=e,n};export{r as fileDialog};
//# sourceMappingURL=file-select-dialog.esm.js.map

@@ -1,2 +0,2 @@

var fileSelectDialog=function(e){"use strict";class t extends Error{}class l extends t{}class n extends t{}const c=(e,t=",")=>e.join(t),r={accept:"*",multiple:!1},i=(e,t)=>new Promise(((c,r)=>{if(!e)return r(new l);const i=s(e,t);if(!i)return r(new n);c(i)})),s=(e,t)=>t?e:1===e.length?e[0]:null,u=({accept:e,multiple:t})=>{const l=document.createElement("input");return l.type="file",l.multiple=t,l.accept=e,l};return e.fileDialog=e=>{const{accept:t,multiple:l}={...r,...e},n=u({multiple:l,accept:Array.isArray(t)?c(t):t});return new Promise((e=>{n.onchange=()=>{e(i(n.files,l)),n.remove()},n.click()}))},Object.defineProperty(e,"__esModule",{value:!0}),e}({});
var fileSelectDialog=function(e){"use strict";class t extends Error{}class l extends t{}class n extends t{}const c=(e,t=",")=>e.join(t),r={accept:"*",multiple:!1,strict:!1},i=(e,t,c)=>new Promise(((r,i)=>{if(!e)return i(new l);const u=s(e,t,c);if(!u)return i(new n);r(u)})),s=(e,t,l)=>!t&&l?1===e.length?e[0]:null:e.length?e:null,u=({accept:e,multiple:t})=>{const l=document.createElement("input");return l.type="file",l.multiple=t,l.accept=e,l};return e.fileDialog=e=>{const{accept:t,multiple:l,strict:n}={...r,...e},s=u({multiple:l,accept:Array.isArray(t)?c(t):t});return new Promise((e=>{s.onchange=()=>{e(i(s.files,l,n)),s.remove()},s.click()}))},Object.defineProperty(e,"__esModule",{value:!0}),e}({});
//# sourceMappingURL=file-select-dialog.global.js.map

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});class e extends Error{}class t extends e{}class c extends e{}const l=(e,t=",")=>e.join(t),n={accept:"*",multiple:!1},r=(e,l)=>new Promise(((n,r)=>{if(!e)return r(new t);const i=s(e,l);if(!i)return r(new c);n(i)})),s=(e,t)=>t?e:1===e.length?e[0]:null,i=({accept:e,multiple:t})=>{const c=document.createElement("input");return c.type="file",c.multiple=t,c.accept=e,c};exports.fileDialog=e=>{const{accept:t,multiple:c}={...n,...e},s=i({multiple:c,accept:Array.isArray(t)?l(t):t});return new Promise((e=>{s.onchange=()=>{e(r(s.files,c)),s.remove()},s.click()}))};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});class e extends Error{}class t extends e{}class l extends e{}const c=(e,t=",")=>e.join(t),n={accept:"*",multiple:!1,strict:!1},r=(e,c,n)=>new Promise(((r,i)=>{if(!e)return i(new t);const o=s(e,c,n);if(!o)return i(new l);r(o)})),s=(e,t,l)=>!t&&l?1===e.length?e[0]:null:e.length?e:null,i=({accept:e,multiple:t})=>{const l=document.createElement("input");return l.type="file",l.multiple=t,l.accept=e,l};exports.fileDialog=e=>{const{accept:t,multiple:l,strict:s}={...n,...e},o=i({multiple:l,accept:Array.isArray(t)?c(t):t});return new Promise((e=>{o.onchange=()=>{e(r(o.files,l,s)),o.remove()},o.click()}))};
//# sourceMappingURL=index.js.map
{
"name": "file-select-dialog",
"version": "1.4.1",
"version": "1.5.0",
"description": "Call file select dialog programmatically",

@@ -56,2 +56,3 @@ "types": "dist/index.d.ts",

"tscpaths": "^0.0.9",
"typedoc": "^0.20.0-beta.24",
"typescript": "^4.0.5"

@@ -58,0 +59,0 @@ },

@@ -16,3 +16,3 @@ # file-select-dialog

## Feature
## :sparkles: Feature

@@ -26,3 +26,3 @@ - Supports ES6 Modules

## Install
## :truck: Install

@@ -41,4 +41,18 @@ ```bash

## Examples
## :page_facing_up: Docs
Reference is [here](https://tomokimiyauci.github.io/file-select-dialog/modules/file_dialog.html#filedialog).
### :pencil2: Argument
Parameters `Object`
| key | type | default |
| -------- | ---------------------- | ------- |
| accept | (string \| stirng[] )? | '\*' |
| multiple | boolean? | `false` |
| strict | boolean? | `false` |
## :mag: Examples
[Demo](https://file-select-dialog.vercel.app/)

@@ -48,20 +62,45 @@

Get a File object by default.
By default can only select a single file and get a FileList object.
```ts
const onClick = async () => {
const file = await fileDialog() // open file select dialog and waiting user selection then return File object. Your editor suggest File object types.
// open file select dialog and waiting user selection then return FileList object.
const fileList = await fileDialog()
}
```
Get a FileList object when parameters of `multiple` is true.
If the `multiple` parameter is `true`, can select multiple files and get a FileList object.
```ts
const onClick = async () => {
const fileList = await fileDialog({ multiple: true }) // return FileList object. Your editor suggest FileList object types.
const fileList = await fileDialog({ multiple: true })
}
```
## LICENSE
The `accept` parameter limit the selecable file types.
```ts
const onClick = async () => {
const fileList = await fileDialog({ accept: '.png' })
// multiple acceptable types
const fileList = await fileDialog({ accept: ['.jpg', '.pdf'] })
}
```
### :zap: Advanced
If the parameter of `multiple` is `false` and `strict` is `true`, can get File object directly.
Your editor suggest File object types.
```ts
const onClick = async () => {
const file = await fileDialog({ strict: true })
}
```
## :bulb: LICENSE
[MIT](https://github.com/TomokiMiyauci/file-select-dialog/blob/main/LICENSE)


Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc