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
0
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 4.0.0 to 4.0.1

dist/src/index.d.ts

2

dist/canvas-to-buffer.esm.js

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

import t from"typedarray-to-buffer";import e from"atob";var i,r="undefined"!=typeof document&&"function"==typeof document.createElement,n=r?["webp","jpeg"]:["png"],o=/*#__PURE__*/function(){function o(t,e,i){if(void 0===e&&(e=n),void 0===i&&(i=.5),this.quality=void 0,this.types=void 0,this.canvas=void 0,e.length>2)throw new Error("Too many image types are specified!");this.canvas=t,this.quality=i,this.types=e}var a=o.prototype;return a.composeMimeType=function(t){var e;return this.types[t]&&(e="image/"+this.types[t]),e},a.isMatch=function(t,e){return t.match(e)},a.getTestCanvas=function(){var t;return r?(t=document.createElement("canvas")).width=t.height=1:t=this.canvas,t},a.canvasSupportsMimeType=function(t){try{var e=this.getTestCanvas(),i=e.toDataURL&&e.toDataURL(t);return this.isMatch(i,t)}catch(t){return!1}},a.figureMimeType=function(){var t=this.composeMimeType(0);return t&&this.canvasSupportsMimeType(t)||(this.types[1]?(t=this.composeMimeType(1))&&!this.canvasSupportsMimeType(t)&&(t=void 0):t=void 0),t},a.uriToBuffer=function(i){var r,n=i.split(",")[1];if(!n)throw new Error("Empty uri string given!");if("function"!=typeof e)throw new Error("atob function is missing");r=e(n);for(var o=new Uint8Array(r.length),a=0,s=r.length;a<s;a++)o[a]=r.charCodeAt(a);return t(o)},a.toBuffer=function(){var t,e=this.getMimeType();if(e){var i=this.canvas.toDataURL(e,this.quality);t=this.uriToBuffer(i)}return t},a.getMimeType=function(){return i&&r||(i=this.figureMimeType()),i},o}();o.atob=void 0;export{o as default};
import t from"typedarray-to-buffer";var e,i="undefined"!=typeof document&&"function"==typeof document.createElement,r=i?["webp","jpeg"]:["png"],n=/*#__PURE__*/function(){function n(t,e,i){if(void 0===e&&(e=r),void 0===i&&(i=.5),this.quality=void 0,this.types=void 0,this.canvas=void 0,e.length>2)throw new Error("Too many image types are specified!");this.canvas=t,this.quality=i,this.types=e}var o=n.prototype;return o.composeMimeType=function(t){var e;return this.types[t]&&(e="image/"+this.types[t]),e},o.isMatch=function(t,e){return t.match(e)},o.getTestCanvas=function(){var t;return i?(t=document.createElement("canvas")).width=t.height=1:t=this.canvas,t},o.canvasSupportsMimeType=function(t){try{var e=this.getTestCanvas(),i=e.toDataURL&&e.toDataURL(t);return this.isMatch(i,t)}catch(t){return!1}},o.figureMimeType=function(){var t=this.composeMimeType(0);return t&&this.canvasSupportsMimeType(t)||(this.types[1]?(t=this.composeMimeType(1))&&!this.canvasSupportsMimeType(t)&&(t=void 0):t=void 0),t},o.uriToBuffer=function(e){var r,o=e.split(",")[1];if(!o)throw new Error("Empty uri string given!");if(!(r=i?window.atob(o):null==n.atob?void 0:n.atob(o)))throw new Error("Byte are empty, something within atob went wrong.");for(var a=new Uint8Array(r.length),s=0,u=r.length;s<u;s++)a[s]=r.charCodeAt(s);return t(a)},o.toBuffer=function(){var t,e=this.getMimeType();if(e){var i=this.canvas.toDataURL(e,this.quality);t=this.uriToBuffer(i)}return t},o.getMimeType=function(){return e&&i||(e=this.figureMimeType()),e},n}();n.atob=void 0;export{n as default};
//# sourceMappingURL=canvas-to-buffer.esm.js.map

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

