@alwatr/platform-info

中文文档
10.4.0发布于 2026/10/01MITTypeScriptES Module零依赖近 30 天下载 2987

This module provides a way to detect the current platform where the script is running. It defines a constant platformInfo which holds the information about the current platform.

原始使用文档
文档目录6 节
  1. PlatformInfo Object
  2. Development Mode Detection
  3. Installation
  4. Usage
  5. Sponsors
  6. Contributing

Platform Info

This module provides a way to detect the current platform where the script is running. It defines a constant platformInfo which holds the information about the current platform.

PlatformInfo Object

The platformInfo constant object has the following properties:

  • name: The name of the current platform. It can be 'browser', 'node', 'semi-node', or 'unknown'.
  • development: A boolean indicating whether the NODE_ENV environment variable is not set to production or in browser location.hostname is localhost or 127.xxx.
  • isNode: A boolean indicating whether the current platform is node.js.
  • isBrowser: A boolean indicating whether the current platform is a browser.
  • isWebWorker: A boolean indicating whether the current platform is a web worker.
  • isDeno: A boolean indicating whether the current platform is Deno.
  • isNw: A boolean indicating whether the current platform is nw.js.
  • isElectron: A boolean indicating whether the current platform is Electron.

Development Mode Detection

The code also checks whether the script is running in development mode. If the script is running in a browser, it checks if the hostname is 'localhost' or 127.xxx. If the script is running in a 'semi-node' environment, it checks if the NODE_ENV environment variable is not set to 'production'. The result is stored in the development property of the platformInfo object.

Installation

yarn add @alwatr/platform-info

Usage

import {platformInfo} from '@alwatr/platform-info';

console.log(platformInfo.name); // 'browser' | 'node' | 'semi-node' | 'unknown'
console.log(platformInfo.development); // true | false
console.log(platformInfo.isNode); // true | false
console.log(platformInfo.isBrowser); // true | false

Sponsors

The following companies, organizations, and individuals support Nanolib ongoing maintenance and development. Become a Sponsor to get your logo on our README and website.

Contributing

Contributions are welcome! Please read our contribution guidelines before submitting a pull request.

版本与发布记录

@alwatr/platform-info 共发布 93 个版本,首次发布于 2023/12/23;过去 12 个月发布了 37 个版本。

版本发布日期距今
10.4.0latest2026/10/011 个月前
10.3.02026/09/211 个月前
10.2.02026/09/091 个月前
10.1.02026/08/312 个月前
10.0.02026/07/263 个月前
9.38.22026/07/123 个月前

关于 @alwatr/platform-info 的常见问题

@alwatr/platform-info 是什么?

This module provides a way to detect the current platform where the script is running. It defines a constant platformInfo which holds the information about the current platform.

如何安装 @alwatr/platform-info?

在项目目录运行 npm install @alwatr/platform-info,或使用 pnpm add / yarn add / bun add。

@alwatr/platform-info 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@alwatr/platform-info 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@alwatr/platform-info 可以商用吗?

@alwatr/platform-info 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@alwatr/platform-info 的下载量有多少?

根据 npm 官方下载统计,@alwatr/platform-info 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,987 次,日均约 100 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@alwatr/platform-info 还在维护吗?

最新版本 10.4.0 发布于 2026/10/01(1 个月前);至今共发布 93 个版本,其中过去 12 个月发布了 37 个;首次发布于 2023/12/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。