🚀 Big News:Socket Has Acquired Secure Annex.Learn More
Socket
Book a DemoSign in
Socket

browser-nativefs

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-nativefs - npm Package Compare versions

Comparing version
0.10.1
to
0.10.2
+2
dist/legacy/directory-open.mjs
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
export default async(e={})=>(e.recursive=e.recursive||!1,new Promise(t=>{const r=document.createElement("input");r.type="file",r.webkitdirectory=!0,r.addEventListener("change",()=>{let i=Array.from(r.files);e.recursive||(i=i.filter(e=>2===e.webkitRelativePath.split("/").length)),t(i)}),r.click()}));
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
export default async(e={})=>new Promise(t=>{const i=document.createElement("input");i.type="file";const n=[...e.mimeTypes?e.mimeTypes:[],e.extensions?e.extensions.map(e=>"."+e):[]].join();i.multiple=e.multiple||!1,i.accept=n||"*/*",i.addEventListener("change",()=>{t(i.multiple?i.files:i.files[0])}),i.click()});
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
export default async(e,t={})=>{const c=document.createElement("a");c.download=t.fileName||"Untitled",c.href=URL.createObjectURL(e),c.addEventListener("click",()=>{setTimeout(()=>URL.revokeObjectURL(c.href),3e4)}),c.click()};
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
const e=async(t,r,i=t.name)=>{const a=[],s=[];for await(const n of t.getEntries()){const t=`${i}/${n.name}`;n.isFile?s.push(n.getFile().then(e=>Object.defineProperty(e,"webkitRelativePath",{configurable:!0,enumerable:!0,get:()=>t}))):n.isDirectory&&r&&a.push(e(n,r,t))}return[...(await Promise.all(a)).flat(),...await Promise.all(s)]};export default async(t={})=>{t.recursive=t.recursive||!1;const r=await window.chooseFileSystemEntries({type:"open-directory"});return e(r,t.recursive)};
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
const e=async e=>{const t=await e.getFile();return t.handle=e,t};export default async(t={})=>{const i=await window.chooseFileSystemEntries({accepts:[{description:t.description||"",mimeTypes:t.mimeTypes||["*/*"],extensions:t.extensions||[""]}],multiple:t.multiple||!1});return t.multiple?Promise.all(i.map(e)):e(i)};
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
export default async(e,t={},i=null)=>{t.fileName=t.fileName||"Untitled",i=i||await window.chooseFileSystemEntries({type:"save-file",accepts:[{description:t.description||"",mimeTypes:[e.type],extensions:t.extensions||[""]}]});const a=await i.createWritable();return await a.write(e),await a.close(),i};
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
const e=async(t,r,a=t.name)=>{const i=[],n=[];for await(const o of t.values()){const t=`${a}/${o.name}`;"file"===o.kind?n.push(o.getFile().then(e=>Object.defineProperty(e,"webkitRelativePath",{configurable:!0,enumerable:!0,get:()=>t}))):"directory"===o.kind&&r&&i.push(e(o,r,t))}return[...(await Promise.all(i)).flat(),...await Promise.all(n)]};export default async(t={})=>{t.recursive=t.recursive||!1;const r=await window.showDirectoryPicker();return e(r,t.recursive)};
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
const e=async e=>{const t=await e.getFile();return t.handle=e,t};export default async(t={})=>{const i={};t.mimeTypes?t.mimeTypes.map(e=>{i[e]=t.extensions||[]}):i["*.*"]=t.extensions||[];const n=await window.showOpenFilePicker({types:[{description:t.description||"",accept:i}],multiple:t.multiple||!1}),s=await Promise.all(n.map(e));return t.multiple?s:s[0]};
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
export default async(e,t={},i=null)=>{t.fileName=t.fileName||"Untitled",i=i||await window.showSaveFilePicker({types:[{description:t.description||"",accept:{[e.type]:t.extensions||[""]}}]});const a=await i.createWritable();return await a.write(e),await a.close(),i};
+1
-1
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
import e from"./supported.mjs";const t=e?"chooseFileSystemEntries"===e?import("./nativefs-legacy/directory-open-nativefs.mjs"):import("./nativefs/directory-open-nativefs.mjs"):import("./legacy/directory-open-legacy.mjs");export async function directoryOpen(...e){return(await t).default(...e)}
import e from"./supported.mjs";const t=e?"chooseFileSystemEntries"===e?import("./nativefs-legacy/directory-open.mjs"):import("./nativefs/directory-open.mjs"):import("./legacy/directory-open.mjs");export async function directoryOpen(...e){return(await t).default(...e)}
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
import e from"./supported.mjs";const t=e?"chooseFileSystemEntries"===e?import("./nativefs-legacy/file-open-nativefs.mjs"):import("./nativefs/file-open-nativefs.mjs"):import("./legacy/file-open-legacy.mjs");export async function fileOpen(...e){return(await t).default(...e)}
import e from"./supported.mjs";const t=e?"chooseFileSystemEntries"===e?import("./nativefs-legacy/file-open.mjs"):import("./nativefs/file-open.mjs"):import("./legacy/file-open.mjs");export async function fileOpen(...e){return(await t).default(...e)}
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
import e from"./supported.mjs";const s=e?"chooseFileSystemEntries"===e?import("./nativefs-legacy/file-save-nativefs.mjs"):import("./nativefs/file-save-nativefs.mjs"):import("./legacy/file-save-legacy.mjs");export async function fileSave(...e){return(await s).default(...e)}
import e from"./supported.mjs";const s=e?"chooseFileSystemEntries"===e?import("./nativefs-legacy/file-save.mjs"):import("./nativefs/file-save.mjs"):import("./legacy/file-save.mjs");export async function fileSave(...e){return(await s).default(...e)}
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
export{fileOpen}from"./file-open.mjs";export{directoryOpen}from"./directory-open.mjs";export{fileSave}from"./file-save.mjs";export{imageToBlob}from"./util/image-to-blob.mjs";
export{fileOpen}from"./file-open.mjs";export{directoryOpen}from"./directory-open.mjs";export{fileSave}from"./file-save.mjs";

