# fixturify

> Convert objects into directory structures and back again

Latest version **3.0.0** (published 2022-10-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install fixturify
pnpm add fixturify
yarn add fixturify
bun add fixturify
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2022-10-27 |
| First published | 2014-04-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | 14.* \|\| >= 16.* |
| Dependencies | 6 |
| Unpacked size | 11.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 20 |
| Author | Jo Liss |
| Maintainers | joliss, stefanpenner |

## Links

- npm: https://www.npmjs.com/package/fixturify
- Repository: https://github.com/joliss/node-fixturify
- Homepage: https://github.com/joliss/node-fixturify#readme
- Issues: https://github.com/joliss/node-fixturify/issues
- npm.io page: https://npm.io/package/fixturify

## Dependencies (6)

- [fs-extra](https://npm.io/package/fs-extra.md) ^10.1.0
- [walk-sync](https://npm.io/package/walk-sync.md) ^3.0.0
- [@types/rimraf](https://npm.io/package/@types/rimraf.md) ^3.0.2
- [@types/fs-extra](https://npm.io/package/@types/fs-extra.md) ^9.0.13
- [@types/minimatch](https://npm.io/package/@types/minimatch.md) ^3.0.3
- [matcher-collection](https://npm.io/package/matcher-collection.md) ^2.0.1

## Recent versions

- 3.0.0 (latest) — 2022-10-27
- 2.1.1 — 2021-04-19
- 2.1.0 — 2020-02-23
- 2.0.0 — 2020-02-23
- 1.3.0 — 2020-02-22
- 1.2.0 — 2019-03-27
- 1.1.0 — 2019-03-26
- 1.0.1 — 2019-03-09
- 1.0.0 — 2019-03-09
- 0.3.4 — 2017-09-15
- 0.3.3 — 2017-03-16
- 0.3.2 — 2016-11-18
- 0.3.1 — 2016-11-17
- 0.3.0 — 2016-08-18
- 0.2.0 — 2015-10-15
- … 2 more at https://npm.io/package/fixturify/versions

## README

# node-fixturify
![CI](https://github.com/joliss/node-fixturify/workflows/CI/badge.svg)

Convert JSON objects into directory structures on the file system, and back
again. This package is primarily useful for writing tests.

## Installation

```bash
yarn add fixturify
```

## Usage

```js
const fixturify = require('fixturify')

const obj = {
  'foo.txt': 'foo.txt contents',
  'subdir': {
    'bar.txt': 'bar.txt contents'
  }
}

fixturify.writeSync('testdir', obj) // write it to disk

fixturify.readSync('testdir') // => deep-equals obj

fixturify.readSync('testdir', { globs: ['foo*'] }) // glob support
// => { foo.txt: 'foo.text contents' }

fixturify.readSync('testdir', { ignore: ['foo*'] }) // glob support
// => { subdir: { bar.txt: 'bar.text contents' } }

fixturify.writeSync('testDir', {
  'subdir': { 'bar.txt': null }
}) // remove subdir/bar.txt

fixturify.readSync('testdir') // => { foo.txt: 'foo.text contents' }

fixturify.writeSync('testDir', {
  'subdir': null
}) // remove subdir/

```

```js
const fixturify = require('fixturify')

const obj = {
  'subdir': {
    'foo.txt': 'foo.txt contents'
  },
  'emptydir': {}
}

fixturify.writeSync('testdir', obj) // write it to disk

fixturify.readSync('testdir', { ignoreEmptyDirs: true })
// => { subdir: { foo.txt': 'foo.txt contents' } }

```

File contents are decoded and encoded with UTF-8.

`fixture.readSync` follows symlinks. It throws an error if it encounters a
broken symlink.

## Limitations

To keep the API simple, node-fixturify has the following limitations:

* Reading or setting file stats (last-modified time, permissions, etc.) is
  not supported.

* Creating symlinks is not supported. Symlinks are traversed when reading. Broken symlinks throw.

* Special files like FIFOs, sockets, or devices are not supported.

* File contents are automatically encoded/decoded into strings. Binary files
  are not supported.

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