# extra-watcher

> ```sh npm install --save extra-watcher # or yarn add extra-watcher ```

Latest version **0.2.2** (published 2023-06-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install extra-watcher
pnpm add extra-watcher
yarn add extra-watcher
bun add extra-watcher
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2023-06-11 |
| First published | 2022-03-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 67.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | BlackGlory |
| Maintainers | black_glory |

## Links

- npm: https://www.npmjs.com/package/extra-watcher
- Repository: https://github.com/BlackGlory/extra-watcher
- Homepage: https://github.com/BlackGlory/extra-watcher#readme
- Issues: https://github.com/BlackGlory/extra-watcher/issues
- npm.io page: https://npm.io/package/extra-watcher

## Dependencies (5)

- [rxjs](https://npm.io/package/rxjs.md) ^7.5.6
- [watcher](https://npm.io/package/watcher.md) ^1.2.0
- [extra-filesystem](https://npm.io/package/extra-filesystem.md) ^0.4.4
- [@blackglory/wait-for](https://npm.io/package/@blackglory/wait-for.md) ^0.5.1
- [@blackglory/structures](https://npm.io/package/@blackglory/structures.md) ^0.6.0

## Recent versions

- 0.2.2 (latest) — 2023-06-11
- 0.2.1 — 2022-08-01
- 0.2.0 — 2022-08-01
- 0.1.1 — 2022-03-26
- 0.1.0 — 2022-03-26

## README

# extra-watcher
## Install
```sh
npm install --save extra-watcher
# or
yarn add extra-watcher
```

## API
### DirectoryWatcher
```ts
type Event =
| ICreatedEvent
| IModifiedEvent
| IDeletedEvent

interface ICreatedEvent {
  type: 'created'
  target: Target
  pathname: string
}

interface IModifiedEvent {
  type: 'modified'
  target: Target.File
  pathname: string
}

interface IDeletedEvent {
  type: 'deleted'
  target: Target
  pathname: string
}

enum Target {
  File = 'file'
, Directory = 'directory'
}

class DirectoryWatcher {
  events: readonly Event[]

  constructor(dirname: string)

  observe(): Observable<Event>
  start(): Promise<void>
  stop(): void
  reset(): void

  isChanged(): boolean
  isFileCreated(filename: string): boolean
  isDirectoryCreated(dirname: string): boolean
  isFileModified(filename: string): boolean
  isDirectoryModified(dirname: string): boolean
  isFileDeleted(filename: string): boolean
  isDirectoryDeleted(dirname: string): boolean
}
```

DirectoryWatcher based on event sourcing, `reset` can clear events.
A watcher can only be started and stopped once.

The following method checks "whether this condition is eventually true",
not "whether this event has occurred":
- `isFileCreated`
- `isDirectoryCreated`
- `isFileModified`
- `isDirectoryModified`
- `isFileDeleted`
- `isDirectoryDeleted`

### FileWatcher
```ts
type Event =
| ICreatedEvent
| IModifiedEvent
| IDeletedEvent

interface ICreatedEvent {
  type: 'created'
}

interface IModifiedEvent {
  type: 'modified'
}

interface IDeletedEvent {
  type: 'deleted'
}

class FileWatcher {
  events: readonly Event[]

  constructor(filename: string)

  observe(): Observable<Event>
  start(): Promise<void>
  stop(): void
  reset(): void

  isChanged(): boolean
  isCreated(): boolean
  isModified(): boolean
  isDeleted(): boolean
}
```

FileWatcher based on event sourcing, `reset` can clear events.
A watcher can only be started and stopped once.

The following method checks "whether this condition is eventually true",
not "whether this event has occurred":
- `isCreated`
- `isModified`
- `isDeleted`

---
_Source: https://npm.io/package/extra-watcher · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