@@ -1,38 +0,42 @@

export function fileOpen(options?: {
/**
* Opens file(s) from disk.
*/
export function fileOpen<M extends boolean>(options?: {
/** Acceptable MIME types. [] */
mimeTypes?: string[];
/** Acceptable file extensions. Defaults to "". */
extensions?: string[];
/** Suggested file description. Defaults to "". */
description?: string;
multiple: true;
}): Promise<File[]>;
/** Allow multiple files to be selected. Defaults to false. */
multiple?: M;
}): M extends true ? Promise<File[]> : Promise<File>;
export function fileOpen(options?: {
mimeTypes?: string[];
extensions?: string[];
/** defaults to "" */
description?: string;
multiple?: false;
}): Promise<File>;
export interface FileSaveOptions {
mimeTypes: string[];
extensions: string[];
multiple: boolean;
/** defaults to "Untitled" */
fileName?: string;
/** defaults to "" */
description?: string;
}
/**
* Saves a file to disk.
* @returns Optional file handle to save in place.
*/
export function fileSave(
/** To-be-saved blob */
blob: Blob,
options?: FileSaveOptions,
options?: {
/** Suggested file name. Defaults to "Untitled". */
fileName?: string;
/** Suggested file extensions. Defaults to [""]. */
extensions?: string[];
/** Suggested file description. Defaults to "". */
description?: string;
},
handle?: FileSystemHandle | null
): Promise<FileSystemHandle>;
export interface DirectoryOpenOptions {
/**
* Opens a directory from disk using the Native File System API.
* @returns Contained files.
*/
export function directoryOpen(options?: {
/** Whether to recursively get subdirectories. */
recursive: boolean;
}
}): Promise<File[]>;
export function directoryOpen(options?: DirectoryOpenOptions): Promise<File[]>;
export function imageToBlob(img: HTMLImageElement): Promise<Blob>;

@@ -45,8 +49,8 @@

export interface FileSystemHandlePermissionDescriptor {
writable: boolean;
fileSystemHandle: FileSystemHandle;
mode: 'read' | 'readWrite';
}
export interface FileSystemHandle {
readonly isFile: boolean;
readonly isDirectory: boolean;
readonly kind: 'file' | 'directory';
readonly name: string;

@@ -53,0 +57,0 @@

{
"name": "browser-nativefs",
"version": "0.10.1",
"version": "0.10.2",
"description": "Native File System API with legacy fallback in the browser.",

@@ -12,3 +12,3 @@ "browser": "dist/index.js",

"clean": "shx rm -rf ./dist",
"build": "npm run clean && shx mkdir ./dist && shx mkdir ./dist/util && shx mkdir ./dist/legacy && shx mkdir ./dist/nativefs && shx mkdir ./dist/nativefs-legacy && bash ./build.sh",
"build": "npm run clean && shx mkdir ./dist && shx mkdir ./dist/legacy && shx mkdir ./dist/nativefs && shx mkdir ./dist/nativefs-legacy && bash ./build.sh",
"prepare": "npm run lint && npm run fix && npm run build",

@@ -56,4 +56,7 @@ "lint": "npx eslint . --ext .js,.mjs --fix --ignore-pattern dist/",

"prettier"
]
],
"rules": {
"valid-jsdoc": "off"
}
}
}
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
export default async(e={})=>(e.recursive=e.recursive||!1,new Promise(t=>{const r=document.createElement("input");r.type="file",r.webkitdirectory=!0,r.addEventListener("change",()=>{let i=Array.from(r.files);e.recursive||(i=i.filter(e=>2===e.webkitRelativePath.split("/").length)),t(i)}),r.click()}));
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
export default async(e={})=>new Promise(t=>{const i=document.createElement("input");i.type="file";const n=[...e.mimeTypes?e.mimeTypes:[],e.extensions?e.extensions.map(e=>"."+e):[]].join();i.multiple=e.multiple||!1,i.accept=n||"*/*",i.addEventListener("change",()=>{t(i.multiple?i.files:i.files[0])}),i.click()});
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
export default async(e,t={})=>{const c=document.createElement("a");c.download=t.fileName||"Untitled",c.href=URL.createObjectURL(e),c.addEventListener("click",()=>{setTimeout(()=>URL.revokeObjectURL(c.href),3e4)}),c.click()};
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
const e=async(t,r,i=t.name)=>{const a=[],s=[];for await(const n of t.getEntries()){const t=`${i}/${n.name}`;n.isFile?s.push(n.getFile().then(e=>Object.defineProperty(e,"webkitRelativePath",{configurable:!0,enumerable:!0,get:()=>t}))):n.isDirectory&&r&&a.push(e(n,r,t))}return[...(await Promise.all(a)).flat(),...await Promise.all(s)]};export default async(t={})=>{t.recursive=t.recursive||!1;const r=await window.chooseFileSystemEntries({type:"open-directory"});return e(r,t.recursive)};
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
const e=async e=>{const t=await e.getFile();return t.handle=e,t};export default async(t={})=>{const i=await window.chooseFileSystemEntries({accepts:[{description:t.description||"",mimeTypes:t.mimeTypes||["*/*"],extensions:t.extensions||[""]}],multiple:t.multiple||!1});return t.multiple?Promise.all(i.map(e)):e(i)};
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
export default async(e,t={},i=null)=>{t.fileName=t.fileName||"Untitled",i=i||await window.chooseFileSystemEntries({type:"save-file",accepts:[{description:t.description||"",mimeTypes:[e.type],extensions:t.extensions||[""]}]});const a=await i.createWritable();return await a.write(e),await a.close(),i};
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
const e=async(t,r,a=t.name)=>{const i=[],n=[];for await(const o of t.values()){const t=`${a}/${o.name}`;"file"===o.kind?n.push(o.getFile().then(e=>Object.defineProperty(e,"webkitRelativePath",{configurable:!0,enumerable:!0,get:()=>t}))):"directory"===o.kind&&r&&i.push(e(o,r,t))}return[...(await Promise.all(i)).flat(),...await Promise.all(n)]};export default async(t={})=>{t.recursive=t.recursive||!1;const r=await window.showDirectoryPicker();return e(r,t.recursive)};
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
const e=async e=>{const t=await e.getFile();return t.handle=e,t};export default async(t={})=>{const i={};t.mimeTypes?t.mimeTypes.map(e=>{i[e]=t.extensions||[]}):i["*.*"]=t.extensions||[];const n=await window.showOpenFilePicker({types:[{description:t.description||"",accept:i}],multiple:t.multiple||!1}),s=await Promise.all(n.map(e));return t.multiple?s:s[0]};
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
export default async(e,t={},i=null)=>{t.fileName=t.fileName||"Untitled",i=i||await window.showSaveFilePicker({types:[{description:t.description||"",accept:{[e.type]:t.extensions||[""]}}]});const a=await i.createWritable();return await a.write(e),await a.close(),i};
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
const t=async t=>new Promise(e=>{const a=document.createElement("canvas");a.width=t.naturalWidth,a.height=t.naturalHeight;a.getContext("2d").drawImage(t,0,0),a.toBlob(t=>{e(t)})});export{t as imageToBlob};