import t from"typedarray-to-buffer";import e from"atob";const i="undefined"!=typeof document&&"function"==typeof document.createElement,s=i?["webp","jpeg"]:["png"];let r;class o{constructor(t,e=s,i=.5){if(this.quality=void 0,this.types=void 0,this.canvas=void 0,e.length>2)throw new Error("Too many image types are specified!");this.canvas=t,this.quality=i,this.types=e}composeMimeType(t){let e;return this.types[t]&&(e="image/"+this.types[t]),e}isMatch(t,e){return t.match(e)}getTestCanvas(){let t;return i?(t=document.createElement("canvas"),t.width=t.height=1):t=this.canvas,t}canvasSupportsMimeType(t){try{const e=this.getTestCanvas(),i=e.toDataURL&&e.toDataURL(t);return this.isMatch(i,t)}catch(t){return!1}}figureMimeType(){let t=this.composeMimeType(0);return t&&this.canvasSupportsMimeType(t)||(this.types[1]?(t=this.composeMimeType(1),t&&!this.canvasSupportsMimeType(t)&&(t=void 0)):t=void 0),t}uriToBuffer(i){const s=i.split(",")[1];let r;if(!s)throw new Error("Empty uri string given!");if("function"!=typeof e)throw new Error("atob function is missing");r=e(s);const o=new Uint8Array(r.length);for(let t=0,e=r.length;t<e;t++)o[t]=r.charCodeAt(t);return t(o)}toBuffer(){const t=this.getMimeType();let e;if(t){const i=this.canvas.toDataURL(t,this.quality);e=this.uriToBuffer(i)}return e}getMimeType(){return r&&i||(r=this.figureMimeType()),r}}o.atob=void 0;export{o as default};
import t from"typedarray-to-buffer";const e="undefined"!=typeof document&&"function"==typeof document.createElement,i=e?["webp","jpeg"]:["png"];let s;class r{constructor(t,e=i,s=.5){if(this.quality=void 0,this.types=void 0,this.canvas=void 0,e.length>2)throw new Error("Too many image types are specified!");this.canvas=t,this.quality=s,this.types=e}composeMimeType(t){let e;return this.types[t]&&(e="image/"+this.types[t]),e}isMatch(t,e){return t.match(e)}getTestCanvas(){let t;return e?(t=document.createElement("canvas"),t.width=t.height=1):t=this.canvas,t}canvasSupportsMimeType(t){try{const e=this.getTestCanvas(),i=e.toDataURL&&e.toDataURL(t);return this.isMatch(i,t)}catch(t){return!1}}figureMimeType(){let t=this.composeMimeType(0);return t&&this.canvasSupportsMimeType(t)||(this.types[1]?(t=this.composeMimeType(1),t&&!this.canvasSupportsMimeType(t)&&(t=void 0)):t=void 0),t}uriToBuffer(i){const s=i.split(",")[1];let o;if(!s)throw new Error("Empty uri string given!");if(o=e?window.atob(s):null==r.atob?void 0:r.atob(s),!o)throw new Error("Byte are empty, something within atob went wrong.");const n=new Uint8Array(o.length);for(let t=0,e=o.length;t<e;t++)n[t]=o.charCodeAt(t);return t(n)}toBuffer(){const t=this.getMimeType();let e;if(t){const i=this.canvas.toDataURL(t,this.quality);e=this.uriToBuffer(i)}return e}getMimeType(){return s&&e||(s=this.figureMimeType()),s}}r.atob=void 0;export{r as default};
//# sourceMappingURL=canvas-to-buffer.modern.js.map

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

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("typedarray-to-buffer"),require("atob")):"function"==typeof define&&define.amd?define(["typedarray-to-buffer","atob"],e):(t||self).canvasToBuffer=e(t.typedarrayToBuffer,t.atob)}(this,function(t,e){function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n,r=/*#__PURE__*/i(t),o=/*#__PURE__*/i(e),a="undefined"!=typeof document&&"function"==typeof document.createElement,u=a?["webp","jpeg"]:["png"],s=/*#__PURE__*/function(){function t(t,e,i){if(void 0===e&&(e=u),void 0===i&&(i=.5),this.quality=void 0,this.types=void 0,this.canvas=void 0,e.length>2)throw new Error("Too many image types are specified!");this.canvas=t,this.quality=i,this.types=e}var e=t.prototype;return e.composeMimeType=function(t){var e;return this.types[t]&&(e="image/"+this.types[t]),e},e.isMatch=function(t,e){return t.match(e)},e.getTestCanvas=function(){var t;return a?(t=document.createElement("canvas")).width=t.height=1:t=this.canvas,t},e.canvasSupportsMimeType=function(t){try{var e=this.getTestCanvas(),i=e.toDataURL&&e.toDataURL(t);return this.isMatch(i,t)}catch(t){return!1}},e.figureMimeType=function(){var t=this.composeMimeType(0);return t&&this.canvasSupportsMimeType(t)||(this.types[1]?(t=this.composeMimeType(1))&&!this.canvasSupportsMimeType(t)&&(t=void 0):t=void 0),t},e.uriToBuffer=function(t){var e,i=t.split(",")[1];if(!i)throw new Error("Empty uri string given!");if("function"!=typeof o.default)throw new Error("atob function is missing");e=o.default(i);for(var n=new Uint8Array(e.length),a=0,u=e.length;a<u;a++)n[a]=e.charCodeAt(a);return r.default(n)},e.toBuffer=function(){var t,e=this.getMimeType();if(e){var i=this.canvas.toDataURL(e,this.quality);t=this.uriToBuffer(i)}return t},e.getMimeType=function(){return n&&a||(n=this.figureMimeType()),n},t}();return s.atob=void 0,s});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("typedarray-to-buffer")):"function"==typeof define&&define.amd?define(["typedarray-to-buffer"],e):(t||self).canvasToBuffer=e(t.typedarrayToBuffer)}(this,function(t){function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i,n=/*#__PURE__*/e(t),r="undefined"!=typeof document&&"function"==typeof document.createElement,o=r?["webp","jpeg"]:["png"],a=/*#__PURE__*/function(){function t(t,e,i){if(void 0===e&&(e=o),void 0===i&&(i=.5),this.quality=void 0,this.types=void 0,this.canvas=void 0,e.length>2)throw new Error("Too many image types are specified!");this.canvas=t,this.quality=i,this.types=e}var e=t.prototype;return e.composeMimeType=function(t){var e;return this.types[t]&&(e="image/"+this.types[t]),e},e.isMatch=function(t,e){return t.match(e)},e.getTestCanvas=function(){var t;return r?(t=document.createElement("canvas")).width=t.height=1:t=this.canvas,t},e.canvasSupportsMimeType=function(t){try{var e=this.getTestCanvas(),i=e.toDataURL&&e.toDataURL(t);return this.isMatch(i,t)}catch(t){return!1}},e.figureMimeType=function(){var t=this.composeMimeType(0);return t&&this.canvasSupportsMimeType(t)||(this.types[1]?(t=this.composeMimeType(1))&&!this.canvasSupportsMimeType(t)&&(t=void 0):t=void 0),t},e.uriToBuffer=function(e){var i,o=e.split(",")[1];if(!o)throw new Error("Empty uri string given!");if(!(i=r?window.atob(o):null==t.atob?void 0:t.atob(o)))throw new Error("Byte are empty, something within atob went wrong.");for(var a=new Uint8Array(i.length),s=0,u=i.length;s<u;s++)a[s]=i.charCodeAt(s);return n.default(a)},e.toBuffer=function(){var t,e=this.getMimeType();if(e){var i=this.canvas.toDataURL(e,this.quality);t=this.uriToBuffer(i)}return t},e.getMimeType=function(){return i&&r||(i=this.figureMimeType()),i},t}();return a.atob=void 0,a});
//# sourceMappingURL=canvas-to-buffer.umd.js.map
{
"name": "canvas-to-buffer",
"version": "4.0.0",
"version": "4.0.1",
"description": "Converts a Canvas graphic into a Buffer, as fast as possible and without a copy.",
"type": "module",
"source": "src/index.ts",
"types": "./dist/index.d.ts",
"types": "./dist/src/index.d.ts",
"exports": {
"types": "./dist/index.d.ts",
"types": "./dist/src/index.d.ts",
"require": "./dist/canvas-to-buffer.cjs",

@@ -49,3 +49,2 @@ "default": "./dist/canvas-to-buffer.modern.js"

"dependencies": {
"atob": "2.1.2",
"typedarray-to-buffer": "4.0.0"

@@ -61,2 +60,3 @@ },

"@typescript-eslint/parser": "7.18.0",
"atob": "2.1.2",
"canvas": "2.11.2",

@@ -63,0 +63,0 @@ "cross-env": "7.0.3",

import toBuffer from "typedarray-to-buffer";
import atob from "atob";
import { Canvas } from "canvas";

@@ -95,13 +94,17 @@ const isBrowser =

const uriSplitted = uri.split(",")[1];
let bytes: string;
let bytes: string | undefined;
if (!uriSplitted) {
throw new Error("Empty uri string given!");
} else if (typeof atob === "function") {
} else if (isBrowser) {
bytes = window.atob(uriSplitted);
} else {
// Beware that the atob function might be a static one for server side tests
bytes = atob(uriSplitted);
} else {
throw new Error("atob function is missing");
bytes = Frame.atob?.(uriSplitted);
}
if (!bytes) {
throw new Error("Byte are empty, something within atob went wrong.");
}
const arr = new Uint8Array(bytes.length);

@@ -119,2 +122,3 @@

const mimeType = this.getMimeType();
let buffer;

@@ -121,0 +125,0 @@

{
"include": ["src"],
"include": ["src", ".eslintrc.cjs", "prettier.config.cjs"],
"extends": ["@tsconfig/strictest/tsconfig.json", "@tsconfig/node20/tsconfig.json"],

@@ -4,0 +4,0 @@ "compilerOptions": {

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