JSPM

js-runtime-check

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q12022F
  • License ISC

A npm package to check if this is client or server

Package Exports

  • js-runtime-check
  • js-runtime-check/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (js-runtime-check) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

js-runtime-check

A simple utility function to determine if JavaScript code is currently executing on the client or server side.

Installation

Install via npm:

npm install js-runtime-check

Or via yarn:

yarn add js-runtime-check

Usage

import { isServer } from "js-runtime-check";

// Example usage
if (isServer()) {
  console.log("Code is running on the server side.");
} else {
  console.log("Code is running on the client side.");
}

API

isServer()

  • Returns: boolean - true if code is running on the server side, false if running on the client side.

Example

import { isServer } from "js-runtime-check";

if (isServer()) {
  // Code to execute on the server side
} else {
  // Code to execute on the client side
}

Contributing

Contributions are welcome! Please feel free to open issues or submit pull requests on GitHub.

License

This project is licensed under the MIT License - see the LICENSE file for details.