πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
DemoInstallSign in
Socket

icojs

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

icojs

parse ico file

0.19.5
latest
Source
npm
Version published
Weekly downloads
3.5K
-22.55%
Maintainers
1
Weekly downloads
Β 
Created
Source

icojs

npm CI Coverage Status codebeat badge

A JavaScript library to use ICO. Works on both Node.js and the browser.

Install

npm install icojs

Node.js:

import { isICO, parseICO } from 'icojs';

Browser:

import { isICO, parseICO } from 'icojs/browser';

or

<script type="text/javascript" src="node_modules/icojs/dist/ico.js"></script>

To fully use this library, browsers must support JavaScript typed arrays, Canvas API and Promise. Chrome, Edge 12, Firefox and Safari 9 support these functions.

Example

Node.js:

import { readFile, writeFile } from 'node:fs/promises';
import { parseICO } from 'icojs';

const buffer = await readFile('favicon.ico');
const images = await parseICO(buffer, 'image/png');
// save as png files
images.forEach(image => {
  const file = `${image.width}x${image.height}-${image.bpp}bit.png`;
  const data = Buffer.from(image.buffer);
  writeFile(file, data);
});

Browser:

<input type="file" id="input-file" />
<script>
  document.getElementById('input-file').addEventListener('change', evt => {
    // use FileReader for converting File object to ArrayBuffer object
    var reader = new FileReader();
    reader.onload = async e => {
      const images = await ICO.parseICO(e.target.result);
      // logs images
      console.dir(images);
    };
    reader.readAsArrayBuffer(evt.target.files[0]);
  }, false);
</script>

Demo

https://egy186.github.io/icojs/#demo

API

ICO

isICO(source) β‡’ boolean ⏏

Check the ArrayBuffer is valid ICO.

Kind: global method of ICO
Returns: boolean - True if arg is ICO.

ParamTypeDescription
sourceArrayBuffer | BufferICO file data.

parseICO(buffer, [mime]) β‡’ Promise.<Array.<ParsedImage>> ⏏

Parse ICO and return some images.

Kind: global method of ICO
Returns: Promise.<Array.<ParsedImage>> - Resolves to an array of ParsedImage.

ParamTypeDefaultDescription
bufferArrayBuffer | BufferICO file data.
[mime]string"image/png"MIME type for output.

Typedefs

ParsedImage : object

Kind: global typedef
Properties

NameTypeDescription
widthnumberImage width.
heightnumberImage height.
bppnumberImage color depth as bits per pixel.
bufferArrayBufferImage buffer.

License

MIT license

Keywords

ico

FAQs

Package last updated on 07 Feb 2025

Did you know?

Socket

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.

Install

Related posts