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 🙏

© 2024 – Pkg Stats / Ryan Hefner

stat-mode

v1.0.0

Published

Offers convenient getters and setters for the stat `mode`

Downloads

3,482,007

Readme

stat-mode

Offers convenient getters and setters for the stat mode

Build Status

You know that mode property on the fs.Stat object that you probably usually just ignore? Well there's acutally a lot of information packed into that number.

The specific information includes:

This module helps you extract that information.

All the getters are also setters, which change the mode property appropriately. This is useful for when you have to build up your own fs.Stat object for whatever reason (like when implementing a FUSE filesystem.

Installation

$ npm install stat-mode

Example

So given some arbitrary file (let's say /bin/echo):

$ ls -l /bin/echo
-rwxr-xr-x 1 root wheel 14128 Aug 11  2013 /bin/echo

We can inspect it using the fs.stat() call and creating a Mode instance on top of it.

var fs = require('fs');
var Mode = require('stat-mode');

fs.stat('/bin/echo', function (err, stat) {
  if (err) throw err;

  // create a "Mode" instance on top of the `stat` object
  var mode = new Mode(stat);

  // you can check what kind of file it is:
  mode.isDirectory();
  // false

  mode.isFIFO();
  // false

  mode.isFile();
  // true


  // and you can also check individual owner, group and others permissions
  mode.owner.read;
  // true

  mode.owner.write;
  // true

  mode.owner.execute;
  // true

  mode.group.read;
  // true

  mode.group.write;
  // false

  mode.group.execute;
  // true

  mode.others.read;
  // true

  mode.others.write;
  // false

  mode.others.execute;
  // true


  // the `toString()` output resembes the `ls -l` output:
  mode.toString();
  // '-rwxr-xr-x'
});

API

new Mode(Object stat) → Mode

You must pass in "stat" object to the Mode constructor. The "stat" object can be a real fs.Stat instance, or really any Object with a mode property.

mode.isDirectory([Boolean set]) → Boolean

Returns true if the mode's file type is "directory", false otherwise. If you pass true to the function, then the mode will be set to "directory".

mode.isFile([Boolean set]) → Boolean

Returns true if the mode's file type is "file", false otherwise. If you pass true to the function, then the mode will be set to "file".

mode.isBlockDevice([Boolean set]) → Boolean

Returns true if the mode's file type is "block device", false otherwise. If you pass true to the function, then the mode will be set to "block device".

mode.isCharacterDevice([Boolean set]) → Boolean

Returns true if the mode's file type is "character device", false otherwise. If you pass true to the function, then the mode will be set to "character device".

mode.isSymbolicLink([Boolean set]) → Boolean

Returns true if the mode's file type is "symbolic link", false otherwise. If you pass true to the function, then the mode will be set to "symbolic link".

mode.isFIFO([Boolean set]) → Boolean

Returns true if the mode's file type is "FIFO", false otherwise. If you pass true to the function, then the mode will be set to "FIFO".

mode.isSocket([Boolean set]) → Boolean

Returns true if the mode's file type is "socket", false otherwise. If you pass true to the function, then the mode will be set to "socket".

mode.owner.read → Boolean [Getter/Setter]

true if the mode is "owner read" rights, false otherwise.

mode.owner.write → Boolean [Getter/Setter]

true if the mode is "owner write" rights, false otherwise.

mode.owner.execute → Boolean [Getter/Setter]

true if the mode is "owner execute" rights, false otherwise.

mode.group.read → Boolean [Getter/Setter]

true if the mode is "group read" rights, false otherwise.

mode.group.write → Boolean [Getter/Setter]

true if the mode is "group write" rights, false otherwise.

mode.group.execute → Boolean [Getter/Setter]

true if the mode is "group execute" rights, false otherwise.

mode.others.read → Boolean [Getter/Setter]

true if the mode is "others read" rights, false otherwise.

mode.others.write → Boolean [Getter/Setter]

true if the mode is "others write" rights, false otherwise.

mode.others.execute → Boolean [Getter/Setter]

true if the mode is "others execute" rights, false otherwise.