Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

icojs

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

icojs - npm Package Compare versions

Comparing version 0.5.0-alpha to 0.5.0

readme.json

2

dist/ico.js

@@ -1,2 +0,2 @@

!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.ICO=r():t.ICO=r()}(this,function(){return function(t){function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{},id:n,loaded:!1};return t[n].call(i.exports,i,i.exports,r),i.loaded=!0,i.exports}var e={};return r.m=t,r.c=e,r.p="",r(0)}([function(t,r,e){"use strict";var n=e(3),i=e(5),o=i({Image:n});t.exports=o},function(t,r){"use strict";var e={of1:function(t){for(var r=new Uint8Array(t),e="",n=0;n<r.byteLength;n++)e+=("000000000"+r[n].toString(2)).slice(-8);return e.split("").map(function(t){return parseInt(t,2)})},of4:function(t){for(var r=new Uint8Array(t),e="",n=0;n<r.byteLength;n++)e+=("00"+r[n].toString(16)).slice(-2);return e.split("").map(function(t){return parseInt(t,16)})},of8:function(t){for(var r=new Uint8Array(t),e=[],n=0;n<r.byteLength;n++)e.push(r[n]);return e}};t.exports=e},function(t,r){"use strict";var e=function(t){var r=t%4;return t%4===0?t:t+4-r};t.exports=e},function(t,r){"use strict";var e=function(t){for(var r=atob(t.replace(/.+,/,"")),e=new Uint8Array(r.length),n=0;n<r.length;n++)e[n]=r.charCodeAt(n);return e.buffer},n={encode:function(t,r){return new Promise(function(n){var i=t.data,o=document.createElement("canvas");o.width=t.width,o.height=t.height;for(var a=o.getContext("2d"),f=a.createImageData(t.width,t.height),u=f.data,c=0;c<u.length;c++)u[c]=i[c];a.putImageData(f,0,0),n(e(o.toDataURL(r||"image/png")))})}};t.exports=n},function(t,r,e){"use strict";var n=e(1),i=e(2),o=function(t,r){for(var e=new DataView(t),o=e.getUint8(6+16*r)||256,a=e.getUint8(7+16*r)||256,f=e.getUint32(18+16*r,!0),u=e.getUint16(f+14,!0),c=e.getUint32(18+16*r,!0)+e.getUint32(f,!0),h=e.getUint32(f+32,!0),s=c+4*h,d=s+i(o*u/8)*a,w={width:o,height:a,colorCount:e.getUint8(8+16*r),bit:u,colors:[],xor:t.slice(s,d),and:t.slice(d,d+i(o/8)*a)},g=0;g<h;g++)w.colors.push(n.of8(t.slice(c+4*g,c+4*g+4)));return w};t.exports=o},function(t,r,e){(function(r){"use strict";var n=e(4),i=e(6),o=function(t){return new Array(t).fill(0).map(function(t,r){return r})},a=function(t){var e=r.ICO,a=t.Image,f={parse:function(t,r){var e=new DataView(t);if(0!==e.getUint16(0,!0)||1!==e.getUint16(2,!0))return Promise.reject(new Error("buffer is not ico"));var f=Promise.all(o(e.getUint16(4,!0)).map(function(e){var o=n(t,e),f={width:o.width,height:o.height};switch(o.bit){case 1:f.data=i.from1bit(o);break;case 4:f.data=i.from4bit(o);break;case 8:f.data=i.from8bit(o);break;case 24:f.data=i.from24bit(o);break;case 32:f.data=i.from32bit(o)}return a.encode(f,r).then(function(t){return{bit:o.bit,width:o.width,height:o.height,buffer:t}})}));return f},isICO:function(t){if(!(t instanceof ArrayBuffer))return!1;var r=new DataView(t);return 0===r.getUint16(0,!0)&&1===r.getUint16(2,!0)},noConflict:function(){return r.ICO=e,this}};return f};t.exports=a}).call(r,function(){return this}())},function(t,r,e){"use strict";var n=e(1),i=e(2),o={from1bit:function(t){for(var r=n.of1(t.xor),e=n.of1(t.and),o=8*i(t.width*t.bit/8)/t.bit,a=8*i(t.width/8),f=0,u=new Uint8ClampedArray(t.width*t.height*4),c=t.height-1;c>=0;c--)for(var h=0;h<t.width;h++){var s=t.colors[r[c*o+h]];u[f]=s[2],u[f+1]=s[1],u[f+2]=s[0],u[f+3]=e[c*a+h]?0:255,f+=4}return u},from4bit:function(t){for(var r=n.of4(t.xor),e=n.of1(t.and),o=8*i(t.width*t.bit/8)/t.bit,a=8*i(t.width/8),f=0,u=new Uint8ClampedArray(t.width*t.height*4),c=t.height-1;c>=0;c--)for(var h=0;h<t.width;h++){var s=t.colors[r[c*o+h]];u[f]=s[2],u[f+1]=s[1],u[f+2]=s[0],u[f+3]=e[c*a+h]?0:255,f+=4}return u},from8bit:function(t){for(var r=new Uint8Array(t.xor),e=n.of1(t.and),o=8*i(t.width*t.bit/8)/t.bit,a=8*i(t.width/8),f=0,u=new Uint8ClampedArray(t.width*t.height*4),c=t.height-1;c>=0;c--)for(var h=0;h<t.width;h++){var s=t.colors[r[c*o+h]];u[f]=s[2],u[f+1]=s[1],u[f+2]=s[0],u[f+3]=e[c*a+h]?0:255,f+=4}return u},from24bit:function(t){for(var r=new Uint8Array(t.xor),e=n.of1(t.and),o=8*i(t.width*t.bit/8)/t.bit,a=8*i(t.width/8),f=0,u=new Uint8ClampedArray(t.width*t.height*4),c=t.height-1;c>=0;c--)for(var h=0;h<t.width;h++)u[f]=r[3*(c*o+h)+2],u[f+1]=r[3*(c*o+h)+1],u[f+2]=r[3*(c*o+h)],u[f+3]=e[c*a+h]?0:255,f+=4;return u},from32bit:function(t){for(var r=new Uint8Array(t.xor),e=n.of1(t.and),o=8*i(t.width*t.bit/8)/t.bit,a=8*i(t.width/8),f=0,u=new Uint8ClampedArray(t.width*t.height*4),c=t.height-1;c>=0;c--)for(var h=0;h<t.width;h++)u[f]=r[4*(c*o+h)+2],u[f+1]=r[4*(c*o+h)+1],u[f+2]=r[4*(c*o+h)],u[f+3]=1===e[c*a+h]||1===r[4*(c*o+h)+3]?0:r[4*(c*o+h)+3]>1?r[4*(c*o+h)+3]:255,f+=4;return u}};t.exports=o}])});
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.ICO=r():t.ICO=r()}(this,function(){return function(t){function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{},id:n,loaded:!1};return t[n].call(i.exports,i,i.exports,r),i.loaded=!0,i.exports}var e={};return r.m=t,r.c=e,r.p="",r(0)}([function(t,r,e){"use strict";var n=e(3),i=e(5),o=i({Image:n});t.exports=o},function(t,r){"use strict";var e={of1:function(t){for(var r=new Uint8Array(t),e="",n=0;n<r.byteLength;n++)e+=("000000000"+r[n].toString(2)).slice(-8);return e.split("").map(function(t){return parseInt(t,2)})},of4:function(t){for(var r=new Uint8Array(t),e="",n=0;n<r.byteLength;n++)e+=("00"+r[n].toString(16)).slice(-2);return e.split("").map(function(t){return parseInt(t,16)})},of8:function(t){for(var r=new Uint8Array(t),e=[],n=0;n<r.byteLength;n++)e.push(r[n]);return e}};t.exports=e},function(t,r){"use strict";var e=function(t){var r=t%4;return t%4===0?t:t+4-r};t.exports=e},function(t,r){"use strict";var e=function(t){for(var r=atob(t.replace(/.+,/,"")),e=new Uint8Array(r.length),n=0;n<r.length;n++)e[n]=r.charCodeAt(n);return e.buffer},n={encode:function(t,r){return new Promise(function(n){var i=t.data,o=document.createElement("canvas");o.width=t.width,o.height=t.height;for(var a=o.getContext("2d"),f=a.createImageData(t.width,t.height),u=f.data,c=0;c<u.length;c++)u[c]=i[c];a.putImageData(f,0,0),n(e(o.toDataURL(r||"image/png")))})}};t.exports=n},function(t,r,e){"use strict";var n=e(1),i=e(2),o=function(t,r){var e=new DataView(t),o=e.getUint8(6+16*r)||256,a=e.getUint8(7+16*r)||256,f=e.getUint32(18+16*r,!0),u=e.getUint16(f+14,!0),c=e.getUint32(18+16*r,!0)+e.getUint32(f,!0),h=e.getUint32(f+32,!0);0===h&&u<=8&&(h=1<<u);for(var s=c+4*h,d=s+i(o*u/8)*a,w={width:o,height:a,colorCount:e.getUint8(8+16*r),bit:u,colors:[],xor:t.slice(s,d),and:t.slice(d,d+i(o/8)*a)},g=0;g<h;g++)w.colors.push(n.of8(t.slice(c+4*g,c+4*g+4)));return w};t.exports=o},function(t,r,e){(function(r){"use strict";var n=e(4),i=e(6),o=function(t){return new Array(t).fill(0).map(function(t,r){return r})},a=function(t){var e=r.ICO,a=t.Image,f={parse:function(t,r){var e=new DataView(t);if(0!==e.getUint16(0,!0)||1!==e.getUint16(2,!0))return Promise.reject(new Error("buffer is not ico"));var f=Promise.all(o(e.getUint16(4,!0)).map(function(e){var o=n(t,e),f={width:o.width,height:o.height};switch(o.bit){case 1:f.data=i.from1bit(o);break;case 4:f.data=i.from4bit(o);break;case 8:f.data=i.from8bit(o);break;case 24:f.data=i.from24bit(o);break;case 32:f.data=i.from32bit(o)}return a.encode(f,r).then(function(t){return{bit:o.bit,width:o.width,height:o.height,buffer:t}})}));return f},isICO:function(t){if(!(t instanceof ArrayBuffer))return!1;var r=new DataView(t);return 0===r.getUint16(0,!0)&&1===r.getUint16(2,!0)},noConflict:function(){return r.ICO=e,this}};return f};t.exports=a}).call(r,function(){return this}())},function(t,r,e){"use strict";var n=e(1),i=e(2),o={from1bit:function(t){for(var r=n.of1(t.xor),e=n.of1(t.and),o=8*i(t.width*t.bit/8)/t.bit,a=8*i(t.width/8),f=0,u=new Uint8ClampedArray(t.width*t.height*4),c=t.height-1;c>=0;c--)for(var h=0;h<t.width;h++){var s=t.colors[r[c*o+h]];u[f]=s[2],u[f+1]=s[1],u[f+2]=s[0],u[f+3]=e[c*a+h]?0:255,f+=4}return u},from4bit:function(t){for(var r=n.of4(t.xor),e=n.of1(t.and),o=8*i(t.width*t.bit/8)/t.bit,a=8*i(t.width/8),f=0,u=new Uint8ClampedArray(t.width*t.height*4),c=t.height-1;c>=0;c--)for(var h=0;h<t.width;h++){var s=t.colors[r[c*o+h]];u[f]=s[2],u[f+1]=s[1],u[f+2]=s[0],u[f+3]=e[c*a+h]?0:255,f+=4}return u},from8bit:function(t){for(var r=new Uint8Array(t.xor),e=n.of1(t.and),o=8*i(t.width*t.bit/8)/t.bit,a=8*i(t.width/8),f=0,u=new Uint8ClampedArray(t.width*t.height*4),c=t.height-1;c>=0;c--)for(var h=0;h<t.width;h++){var s=t.colors[r[c*o+h]];u[f]=s[2],u[f+1]=s[1],u[f+2]=s[0],u[f+3]=e[c*a+h]?0:255,f+=4}return u},from24bit:function(t){for(var r=new Uint8Array(t.xor),e=n.of1(t.and),o=8*i(t.width*t.bit/8)/t.bit,a=8*i(t.width/8),f=0,u=new Uint8ClampedArray(t.width*t.height*4),c=t.height-1;c>=0;c--)for(var h=0;h<t.width;h++)u[f]=r[3*(c*o+h)+2],u[f+1]=r[3*(c*o+h)+1],u[f+2]=r[3*(c*o+h)],u[f+3]=e[c*a+h]?0:255,f+=4;return u},from32bit:function(t){for(var r=new Uint8Array(t.xor),e=n.of1(t.and),o=8*i(t.width*t.bit/8)/t.bit,a=8*i(t.width/8),f=0,u=new Uint8ClampedArray(t.width*t.height*4),c=t.height-1;c>=0;c--)for(var h=0;h<t.width;h++)u[f]=r[4*(c*o+h)+2],u[f+1]=r[4*(c*o+h)+1],u[f+2]=r[4*(c*o+h)],u[f+3]=1===e[c*a+h]||1===r[4*(c*o+h)+3]?0:r[4*(c*o+h)+3]>1?r[4*(c*o+h)+3]:255,f+=4;return u}};t.exports=o}])});
//# sourceMappingURL=ico.js.map
{
"name": "icojs",
"description": "parse ico file",
"version": "0.5.0-alpha",
"version": "0.5.0",
"author": "egy186",

@@ -13,3 +13,3 @@ "bugs": {

"devDependencies": {
"@egy186/eslint-config": "^0.8.0",
"@egy186/eslint-config": "^0.16.0",
"babel-core": "^6.17.0",

@@ -19,7 +19,11 @@ "babel-loader": "^6.2.5",

"chai": "^3.5.0",
"chai-as-promised": "^5.3.0",
"eslint": "^2.13.0",
"chai-as-promised": "^6.0.0",
"eslint": "^3.8.1",
"istanbul": "^0.4.4",
"jsdoc-to-markdown": "^1.3.6",
"mocha": "^2.5.3",
"jsdoc-to-markdown": "^2.0.1",
"jstransformer-markdown-it": "^2.0.0",
"markdown-include": "^0.4.3",
"mocha": "^3.1.2",
"npm-run-all": "^3.1.1",
"pug-cli": "^1.0.0-alpha6",
"rimraf": "^2.5.2",

@@ -49,8 +53,11 @@ "webpack": "^1.13.2"

"scripts": {
"build": "webpack --config webpack.config.js",
"clean": "rimraf coverage dist",
"doc": "jsdoc2md src/ico.js --template templates/README.md > README.md",
"lint": "eslint src test",
"build": "npm-run-all jsdoc --parallel build:*",
"build:dist": "webpack --config webpack.config.js",
"build:docs": "pug templates/index.pug --out docs",
"build:readme": "markdown-include readme.json",
"clean": "rimraf coverage dist docs/index.html templates/documentation.md README.md",
"jsdoc": "jsdoc2md src/ico.js --template templates/documentation.hbs > templates/documentation.md",
"lint": "eslint .",
"test": "istanbul cover --root src --report lcov --dir coverage node_modules/mocha/bin/_mocha -- test/*.js"
}
}
# icojs
[![npm version](https://img.shields.io/npm/v/icojs.svg)](https://www.npmjs.com/package/icojs)
[![Build Status](https://img.shields.io/travis/egy186/icojs.svg)](https://travis-ci.org/egy186/icojs)

@@ -13,22 +12,22 @@ [![Coverage Status](https://img.shields.io/coveralls/egy186/icojs.svg)](https://coveralls.io/r/egy186/icojs)

## Install
```sh
npm install icojs
```
### Node.js:
```js
const fs = require('fs');
const ICO = require('icojs');
const arrayBuffer = new Uint8Array(fs.readFileSync('favicon.ico')).buffer;
ICO.parse(arrayBuffer).then(images => {
// do something
});
```
## Install
### Browser:
```sh
npm install icojs
```js
const ICO = require('icojs/browser')
```
### Browser
or
Include to HTML:
```html

@@ -41,2 +40,35 @@ <script type="text/javascript" src="node_modules/icojs/dist/ico.js"></script>

## Example
### Node.js:
```js
const fs = require('fs');
const ICO = require('icojs');
const arrayBuffer = new Uint8Array(fs.readFileSync('favicon.ico')).buffer;
ICO.parse(arrayBuffer).then(images => {
// do something
});
```
### Browser:
```html
<input type="file" id="input-file" />
<script>
document.getElementById('input-file').addEventListener('change', function (evt) {
// use FileReader for converting File object to ArrayBuffer object
var reader = new FileReader();
reader.onload = function (e) {
ICO.parse(e.target.result).then(function (images) {
// logs images
console.dir(images);
})
};
reader.readAsArrayBuffer(evt.target.files[0]);
}, false);
</script>
```
## Demo

@@ -46,5 +78,6 @@

<a name="ICO"></a>
## Documentation
<a name="ICO"></a>
* [ICO](#ICO)

@@ -51,0 +84,0 @@ * [.parse(buffer, mime)](#ICO.parse) ⇒ <code>Promise.&lt;Array.&lt;Object&gt;&gt;</code>

@@ -27,3 +27,6 @@ 'use strict';

const icoColorsOffset = dv.getUint32(18 + (index * 16), true) + dv.getUint32(icoOffset, true);
const icoColorsCount = dv.getUint32(icoOffset + 32, true);
let icoColorsCount = dv.getUint32(icoOffset + 32, true);
if (icoColorsCount === 0 && icoBit <= 8) {
icoColorsCount = 1 << icoBit;
}
const icoXorOffset = icoColorsOffset + (icoColorsCount * 4);

@@ -30,0 +33,0 @@ const icoAndOffset = icoXorOffset + (toDividableBy4(icoWidth * icoBit / 8) * icoHeight);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc