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

magicpen-media

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

magicpen-media - npm Package Compare versions

Comparing version 1.3.1 to 1.4.0

53

lib/magicPenMedia.js
/*global URL, Blob, btoa*/
var _ = require('lodash');
var _ = require('lodash'),
fs = require('fs'),
pathModule = require('path'),
mime = require('mime'),
getTemporaryFilePath = require('gettemporaryfilepath');

@@ -28,3 +32,11 @@ function sanitizeContentType(contentType) {

var title = options.title;
var fallbackToDisc = options.fallbackToDisc;
if (typeof media === 'string' && !/data:/.test(media) && (typeof contentType === 'undefined' || contentType.indexOf('/') === -1)) {
var extension = pathModule.extname(media);
if (extension) {
contentType = mime.types[extension.replace(/^\./, '')] || contentType;
}
}
this.alt({

@@ -38,4 +50,6 @@ html: {

src = media;
if (typeof title === 'undefined' && !/^data:/.test(media)) {
title = media;
if (!/^data:/.test(media)) {
if (typeof title === 'undefined') {
title = media;
}
}

@@ -84,15 +98,36 @@ } else if (typeof URL !== 'undefined' && typeof URL.createObjectURL === 'function' && typeof Blob !== 'undefined') {

fallback: function () {
var text;
function writeToDisc(data) {
if (data.constructor.name === 'Uint8Array') {
data = new Buffer(data);
}
var fileName;
if (typeof fallbackToDisc === 'string') {
fileName = fallbackToDisc;
} else {
fileName = getTemporaryFilePath({ suffix: '.' + (mime.extensions[contentType] || majorContentType || 'data') });
}
fs.writeFileSync(fileName, data);
return fileName;
}
if (typeof media === 'string') {
var matchDataUrl = media.match(/^data:([\w\-\+\.]+\/[\w\-\+\.]+)?(?:;charset=([\w\/\-]+))?(;base64)?,([\u0000-\u007f]*)$/);
if (matchDataUrl) {
text = 'data:' + matchDataUrl[1] || 'text/plain';
contentType = matchDataUrl[1] || contentType || 'text/plain';
if (matchDataUrl[3] && options.fallbackToDisc && fs.writeFileSync) {
this.text(writeToDisc(new Buffer(matchDataUrl[4], 'base64')) + ' (' + contentType + ')');
} else {
this.text('data url (' + contentType + ')');
}
} else {
// path or non-data: url
text = media;
this.text(media + ' (' + (contentType || 'media') + ')');
}
this.text((matchDataUrl ? matchDataUrl[1] || 'text/plain' : media) + ' (' + (contentType || 'media') + ')');
} else {
// Uint8Array or Buffer
this.text(media.constructor.name + '[' + media.length + '] (' + (contentType || 'media') + ')');
if (options.fallbackToDisc && fs.writeFileSync) {
this.text(writeToDisc(media) + ' (' + contentType + ')');
} else {
this.text(media.constructor.name + '[' + media.length + '] (' + (contentType || 'media') + ')');
}
}

@@ -99,0 +134,0 @@ }

7

package.json
{
"name": "magicpen-media",
"version": "1.3.1",
"version": "1.4.0",
"description": "Add media support to magicpen (images, audio, video)",

@@ -21,2 +21,3 @@ "repository": {

"unexpected": "9.0.0",
"unexpected-fs": "1.1.0",
"unexpected-sinon": "6.4.1"

@@ -36,4 +37,6 @@ },

"dependencies": {
"lodash": "3.10.0"
"gettemporaryfilepath": "0.0.1",
"lodash": "3.10.0",
"mime": "1.3.4"
}
}

Sorry, the diff of this file is too big to display

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