{"id":13468463,"url":"https://github.com/sindresorhus/file-icon","last_synced_at":"2025-04-05T14:09:54.631Z","repository":{"id":41165418,"uuid":"84315560","full_name":"sindresorhus/file-icon","owner":"sindresorhus","description":"Get the icon of a file or app as a PNG image (macOS)","archived":false,"fork":false,"pushed_at":"2022-12-09T12:18:29.000Z","size":33,"stargazers_count":214,"open_issues_count":1,"forks_count":23,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-28T21:28:16.282Z","etag":null,"topics":["app","file","icon","image","macos","nodejs","path","png","swift"],"latest_commit_sha":null,"homepage":null,"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":{"funding":{"github":"sindresorhus","open_collective":"sindresorhus","custom":"https://sindresorhus.com/donate"},"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-08T12:01:32.000Z","updated_at":"2025-03-06T08:05:22.000Z","dependencies_parsed_at":"2023-01-25T16:01:16.096Z","dependency_job_id":null,"html_url":"https://github.com/sindresorhus/file-icon","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Ffile-icon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Ffile-icon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Ffile-icon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Ffile-icon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/file-icon/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246759624,"owners_count":20829127,"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":["app","file","icon","image","macos","nodejs","path","png","swift"],"created_at":"2024-07-31T15:01:11.419Z","updated_at":"2025-04-05T14:09:54.594Z","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":["JavaScript"],"sub_categories":[],"readme":"# file-icon\n\n\u003e Get the icon of a file or app as a PNG image\n\nRequires macOS 10.10 or later. macOS 10.13 or earlier needs to download the [Swift runtime support libraries](https://support.apple.com/kb/DL1998).\n\n## Install\n\n```sh\nnpm install file-icon\n```\n\n## Usage\n\n```js\nimport fs from 'node:fs';\nimport {fileIconToBuffer, fileIconToFile} from 'file-icon';\n\n// An app name can be used\nconst buffer = await fileIconToBuffer('Safari');\nfs.writeFileSync('safari-icon.png', buffer);\n\n// An array of app names\nconst apps = ['Finder', 'Safari'];\nconst buffers = await fileIconToBuffer(apps);\nbuffers.map((buffer, index) =\u003e fs.writeFileSync(`${apps[index]}-icon.png`, buffer));\n\n// Or a bundle ID\nconst buffer2 = await fileIconToBuffer('com.apple.Safari', {size: 64});\nfs.writeFileSync('safari-icon.png', buffer2);\n\n// Or a an array of bundle IDs\nconst bundleIds = ['com.apple.Finder', 'com.apple.Safari'];\nconst buffers2 = await fileIconToBuffer(bundleIds);\nbuffers2.map((buffer, index) =\u003e fs.writeFileSync(`${bundleIds[index]}-icon.png`, buffer));\n\n// Or a process ID\nconst buffer3 = await fileIconToBuffer(257);\nfs.writeFileSync('pid.png', buffer3);\n\n// Or an array of process IDs\nconst pids = [257, 16];\nconst buffers3 = await fileIconToBuffer(pids, {size: 128});\nbuffers3.map((buffer, index) =\u003e fs.writeFileSync(`${pids[index]}-icon.png`, buffer));\n\n// Or a path to an app / file\nconst buffer4 = await fileIconToBuffer('/Applications/Safari.app');\nfs.writeFileSync('safari-icon.png', buffer4);\n\n// Or an array of filenames\nconst paths = ['/Applications/Safari.app', '/Applications/Calculator.app'];\nconst buffers4 = await fileIconToBuffer(paths);\nbuffers4.map((buffer, index) =\u003e fs.writeFileSync(`${paths[index].split(/\\/|\\./)[2]}-icon.png`, buffer));\nfs.writeFileSync('jpeg-file-type-icon.png', buffer4);\n\n// Or a mix of all of them!\nawait fileIconToBuffer(['Finder', 257, 'com.apple.Calculator', '/Applications/Safari.app']);\n\n// You can also use `fileIconToFile` and provide `options.destination` with the path to write to\nawait fileIconToFile('Safari', {destination: 'safari-icon.png'});\n\n// You can also use same length arrays for `input` and `options.destination`\nawait fileIconToFile(['Safari', 'Finder'], {destination: ['safari-icon.png', 'finder-icon.png']});\n\nconsole.log('Done');\n```\n\n## API\n\n### fileIconToBuffer(input, options?)\n\nReturns a `Promise\u003cBuffer\u003e` for a PNG image if `input` is of type `string` or `number`.\n\nReturns a `Promise\u003cBuffer[]\u003e` for multiple PNG images if `input` is of type `Array\u003cstring | number\u003e`.\n\n### input\n\nType: `string | number | Array\u003cstring | number\u003e`\n\nEither:\n- App name *(string)*\n- App bundle identifier *(string)*\n- App process ID *(number)*\n- Path to an app *(string)*\n- Path to a file *(string)*\n\n### options\n\nType: `object`\n\n#### size\n\nType: `number`\\\nDefault: `1024`\\\nMaximum: `1024`\n\nSize of the returned icon.\n\n### fileIconToFile(input, options)\n\nReturns a `Promise` that resolves when the files are written to `options.destination`.\n\n### input\n\nType: `string | number | Array\u003cstring | number\u003e`\n\n### options\n\nType: `object`\n\n#### size\n\nType: `number`\\\nDefault: `1024`\\\nMaximum: `1024`\n\nSize of the returned icon.\n\n#### destination\n\n*Required*\\\nType: `string | string[]`\n\nOutput file for the icon. If `input` is a single value, `options.destination` *must* be of type `string`.  If `input` is an `Array`, `options.destination` *must* be of type `string[]` with the same `length` as `input`.\n\n## Related\n\n- [file-icon-cli](https://github.com/sindresorhus/file-icon-cli) - CLI for this module\n- [app-path](https://github.com/sindresorhus/app-path) - Get the path to an app\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Ffile-icon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Ffile-icon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Ffile-icon/lists"}