
Security News
Another Round of TEA Protocol Spam Floods npm, But It’s Not a Worm
Recent coverage mislabels the latest TEA protocol spam as a worm. Here’s what’s actually happening.
filenamify
Advanced tools
Convert a string to a valid safe filename
On Unix-like systems, / is reserved. On Windows, <>:"/\|?* along with trailing periods and spaces are reserved.
This module also removes non-printable control characters (including Unicode bidirectional marks) and normalizes Unicode whitespace.
npm install filenamify
import filenamify from 'filenamify';
filenamify('<foo/bar>');
//=> '!foo!bar!'
filenamify('foo:"bar"', {replacement: '🐴'});
//=> 'foo🐴bar🐴'
Convert a string to a valid filename.
Convert the filename in a path to a valid filename and return the augmented path.
import {filenamifyPath} from 'filenamify';
filenamifyPath('foo:bar');
//=> 'foo!bar'
Type: object
Type: string
Default: '!'
String to use as replacement for reserved filename characters.
Cannot contain: < > : " / \ | ? * or control characters.
Type: number
Default: 100
Truncate the filename to the given length.
Only the base of the filename is truncated, preserving the extension. If the extension itself is longer than maxLength, you will get a string that is longer than maxLength, so you need to check for that if you allow arbitrary extensions.
Truncation is grapheme-aware and will not split Unicode characters (surrogate pairs or extended grapheme clusters). If the remaining budget (after accounting for the extension) is smaller than a whole grapheme, the base filename may be truncated to an empty string to avoid splitting.
Systems generally allow up to 255 characters, but we default to 100 for usability reasons.
You can also import filenamify/browser, which only imports filenamify and not filenamifyPath, which relies on path being available or polyfilled. Importing filenamify this way is therefore useful when it is shipped using webpack or similar tools, and if filenamifyPath is not needed.
import filenamify from 'filenamify/browser';
filenamify('<foo/bar>');
//=> '!foo!bar!'
The sanitize-filename package is similar to filenamify in that it sanitizes input to be safe for use as a filename. It removes or replaces invalid characters and is a straightforward alternative to filenamify.
While slugify is primarily used for creating URL slugs from strings, it can also be used to generate safe filenames. It converts strings into a URL-friendly format, which is also generally safe for filenames, though its primary use case is not for sanitizing filenames like filenamify.
FAQs
Convert a string to a valid safe filename
The npm package filenamify receives a total of 5,716,384 weekly downloads. As such, filenamify popularity was classified as popular.
We found that filenamify demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.

Security News
Recent coverage mislabels the latest TEA protocol spam as a worm. Here’s what’s actually happening.

Security News
PyPI adds Trusted Publishing support for GitLab Self-Managed as adoption reaches 25% of uploads

Research
/Security News
A malicious Chrome extension posing as an Ethereum wallet steals seed phrases by encoding them into Sui transactions, enabling full wallet takeover.