https://github.com/studimax/electron-path-ipc
Express style path for Electron IPC
https://github.com/studimax/electron-path-ipc
electron express ipc path regex
Last synced: 2 months ago
JSON representation
Express style path for Electron IPC
- Host: GitHub
- URL: https://github.com/studimax/electron-path-ipc
- Owner: studimax
- Created: 2021-04-07T21:01:51.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T06:33:27.000Z (over 3 years ago)
- Last Synced: 2025-11-07T19:10:51.470Z (7 months ago)
- Topics: electron, express, ipc, path, regex
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/electron-path-ipc
- Size: 547 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# electron-path-ipc
[](https://www.npmjs.com/package/electron-path-ipc)
[](https://github.com/google/gts)
[](https://github.com/microsoft/TypeScript)
[](https://github.com/studimax)
# Installation
```bash
# with npm
$ npm install electron-path-ipc
# with yarn
$ yarn add electron-path-ipc
```
# Usage
By default, the main process send a request to all renderer process.
```js
// main process
import {ipcMain} from 'electron-path-ipc';
ipcMain.on(':identifier/action', (headers,...args)=>{
console.log(headers.params); // {identifier: 'my-identifier'}
console.log(args); // ['hello world']
})
// renderer process
import {ipcRenderer} from 'electron-path-ipc';
ipcRenderer.send('my-identifier/action', 'hello world');
```
You can use invoke/handle in both main and renderer process.
```js
// main process
import {ipcMain} from 'electron-path-ipc';
ipcMain.handle(':identifier/action', (headers, arg) => {
console.log(headers.params); // { identifier: 'my-identifier' }
return `${arg} world !`
})
// renderer process
import {ipcRenderer} from 'electron-path-ipc';
ipcRenderer.invoke('my-identifier/action', 'hello')
.then(console.log) // 'hello world'
```
You can use prefix to simplify yours requests
```js
// main process
const prefixedIpc = ipcMain.prefix('test/').prefix('test2/');
prefixedIpc.handle(':identifier/action', (headers, arg) => {
return `${arg} world !`
})
// is the equivalent of
ipcMain.handle('test/test2/:identifier/action', (headers, arg) => {
return `${arg} world !`
})
```