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.9.1 to 0.10.0

src/parse/index.js

4

dist/ico.js
/*!
* icojs v0.9.1
* icojs v0.10.0
* (c) egy186
* https://github.com/egy186/icojs/blob/master/LICENSE
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.ICO=e()}(this,function(){"use strict";var t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},e=function(t){for(var e=atob(t.replace(/.+,/,"")),n=new Uint8Array(e.length),r=0;r<e.length;r++)n[r]=e.charCodeAt(r);return n.buffer},n={decode:function(t){return new Promise(function(e){var n=URL.createObjectURL(new Blob([t])),r=document.createElement("img");r.src=n,r.onload=function(){var t=r.naturalWidth,n=r.naturalHeight,i=document.createElement("canvas");i.width=t,i.height=n;var a=i.getContext("2d");a.drawImage(r,0,0);var o=a.getImageData(0,0,t,n);e({width:o.width,height:o.height,data:o.data})}})},encode:function(t,n){return new Promise(function(r){var i=t.data,a=document.createElement("canvas");a.width=t.width,a.height=t.height;for(var o=a.getContext("2d"),u=o.createImageData(t.width,t.height),f=u.data,c=0;c<f.length;c++)f[c]=i[c];o.putImageData(u,0,0),r(e(a.toDataURL(n||"image/png")))})}},r=function(t){if(!(t instanceof ArrayBuffer))return!1;var e=new DataView(t);return 0===e.getUint16(0,!0)&&1===e.getUint16(2,!0)},i=function(t){var e=new DataView(t),n=e.getUint8(24),r=e.getUint8(25);return 2===r?3*n:4===r?2*n:6===r?4*n:n},a=function(t){if(!(t instanceof ArrayBuffer))return!1;var e=new DataView(t);return 0===e.getUint16(0,!0)&&2===e.getUint16(2,!0)},o=function(t){if(!(t instanceof ArrayBuffer))return!1;var e=new DataView(t);return 2303741511===e.getUint32(0,!1)&&218765834===e.getUint32(4,!1)},u={of1:function(t){for(var e=new Uint8Array(t),n="",r=0;r<e.byteLength;r++)n+=("000000000"+e[r].toString(2)).slice(-8);return n.split("").map(function(t){return parseInt(t,2)})},of4:function(t){for(var e=new Uint8Array(t),n="",r=0;r<e.byteLength;r++)n+=("00"+e[r].toString(16)).slice(-2);return n.split("").map(function(t){return parseInt(t,16)})},of8:function(t){var e=new Uint8Array(t);return Array.from(e)}},f=function(t){return new Array(t).fill(0).map(function(t,e){return e})},c=function(t){return t%4==0?t:t+4-t%4},d=function(t){for(var e=t.width,n=t.height,r=new Uint8ClampedArray(e*n*4),i=new Uint8Array(t.xor),a=u.of1(t.and),o=t.bit/8,f=c(e*o),d=8*c(e/8),g=0;g<n;g++)for(var h=0;h<e;h++){var s=g*f+h*o;r.set([i[s+2],i[s+1],i[s],a[g*d+h]?0:255],function(t,r){return 4*((n-r-1)*e+t)}(h,g))}return{data:r,height:n,width:e}},g=function(t){for(var e=t.width,n=t.height,r=new Uint8ClampedArray(e*n*4),i=new Uint8Array(t.xor),a=!u.of8(i).every(function(t,e){return(e+1)%4!=0||0===t}),o=u.of1(t.and),f=t.bit/8,d=c(e*f),g=8*c(e/8),h=0;h<n;h++)for(var s=0;s<e;s++){var w=h*d+s*f;r.set([i[w+2],i[w+1],i[w],a?i[w+3]:o[h*g+s]?0:255],function(t,r){return 4*((n-r-1)*e+t)}(s,h))}return{data:r,height:n,width:e}},h=function(t){for(var e=t.width,n=t.height,r=new Uint8ClampedArray(e*n*4),i=u["of"+t.bit](t.xor),a=u.of1(t.and),o=8*c(e*t.bit/8)/t.bit,f=8*c(e/8),d=0;d<n;d++)for(var g=0;g<e;g++){var h=d*o+g,s=t.colors[i[h]];r.set([s[2],s[1],s[0],a[d*f+g]?0:255],function(t,r){return 4*((n-r-1)*e+t)}(g,d))}return{data:r,height:n,width:e}},s=function(t){return 32===t.bit?g(t):24===t.bit?d(t):h(t)},w=function(t,e,n){var r=new DataView(n),i=r.getUint32(0,!0),a=r.getUint16(14,!0),o=r.getUint32(32,!0);0===o&&a<=8&&(o=1<<a);var d=i+4*o,g=d+c(t*a/8)*e,h={and:n.slice(g,g+c(t/8)*e),bit:a,colors:f(o).map(function(t){var e=i+4*t;return u.of8(n.slice(e,e+4))}),height:e,width:t,xor:n.slice(d,g)};return Object.assign(s(h),{bit:a})},l=function(t,e,n){if(!(t instanceof ArrayBuffer))return Promise.reject(new TypeError('"buffer" argument must be an ArrayBuffer'));if(!a(t)&&!r(t))return Promise.reject(new Error("buffer is not ico"));var u=new DataView(t).getUint16(4,!0),c=f(u).map(function(e){var n=6+16*e;return t.slice(n,n+16)}),d=f(u).map(function(e){var n=new DataView(c[e]),r=n.getUint32(8,!0),i=n.getUint32(12,!0);return t.slice(i,i+r)}),g=function(t,e,r){if(o(r)){var a=i(r);return n.decode(r).then(function(t){return Object.assign(t,{bit:a})})}return Promise.resolve(w(t,e,r))},h=f(u).map(function(r){var i=new DataView(c[r]),o=i.getUint8(0)||256,u=i.getUint8(1)||256;return g(o,u,d[r]).then(function(r){return a(t)&&(r.hotspot={x:i.getUint16(4,!0),y:i.getUint16(6,!0)}),n.encode(r,e).then(function(t){var e=Object.assign({buffer:t},r);return delete e.data,e})})});return Promise.all(h)},v=t.ICO;return{isICO:r,noConflict:function(){return t.ICO=v,this},parse:function(t,e){return l(t,e,n)}}});
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.ICO=n()}(this,function(){"use strict";var t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=function(t){for(var n=atob(t.replace(/.+,/,"")),e=new Uint8Array(n.length),r=0;r<n.length;r++)e[r]=n.charCodeAt(r);return e.buffer},e={decode:function(t){return new Promise(function(n){var e=URL.createObjectURL(new Blob([t])),r=document.createElement("img");r.src=e,r.onload=function(){var t=r.naturalWidth,e=r.naturalHeight,i=document.createElement("canvas");i.width=t,i.height=e;var a=i.getContext("2d");a.drawImage(r,0,0);var o=a.getImageData(0,0,t,e);n({width:o.width,height:o.height,data:o.data})}})},encode:function(t,e){return new Promise(function(r){var i=t.data,a=document.createElement("canvas");a.width=t.width,a.height=t.height;for(var o=a.getContext("2d"),u=o.createImageData(t.width,t.height),f=u.data,c=0;c<f.length;c++)f[c]=i[c];o.putImageData(u,0,0),r(n(a.toDataURL(e||"image/png")))})}},r=function(t){if(!(t instanceof ArrayBuffer))return!1;var n=new DataView(t);return 0===n.getUint16(0,!0)&&1===n.getUint16(2,!0)},i=function(t){var n=new DataView(t),e=n.getUint8(24),r=n.getUint8(25);return 2===r?3*e:4===r?2*e:6===r?4*e:e},a=function(t,n,e){var r={bit:e,buffer:n,height:t.height,width:t.width};return t.hotspot&&(r.hotspot=t.hotspot),r},o=function(t){if(!(t instanceof ArrayBuffer))return!1;var n=new DataView(t);return 2303741511===n.getUint32(0,!1)&&218765834===n.getUint32(4,!1)},u={of1:function(t){for(var n=new Uint8Array(t),e="",r=0;r<n.byteLength;r++)e+=("000000000"+n[r].toString(2)).slice(-8);return e.split("").map(function(t){return parseInt(t,2)})},of4:function(t){for(var n=new Uint8Array(t),e="",r=0;r<n.byteLength;r++)e+=("00"+n[r].toString(16)).slice(-2);return e.split("").map(function(t){return parseInt(t,16)})},of8:function(t){var n=new Uint8Array(t);return Array.from(n)}},f=function(t){return new Array(t).fill(0).map(function(t,n){return n})},c=function(t){return t%4==0?t:t+4-t%4},h=function(t){for(var n=t.width,e=t.height,r=new Uint8ClampedArray(n*e*4),i=new Uint8Array(t.xor),a=u.of1(t.and),o=t.bit/8,f=c(n*o),h=8*c(n/8),d=0;d<e;d++)for(var g=0;g<n;g++){var w=d*f+g*o;r.set([i[w+2],i[w+1],i[w],a[d*h+g]?0:255],function(t,r){return 4*((e-r-1)*n+t)}(g,d))}return{data:r,height:e,width:n}},d=function(t){for(var n=t.width,e=t.height,r=new Uint8ClampedArray(n*e*4),i=new Uint8Array(t.xor),a=!u.of8(i).every(function(t,n){return(n+1)%4!=0||0===t}),o=u.of1(t.and),f=t.bit/8,h=c(n*f),d=8*c(n/8),g=0;g<e;g++)for(var w=0;w<n;w++){var s=g*h+w*f;r.set([i[s+2],i[s+1],i[s],a?i[s+3]:o[g*d+w]?0:255],function(t,r){return 4*((e-r-1)*n+t)}(w,g))}return{data:r,height:e,width:n}},g=function(t){for(var n=t.width,e=t.height,r=new Uint8ClampedArray(n*e*4),i=u["of"+t.bit](t.xor),a=u.of1(t.and),o=8*c(n*t.bit/8)/t.bit,f=8*c(n/8),h=0;h<e;h++)for(var d=0;d<n;d++){var g=h*o+d,w=t.colors[i[g]];r.set([w[2],w[1],w[0],a[h*f+d]?0:255],function(t,r){return 4*((e-r-1)*n+t)}(d,h))}return{data:r,height:e,width:n}},w=function(t){return 32===t.bit?d(t):24===t.bit?h(t):g(t)},s=function(t,n,e){var r=new DataView(e),i=r.getUint32(0,!0),a=r.getUint16(14,!0),o=r.getUint32(32,!0);0===o&&a<=8&&(o=1<<a);var h=i+4*o,d=h+c(t*a/8)*n,g={and:e.slice(d,d+c(t/8)*n),bit:a,colors:f(o).map(function(t){var n=i+4*t;return u.of8(e.slice(n,n+4))}),height:n,width:t,xor:e.slice(h,d)};return Object.assign(w(g),{bit:a})},l=function(t){if(!(t instanceof ArrayBuffer))return!1;var n=new DataView(t);return 0===n.getUint16(0,!0)&&2===n.getUint16(2,!0)},v=function(t){if(!(t instanceof ArrayBuffer))throw new TypeError('"buffer" argument must be an ArrayBuffer');if(!l(t)&&!r(t))throw new Error("buffer is not ico");var n=new DataView(t).getUint16(4,!0),e=f(n).map(function(n){var e=6+16*n;return t.slice(e,e+16)});return f(n).map(function(n){var r=new DataView(e[n]),i=r.getUint32(8,!0),a=r.getUint32(12,!0),o={height:r.getUint8(1)||256,iconImage:t.slice(a,a+i),width:r.getUint8(0)||256};return l(t)&&(o.hotspot={x:r.getUint16(4,!0),y:r.getUint16(6,!0)}),o})},m=function(t,n,e){var r=[];try{r=v(t)}catch(t){return Promise.reject(t)}var u=function(t,n,r){if(o(r)){var a=i(r);return e.decode(r).then(function(t){return Object.assign(t,{bit:a})})}return Promise.resolve(s(t,n,r))},f=r.map(function(t){return u(t.width,t.height,t.iconImage).then(function(r){return e.encode(r,n).then(function(n){return a(t,n,r.bit)})})});return Promise.all(f)},p=t.ICO;return{isICO:r,noConflict:function(){return t.ICO=p,this},parse:function(t,n){return m(t,n,e)}}});
//# sourceMappingURL=ico.js.map
{
"name": "icojs",
"description": "parse ico file",
"version": "0.9.1",
"version": "0.10.0",
"author": "egy186",

@@ -10,7 +10,10 @@ "bugs": {

"dependencies": {
"jimp": "^0.2.24",
"bmp-js": "0.0.3",
"file-type": "^7.2.0",
"jpeg-js": "^0.3.3",
"pngjs": "^3.3.0",
"safe-buffer": "^5.1.1"
},
"devDependencies": {
"@egy186/eslint-config": "~0.29.0",
"@egy186/eslint-config": "~0.30.0",
"babel-core": "^6.26.0",

@@ -22,3 +25,3 @@ "babel-plugin-external-helpers": "^6.22.0",

"concat": "^1.0.3",
"eslint": "~4.11.0",
"eslint": "~4.12.0",
"jsdoc-to-markdown": "^3.0.0",

@@ -30,5 +33,6 @@ "jsonfile": "^4.0.0",

"nyc": "^11.1.0",
"pixelmatch": "^4.0.2",
"pug-cli": "^1.0.0-alpha6",
"rimraf": "^2.5.2",
"rollup": "^0.51.3",
"rollup": "^0.53.0",
"rollup-plugin-babel": "^3.0.2",

@@ -66,5 +70,5 @@ "rollup-plugin-commonjs": "^8.2.1",

"lint": "eslint .",
"test": "nyc --reporter lcov --reporter text-summary --report-dir coverage mocha test/*.js",
"test": "nyc --reporter lcov --reporter text-summary --report-dir coverage mocha \"test/**/*.spec.js\"",
"version": "npm run build && git add docs/index.html README.md"
}
}

