npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

environment-latest

v1.0.1

Published

Modern TypeScript package for detecting JavaScript runtime environments and operating systems

Readme

environment-latest

npm version TypeScript License: MIT YouTube Buy Me a Coffee

Modern TypeScript package for detecting JavaScript runtime environments and operating systems

A comprehensive, zero-dependency TypeScript library for detecting JavaScript runtime environments, operating systems, browser engines, device types, and capabilities. This is an enhanced, modern alternative to the original environment package with additional features and better TypeScript support.

Why Choose environment-latest?

| Feature | environment-latest | environment | | --------------------------- | ------------------ | ----------------- | | TypeScript Support | ✅ Built-in | ❌ External types | | Zero Dependencies | ✅ | ✅ | | Modern Runtimes (Bun, Deno) | ✅ | ✅ | | Edge Functions Support | ✅ | ❌ | | Device Type Detection | ✅ | ❌ | | Browser Engine Detection | ✅ | ❌ | | Capability Detection | ✅ | ❌ | | Architecture Detection | ✅ | ❌ | | Environment Variables | ✅ | ❌ | | Comprehensive API | ✅ | ❌ |

Features

Zero Runtime Dependencies - No external dependencies for maximum compatibility
🎯 TypeScript First - Built with TypeScript 5.6+, includes complete type definitions
🔍 Comprehensive Detection - Detects 40+ different environments and capabilities
🚀 Modern Runtimes - Supports latest JavaScript runtimes (Bun, Deno, Edge Functions)
🔧 Tree Shakable - Import only what you need
📱 Device Detection - Mobile, tablet, desktop, and touch device detection
🌐 Browser Engine Detection - Chrome, Firefox, Safari, Edge, Opera
Performance Focused - Lazy evaluation and efficient detection algorithms
🏗️ Minimal Build - Built with native TypeScript compiler, no bundlers required

Installation

npm install environment-latest
yarn add environment-latest
pnpm add environment-latest
bun add environment-latest

Usage

Basic Usage

import { isBrowser, isNode, isMobile } from "environment-latest";

if (isBrowser) {
  console.log("Running in a browser!");
}

if (isNode) {
  console.log("Running in Node.js!");
}

if (isMobile) {
  console.log("Running on a mobile device!");
}

Comprehensive Detection

import { detectEnvironment } from "environment-latest";

const env = detectEnvironment();

console.log("Environment:", {
  runtime: env.isNode ? "Node.js" : env.isBrowser ? "Browser" : "Other",
  platform: env.system.platform,
  architecture: env.system.arch,
  capabilities: env.capabilities,
});

Specific Feature Detection

import {
  isChrome,
  isIos,
  isArm64,
  isDevelopment,
  getNodeVersion,
  getBrowserInfo,
} from "environment-latest";

// Browser detection
if (isChrome) {
  const browser = getBrowserInfo();
  console.log(`Chrome version: ${browser?.version}`);
}

// Platform detection
if (isIos) {
  console.log("iOS device detected");
}

// Architecture detection
if (isArm64) {
  console.log("ARM64 architecture");
}

// Environment detection
if (isDevelopment) {
  console.log("Development mode");
}

// Node.js version
const nodeVersion = getNodeVersion();
if (nodeVersion) {
  console.log(
    `Node.js ${nodeVersion.major}.${nodeVersion.minor}.${nodeVersion.patch}`
  );
}

API Reference

Runtime Environments

| Export | Type | Description | | --------------------- | --------- | ------------------------------ | | isBrowser | boolean | Web browser environment | | isNode | boolean | Node.js environment | | isBun | boolean | Bun runtime environment | | isDeno | boolean | Deno runtime environment | | isElectron | boolean | Electron environment | | isJsDom | boolean | jsdom environment | | isReactNative | boolean | React Native environment | | isWebView | boolean | WebView environment | | isCloudflareWorkers | boolean | Cloudflare Workers environment | | isVercelEdge | boolean | Vercel Edge Functions | | isNetlifyEdge | boolean | Netlify Edge Functions |

Web Worker Environments

