You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

node-selection

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-selection - npm Package Compare versions

Comparing version

to
0.1.5

example/electron-example/main.js

2

package.json
{
"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