Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jukben/platform-select
Tiny function which evaluates function based on the platform (process.platform)
https://github.com/jukben/platform-select
Last synced: about 1 month ago
JSON representation
Tiny function which evaluates function based on the platform (process.platform)
- Host: GitHub
- URL: https://github.com/jukben/platform-select
- Owner: jukben
- License: mit
- Created: 2018-04-16T23:28:46.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-10-07T12:57:28.000Z (about 3 years ago)
- Last Synced: 2024-10-12T13:26:56.326Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 46.9 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Platform Select
This little library allows you to define precedence which function evaluate based on the platform.
## Usage
```js
select({
[platform: string]: Function
},
[platform: string]: Function
}, ...): Promise
```Currently, possible "Platform" values are ([defined by Node](https://nodejs.org/api/process.html#process_process_platform)):
* 'aix'
* 'darwin'
* 'freebsd'
* 'linux'
* 'openbsd'
* 'sunos'
* 'win32'You can use `_` as fallback for _undefined_ platform.
The function returns Promise of value which is provided by function which win the selection, otherwise, throw an error in format `No suitable job for "darwin"`
The function could also throw an error `Function for current platform ("darwin") is not defined!` when you omit specifics platform definition.
## Example
```js
const select = require("platform-select");
const open = app => () => opn("https://google.com", { app });select(
{
darwin: open("google chrome"),
win32: open("chrome"),
// on other platforms than Windows or Mac try to open...
_: open("google-chrome")
},
{
// if attempt to run Google Chrome was unsuccessful, let's run Safari...
darwin: open("safari")
}
).catch(e => {
// when user is on Darwin and doesn't have Google Chrome or Safari (probably impossible :))
console.error("Unable to run!", e);
}).then(e => {
console.log("Returned value from 'open' function: ", e)
};
```