{"_id":"@crabnebula/file-icons","_rev":"7-338868fbff3631fa5cd424e65ead8726","name":"@crabnebula/file-icons","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@crabnebula/file-icons","version":"0.1.0","keywords":["icons","file-icons"],"author":{"name":"Jonas Kruckenberg","email":"jonas@crabnebula.dev"},"license":"MIT OR Apache-2.0","_id":"@crabnebula/file-icons@0.1.0","maintainers":[{"name":"lucasfernog-crabnebula","email":"lucas@crabnebula.dev"}],"dist":{"shasum":"5a318a385c962d70eabc7aa8105d95cb653d33c3","tarball":"https://registry.npmjs.org/@crabnebula/file-icons/-/file-icons-0.1.0.tgz","fileCount":1017,"integrity":"sha512-b4DjfdIO/DFZYU+t1UJYfbN9F8150A5DEMu0dfmPOkFaWN1Gx3JOBoHnuirTTIMhuWtjrDixsbX8ewQmJXtCjQ==","signatures":[{"sig":"MEQCIH6Q1mggQdrL7TFqD5oVtL2pDIokVkBLGK43eiCo7f22AiApIbbIOlZwSfi6TN51dKB0lWI572PfcvqCfOSAnVhzRw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":3516534},"main":"dist/lib.js","type":"module","types":"dist/lib.d.ts","gitHead":"c3c926064f37e8a3eef873e368a58fdcd0cfa626","scripts":{"build":"rm -rf dist && pnpm build:rust && pnpm build:dts && pnpm build:js","gen-lut":"esbuild scripts/gen-lut.ts --bundle --outdir=scripts --format=esm --platform=node && node scripts/gen-lut.js","build:js":"esbuild src/lib.ts --bundle --format=esm --outdir=dist --loader:.wasm=copy --alias:file_icons.wasm=./target/wasm32-unknown-unknown/release/file_icons.wasm","test:e2e":"pnpm vitest run tests","build:dts":"tsc --declaration --emitDeclarationOnly --declarationDir dist src/lib.ts src/wasm.d.ts","build:rust":"cargo build --release --target wasm32-unknown-unknown --no-default-features --features _web_build -Z build-std=core,panic_abort -Z build-std-features=panic_immediate_abort","build:debug":"rm -rf dist && pnpm build:rust:debug && pnpm build:dts && pnpm build:js:debug","build:js:debug":"esbuild src/lib.ts --bundle --format=esm --outdir=dist --loader:.wasm=copy --alias:file_icons.wasm=./target/wasm32-unknown-unknown/debug/file_icons.wasm","build:rust:debug":"cargo build --target wasm32-unknown-unknown --no-default-features --features _web_build"},"_npmUser":{"name":"lucasfernog-crabnebula","email":"lucas@crabnebula.dev"},"_npmVersion":"6.14.18","description":"File Icons for IDEs","directories":{},"_nodeVersion":"14.21.3","_hasShrinkwrap":false,"devDependencies":{"vitest":"^0.34.6","esbuild":"^0.19.5","typescript":"^5.2.2","webdriverio":"^8.21.0","@vitest/browser":"^0.34.6","vite-plugin-wasm":"^3.2.2","vite-plugin-top-level-await":"^1.3.1"},"_npmOperationalInternal":{"tmp":"tmp/file-icons_0.1.0_1699409071869_0.003379899863435565","host":"s3://npm-registry-packages"}}},"time":{"created":"2023-11-08T02:04:31.777Z","modified":"2025-01-29T12:22:56.494Z","0.1.0":"2023-11-08T02:04:32.102Z"},"author":{"name":"Jonas Kruckenberg","email":"jonas@crabnebula.dev"},"license":"MIT OR Apache-2.0","keywords":["icons","file-icons"],"description":"File Icons for IDEs","maintainers":[{"email":"npm-admin@crabnebula.dev","name":"crabnebula-npm"},{"email":"lucas@crabnebula.dev","name":"lucasfernog-crabnebula"}],"readme":"<div align=\"center\">\n  <h1>\n    <code>file-icons</code>\n  </h1>\n  <p>\n    <strong>File Icons for IDEs</strong>\n  </p>\n  <p>\n\n![MIT or Apache 2.0 licensed][mit-or-apache-badge]\n\n</p>\n</div>\n\n[mit-or-apache-badge]: https://img.shields.io/badge/license-MIT%20or%20Apache%202.0-blue.svg\n\nThis package provides simple & fast programmatic access to the icons from\n[vscode-icons](https://github.com/vscode-icons/vscode-icons), letting you use\nthem in your own projects!\n\nThere are only two functions exported from this package: `getIconForFile` and\n`getIconForFolder`. They employ a matching heuristic similar to the one used in\nvscode-icons to find the best matching icon for a given file or folder.\n\n> Note that this heuristic is simplified from the `vscode-icons` one, so it may\n> not be as accurate or complete. It should be _good enough_ though, but feel\n> free to open a PR if you find any issues!\n\n## Installation\n\nFor usage in JavaScript/TypeScript projects:\n\n```sh\nnpm install file-icons\n# OR\nyarn add file-icons\n# OR\npnpm add file-icons\n```\n\nFor usage in Rust projects:\n\n```sh\ncargo add file-icons\n```\n\n## Usage\n\n### Matching a File Icon\n\n`getIconForFile` returns the URL of the icon for a given file or `null` if no\nmatching icon could be found. You **MUST** call `setCDN` before calling this\nfunction with a valid URL to where the icons from this package are hosted.\n\n```js\nimport { getIconForFile, setCDN } from \"file-icons\";\n\nsetCDN(\"/icons/\"); // point this to wherever you have hosted the file-icons/icons folder\n\nconst icon = getIconForFile(\"foo.js\");\n```\n\n### Matching a Folder Icon\n\n`getIconForFolder` returns the URL of the icon for a given folder or `null` if\nno matching icon could be found. You **MUST** call `setCDN` before calling this\nfunction with a valid URL to where the icons from this package are hosted.\n\n```js\nimport { getIconForFolder, setCDN } from \"file-icons\";\n\nsetCDN(\"/icons/\"); // point this to wherever you have hosted the file-icons/icons folder\n\nconst icon = getIconForFolder(\".github\");\n```\n\n### Usage from Rust\n\nThis package can also be used as a Rust crate. The API is a bit lower level\nthough, i.e. instead of returning a URL to the icon, it returns the `u64` ID of\nthe icon. Each ID maps to a `.svg` file in the `icons` folder.\n\n```rust\nuse file_icons::get_icon_for_file;\n\nfn main() {\n    let icon = get_icon_for_file(\"foo.js\"); // Returns the ID of the icon\n    println!(\"{}\", icon);\n}\n```\n\n## Benchmarks\n\nYou said fast, but how fast is t really?\n\nWell, plenty! Here's the benchmark results on a 2023 MacBook Pro:\n\n```\n                                [   min       mean        max   ]\n_get_icon_for_file      time:   [42.963 ns  43.045 ns  43.134 ns]\n_get_icon_for_folder    time:   [68.751 ns  68.879 ns  69.019 ns]\n```\n\nand here is the same running as WebAssembly in Safari on that same 2023 MacBook Pro:\n\n```\n                                [   min       mean        max   ]   \n_get_icon_for_file      time:   [53.251 ns  53.374 ns  53.538 ns]\n_get_icon_for_folder    time:   [70.595 ns  70.680 ns  70.771 ns]\n```\n\n## Usage with Vite\n\nIf you are using [Vite](https://vitejs.dev/) as your build tool you might want to use the plugin [vite-plugin-static-copy](https://github.com/sapphi-red/vite-plugin-static-copy) to pull the icons from the node_modules folder. \n\nJust install the plugin with\n\n> Taken from the plugin [README](https://github.com/sapphi-red/vite-plugin-static-copy#install)\n\n```shell \nnpm i -D vite-plugin-static-copy # yarn add -D vite-plugin-static-copy\n```\n\nand add the following configuration to your `vite.config.js` / `vite.config.ts`\n\n```javascript\n// vite.config.js / vite.config.ts\nimport { viteStaticCopy } from 'vite-plugin-static-copy'\nimport { normalizePath } from \"vite\";\n\nexport default {\n  plugins: [\n    viteStaticCopy({\n      targets: [\n        {\n          src: normalizePath(\n            path.resolve(__dirname, \"node_modules/file-icons/icons\") + \"/[!.]*\"\n          ),\n          dest: \"./icons/\",\n        }\n      ]\n    })\n  ]\n}\n```\n \n> :warning: **Make sure that the \"dest\" is set correctly** otherwise the ``setCDN(\"/icons/\");`` will not work. Make sure they match.\n\n> :warning: **This will copy all the icons into your ``./dist/icons`` directory on build and add around ~3.32 MB to it**\n\n\n## Contributing\n\nPRs are welcome!\n\n#### License\n\n<sup>\nLicensed under either of <a href=\"LICENSE-APACHE\">Apache License, Version\n2.0</a> or <a href=\"LICENSE-MIT\">MIT license</a> at your option.\n</sup>\n\n<br>\n\n<sub>\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in this crate by you, as defined in the Apache-2.0 license, shall\nbe dual licensed as above, without any additional terms or conditions.\n</sub>\n","readmeFilename":"README.md"}