GithubHelp home page GithubHelp logo

is-electron's Introduction

is-electron build status Coverage Status

NPM

Detect if running in Electron.

Installation

npm install --save is-electron

Usage

import isElectron from 'is-electron';

console.log(isElectron());

License

Copyright (c) 2016 Cheton Wu

Licensed under the MIT License.

is-electron's People

Contributors

cheton avatar hpello avatar hugomrdias avatar nixxquality avatar venryx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

is-electron's Issues

Typings broken since version 2.2.1

In the newest version, I think the index.d.ts is broken.
When using it with typescript 4.5.2, I get the error
[2] node_modules/is-electron/index.d.ts(1,1): error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier.

Proposal: Caching the result

Because this module detects the runtime, we can assume that the result will always be the same, no matter at which time the function is called.
I did some tests and I think we should cache the result instead of checking all these objects again and again when isElectron() is called multiple times.

I wrote some code to demonstrate the performance-benefit:

import isElectron from 'is-electron';

// currently
const time0 = performance.now();
for (let i = 0; i < 1000; i++) {
    isElectron();
}
const time1 = performance.now();
console.log('Non-Cached ' + (time1 - time0) + 'ms');

// with caching
let _isElectronCached = null;
const isElectronCached = function() {
    if (_isElectronCached === null) _isElectronCached = isElectron();
    return _isElectronCached;
}


const time2 = performance.now();
for (let i = 0; i < 1000; i++) {
    isElectronCached();
}
const time3 = performance.now();
console.log('Cached ' + (time3 - time2) + 'ms');

The results in the current electron-version are:

Non-Cached 0.2699999999999818ms
Cached 0.12999999999988177ms

When the test is run in a non-electron-runtime, all 3 checks will be run which slows this down some more. Here in google chrome:

Non-Cached 13.114999999999782ms
Cached 0.4899999999997817ms

Release please?

#5 fixes an error with the typescript typings and was merged but not published, could it be released please?

Function export vs constant?

Why does this module export a function instead of just a constant isElectron: boolean? Whether or not we are currently in electron should never change, so I don't see why we'd want to have to invoke isElectron() potentially a bunch of times instead of just running that code once

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.