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

os-restrictor

v1.0.7

Published

A utility to restrict execution and styling based on OS

Readme

OS Restrictor - A Utility to Restrict Execution to Specific Operating Systems

OS Restrictor is a versatile utility that allows you to control function execution, UI component rendering, and CSS class application based on the user's operating system. It works in both browser and Node.js environments and supports JavaScript, React, Svelte, and HTML.

Features

  • Detects the user's OS (Windows, macOS, Linux, Android, iOS)
  • Restricts function execution to specific OS platforms
  • Dynamically applies CSS classes based on the OS
  • Controls visibility of React and Svelte components
  • Supports class-based restriction in React and Svelte
  • Works seamlessly in JavaScript, React and Svelte

Installation

Install the package using npm:

npm install os-restrictor

OS options

Android
Linux 
Windows
macOS
Ios

Usage

1. Import OS Restrictor in Your Project

import osRestrictor from "os-restrictor";

2. detect current os

console.log("Detected OS:", osRestrictor.currentOS);

2. Restrict Function Execution Based on OS

osRestrictor.run(["Windows", "macOS"], () => {
  console.log("This runs only on Windows or macOS");
});

3. Apply CSS Classes Dynamically Based on OS (JavaScript & HTML)

const myDiv = document.getElementById("myDiv");
osRestrictor.applyClass(myDiv, ["Windows"], "bg-blue-500 text-white");

4. Use in React (Component Restriction)

import React from "react";
import osRestrictor from "os-restrictor";

const OSComponent = () => {
  if (!osRestrictor.isAllowed(["Windows"])) return null;
  return <div className="p-4 bg-blue-500 text-white">Hello, Windows User!</div>;
};
export default OSComponent;

5. Use in Svelte (Component Restriction)

<script>
  import osRestrictor from "os-restrictor";
  let show = osRestrictor.isAllowed(["macOS"]);
</script>

{#if show}
  <div class="p-4 bg-green-500 text-white">Hello, macOS User!</div>
{/if}

6. Use in JavaScript (Class-Based Restriction)

class OSRestrictedComponent {
  constructor(element, allowedOS, className) {
    this.element = document.querySelector(element);
    this.allowedOS = allowedOS;
    this.className = className;
    this.applyRestriction();
  }
  applyRestriction() {
    if (this.element) {
      osRestrictor.applyClass(this.element, this.allowedOS, this.className);
    }
  }
}

new OSRestrictedComponent("#myDiv", ["Linux"], "bg-red-500 text-white");

7. Restrict Function Execution in React

import React from "react";
import osRestrictor from "os-restrictor";

const restrictedFunction = () => {
  osRestrictor.run(["Linux"], () => {
    alert("This function only runs on Linux!");
  });
};

const OSFunctionButton = () => (
  <button onClick={restrictedFunction}>Run Function</button>
);

export default OSFunctionButton;

8. Restrict Function Execution in Svelte

<script>
  import osRestrictor from "os-restrictor";

  function restrictedFunction() {
    osRestrictor.run(["macOS"], () => {
      alert("This function only runs on macOS!");
    });
  }
</script>

<button onclick={restrictedFunction}>Run Function</button>

9. Class-Based Restriction in React

import osRestrictor from "os-restrictor";

const Test = () => {
  console.log("Detected OS:", osRestrictor.currentOS);

  if (!osRestrictor.isAllowed(["Linux"])) {
    return null; // Hide component if the OS is NOT linux
  }

  return (
    <div className="p-4 bg-blue-500 text-white">
      Hello, LinuxUser! Detected OS: {osRestrictor.currentOS}
    </div>
  );
};

export default Test;

10. Class-Based Restriction in Svelte

<script>
  import osRestrictor from "os-restrictor";
  
  export let allowedOS = ["Linux", "Android"];
  let show = osRestrictor.isAllowed(allowedOS);
</script>

{#if show}
  <div class="p-4 bg-green-500 text-white">Hello, Linux & Android User!</div>
{/if}

With OS Restrictor, you can easily control what parts of your application are available based on the user's operating system. This makes it a power