{"id":13447213,"url":"https://github.com/sindresorhus/filenamify","last_synced_at":"2025-05-14T21:10:25.579Z","repository":{"id":25790207,"uuid":"29228740","full_name":"sindresorhus/filenamify","owner":"sindresorhus","description":"Convert a string to a valid safe filename","archived":false,"fork":false,"pushed_at":"2023-04-23T14:50:14.000Z","size":52,"stargazers_count":498,"open_issues_count":6,"forks_count":26,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-04-11T01:25:26.073Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/funding.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null,"governance":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2015-01-14T05:23:21.000Z","updated_at":"2025-04-09T01:36:23.000Z","dependencies_parsed_at":"2023-09-27T10:37:29.234Z","dependency_job_id":null,"html_url":"https://github.com/sindresorhus/filenamify","commit_stats":{"total_commits":62,"total_committers":12,"mean_commits":5.166666666666667,"dds":"0.25806451612903225","last_synced_commit":"7b52f70bb5fdc7f590327accadb542309d9e6401"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Ffilenamify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Ffilenamify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Ffilenamify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Ffilenamify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/filenamify/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248753654,"owners_count":21156315,"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-31T05:01:11.068Z","updated_at":"2025-04-13T17:38:05.824Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["Packages","JavaScript","Repository","包","目录","Filesystem","Uncategorized"],"sub_categories":["Filesystem","文件系统","Uncategorized"],"readme":"# filenamify\n\n\u003e Convert a string to a valid safe filename\n\nOn Unix-like systems, `/` is reserved. On Windows, [`\u003c\u003e:\"/\\|?*`](http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29#naming_conventions) along with trailing periods are reserved.\n\n## Install\n\n```sh\nnpm install filenamify\n```\n\n## Usage\n\n```js\nimport filenamify from 'filenamify';\n\nfilenamify('\u003cfoo/bar\u003e');\n//=\u003e '!foo!bar!'\n\nfilenamify('foo:\"bar\"', {replacement: '🐴'});\n//=\u003e 'foo🐴bar🐴'\n```\n\n## API\n\n### filenamify(string, options?)\n\nConvert a string to a valid filename.\n\n### filenamifyPath(path, options?)\n\nConvert the filename in a path a valid filename and return the augmented path.\n\n```js\nimport {filenamifyPath} from 'filenamify';\n\nfilenamifyPath('foo:bar');\n//=\u003e 'foo!bar'\n```\n\n#### options\n\nType: `object`\n\n##### replacement\n\nType: `string`\\\nDefault: `'!'`\n\nString to use as replacement for reserved filename characters.\n\nCannot contain: `\u003c` `\u003e` `:` `\"` `/` `\\` `|` `?` `*`\n\n##### maxLength\n\nType: `number`\\\nDefault: `100`\n\nTruncate the filename to the given length.\n\nOnly 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.\n\nSystems generally allow up to 255 characters, but we default to 100 for usability reasons.\n\n## Browser-only import\n\nYou 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.\n\n```js\nimport filenamify from 'filenamify/browser';\n\nfilenamify('\u003cfoo/bar\u003e');\n//=\u003e '!foo!bar!'\n```\n\n## Related\n\n- [filenamify-cli](https://github.com/sindresorhus/filenamify-cli) - CLI for this module\n- [filenamify-url](https://github.com/sindresorhus/filenamify-url) - Convert a URL to a valid filename\n- [valid-filename](https://github.com/sindresorhus/valid-filename) - Check if a string is a valid filename\n- [unused-filename](https://github.com/sindresorhus/unused-filename) - Get a unused filename by appending a number if it exists\n- [slugify](https://github.com/sindresorhus/slugify) - Slugify a string\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Ffilenamify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Ffilenamify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Ffilenamify/lists"}