How to use nsfw - 8 common examples

To help you get started, we’ve selected a few nsfw examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github atom / github / lib / models / file-system-change-observer.js View on Github external
if (workdirOrHeadEvent) {
          this.logger.showWorkdirOrHeadEvents();
          this.didChangeWorkdirOrHead();
        }
      }
    };

    if (this.hasAtomAPI) {
      // Atom with watchPath API

      this.currentFileWatcher = await watchPath(this.repository.getWorkingDirectoryPath(), {}, handleEvents);
      this.logger.showStarted(this.repository.getWorkingDirectoryPath(), 'Atom watchPath');
    } else {
      // Atom pre-watchPath API

      this.currentFileWatcher = await nsfw(
        this.repository.getWorkingDirectoryPath(),
        events => {
          const translated = events.map(event => {
            const payload = {
              action: actionText.get(event.action) || `(Unknown action: ${event.action})`,
              path: path.join(event.directory, event.file || event.newFile),
            };

            if (event.oldFile) {
              payload.oldPath = path.join(event.directory, event.oldFile);
            }

            return payload;
          });

          handleEvents(translated);
github eclipse-theia / theia / packages / core / src / node / logger-cli-contribution.ts View on Github external
return nsfw(filename, async (events: nsfw.ChangeEvent[]) => {
            try {
                for (const event of events) {
                    switch (event.action) {
                        case nsfw.actions.CREATED:
                        case nsfw.actions.MODIFIED:
                            await this.slurpLogConfigFile(filename);
                            this.logConfigChangedEvent.fire(undefined);
                            break;
                    }
                }
            } catch (e) {
                console.error(`Error reading log config file ${filename}: ${e}`);
            }
        }).then((watcher: nsfw.NSFW) => {
            watcher.start();
github atom / github / lib / models / file-system-change-observer.js View on Github external
import {Emitter} from 'event-kit';
import nsfw from 'nsfw';
import {watchPath} from 'atom';

import path from 'path';

import EventLogger from './event-logger';

const actionText = new Map([
  [nsfw.actions.CREATED, 'created'],
  [nsfw.actions.DELETED, 'deleted'],
  [nsfw.actions.MODIFIED, 'modified'],
  [nsfw.actions.RENAMED, 'renamed'],
]);

export default class FileSystemChangeObserver {
  constructor(repository) {
    this.hasAtomAPI = watchPath !== undefined;

    this.emitter = new Emitter();
    this.repository = repository;
    this.logger = new EventLogger('fs watcher');

    this.started = false;
  }

  async start() {
    await this.watchRepository();
github atom / github / lib / models / file-system-change-observer.js View on Github external
import {Emitter} from 'event-kit';
import nsfw from 'nsfw';
import {watchPath} from 'atom';

import path from 'path';

import EventLogger from './event-logger';

const actionText = new Map([
  [nsfw.actions.CREATED, 'created'],
  [nsfw.actions.DELETED, 'deleted'],
  [nsfw.actions.MODIFIED, 'modified'],
  [nsfw.actions.RENAMED, 'renamed'],
]);

export default class FileSystemChangeObserver {
  constructor(repository) {
    this.hasAtomAPI = watchPath !== undefined;

    this.emitter = new Emitter();
    this.repository = repository;
    this.logger = new EventLogger('fs watcher');

    this.started = false;
  }
github eclipse-theia / theia / packages / filesystem / src / node / nsfw-watcher / nsfw-filesystem-watcher.ts View on Github external
let watcher: nsfw.NSFW | undefined = await nsfw(fs.realpathSync(basePath), (events: nsfw.ChangeEvent[]) => {
            for (const event of events) {
                if (event.action === nsfw.actions.CREATED) {
                    this.pushAdded(watcherId, this.resolvePath(event.directory, event.file!));
                }
                if (event.action === nsfw.actions.DELETED) {
                    this.pushDeleted(watcherId, this.resolvePath(event.directory, event.file!));
                }
                if (event.action === nsfw.actions.MODIFIED) {
                    this.pushUpdated(watcherId, this.resolvePath(event.directory, event.file!));
                }
                if (event.action === nsfw.actions.RENAMED) {
                    this.pushDeleted(watcherId, this.resolvePath(event.directory, event.oldFile!));
                    this.pushAdded(watcherId, this.resolvePath(event.newDirectory || event.directory, event.newFile!));
                }
            }
        }, {
                errorCallback: error => {
github eclipse-theia / theia / packages / filesystem / src / node / nsfw-watcher / nsfw-filesystem-watcher.ts View on Github external
let watcher: nsfw.NSFW | undefined = await nsfw(fs.realpathSync(basePath), (events: nsfw.ChangeEvent[]) => {
            for (const event of events) {
                if (event.action === nsfw.actions.CREATED) {
                    this.pushAdded(watcherId, this.resolvePath(event.directory, event.file!));
                }
                if (event.action === nsfw.actions.DELETED) {
                    this.pushDeleted(watcherId, this.resolvePath(event.directory, event.file!));
                }
                if (event.action === nsfw.actions.MODIFIED) {
                    this.pushUpdated(watcherId, this.resolvePath(event.directory, event.file!));
                }
                if (event.action === nsfw.actions.RENAMED) {
                    this.pushDeleted(watcherId, this.resolvePath(event.directory, event.oldFile!));
                    this.pushAdded(watcherId, this.resolvePath(event.newDirectory || event.directory, event.newFile!));
                }
            }
        }, {
                errorCallback: error => {

nsfw

A simple file watcher for Node

MIT
Latest version published 1 year ago

Package Health Score

58 / 100
Full package analysis

Popular nsfw functions