https://github.com/kukhariev/sanitize-filepath
Sanitize a string for use as a filename/filepath
https://github.com/kukhariev/sanitize-filepath
filename filepath sanitize
Last synced: 11 months ago
JSON representation
Sanitize a string for use as a filename/filepath
- Host: GitHub
- URL: https://github.com/kukhariev/sanitize-filepath
- Owner: kukhariev
- License: mit
- Created: 2023-06-02T17:15:59.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-01-24T16:26:09.000Z (over 2 years ago)
- Last Synced: 2024-04-25T07:01:09.415Z (about 2 years ago)
- Topics: filename, filepath, sanitize
- Language: TypeScript
- Homepage:
- Size: 46.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sanitize-filepath
[](https://badge.fury.io/js/sanitize-filepath)
Sanitize a string for use as a filename/filepath.
## Installation
```sh
npm i sanitize-filepath
```
## Example
```js
import { sanitize, sanitizePath } from 'sanitize-filepath';
const filename = sanitize('/home/user/.ext'); // homeuserfile.ext
const filepath = sanitizePath('/home/user/.ext'); // home/user/file.ext
```
## Configure
```ts
const options: SanitizeOptions = {
maxLength: 255, // max filename length in bytes
replacement: "" // replacement for invalid characters
whitespaceReplacement: undefined // replacement for spaces, tabs, and newlines
};
const filename = sanitize('/home/user/.ext', options)
```
## License
[MIT](LICENSE)