@igor.dvlpr/open-resource
TypeScript icon, indicating that this package has built-in type declarations

1.1.0Β β€’Β PublicΒ β€’Β Published

Open Resource


πŸ“‚ Opens a given resource (URL, file, etc.) via the default OS handler. πŸ”Ž



πŸ’– Support further development

I work hard for every project, including this one
and your support means a lot to me!

Consider buying me a coffee. β˜•
Thank you for supporting my efforts! πŸ™πŸ˜Š


Donate to igorskyflyer

@igorskyflyer




πŸ“ƒ Table of contents



πŸ€– Features

  • πŸ’» cross-platform, for Windows, macOS, Linux and Android using:
  • ⏳ both sync and async methods
  • πŸ“ƒ supports passing of arguments

πŸ•΅πŸΌ Usage

Install it by executing:

npm i '@igor.dvlpr/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 '@igor.dvlpr/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.


🧬 Related

@igor.dvlpr/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. πŸ—ƒ


@igor.dvlpr/regkeys

πŸ“š An npm package for fetching Windows registry keys. πŸ—


@igor.dvlpr/upath

🎍 Provides a universal way of formatting file-paths in Unix-like and Windows operating systems as an alternative to the built-in path.normalize(). 🧬


@igor.dvlpr/windows-packages

πŸ’» A Node.js module for reading the Packages registry key on Windows 10+. Useful for retrieving Windows 10+ installed Store applications. πŸ“¦


@igor.dvlpr/scrollend-polyfill

πŸ›΄ A performant and light (< 1.5KB) JavaScript polyfill for the scrollend Event. ⛸️


πŸ‘¨πŸ»β€πŸ’» Author

Created by Igor Dimitrijević (@igorskyflyer).

Package Sidebar

Install

npm i @igor.dvlpr/open-resource

Version

1.1.0

License

MIT

Unpacked Size

46.8 kB

Total Files

6

Last publish

Collaborators

  • igor.dvlpr