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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ostypes

v1.0.0

Published

Submodule for Firefox addons that need js-ctypes to tap into platform (Windows, Mac, Linux/Unix) APIs.

Downloads

2

Readme

Table of Contents

How to download this into your addon

As a Submodule

The ostypes repository is meant to be used a submodule. You must be using git. To include it as a submodule open git shell and execute the following:

git submodule add [email protected]:Noitidart/ostypes FOLDER_NAME_HERE

This will add ostypes repo to your root addon directory, into a newly made folder named FOLDER_NAME_HERE. You can change that to whatever you want. You can use a path o a sub-folder such as blah1/blah2/rawr. This will create the directory "blah1" and "blah2" if they don't exist. Then it will create and download the contents into the "rawr" folder.

Updating the Submodule

The ostypes repository is very welcome to pull requests and updates. I update it myself as needed. To update the ostypes submodule that you had previously already included, cd into the sub-folder you downloaded ostypes submodule to, and then and then do git pull. This will update it to the master.

I don't use git

You don't have to use this as a submodule. Simply download the repository, then put the files wherever you want.

Platform Detection Methods

We are using platform dependent APIs so it is important to detect the platform. With both methods below, the list of of possible values is seen here - MDN :: OS_TARGET.

Off of Main Thread - Chrome Worker

By default, a OS global exists in ChromeWorkers, we will use this to determine the platform. We can access the operating system name with OS.Constants.Sys.Name.

Main Thread

OS Global

We can access the system name in the same OS global on the main thread by importing the OS.File module. We won't use all the features of the module, We will only access OS.Constants.Sys.Name to figure out the platform.

Services.jsm

The Services.jsm module has a lot of commonly used features. This is usually always imported to addons and the preferred way to get access to the same OS_TARGET variable. This is preferred to OS.File module because we don't use 99% of what comes with that module when all we need to do is get the platform name. After importing Services.jsm we can access the platform name with Services.appinfo.OS.

const {utils: Cu} = Components;
// var { Cu } = require('chrome'); // if you are using Addon SDK
Cu.import('resource://gre/modules/Services.jsm');

var os_name = Services.appinfo.OS.toLowerCase();

How to import the modules into your addon files

Off of Main Thread - Chrome Worker

You cannot use js-ctypes from a Web Worker, it must be a Chrome Worker. This ostypes module is meant to be run from a ChromeWorker, however some API methods need to be run on the main thread. The code below shows you how to import it into the main thread, it assumes the ostypes repo was download into your addon at a sub-folder in your root directory at path ./modules/ostypes.

Note for Linux/Unix Systems ostypes_x11.jsm is meant for *nix sysstems. GTK and X11 should only be used on the main thread, it will causes unexplainable crashes if used from a ChromeWorker. Inside ostypes_x11.jsm though is XCB, this is what you want to use if you want to do platform stuff on *nix systems from a ChromeWorker.

var GLOBAL_SCOPE = this;

function importOstypes() {
  importScripts('chrome://myaddon/content/ostypes/cutils.jsm');
  importScripts('chrome://myaddon/content/ostypes/ctypes_math.jsm');

  var os_name = OS.Constants.Sys.Name.toLowerCase();
  switch (os_name) {
      case 'winnt':
      case 'winmo':
      case 'wince':
              importScripts('chrome://myaddon/content/ostypes/ostypes_win.jsm');
          break;
      case 'darwin':
              importScripts('chrome://myaddon/content/ostypes/ostypes_mac.jsm');
          break;
      default:
          // we assume it is a GTK based system. All Linux/Unix systems are GTK for Firefox. Even on Qt based *nix systems.
          importScripts('chrome://myaddon/content/ostypes/ostypes_x11.jsm');
  }
}

Main Thread

Sometimes it is necessary to use on the main thread, because certain platform APIs require to be run on the main thread.

We will detect the platofrm, then we will import the the respective ostypes file.

const {utils: Cu} = Components;
// var { Cu } = require('chrome'); // if you are using Addon SDK
Cu.import('resource://gre/modules/Services.jsm');

var GLOBAL_SCOPE = this;

function importOstypes() {
  Services.scriptloader.loadSubScript('chrome://myaddon/content/ostypes/cutils.jsm', GLOBAL_SCOPE);
  Services.scriptloader.loadSubScript('chrome://myaddon/content/ostypes/ctypes_math.jsm', GLOBAL_SCOPE);

  var os_name = Services.appinfo.OS.toLowerCase();
  switch (os_name) {
      case 'winnt':
      case 'winmo':
      case 'wince':
              Services.scriptloader.loadSubScript('chrome://myaddon/content/ostypes/ostypes_win.jsm', GLOBAL_SCOPE);
          break;
      case 'darwin':
              Services.scriptloader.loadSubScript('chrome://myaddon/content/ostypes/ostypes_darwn.jsm', GLOBAL_SCOPE);
          break;
      default:
          // we assume it is a GTK based system. All Linux/Unix systems are GTK for Firefox. Even on Qt based *nix systems.
          Services.scriptloader.loadSubScript('chrome://myaddon/content/ostypes/ostypes_x11.jsm', GLOBAL_SCOPE);
  }
}

Usage after importing the files

...

Why cutils.jsm and ctypes_math.jsm?

...