Socket
Socket
Sign inDemoInstall

fixturify

Package Overview
Dependencies
15
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    fixturify

Convert objects into directory structures and back again


Version published
Maintainers
2
Install size
3.97 MB
Created

Changelog

Source

1.3.0

  • Switch to GH Actions
  • Document DirJSON interface
  • Add more detail to symlinks docs

Readme

Source

node-fixturify

CI

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

Installation

yarn add fixturify

Usage

const fs = require('fs')
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', { include: ['foo*'] }) // glob support
// => { foo.txt: 'foo.text contents' }

fixturify.readSync('testdir', { exclude: ['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/

const fs = require('fs')
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.

FAQs

Last updated on 22 Feb 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc