Socket
Socket
Sign inDemoInstall

filenamify

Package Overview
Dependencies
4
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    filenamify

Convert a string to a valid safe filename


Version published
Weekly downloads
4.1M
increased by0.55%
Maintainers
1
Install size
20.1 kB
Created
Weekly downloads
 

Package description

What is filenamify?

The filenamify npm package is used to convert a string into a valid and safe filename by removing or replacing invalid characters that are not allowed in filenames on certain file systems. It can be used to sanitize user input for filenames, ensuring that the resulting string can be safely used as a filename on most platforms.

What are filenamify's main functionalities?

Sanitize a string to be safe as a filename

This feature allows you to take any string and convert it into a string that is safe to use as a filename by replacing or removing invalid characters.

const filenamify = require('filenamify');
console.log(filenamify('foo/bar')); // 'foo!bar'

Customize replacement character

This feature allows you to specify a custom replacement character for invalid filename characters, giving you control over how the sanitized filename looks.

const filenamify = require('filenamify');
console.log(filenamify('foo:bar', {replacement: '-'})); // 'foo-bar'

Limit filename length

This feature allows you to limit the length of the resulting filename, which can be useful for file systems with length restrictions on filenames.

const filenamify = require('filenamify');
console.log(filenamify('a very long filename that will be truncated', {maxLength: 10})); // 'a very lon'

Other packages similar to filenamify

Readme

Source

filenamify Build Status

Convert a string to a valid safe filename

On Unix-like systems / is reserved and <>:"/\|?* on Windows.

Install

$ npm install --save filenamify

Usage

const filenamify = require('filenamify');

filenamify('<foo/bar>');
//=> 'foo!bar'

filenamify('foo:"bar"', {replacement: '🐴'});
//=> 'foo🐴bar'

API

filenamify(input, [options])

Accepts a filename and returns a valid filename.

filenamify.path(input, [options])

Accepts a path and returns the path with a valid filename.

input

Type: string

options
replacement

Type: string
Default: '!'

String to use as replacement for reserved filename characters.

Cannot contain: < > : " / \ | ? *

  • filenamify-url - Convert a URL to a valid filename
  • valid-filename - Check if a string is a valid filename

License

MIT © Sindre Sorhus

Keywords

FAQs

Last updated on 07 Apr 2016

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