@@ -90,2 +90,3 @@ # icojs

* [parse(buffer, [mime])](#exp_module_ICO--parse) ⇒ <code>Promise.&lt;Array.&lt;ParsedImage&gt;&gt;</code> ⏏
* [parseSync(buffer, [mime])](#exp_module_ICO--parseSync) ⇒ [<code>Array.&lt;ParsedImage&gt;</code>](#ParsedImage) ⏏

@@ -117,3 +118,16 @@ <a name="exp_module_ICO--isICO"></a>

<a name="exp_module_ICO--parseSync"></a>
#### parseSync(buffer, [mime]) ⇒ [<code>Array.&lt;ParsedImage&gt;</code>](#ParsedImage) ⏏
Parse ICO and return some images synchronously.
**Kind**: global method of [<code>ICO</code>](#module_ICO)
**Returns**: [<code>Array.&lt;ParsedImage&gt;</code>](#ParsedImage) - Returns an array of [ParsedImage](#ParsedImage).
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| buffer | <code>ArrayBuffer</code> \| <code>Buffer</code> | | ICO file data. |
| [mime] | <code>String</code> | <code>image/png</code> | MIME type for output. |
## API (browser)

@@ -120,0 +134,0 @@

'use strict';
const Image = require('./image');
const isICO = require('../is-ico');
const parseICO = require('../parse-ico');
const parseICO = require('../parse');

@@ -8,0 +7,0 @@ const globalICO = global.ICO;

'use strict';
const Buffer = require('safe-buffer').Buffer;
const Jimp = require('jimp');
const PNG = require('pngjs').PNG;
const bmp = require('bmp-js');
const bufferToArrayBuffer = require('./buffer-to-arraybuffer');
const fileType = require('file-type');
const jpeg = require('jpeg-js');
const MIME_BMP = 'image/bmp';
const MIME_JPEG = 'image/jpeg';
const MIME_PNG = 'image/png';
const decoders = {
[MIME_BMP]: bmp.decode,
[MIME_JPEG]: jpeg.decode,
[MIME_PNG]: PNG.sync.read
};
const encoders = {
[MIME_BMP]: imageData => bmp.encode(imageData).data,
[MIME_JPEG]: imageData => jpeg.encode(imageData).data,
[MIME_PNG]: PNG.sync.write
};
const Image = {
/**
* Asynchronously create imageData from image
* @access private
* @param {ArrayBuffer} arrayBuffer image buffer
* @returns {Promise<ImageData>} Resolves to imageData
*/
decode (arrayBuffer) {
try {
const imageData = this.decodeSync(arrayBuffer);
return Promise.resolve(imageData);
} catch (err) {
/* istanbul ignore next */
return Promise.reject(err);
}
},
/**
* Create imageData from image

@@ -15,11 +48,37 @@ * @access private

*/
decode (arrayBuffer) {
decodeSync (arrayBuffer) {
const buffer = Buffer.from(arrayBuffer);
return Jimp.read(buffer).then(image => ({
width: image.bitmap.width,
height: image.bitmap.height,
data: new Uint8ClampedArray(image.bitmap.data)
}));
const type = fileType(buffer);
const mime = type ? type.mime : null;
if (!(mime in decoders)) {
throw new TypeError(`${mime} is not supported`);
}
const decoder = decoders[mime];
const imageData = decoder(buffer);
return {
data: new Uint8ClampedArray(imageData.data),
height: imageData.height,
width: imageData.width
};
},
/**
* Asynchronously create image from imgData.data
* @access private
* @param {Object} image data
* @param {Number} image.width img width
* @param {Number} image.height img height
* @param {Uint8ClampedArray} image.data same as imageData.data
* @param {String} [mime=image/png] MIME type
* @returns {Promise<ArrayBuffer>} Resolves to image
*/
encode (image, mime) {
try {
const imageArrayBuffer = this.encodeSync(image, mime);
return Promise.resolve(imageArrayBuffer);
} catch (err) {
/* istanbul ignore next */
return Promise.reject(err);
}
},
/**
* Create image from imgData.data

@@ -34,21 +93,11 @@ * @access private

*/
encode (image, mime) {
const data = image.data;
const jimp = new Jimp(image.width, image.height);
jimp.scan(0, 0, jimp.bitmap.width, jimp.bitmap.height, function scan (x, y, idx) {
this.bitmap.data[idx + 0] = data[idx + 0]; // eslint-disable-line no-invalid-this
this.bitmap.data[idx + 1] = data[idx + 1]; // eslint-disable-line no-invalid-this
this.bitmap.data[idx + 2] = data[idx + 2]; // eslint-disable-line no-invalid-this
this.bitmap.data[idx + 3] = data[idx + 3]; // eslint-disable-line no-invalid-this
});
return new Promise((resolve, reject) => {
jimp.getBuffer(mime || Jimp.MIME_PNG, (err, buffer) => {
/* istanbul ignore if */
if (err) {
reject(err);
} else {
resolve(bufferToArrayBuffer(buffer));
}
});
});
encodeSync (image, mime) {
const imageData = {
data: Buffer.from(image.data),
height: image.height,
width: image.width
};
const encoder = mime in encoders ? encoders[mime] : encoders[MIME_PNG];
const imageBuffer = encoder(imageData);
return bufferToArrayBuffer(imageBuffer);
}

@@ -55,0 +104,0 @@ };

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

const bufferToArrayBuffer = require('./buffer-to-arraybuffer');
const parseICO = require('../parse-ico');
const parseICO = require('../parse');
const parseICOSync = require('../parse/sync');

@@ -39,2 +40,17 @@ /**

/**
* Parse ICO and return some images synchronously.
* @alias module:ICO
* @param {ArrayBuffer|Buffer} buffer ICO file data.
* @param {String} [mime=image/png] MIME type for output.
* @returns {ParsedImage[]} Returns an array of {@link ParsedImage}.
*/
const parseSync = (buffer, mime) => {
const arrayBuffer = bufferToArrayBuffer(buffer);
if (!arrayBuffer) {
throw new TypeError('"buffer" argument must be a Buffer or ArrayBuffer');
}
return parseICOSync(arrayBuffer, mime, Image);
};
/**
* @module ICO

@@ -44,5 +60,6 @@ */

isICO,
parse
parse,
parseSync
};
module.exports = ICO;

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