https://github.com/gobwas/salvator
Safe write path checker
https://github.com/gobwas/salvator
Last synced: about 1 month ago
JSON representation
Safe write path checker
- Host: GitHub
- URL: https://github.com/gobwas/salvator
- Owner: gobwas
- Created: 2015-07-17T12:40:22.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-11-15T20:09:50.000Z (over 9 years ago)
- Last Synced: 2025-02-24T19:39:58.726Z (2 months ago)
- Language: JavaScript
- Size: 117 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url]
> Checks given filepath to exist, and if yes, returns safe version of filepath
## Install
```sh
$ npm install --save salvator
```## Usage
```js
var salvator = require('salvator');salvator.safe('/path/to/my/file.js')
.then(function(result) {
// result is a safe to write filepath like a
// /path/to/my/file(1).js
});
```## API
##### salvator.safe(filepath: string[, options: Object]) : Promise
###### options.format
Type: `string`
Default: `"${dirname}/${filename}(${fix}).${extname}"`Template for a new path iterator.
###### options.counter
Type: `Function(fix: Any)`
Default: `[incremental function]`Where `fix` is a result from previous call, or `undefined`.
###### options.limit
Type: `number`
Default: `999`Limit of iterations.
###### options.exclude
Type: `Array`
Default: `[]`Contains a list of "excluded" filepaths that will not be returned by the module in any case.
## License
MIT © [Sergey Kamrdin](https://github.com/gobwas)
[npm-image]: https://badge.fury.io/js/salvator.svg
[npm-url]: https://npmjs.org/package/salvator
[travis-image]: https://travis-ci.org/gobwas/salvator.svg?branch=master
[travis-url]: https://travis-ci.org/gobwas/salvator
[daviddm-image]: https://david-dm.org/gobwas/salvator.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/gobwas/salvator