# サードパーティモジュールの使用

## サードパーティモジュール is.js の利用

サードパーティモジュールの利用方法は、ネイティブモジュールの利用と似ており、`require()`関数でモジュールを読み込むだけです。

例として`is.js`を挙げます。`is.js`は、JavaScriptのデータタイプ判定ライブラリです。一連の方法で、変数のデータタイプが期待通りであるかを判定します。

まず、Node.jsで`is.js`モジュールをインストールする必要があります。以下のコマンドでインストールできます：

```bash
npm install is_js --save
```

{% hint style="warning" %}
注意：is.jsのnpmパッケージ名はis\_jsで、アンダースコアが含まれています。
{% endhint %}

インストールが完了すると、Node.jsアプリケーションで`is.js`モジュールを使用できます。例えば、以下の方法で`is.js`モジュールを導入し、その関数を使用することができます：

```javascript
const is = require('is_js');

if (is.number(x)) {
  console.log('xは数字です');
}
else {
  console.log('xは数字ではありません');
}
```

`is.js`ライブラリを使えば、JavaScriptの変数に対して簡単に型判定を行い、型不一致によるエラーを避けることができます。

Eagleプラグインに統合する場合、以下にサンプルコードと実行結果を示します：

```javascript
const is = require('is_js');

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

    if (is.number(x)) {
        document.write('xは数字です');
    } else {
        document.write('xは数字ではありません');
    }
});
```

<figure><img src="/files/IkhaRSpBEUcRKDGLtMYA" alt=""><figcaption><p>実行結果</p></figcaption></figure>

{% hint style="info" %}
上記のサンプルプロジェクトは[こちら](https://github.com/eagle-app/eagle-plugin-examples/tree/main/3rd-party)で入手可能です。
{% endhint %}

***

## サードパーティパッケージ管理ツール：NPM <a href="#zql65" id="zql65"></a>

npmはNode.jsの公式パッケージ管理ツールであり、サードパーティモジュールの管理や自身のモジュールの公開に便利な方法を提供しています。npmを通じて、`npm install`コマンドで簡単にモジュールをインストールできます。npmは強力なモジュール管理機能を提供し、プロジェクトの依存関係やモジュールバージョンの管理を助け、プロジェクトの開発効率を向上させます。

また、npmはオンラインのモジュールリポジトリも提供しており、ここでサードパーティモジュールを検索したりダウンロードしたりできます。全体として、npmはNode.js開発者にとって欠かせないツールであり、一連の便利な機能を提供して、あなたのプロジェクトの開発と管理をより良くするのに役立ちます。

{% hint style="info" %}
**npm公式ウェブサイト -** <https://www.npmjs.com/>
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.eagle.cool/plugin-api/ja-jp/tutorial/3rd-modules.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
