0.1.3 • Published 6 years ago

system-icon v0.1.3

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

system-icon

Get associated file/folder icon for Node.js.

Installation

$ npm install --save system-icon

Supported platforms

  • macOS 10.6 or later
  • Windows Vista or later

Usage

Get icon for file or folder path:

const {writeFileSync} = require('fs');
const {
  getIconForPath,
  ICON_SIZE_MEDIUM
} = require('system-icon');

getIconForPath("/path/to/file_or_folder", ICON_SIZE_MEDIUM, (err, result) => {
  if (err) {
    console.error(err);
  } else {
    writeFileSync("icon.png", result);
  }
});

Get icon for file extension:

const {writeFileSync} = require('fs');
const {
  getIconForExtension,
  ICON_SIZE_MEDIUM
} = require('system-icon');

getIconForExtension(".ext", ICON_SIZE_MEDIUM, (err, result) => {
  if (err) {
    console.error(err);
  } else {
    writeFileSync("icon.png", result);
  }
});

API

Constants

Size constants

The correspondence between the size constants and the icon size actually obtainable on each platform is as follows:

ConstantWindowsmacOS
ICON_SIZE_EXTRA_SMALL16x1616x16
ICON_SIZE_SMALL32x3232x32
ICON_SIZE_MEDIUM64x6464x64
ICON_SIZE_LARGE256x256256x256
ICON_SIZE_EXTRA_LARGE256x256512x512

Functions

getIconForPath(path, size, callback)

Gets associated icon for file or folder path, and returns it in the PNG format.

getIconForExtension(extension, size, callback)

Gets associated icon for file extension, and returns it in the PNG format.

License

MIT