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

node-xattr

v1.3.5

Published

[![npm version](https://badge.fury.io/js/node-xattr.svg)](https://badge.fury.io/js/node-xattr)

Readme

npm version

node-xattr

A library to manipulate xattr on macOS with Typescript support. APIs provided by this library are similar to node's fs module.

What's xattr

Extended attributes are arbitrary metadata stored with a file, but separate from the filesystem attributes (such as modification time or file size). The metadata is often a null-terminated UTF-8 string, but can also be arbitrary binary data.

Xattr is a mechanism provided by the system. With xattr, you can store your own data as attributes to file. Also, you can pass data to Finder or other apps.

For example, you can set custom icon for a file:

You can add a com.apple.quarantine xattr to make the system check the origin of the file you download:

Or you can remove this xattr on an existing file, and this window will not display.

Requirements

Runtime

  • Node.js v10+ (Electron with Node.js 10+ works)

Development

  • macOS 10.14+ with XCode

Installation

$ yarn add node-xattr

When to use the sync version

Technically, the sync version would be a little faster. Because the async version waits for a queue to schedule. Also, The sync verion is realtime, it would be an advantage in some scenarios. The disadvantage of the sync version is that it will probably block the process. So DO NOT use sync version in some UI process(such as the renderer process of Electron). The best scenario to use sync version is in background worker/process/thread.

Set xattr

setXattrSync(path: string, name: string, value: string | Buffer): void;

setXattr(path: string, name: string, value: string | Buffer): Promise<void>;

Sync

const { setXattrSync } = require('node-xattr');
setXattrSync('./test.txt', 'key', 'value');

Async

const { setXattr } = require('node-xattr');

setXattr('./test.txt', 'key', 'value').catch(err => console.error(err));

Get xattr

getXattrSync(path: string, name: string): Buffer;

getXattrSync(path: string, name: string, encoding: string): string;

getXattr(path: string, name: string): Promise<Buffer>;

getXattr(path: string, name: string, encoding: string): Promise<string>;

Sync

const { getXattrSync } = require('node-xattr');
const buffer = getXattrSync('./test.txt', 'key');
const string = getXattrSync('./test.txt', 'key', 'utf8');

Async

const { getXattr } = require('node-xattr');

getXattr('./test.txt', 'key', function (err, buffer) {
  if (err) {
    console.error(err);
    return;
  }
  console.log(buffer);
});

getXattr('./test.txt', 'key').then(buffer => console.log(buffer)).catch(err => console.error(err));

getXattr('./test.txt', 'key', 'utf8').then(str => console.log(str)).catch(err => console.error(err));

List xattr

listXattrSync(path: string): string[];

listXattr(path: string): Promise<string[]>;

Sync

const { listXattrSync } = require('node-xattr');

const list = listXattrSync('./test.txt');

Async

const { listXattr } = require('node-xattr');

listXattr('./test.txt').then(list => console.log(list)).catch(err => console.error(err));

Remove xattr

removeXattrSync(path: string, name: string): void;

removeXattr(path: string, name: string): Promise<void>;

Sync

const { removeXattrSync } = require('node-xattr');
removeXattrSync('./test.txt', 'key');

Async

const { removeXattr } = require('node-xattr');
removeXattr('./test.txt', 'key').catch(err => console.error(err));

Set Custom Icon

setCustomIcon are in macUtils namespace:

setCustomIcon(filePath: string, iconPath: string): Promise<void>;
setCustomIconSync(filePath: string, iconPath: string): void;

Sync

const { macUtils } = require('node-xattr');

macUtils.setCustomIconSync(TestFile, iconPath);

Async

const { macUtils } = require('node-xattr');
macUtils.setCustomIcon(TestFile, iconPath).catch(err => console.log(err));

Parse FileMeta

This library provide utils to parse some content written by system:

serializeArrayOfString(content: string[]): Buffer;
deserializeArrayOfString(buffer: Buffer): string[];

You can use above functions in macUtils to parse com.apple.metadata:kMDItemWhereFroms.