node-selection
Advanced tools
Comparing version
{ | ||
"name": "node-selection", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Get current selected text by using system accessibility APIs", | ||
@@ -5,0 +5,0 @@ "gypfile": true, |
# node-selection | ||
> Get current selected text by using system accessibility APIs. | ||
> Get current selected text by using system accessibility APIs | ||
## Prerequisite | ||
## Installation | ||
- Xcode (for macOS) | ||
- Visual Studio (for Windows) | ||
## Install | ||
```sh | ||
@@ -18,19 +13,52 @@ npm i node-selection | ||
### `checkAccessibilityPermissions({ prompt = false }): Promise<boolean>` | ||
### Accessibility permissions | ||
`getSelection` requires accessibility permissions to be granted. | ||
This function checks if accessibility permissions are granted. | ||
macOS requires accessibility permissions to be granted before a program | ||
can control the Mac by using accessibility features. | ||
If `prompt` is set to `true`, a prompt window that allows user | ||
open Accessibility panel will be shown. | ||
#### `checkAccessibilityPermissions([options])` | ||
On Windows, it always returns `true`. | ||
- `options`: `<Object>` | ||
- `prompt`: `<boolean>` **Default:** `false` | ||
### `getSelection(): Promise<{ text?: string }>` | ||
Returns: `<Promise>` Fullfills upon success with a boolean indicating | ||
whether accessibility permissions have been granted to this program. | ||
Get current selected text. An error will be thrown if this operation | ||
is failed or nothing is selected. | ||
If `prompt` is `true`, a prompt window will be shown when accessibility | ||
permissions have not been granted. | ||
## Example | ||
If this method is invoked on non-macOS platform, it always returns `true`. | ||
See [example/getSelection.js](example/getSelection.js). | ||
```js | ||
import { checkAccessibilityPermissions } from 'node-selection'; | ||
if (!(await checkAccessibilityPermissions({ prompt: true }))) { | ||
console.log('grant accessibility permissions and restart this program'); | ||
process.exit(1); | ||
} | ||
``` | ||
### Selection | ||
#### `getSelection()` | ||
Returns: `<Promise>` Fullfills upon success with an object with one property: | ||
- `text`: `<string>` | `<undefined>` Current selected text. | ||
```js | ||
import { getSelection } from 'node-selection'; | ||
try { | ||
const { text } = await getSelection(); | ||
console.log('current selection:', text); | ||
} catch (error) { | ||
// no valid selection | ||
console.error('error', error); | ||
} | ||
``` | ||
## Examples | ||
- [Node](example/node-example) | ||
- [Electron](example/electron-example) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
188177
855.02%24
26.32%4506
3237.78%64
77.78%1
Infinity%3
200%