| Export | Type | Description | | ------------------- | --------- | ---------------------------- | | isWebWorker | boolean | Any Web Worker environment | | isDedicatedWorker | boolean | Dedicated Worker environment | | isSharedWorker | boolean | Shared Worker environment | | isServiceWorker | boolean | Service Worker environment |

Operating Systems

| Export | Type | Description | | ----------- | --------- | ------------------------ | | isMacOs | boolean | macOS operating system | | isWindows | boolean | Windows operating system | | isLinux | boolean | Linux operating system | | isIos | boolean | iOS operating system | | isAndroid | boolean | Android operating system | | isFreeBSD | boolean | FreeBSD operating system | | isOpenBSD | boolean | OpenBSD operating system |

Architecture

| Export | Type | Description | | --------- | --------- | -------------------------- | | isArm64 | boolean | ARM64/AArch64 architecture | | isX64 | boolean | x64/x86_64 architecture | | is32Bit | boolean | 32-bit architecture | | is64Bit | boolean | 64-bit architecture |

Environment Types

| Export | Type | Description | | --------------- | --------- | ---------------------------------- | | isDevelopment | boolean | Development environment | | isProduction | boolean | Production environment | | isTest | boolean | Test environment | | isCI | boolean | Continuous Integration environment | | isDocker | boolean | Docker container environment |

Browser Engines

| Export | Type | Description | | ----------- | --------- | ----------------------- | | isChrome | boolean | Chrome/Chromium browser | | isFirefox | boolean | Firefox browser | | isSafari | boolean | Safari browser | | isEdge | boolean | Microsoft Edge browser | | isOpera | boolean | Opera browser |

Device Types

| Export | Type | Description | | --------------- | --------- | -------------------- | | isMobile | boolean | Mobile device | | isTablet | boolean | Tablet device | | isDesktop | boolean | Desktop device | | isTouchDevice | boolean | Touch-enabled device |

Helper Functions

getNodeVersion(): NodeVersionInfo | null

Returns Node.js version information or null if not in Node.js environment.

const version = getNodeVersion();
if (version) {
  console.log(`Node.js ${version.major}.${version.minor}.${version.patch}`);
}

getBrowserInfo(): BrowserInfo | null

Returns browser information or null if not in browser environment.

const browser = getBrowserInfo();
if (browser) {
  console.log(`${browser.name} ${browser.version} (${browser.engine})`);
}

getSystemInfo(): SystemInfo

Returns comprehensive system information.

const system = getSystemInfo();
console.log(`Platform: ${system.platform}, Architecture: ${system.arch}`);

getCapabilities(): Capabilities

Returns available platform capabilities.

const capabilities = getCapabilities();
if (capabilities.hasWebGL) {
  console.log("WebGL is supported");
}

detectEnvironment(): EnvironmentDetectionResult

Returns comprehensive environment detection result including all boolean flags, system info, and capabilities.

const env = detectEnvironment();
console.log("Complete environment info:", env);

TypeScript Support

This package is written in TypeScript and includes complete type definitions:

import type {
  EnvironmentInfo,
  NodeVersionInfo,
  BrowserInfo,
  SystemInfo,
  EnvironmentDetectionResult,
} from "environment-latest";

const handleEnvironment = (env: EnvironmentDetectionResult) => {
  // Full type safety
  if (env.isBrowser && env.capabilities.hasWebGL) {
    // Browser with WebGL support
  }
};

Performance

  • Zero Runtime Dependencies: No external dependencies to minimize bundle size
  • Lazy Evaluation: Detection logic runs only when accessed
  • Tree Shaking: Import only the detectors you need
  • Caching: Results are computed once and cached
  • Small Bundle Size: < 5KB minified and gzipped
  • Modern Build: Built with TypeScript 5.6+ and native compiler

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development

# Install dependencies (only TypeScript!)
npm install

# Run tests
npm test

# Build the package
npm run build

# Type checking
npm run typecheck

License

MIT © Noor Mohammad

Changelog

1.0.0

  • Initial release
  • Comprehensive environment detection
  • TypeScript support
  • Zero dependencies
  • 40+ detection capabilities

Made with ❤️ by Noor Mohammad