The Principal Dev – Masterclass for Tech Leads

The Principal Dev – Masterclass for Tech LeadsNov 27-28

Join

electron-util

Useful utilities for Electron apps and modules

You can use this package directly in both the main and renderer process.

This package is organized into three parts:

To use features from the "main" part in the renderer process, you will need to set up IPC channels.

Install

npm install electron-util

[!NOTE] Requires Electron 37 or later.

Usage

The “shared” API you can access directly:

import {is} from 'electron-util';

console.log(is.macos && is.main);
//=> true

For the “main” API, use the /main sub-export:

import {isDev} from 'electron-util/main';

console.log(isDev);
//=> false

For the “node” API, use the /node sub-export:

import {isElectron, fixPathForAsarUnpack} from 'electron-util/node';

console.log(isElectron);
//=> true when running in Electron, false in plain Node.js

const fixedPath = fixPathForAsarUnpack('/path/app.asar/binary');
//=> '/path/app.asar.unpacked/binary' when in ASAR, or unchanged otherwise

API

Documentation (The service is broken)

Look at the types for now.

Join libs.tech

...and unlock some superpowers

GitHub

We won't share your data with anyone else.