https://github.com/sapegin/deabsdeep
Recursively replace absolute paths in objects and arrays with ~
https://github.com/sapegin/deabsdeep
Last synced: 3 months ago
JSON representation
Recursively replace absolute paths in objects and arrays with ~
- Host: GitHub
- URL: https://github.com/sapegin/deabsdeep
- Owner: sapegin
- License: mit
- Created: 2017-12-06T10:18:32.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-03-01T12:24:06.000Z (almost 3 years ago)
- Last Synced: 2025-08-24T13:33:16.555Z (5 months ago)
- Language: JavaScript
- Size: 468 KB
- Stars: 3
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Contributing: Contributing.md
- License: License.md
Awesome Lists containing this project
README
# deabsdeep
[](https://travis-ci.org/sapegin/deabsdeep) [](https://www.npmjs.com/package/deabsdeep)
Recursively replace absolute paths in object keys and values or array values with a `~`.
## Installation
```bash
npm install deabsdeep
```
## Usage
```js
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:
```js
deabsDeep(obj, { root: '/root/directory' });
```
### `mask` (default: `~`)
A string to replace the root folder with:
```js
deabsDeep(obj, { mask: '' });
```
## Jest serializer
Update your `package.json` to make Jest replace all absolute paths in snapshots:
```json
{
"jest": {
"snapshotSerializers": ["deabsdeep/serializer"]
}
}
```
## Change log
The change log can be found on the [Releases page](https://github.com/sapegin/deabsdeep/releases).
## Contributing
Everyone is welcome to contribute. Please take a moment to review the [contributing guidelines](Contributing.md).
## Authors and license
[Artem Sapegin](http://sapegin.me) and [contributors](https://github.com/sapegin/deabsdeep/graphs/contributors).
MIT License, see the included [License.md](License.md) file.