New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

canvas-to-buffer

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

canvas-to-buffer - npm Package Compare versions

Comparing version 1.1.1 to 2.0.0

dist/canvas-to-buffer.modern.js

5

.eslintrc.json
{
"parser": "babel-eslint",
"plugins": [],
"extends": ["standard"],
"env": {
},
"rules": {
"no-else-return": 1,
"space-before-function-paren": 0
},
"globals": {
}
}

2

dist/canvas-to-buffer.js

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

var t,e=require("typedarray-to-buffer"),n=require("atob"),a="undefined"!=typeof document&&"function"==typeof document.createElement;module.exports=function(i,r){var o=this;if((r=r||{}).image=r.image?r.image:{},r.image.types=r.image.types?r.image.types:[],r.image.types.length>2)throw new Error("Too many image types are specified!");r.image.types.length<1&&(r.image.types=a?["webp","jpeg"]:["png"]),r.image.quality||(r.image.quality=.5);var u=parseFloat(r.image.quality);function g(t){var e;return r.image.types[t]&&(e="image/"+r.image.types[t]),e}function f(t,e){var n=t&&t.match(e);return n&&r.debug&&r.debug("Image type %s verified",e),n}function c(){var t;return a?(t=document.createElement("canvas")).width=t.height=1:t=i,t}function l(t,e){try{c().toDataURL(t,function(n,a){n?e(n):e(null,f(a,t))})}catch(t){e(null,!1)}}function m(t){var e;try{var n=c();e=f(n.toDataURL&&n.toDataURL(t),t)}catch(e){r.debug&&r.logger.debug("Failed to call toDataURL() on canvas for image type %s",t)}return e}function y(t){var e=g(0);if(!t)return function(t){return m(t)||r.image.types[1]&&m(t=g(1))||(t=null),!t&&r.debug&&r.logger.debug("Unable to verify image type"),t}(e);!function(t,e){l(t,function(n,a){n?e(n):a?e(null,t):l(t=g(1),function(n,a){n?e(n):e(null,a?t:null)})})}(e,t)}function p(t){var a,i=t.split(",")[1];if("function"==typeof n)a=n(i);else{if("function"!=typeof o.constructor.atob)throw new Error("atob function is missing");a=o.constructor.atob(i)}for(var r=new Uint8Array(a.length),u=0,g=a.length;u<g;u++)r[u]=a.charCodeAt(u);return e(r)}this.toBuffer=function(t){if(!t)return(n=o.getImageType())&&(e=p(i.toDataURL(n,u))),e;var e,n;!function(t){o.getImageType(function(e,n){e?t(e):n?i.toDataURL(n,function(e,n){e?t(e):t(null,p(n))}):t()})}(t)},this.getImageType=function(e){if(!e)return t&&a||(t=y()),t;t&&a?e(null,t):y(function(n,a){n?e(n):e(null,t=a)})}};
var t,e=require("typedarray-to-buffer"),n=require("atob"),a="undefined"!=typeof document&&"function"==typeof document.createElement;module.exports=function(i,r){void 0===r&&(r={});var o=this;if(r.image=r.image?r.image:{},r.image.types=r.image.types?r.image.types:[],r.image.types.length>2)throw new Error("Too many image types are specified!");r.image.types.length<1&&(r.image.types=a?["webp","jpeg"]:["png"]),r.image.quality||(r.image.quality=.5);var u=parseFloat(r.image.quality);function g(t){var e;return r.image.types[t]&&(e="image/"+r.image.types[t]),e}function f(t,e){var n=t&&t.match(e);return n&&r.debug&&r.debug("Image type %s verified",e),n}function c(){var t;return a?(t=document.createElement("canvas")).width=t.height=1:t=i,t}function l(t,e){try{c().toDataURL(t,function(n,a){n?e(n):e(null,f(a,t))})}catch(t){e(null,!1)}}function m(t){var e;try{var n=c();e=f(n.toDataURL&&n.toDataURL(t),t)}catch(e){r.debug&&r.logger.debug("Failed to call toDataURL() on canvas for image type %s",t)}return e}function y(t){var e=g(0);if(!t)return function(t){return m(t)||r.image.types[1]&&m(t=g(1))||(t=null),!t&&r.debug&&r.logger.debug("Unable to verify image type"),t}(e);!function(t,e){l(t,function(n,a){n?e(n):a?e(null,t):l(t=g(1),function(n,a){n?e(n):e(null,a?t:null)})})}(e,t)}function p(t){var a,i=t.split(",")[1];if("function"==typeof n)a=n(i);else{if("function"!=typeof o.constructor.atob)throw new Error("atob function is missing");a=o.constructor.atob(i)}for(var r=new Uint8Array(a.length),u=0,g=a.length;u<g;u++)r[u]=a.charCodeAt(u);return e(r)}this.toBuffer=function(t){if(!t)return(n=o.getImageType())&&(e=p(i.toDataURL(n,u))),e;var e,n;!function(t){o.getImageType(function(e,n){e?t(e):n?i.toDataURL(n,function(e,n){e?t(e):t(null,p(n))}):t()})}(t)},this.getImageType=function(e){if(!e)return t&&a||(t=y()),t;t&&a?e(null,t):y(function(n,a){n?e(n):e(null,t=a)})}};
//# sourceMappingURL=canvas-to-buffer.js.map

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(0,function(){var e,t=require("typedarray-to-buffer"),n=require("atob"),i="undefined"!=typeof document&&"function"==typeof document.createElement;module.exports=function(a,o){var r=this;if((o=o||{}).image=o.image?o.image:{},o.image.types=o.image.types?o.image.types:[],o.image.types.length>2)throw new Error("Too many image types are specified!");o.image.types.length<1&&(o.image.types=i?["webp","jpeg"]:["png"]),o.image.quality||(o.image.quality=.5);var u=parseFloat(o.image.quality);function f(e){var t;return o.image.types[e]&&(t="image/"+o.image.types[e]),t}function c(e,t){var n=e&&e.match(t);return n&&o.debug&&o.debug("Image type %s verified",t),n}function g(){var e;return i?(e=document.createElement("canvas")).width=e.height=1:e=a,e}function l(e,t){try{g().toDataURL(e,function(n,i){n?t(n):t(null,c(i,e))})}catch(e){t(null,!1)}}function m(e){var t;try{var n=g();t=c(n.toDataURL&&n.toDataURL(e),e)}catch(t){o.debug&&o.logger.debug("Failed to call toDataURL() on canvas for image type %s",e)}return t}function y(e){var t=f(0);if(!e)return function(e){return m(e)||o.image.types[1]&&m(e=f(1))||(e=null),!e&&o.debug&&o.logger.debug("Unable to verify image type"),e}(t);!function(e,t){l(e,function(n,i){n?t(n):i?t(null,e):l(e=f(1),function(n,i){n?t(n):t(null,i?e:null)})})}(t,e)}function p(e){var i,a=e.split(",")[1];if("function"==typeof n)i=n(a);else{if("function"!=typeof r.constructor.atob)throw new Error("atob function is missing");i=r.constructor.atob(a)}for(var o=new Uint8Array(i.length),u=0,f=i.length;u<f;u++)o[u]=i.charCodeAt(u);return t(o)}this.toBuffer=function(e){if(!e)return(n=r.getImageType())&&(t=p(a.toDataURL(n,u))),t;var t,n;!function(e){r.getImageType(function(t,n){t?e(t):n?a.toDataURL(n,function(t,n){t?e(t):e(null,p(n))}):e()})}(e)},this.getImageType=function(t){if(!t)return e&&i||(e=y()),e;e&&i?t(null,e):y(function(n,i){n?t(n):t(null,e=i)})}}});
!function(e){"function"==typeof define&&define.amd?define(e):e()}(function(){var e,t=require("typedarray-to-buffer"),n=require("atob"),i="undefined"!=typeof document&&"function"==typeof document.createElement;module.exports=function(a,o){void 0===o&&(o={});var r=this;if(o.image=o.image?o.image:{},o.image.types=o.image.types?o.image.types:[],o.image.types.length>2)throw new Error("Too many image types are specified!");o.image.types.length<1&&(o.image.types=i?["webp","jpeg"]:["png"]),o.image.quality||(o.image.quality=.5);var u=parseFloat(o.image.quality);function f(e){var t;return o.image.types[e]&&(t="image/"+o.image.types[e]),t}function c(e,t){var n=e&&e.match(t);return n&&o.debug&&o.debug("Image type %s verified",t),n}function g(){var e;return i?(e=document.createElement("canvas")).width=e.height=1:e=a,e}function l(e,t){try{g().toDataURL(e,function(n,i){n?t(n):t(null,c(i,e))})}catch(e){t(null,!1)}}function m(e){var t;try{var n=g();t=c(n.toDataURL&&n.toDataURL(e),e)}catch(t){o.debug&&o.logger.debug("Failed to call toDataURL() on canvas for image type %s",e)}return t}function y(e){var t=f(0);if(!e)return function(e){return m(e)||o.image.types[1]&&m(e=f(1))||(e=null),!e&&o.debug&&o.logger.debug("Unable to verify image type"),e}(t);!function(e,t){l(e,function(n,i){n?t(n):i?t(null,e):l(e=f(1),function(n,i){n?t(n):t(null,i?e:null)})})}(t,e)}function p(e){var i,a=e.split(",")[1];if("function"==typeof n)i=n(a);else{if("function"!=typeof r.constructor.atob)throw new Error("atob function is missing");i=r.constructor.atob(a)}for(var o=new Uint8Array(i.length),u=0,f=i.length;u<f;u++)o[u]=i.charCodeAt(u);return t(o)}this.toBuffer=function(e){if(!e)return(n=r.getImageType())&&(t=p(a.toDataURL(n,u))),t;var t,n;!function(e){r.getImageType(function(t,n){t?e(t):n?a.toDataURL(n,function(t,n){t?e(t):e(null,p(n))}):e()})}(e)},this.getImageType=function(t){if(!t)return e&&i||(e=y()),e;e&&i?t(null,e):y(function(n,i){n?t(n):t(null,e=i)})}}});
//# sourceMappingURL=canvas-to-buffer.umd.js.map
{
"name": "canvas-to-buffer",
"version": "1.1.1",
"version": "2.0.0",
"description": "Converts a Canvas graphic into a Buffer, as fast as possible and without a copy.",

@@ -10,4 +10,5 @@ "source": "index.js",

"scripts": {
"lint": "standard index.js",
"build": "microbundle",
"lint": "standard src",
"lint:fix": "standard --fix src",
"build": "microbundle src",
"test": "tape test/*.js"

@@ -34,16 +35,15 @@ },

"engines": {
"node": ">=8.10.0",
"yarn": ">=1.3.0",
"npm": ">=5.4.0"
"node": "^16.13.1",
"npm": "^8.1.2"
},
"dependencies": {
"atob": "2.1.2",
"typedarray-to-buffer": "3.1.5"
"typedarray-to-buffer": "4.0.0"
},
"devDependencies": {
"canvas": "2.6.0",
"microbundle": "0.11.0",
"standard": "13.1.0",
"tape": "4.11.0"
"canvas": "2.8.0",
"microbundle": "0.14.2",
"standard": "16.0.4",
"tape": "5.4.0"
}
}

@@ -5,3 +5,3 @@ const test = require('tape')

const Frame = require('./../')
const Frame = require('./../src/index')

@@ -28,4 +28,3 @@ // Add missing function because atob only exists on the browser

}
})
.getImageType(function (err, imageType) {
}).getImageType(function (err, imageType) {
tt.equal(err, null)

@@ -162,24 +161,3 @@ tt.equal(imageType, undefined)

})
tt.test('buffer from large canvas has correct JPG contents', function (tt) {
tt.plan(4)
var frame = new Frame(createCanvas(1000, 1000), {
image: {
types: ['jpeg']
}
})
frame.toBuffer(function (err, buffer) {
tt.equal(err, null)
tt.equal(buffer.length, 16503)
// https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format
const lastTwoBytes = buffer.slice(-2)
tt.equal(0xFF, lastTwoBytes[0])
tt.equal(0xD9, lastTwoBytes[1])
})
})
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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