Recursively replace absolute paths in objects and arrays with ~
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
.editorconfig
.eslintignore
.eslintrc
.gitignore
.npmignore
.travis.yml
Contributing.md
License.md
Readme.md
jsconfig.json
package-lock.json
package.json
serializer.js

Readme.md

deabsdeep

Build Status npm

Recursively replace absolute paths in object keys and values or array values with a ~.

Installation

npm install deabsdeep

Usage

const deabsDeep = require('deabsdeep')

// __dirname = /foo/bar

deabsDeep({
  '/foo/bar/a.txt': {
      baz: '/foo/bar/a.txt'
  }
})
/* =>
{
  '~/a.txt': {
    baz: '~/a.txt'
  }
}
*/

deabsDeep([
  '/foo/bar/a.txt',
  '/foo/bar/a.txt'
])
/* =>
[
  '~/a.txt',
  '~/a.txt'
]
*/

Options

root (default: project root)

A root folder, by default the project root folder (where your package.json is) will be used:

deabsDeep(obj, { root: '/root/directory' })

mask (default: ~)

A string to replace the root folder with:

deabsDeep(obj, { mask: '<rootDir>' })

Jest serializer

Update your package.json to make Jest replace all absolute paths in snapshots:

{
  "jest": {
    "snapshotSerializers": ["deabsdeep/serializer"]
  }
}

Change log

The change log can be found on the Releases page.

Contributing

Everyone is welcome to contribute. Please take a moment to review the contributing guidelines.

Authors and license

Artem Sapegin and contributors.

MIT License, see the included License.md file.