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

popups-file-dialog

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

popups-file-dialog

popups file dialog build in c on top of lib called tinyfiledialogs and ported for node

  • 1.6.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
Maintainers
1
Weekly downloads
 
Created
Source

Popups File Dialog

NPM version NPM downloads MIT License

This is a simple file dialog 0 dependencies for windows, linux and macos.
build on library in c language called tinyfiledialogs.

sence it is build in c , so this lib is super fast unlike any library build in python i saw on npm

now listen, sense node is not natively have a file dialog
so i build this lib as a wrapper for the (tinyfiledialogs library build in c).
i made the cli version of the tinyfiledialogs library.
after that i build this lib as a wrapper for the cli version of the tinyfiledialogs library.
i did think of making the tinyfiledialogs library as a node addon, but this is too much work.
so i go for the easy way, and make the cli version of the tinyfiledialogs library.

still have a lot of work to do

i recently build the lib for windows and linux
i am to lazy to download macos and build the lib for macos
so if you have a macos and want to help me build the lib for macos
feel free to contribute to this lib.
compile and test the lib/vendors/src/cli.c for macos


also feel free to contribute to this lib in general, i am not a pro in c, so i am sure there is a lot of bugs in this lib.
i can really use some help.

demo

const fileDialog = require("popups-file-dialog");
(async () => {
  const result = await fileDialog.openFile({
      title: 'Open File',
      startPath: './',
      filterPatterns: ['*'],
      filterPatternsDescription: 'all files',
      allowMultipleSelects: true,
})
  console.log(result);
})();

windows:

multiple select windows

linux:

multiple select linux

(async () => {
const result = await fileDialog.openDirectory({
        title: "select folder please",
    })
    console.log(result);
})();

windows:

select folder windows

linux:

select folder linux

Installation

npm install popups-file-dialog
yarn add popups-file-dialog

or

git clone https://github.com/native-toolkit/popups-file-dialog.git
cd popups-file-dialog

Change log

1.6.0

  • added the saveFile method
  • fixed the startPath option for supporting directories with spaces in the name
  • some formatting and refactoring

1.5.1

  • add support for linux (finally)
  • fixed some bugs (a lot of bugs)
  • added the openDirectory method to select a folder
  • some formatting and refactoring

Usage

const fileDialog = require("../file-dialog");

const main = async () => {
  console.log(fileDialog.config.vendorPath); // check for the path of the vendor folder if the os is supported
  const result = await fileDialog.openFile({
    title: "Open File",
    startPath: "C:\\Users\\",
    filterPatterns: ["*.exe", "*.txt"],
    filterPatternsDescription: "exe files,txt files",
    allowMultipleSelects: true,
  });
  console.log(result);

  const result2 = await fileDialog.messageBox({
    title: "Message Box",
    message: "Hello World",
    dialogType: "yesNoCancel",
    iconType: "info",
    defaultSelected: "yes",
  });
  console.log(result2);
};
main();

table of content

API

fileDialog.config

super important, and big object, that contain all the config of the lib all the flags with the commands and the path of the vendor folder part of it:

config = {
  vendorPath: path.join(
    __dirname,
    "lib",
    "vendors",
    "bin",
    `${process.platform}${process.platform === "win32" ? ".exe" : ".app"}`
  ),
  availableCommand: {
    open: {
      name: "-open-file",
      flags: {
        title: {
          name: "--title",
          defaultValue: "open",
        },
        startPath: {
          name: "--startPath",
          defaultValue: path.resolve("./"),
        },
        filterPatterns: {
          name: "--filterPatterns",
          defaultValue: "*",
        },
        filterPatternsDescription: {
          name: "--filterPatternsDescription",
          defaultValue: "",
        },
        allowMultipleSelects: {
          name: "--allowMultipleSelects",
          defaultValue: "0",
        },
      },
    },
  },
};

fileDialog.openFile(options)

open file dialog menu

example :

multiple select example:

const result = await fileDialog.openFile({
        title: "Open File",
        startPath: "./",
        filterPatterns: ["*"],
        filterPatternsDescription: "all files",
        allowMultipleSelects: true
    })
    console.log(result);

image on windows 10:

multiple select

expected result:

[
  'C:\\Users\\pc\\Desktop\\workingdir\\projects\\popups-file-dialog\\.gitignore',
  'C:\\Users\\pc\\Desktop\\workingdir\\projects\\popups-file-dialog\\.npmignore',
  'C:\\Users\\pc\\Desktop\\workingdir\\projects\\popups-file-dialog\\file-dialog.js'
]

options

optiontypedefaultdescriptionexample
titlestring"open"title of the dialog"Open File"
startPathstringpath.resolve("./")start path of the dialog"C:\Users\"
filterPatternsstring[]["*"]filter patterns of the dialog["*.exe", "*.txt"]
filterPatternsDescriptionstring""filter patterns description of the dialog"exe files,txt files"
allowMultipleSelectsbooleanfalseallow multiple selects of the dialogtrue

fileDialog.saveFile(options)

save file dialog menu

example :

const result5 = await fileDialog.saveFile({
      title: 'Save File',
      startPath: 'C:\\Users\\pc\\Desktop\\New folder (36)\\test.txt',
      filterPatterns: ['*'],
      filterPatternsDescription: "all",
   })
   console.log(result5)

image on windows 10:

save file

expected result:

"C:\\Users\\pc\\Desktop\\New folder (36)\\test.txt"

options

optiontypedefaultdescriptionexample
titlestring"save"title of the dialog"Save File"
startPathstringpath.resolve("./default.txt")start path and file name"C:\Users\someFile.txt"
filterPatternsstring[]["*"]filter patterns of the dialog["*.exe", "*.txt"]
filterPatternsDescriptionstring""filter patterns description of the dialog"exe files,txt files"

fileDialog.openDirectory(options)

open folder dialog menu

example :

const result = await fileDialog.openDirectory({
        title: "Message Box",
    })
    console.log(result);

image on windows 10:

select folder

expected result:

"C:\\Users\\pc\\Documents\\Adobe"

options

optiontypedefaultdescriptionexample
titlestring"open"title of the dialog"Open Folder"

fileDialog.messageBox(options)

promote message box

example 1:

const result = await fileDialog.messageBox({
        title: "Message Box",
        message: "Hello World",
        dialogType: "yesNoCancel",
        iconType: "info",
        defaultSelected: "yes"
    })
    console.log(result);

image on windows 10:

message box

expected result:

yes -> 1
no -> 2
cancel -> 0

example 2:

const result = await fileDialog.messageBox({
        title: "Message Box",
        message: "Hello World",
        dialogType: "okCancel",
        iconType: "info",
        defaultSelected: "ok"
    })
    console.log(result);

expected result:

ok -> 1
cancel -> 0

example 3:

const result = await fileDialog.messageBox({
        title: "Message Box",
        message: "Hello World",
        dialogType: "yesNo",
        iconType: "info",
        defaultSelected: "ok"
    })
    console.log(result);

expected result:

yes -> 1
no -> 0

options

optiontypedefaultdescriptionexampleavailable options
titlestring"message"title of the dialog"Message Box"
messagestring"message"message of the dialog"Hello World"
dialogTypestring"ok"dialog type of the dialog"okCancel""ok", "okCancel", "yesNo", "yesNoCancel"
iconTypestring"info"icon type of the dialog"info""info", "warning", "error","question"
defaultSelectedstring"ok"default selected of the dialog"ok""ok", "cancel", "yes", "no"

Keywords

FAQs

Package last updated on 25 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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