Plugin API
English
English
  • Getting Started
    • Introduction
    • Your First Plugin
    • File Structure Overview
    • Plugin Types
      • Window
      • Background Service
      • Format Extension
      • Inspector
    • Debug Plugin
  • Distribution
    • Prepare Plugin
    • Package Plugin
    • Publish Plugin
    • Update Plugin
    • Developer Policies
    • Plugin Icon Template
  • Developer Guide
    • manifest.json Configuration
    • Retrieve Data
    • Modify Data
    • Access Local Files
    • Issue Network Requests
    • Using Node.js Native API
    • Using Third-Party Modules
    • Multilingual (i18n)
    • Frameless Window
  • API Reference
    • event
    • item
    • folder
    • tag
    • tagGroup
    • library
    • window
    • app
    • os
    • screen
    • notification
    • contextMenu
    • dialog
    • clipboard
    • drag
    • shell
    • log
  • Extra Moudle
    • FFmpeg
Powered by GitBook
On this page
  • Using the Third-Party Module is.js
  • Third-Party Package Management Tool: NPM
  1. Developer Guide

Using Third-Party Modules

In addition to Node.js's native APIs, you can also use third-party modules in your plugin code. These third-party modules for Node.js are created and maintained by community developers, offering a var

Using the Third-Party Module is.js

Using third-party modules is similar to using native modules; you simply need to import them using the require() function.

Taking is.js as an example, it is a data type checking library for JavaScript. It provides a set of methods to determine if a variable's data type meets expectations.

First, you need to install the is.js module in Node.js using the following command:

npm install is_js --save

Note: The npm package name for is.js is is_js, with an underscore in the name.

After installation, you can use the is.js module in your Node.js application process. For example, you can import the is.js module and use its functions like this:

const is = require('is_js');

if (is.number(x)) {
  console.log('x is a number');
}
else {
  console.log('x is not a number');
}

With the is.js library, you can easily perform type checks on variables in JavaScript, avoiding errors caused by type mismatches.

If you want to integrate it into the Eagle plugin, here is an example code and its execution result:

const is = require('is_js');

eagle.onPluginCreate(() => {
    var x = 1;

    if (is.number(x)) {
        document.write('x is a number');
    } else {
        document.write('x is not a number');
    }
});

The example project above can be obtained here


Third-Party Package Management Tool: NPM

npm is the official package management tool for Node.js that provides a convenient way to manage third-party modules and publish your own modules. With npm, you can quickly install modules using the npm install command. npm offers powerful module management features to help you better manage project dependencies and module versions, improving development efficiency.

Additionally, npm provides an online module repository where you can search and download third-party modules. Overall, npm is an indispensable tool for Node.js developers, offering a range of practical features to help you better develop and manage your projects.

npm Official Website - https://www.npmjs.com/

PreviousUsing Node.js Native APINextMultilingual (i18n)

Last updated 1 year ago

Execution result