{"id":13487441,"url":"https://github.com/parshap/node-sanitize-filename","last_synced_at":"2025-10-25T06:02:19.186Z","repository":{"id":37677286,"uuid":"12495685","full_name":"parshap/node-sanitize-filename","owner":"parshap","description":"Sanitize string for use as filename","archived":false,"fork":false,"pushed_at":"2024-01-18T15:49:19.000Z","size":315,"stargazers_count":352,"open_issues_count":23,"forks_count":53,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-15T02:08:53.225Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/parshap.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-08-30T21:11:46.000Z","updated_at":"2025-05-06T13:37:43.000Z","dependencies_parsed_at":"2024-06-04T13:14:41.538Z","dependency_job_id":"f0c2c519-f57e-442a-b9fc-60d9345b8656","html_url":"https://github.com/parshap/node-sanitize-filename","commit_stats":{"total_commits":95,"total_committers":11,"mean_commits":8.636363636363637,"dds":0.2421052631578947,"last_synced_commit":"209c39b914c8eb48ee27bcbde64b2c7822fdf3de"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parshap%2Fnode-sanitize-filename","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parshap%2Fnode-sanitize-filename/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parshap%2Fnode-sanitize-filename/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parshap%2Fnode-sanitize-filename/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/parshap","download_url":"https://codeload.github.com/parshap/node-sanitize-filename/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254259384,"owners_count":22040820,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T18:00:59.376Z","updated_at":"2025-10-25T06:02:16.858Z","avatar_url":"https://github.com/parshap.png","language":"JavaScript","funding_links":[],"categories":["Npm","JavaScript"],"sub_categories":[],"readme":"# sanitize-filename [![build status](https://secure.travis-ci.org/parshap/node-sanitize-filename.svg?branch=master)](http://travis-ci.org/parshap/node-sanitize-filename)\n\nSanitize a string to be safe for use as a filename by removing directory\npaths and invalid characters.\n\n## Install\n\n[npm: *sanitize-filename*](https://www.npmjs.com/package/sanitize-filename)\n\n```\nnpm install sanitize-filename\n```\n\n## Example\n\n```js\nvar sanitize = require(\"sanitize-filename\");\n\n// Some string that may be unsafe or invalid as a filename\nvar UNSAFE_USER_INPUT = \"~/.\\u0000ssh/authorized_keys\";\n\n// Sanitize the string to be safe for use as a filename.\nvar filename = sanitize(UNSAFE_USER_INPUT);\n// -\u003e \"~.sshauthorized_keys\"\n```\n\n## Details\n\n*sanitize-filename* removes the following:\n\n * [Control characters][] (`0x00`–`0x1f` and `0x80`–`0x9f`)\n * [Reserved characters][] (`/`, `?`, `\u003c`, `\u003e`, `\\`, `:`, `*`, `|`, and\n   `\"`)\n * Unix reserved filenames (`.` and `..`)\n * Trailing periods and spaces ([for Windows][windows trailing])\n * Windows reserved filenames (`CON`, `PRN`, `AUX`, `NUL`, `COM1`,\n   `COM2`, `COM3`, `COM4`, `COM5`, `COM6`, `COM7`, `COM8`, `COM9`,\n   `LPT1`, `LPT2`, `LPT3`, `LPT4`, `LPT5`, `LPT6`, `LPT7`, `LPT8`, and\n   `LPT9`)\n\n[control characters]: https://en.wikipedia.org/wiki/C0_and_C1_control_codes\n[reserved characters]: https://kb.acronis.com/content/39790\n[windows trailing]: https://msdn.microsoft.com/en-us/library/aa365247(v=vs.85).aspx#Naming_Conventions\n\nThe resulting string is truncated to [255 bytes in length][255]. The\nstring will not contain any directory paths and will be safe to use as a\nfilename.\n\n[255]: http://unix.stackexchange.com/questions/32795/what-is-the-maximum-allowed-filename-and-folder-size-with-ecryptfs\n\n### Empty String `\"\"` Result\n\nAn empty string `\"\"` can be returned. For example:\n\n```js\nvar sanitize = require(\"sanitize-filename\");\nsanitize(\"..\")\n// -\u003e \"\"\n\n```\n\n### Non-unique Filenames\n\nTwo different inputs can return the same value. For example:\n\n```js\nvar sanitize = require(\"sanitize-filename\");\nsanitize(\"file?\")\n// -\u003e \"file\"\nsanitize (\"*file*\")\n// -\u003e \"file\"\n```\n\n### File Systems\n\nSanitized filenames will be safe for use on modern Windows, OS X, and\nUnix file systems (`NTFS`, `ext`, etc.).\n\n[`FAT` 8.3 filenames][8.3] are not supported.\n\n[8.3]: https://en.wikipedia.org/wiki/8.3_filename\n\n#### Test Your File System\n\nThe test program will use various strings (including the [Big List of\nNaughty Strings][blns]) to create files in the working directory. Run\n`npm test` to run tests against your file system.\n\n[blns]: https://github.com/minimaxir/big-list-of-naughty-strings\n\n## API\n\n### `sanitize(inputString, [options])`\n\nSanitize `inputString` by removing or replacing invalid characters.\n\nOptions:\n\n * `options.replacement`: *optional, string/function, default: `\"\"`*. If passed\n as a string, it's used as the replacement for invalid characters. If passed as\n a function, the function will be called with the invalid characters and it's\n return value will be used as the replacement. See [`String.prototype.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)\n for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparshap%2Fnode-sanitize-filename","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparshap%2Fnode-sanitize-filename","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparshap%2Fnode-sanitize-filename/lists"}