1.0.0 • Published 5 years ago

stat-mode v1.0.0

Weekly downloads
481,140
License
MIT
Repository
github
Last release
5 years ago

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.

@someok/txt2epubfun-runtimes-test@everything-registry/sub-chunk-2821xchmodwukongsgntj-builder-utilshinobi-ftpdshopify-ftp-accessshopify-ftp2shimo-funreader-stattechfi-cliserve-index-lighttest-public-proser-ftpdmetalsmith-copy-assets-540metalsmith-assetsmetalsmith-assets-2metalsmith-assets-exmetalsmithmetalsmith-gitmetalsmith-include-fileslbrhyper-gateway-ftpibackuptoolid-lsmrs-smith-assetsmonitorg-builder-utilhutoolsifuckuptoolgulp-chflagsgulp-chmodh5-templetekayhendo-clihendo-cli-luozheaoghost-clils-cmdorganization-robotics-sensors-website-application-electronorganization-algorithm-model-research-website-application-electronorganization-application-ui-ux-website-application-electronorganization-artificial-intelligence-computer-vision-website-application-electronpublish-previewnpmdoctorprofoundjspunkernetworksetup-proxyraml2slaterc-ghost-clirecess-buildrf-lsstaticsmithskarsignalk-serversimple-ftpdsofa-dev-utils@akiroz/simple-ftpd@chartiq/vinyl-tar7ghost-cli@delicate/builder-utilzcesmithxys_cliwcq-vuewebfmunexpected-documentation-site-generator@johnf/electron-builder-util@homeofthings/node-sys@igames/ghost-cli@git-stack/server-core@infinitebrahmanuniverse/nolb-stat-@krisdages/builder-util@loftysoul/soul-cli@lifter/networksetup-proxy@lifter/lifter-app@nisyaban/metalsmith@mike-north/metalsmith@monitorg/builder-util@jamesperet/codex-server@khulnasoft/fun@oleavr/ftpd@riscv-forks/builder-util@svrooij/ftpd@someok/node-utils@replace5/builder-util@rstacruz/pnpmelectron-builder-utilextrastat2@theia/filesystemfind-file@vercel/fun@walkthunder/builder-util@zeit/fun@zce/ghost-cliapeman-task-js-beautifyfs-chmodftpdftpd-with-resetbetter-statsbuilder-utilbuilder-util-china
1.0.0

5 years ago

0.3.0

6 years ago

0.2.2

8 years ago

0.2.1

10 years ago

0.2.0

11 years ago

0.1.0

11 years ago

0.0.1

11 years ago