@igorskyflyer/open-resource
v1.2.0
Published
๐ Opens a given resource (URL, file, etc.) via the default OS handler. ๐
Downloads
4
Maintainers
Readme
๐ Table of Contents
๐ค Features
- ๐ Opens any file, folder, or URL with the default app on your system
- โก Works instantly in sync mode for quick, blocking execution
- โณ Runs in async mode so your app can keep going while it opens things
- ๐ฅ Adapts automatically to Windows, macOS, Linux, and Android
- ๐ Lets you pass extra arguments to fineโtune how the resource opens
- ๐ซ Gives clear errors if the resource is missing or the platform isnโt supported
โน๏ธ Uses:
start/Start-Processfor Windowsxdg-openfor Linux (either native or bundled) and Android (alias oftermux-open)openfor macOS
๐ต๐ผ Usage
Install it by executing any of the following, depending on your preferred package manager:
pnpm add @igorskyflyer/open-resourceyarn add @igorskyflyer/open-resourcenpm i @igorskyflyer/open-resource๐คน๐ผ API
An options object can be passed to the open() functions, it being described by the interface IOptions as follows:
IOptions
interface IOptions {
args?: string[]
msShell?: 'cmd' | 'powershell'
}args - The arguments to pass to the command.
msShell - The shell to use for the command execution. Only available on Windows.
openSync(resource: string, options?: IOptions): void
Opens a specified resource synchronously using the appropriate command for the current platform.
resource - The resource to be opened, a path, URL, etc. Must be a non-empty string.
options - Optional configuration for the command execution.
Throws an error if no resource is specified, if the arguments are invalid, or an error occurs during execution.
open(resource: string, options?: IOptions): Promise<void>
Opens a specified resource asynchronously using the appropriate command for the current platform.
resource - The resource to be opened, a path, URL, etc. Must be a non-empty string.
options - Optional configuration for the command execution.
Throws an error if no resource is specified, if the arguments are invalid, or an error occurs during execution.
โจ Examples
example.mts
import { openSync } from '@igorskyflyer/open-resource'
openSync('https://igorskyflyer.me') // will open the default browser and navigate to the site
openSync('D:\\Data\\file.txt') // will open the text file in the default text viewer/editor๐ Changelog
๐ The changelog is available here, CHANGELOG.md.
๐ชช License
Licensed under the MIT license which is available here, MIT license.
๐ Support
๐งฌ Related
@igorskyflyer/registry-apppaths
๐ช A Node.js module for reading the AppPaths registry key on Windows. Useful for retrieving applications that can be launched from the command prompt. ๐
๐ An npm package for fetching Windows registry keys. ๐
๐ Provides a universal way of formatting file-paths in Unix-like and Windows operating systems as an alternative to the built-in path.normalize(). ๐งฌ
@igorskyflyer/windows-packages
๐ป A Node.js module for reading the Packages registry key on Windows 10+. Useful for retrieving Windows 10+ installed Store applications. ๐ฆ
@igorskyflyer/scrollend-polyfill
๐ด A performant and light (< 1.5KB) JavaScript polyfill for the scrollend Event. โธ๏ธ
๐จ๐ปโ๐ป Author
Created by Igor Dimitrijeviฤ (@igorskyflyer).
