Comparing version 1.1.1 to 1.1.2
@@ -8,3 +8,2 @@ #!/usr/bin/env node | ||
var Promise = require('bluebird'); | ||
var request = require('request'); | ||
var http_server = require("http-server"); | ||
@@ -16,3 +15,9 @@ var fs = require('fs'); | ||
var watchify = require("watchify"); | ||
var w = watchify(indexfile); | ||
var browserify = require('browserify'); | ||
var w = watchify(browserify(indexfile, { | ||
cache: {}, | ||
packageCache: {}, | ||
fullPaths: true, | ||
debug: true | ||
})); | ||
@@ -19,0 +24,0 @@ w.on('update', bundle); |
@@ -9,2 +9,3 @@ #!/usr/bin/env node | ||
var sauceConnectLauncher = require('sauce-connect-launcher'); | ||
var selenium = require('selenium-standalone'); | ||
var querystring = require("querystring"); | ||
@@ -15,5 +16,2 @@ var request = require('request').defaults({json: true}); | ||
var SELENIUM_PATH = '../vendor/selenium-server-standalone-2.38.0.jar'; | ||
var SELENIUM_HUB = 'http://localhost:4444/wd/hub/status'; | ||
var testTimeout = 30 * 60 * 1000; | ||
@@ -47,8 +45,2 @@ | ||
} | ||
if (process.env.ADAPTERS) { | ||
qs.adapters = process.env.ADAPTERS; | ||
} | ||
if (process.env.ES5_SHIM || process.env.ES5_SHIMS) { | ||
qs.es5shim = true; | ||
} | ||
testUrl += '?'; | ||
@@ -92,27 +84,14 @@ testUrl += querystring.stringify(qs); | ||
function startSelenium(callback) { | ||
// Start selenium | ||
spawn('java', ['-jar', path.resolve(__dirname, SELENIUM_PATH)], {}); | ||
var retries = 0; | ||
var started = function () { | ||
if (++retries > 30) { | ||
console.error('Unable to connect to selenium'); | ||
var opts = {version: '2.45.0'}; | ||
selenium.install(opts, function(err) { | ||
if (err) { | ||
console.error('Failed to install selenium'); | ||
process.exit(1); | ||
return; | ||
} | ||
request(SELENIUM_HUB, function (err, resp) { | ||
if (resp && resp.statusCode === 200) { | ||
sauceClient = wd.promiseChainRemote(); | ||
callback(); | ||
} else { | ||
setTimeout(started, 1000); | ||
} | ||
selenium.start(opts, function(err, server) { | ||
sauceClient = wd.promiseChainRemote(); | ||
callback(); | ||
}); | ||
}; | ||
started(); | ||
}); | ||
} | ||
@@ -119,0 +98,0 @@ |
{ | ||
"name": "blob-util", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Utilities for working with Blob objects in the browser", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/nolanlawson/blob-util", |
@@ -1,312 +0,3 @@ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.blobUtil=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
'use strict'; | ||
var utils = require('./utils'); | ||
/* jshint -W079 */ | ||
var Blob = require('blob'); | ||
var Promise = utils.Promise; | ||
// | ||
// PRIVATE | ||
// | ||
// From http://stackoverflow.com/questions/14967647/ (continues on next line) | ||
// encode-decode-image-with-base64-breaks-image (2013-04-21) | ||
function binaryStringToArrayBuffer(binary) { | ||
var length = binary.length; | ||
var buf = new ArrayBuffer(length); | ||
var arr = new Uint8Array(buf); | ||
var i = -1; | ||
while (++i < length) { | ||
arr[i] = binary.charCodeAt(i); | ||
} | ||
return buf; | ||
} | ||
// Can't find original post, but this is close | ||
// http://stackoverflow.com/questions/6965107/ (continues on next line) | ||
// converting-between-strings-and-arraybuffers | ||
function arrayBufferToBinaryString(buffer) { | ||
var binary = ''; | ||
var bytes = new Uint8Array(buffer); | ||
var length = bytes.byteLength; | ||
var i = -1; | ||
while (++i < length) { | ||
binary += String.fromCharCode(bytes[i]); | ||
} | ||
return binary; | ||
} | ||
// doesn't download the image more than once, because | ||
// browsers aren't dumb. uses the cache | ||
function loadImage(src, crossOrigin) { | ||
return new Promise(function (resolve, reject) { | ||
var img = new Image(); | ||
if (crossOrigin) { | ||
img.crossOrigin = crossOrigin; | ||
} | ||
img.onload = function () { | ||
resolve(img); | ||
}; | ||
img.onerror = reject; | ||
img.src = src; | ||
}); | ||
} | ||
function imgToCanvas(img) { | ||
var canvas = document.createElement('canvas'); | ||
canvas.width = img.width; | ||
canvas.height = img.height; | ||
// copy the image contents to the canvas | ||
var context = canvas.getContext('2d'); | ||
context.drawImage( | ||
img, | ||
0, 0, | ||
img.width, img.height, | ||
0, 0, | ||
img.width, img.height); | ||
return canvas; | ||
} | ||
// | ||
// PUBLIC | ||
// | ||
/** | ||
* Shim for | ||
* [new Blob()]{@link https://developer.mozilla.org/en-US/docs/Web/API/Blob.Blob} | ||
* to support | ||
* [older browsers that use the deprecated <code>BlobBuilder</code> API]{@link http://caniuse.com/blob}. | ||
* | ||
* @param {Array} parts - content of the <code>Blob</code> | ||
* @param {Object} options - usually just <code>{type: myContentType}</code> | ||
* @returns {Blob} | ||
*/ | ||
function createBlob(parts, options) { | ||
options = options || {}; | ||
if (typeof options === 'string') { | ||
options = {type: options}; // do you a solid here | ||
} | ||
return new Blob(parts, options); | ||
} | ||
/** | ||
* Shim for | ||
* [URL.createObjectURL()]{@link https://developer.mozilla.org/en-US/docs/Web/API/URL.createObjectURL} | ||
* to support browsers that only have the prefixed | ||
* <code>webkitURL</code> (e.g. Android <4.4). | ||
* @param {Blob} blob | ||
* @returns {string} url | ||
*/ | ||
function createObjectURL(blob) { | ||
return (window.URL || window.webkitURL).createObjectURL(blob); | ||
} | ||
/** | ||
* Shim for | ||
* [URL.revokeObjectURL()]{@link https://developer.mozilla.org/en-US/docs/Web/API/URL.revokeObjectURL} | ||
* to support browsers that only have the prefixed | ||
* <code>webkitURL</code> (e.g. Android <4.4). | ||
* @param {string} url | ||
*/ | ||
function revokeObjectURL(url) { | ||
return (window.URL || window.webkitURL).revokeObjectURL(url); | ||
} | ||
/** | ||
* Convert a <code>Blob</code> to a binary string. Returns a Promise. | ||
* | ||
* @param {Blob} blob | ||
* @returns {Promise} Promise that resolves with the binary string | ||
*/ | ||
function blobToBinaryString(blob) { | ||
return new Promise(function (resolve, reject) { | ||
var reader = new FileReader(); | ||
var hasBinaryString = typeof reader.readAsBinaryString === 'function'; | ||
reader.onloadend = function (e) { | ||
var result = e.target.result || ''; | ||
if (hasBinaryString) { | ||
return resolve(result); | ||
} | ||
resolve(arrayBufferToBinaryString(result)); | ||
}; | ||
reader.onerror = reject; | ||
if (hasBinaryString) { | ||
reader.readAsBinaryString(blob); | ||
} else { | ||
reader.readAsArrayBuffer(blob); | ||
} | ||
}); | ||
} | ||
/** | ||
* Convert a base64-encoded string to a <code>Blob</code>. Returns a Promise. | ||
* @param {string} base64 | ||
* @param {string|undefined} type - the content type (optional) | ||
* @returns {Promise} Promise that resolves with the <code>Blob</code> | ||
*/ | ||
function base64StringToBlob(base64, type) { | ||
return Promise.resolve().then(function () { | ||
var parts = [binaryStringToArrayBuffer(atob(base64))]; | ||
return type ? createBlob(parts, {type: type}) : createBlob(parts); | ||
}); | ||
} | ||
/** | ||
* Convert a binary string to a <code>Blob</code>. Returns a Promise. | ||
* @param {string} binary | ||
* @param {string|undefined} type - the content type (optional) | ||
* @returns {Promise} Promise that resolves with the <code>Blob</code> | ||
*/ | ||
function binaryStringToBlob(binary, type) { | ||
return Promise.resolve().then(function () { | ||
return base64StringToBlob(btoa(binary), type); | ||
}); | ||
} | ||
/** | ||
* Convert a <code>Blob</code> to a binary string. Returns a Promise. | ||
* @param {Blob} blob | ||
* @returns {Promise} Promise that resolves with the binary string | ||
*/ | ||
function blobToBase64String(blob) { | ||
return blobToBinaryString(blob).then(function (binary) { | ||
return btoa(binary); | ||
}); | ||
} | ||
/** | ||
* Convert a data URL string | ||
* (e.g. <code>'data:image/png;base64,iVBORw0KG...'</code>) | ||
* to a <code>Blob</code>. Returns a Promise. | ||
* @param {string} dataURL | ||
* @returns {Promise} Promise that resolves with the <code>Blob</code> | ||
*/ | ||
function dataURLToBlob(dataURL) { | ||
return Promise.resolve().then(function () { | ||
var type = dataURL.match(/data:([^;]+)/)[1]; | ||
var base64 = dataURL.replace(/^[^,]+,/, ''); | ||
var buff = binaryStringToArrayBuffer(atob(base64)); | ||
return createBlob([buff], {type: type}); | ||
}); | ||
} | ||
/** | ||
* Convert an image's <code>src</code> URL to a data URL by loading the image and painting | ||
* it to a <code>canvas</code>. Returns a Promise. | ||
* | ||
* <p/>Note: this will coerce the image to the desired content type, and it | ||
* will only paint the first frame of an animated GIF. | ||
* | ||
* @param {string} src | ||
* @param {string|undefined} type - the content type (optional, defaults to 'image/png') | ||
* @param {string|undefined} crossOrigin - for CORS-enabled images, set this to | ||
* 'Anonymous' to avoid "tainted canvas" errors | ||
* @returns {Promise} Promise that resolves with the data URL string | ||
*/ | ||
function imgSrcToDataURL(src, type, crossOrigin) { | ||
type = type || 'image/png'; | ||
return loadImage(src, crossOrigin).then(function (img) { | ||
return imgToCanvas(img); | ||
}).then(function (canvas) { | ||
return canvas.toDataURL(type); | ||
}); | ||
} | ||
/** | ||
* Convert a <code>canvas</code> to a <code>Blob</code>. Returns a Promise. | ||
* @param {string} canvas | ||
* @param {string|undefined} type - the content type (optional, defaults to 'image/png') | ||
* @returns {Promise} Promise that resolves with the <code>Blob</code> | ||
*/ | ||
function canvasToBlob(canvas, type) { | ||
return Promise.resolve().then(function () { | ||
if (typeof canvas.toBlob === 'function') { | ||
return new Promise(function (resolve) { | ||
canvas.toBlob(resolve, type); | ||
}); | ||
} | ||
return dataURLToBlob(canvas.toDataURL(type)); | ||
}); | ||
} | ||
/** | ||
* Convert an image's <code>src</code> URL to a <code>Blob</code> by loading the image and painting | ||
* it to a <code>canvas</code>. Returns a Promise. | ||
* | ||
* <p/>Note: this will coerce the image to the desired content type, and it | ||
* will only paint the first frame of an animated GIF. | ||
* | ||
* @param {string} src | ||
* @param {string|undefined} type - the content type (optional, defaults to 'image/png') | ||
* @param {string|undefined} crossOrigin - for CORS-enabled images, set this to | ||
* 'Anonymous' to avoid "tainted canvas" errors | ||
* @returns {Promise} Promise that resolves with the <code>Blob</code> | ||
*/ | ||
function imgSrcToBlob(src, type, crossOrigin) { | ||
type = type || 'image/png'; | ||
return loadImage(src, crossOrigin).then(function (img) { | ||
return imgToCanvas(img); | ||
}).then(function (canvas) { | ||
return canvasToBlob(canvas, type); | ||
}); | ||
} | ||
/** | ||
* Convert an <code>ArrayBuffer</code> to a <code>Blob</code>. Returns a Promise. | ||
* | ||
* @param {ArrayBuffer} buffer | ||
* @param {string|undefined} type - the content type (optional) | ||
* @returns {Promise} Promise that resolves with the <code>Blob</code> | ||
*/ | ||
function arrayBufferToBlob(buffer, type) { | ||
return Promise.resolve().then(function () { | ||
return createBlob([buffer], type); | ||
}); | ||
} | ||
/** | ||
* Convert a <code>Blob</code> to an <code>ArrayBuffer</code>. Returns a Promise. | ||
* @param {Blob} blob | ||
* @returns {Promise} Promise that resolves with the <code>ArrayBuffer</code> | ||
*/ | ||
function blobToArrayBuffer(blob) { | ||
return blobToBinaryString(blob).then(function (binary) { | ||
return binaryStringToArrayBuffer(binary); | ||
}); | ||
} | ||
module.exports = { | ||
createBlob : createBlob, | ||
createObjectURL : createObjectURL, | ||
revokeObjectURL : revokeObjectURL, | ||
imgSrcToBlob : imgSrcToBlob, | ||
imgSrcToDataURL : imgSrcToDataURL, | ||
canvasToBlob : canvasToBlob, | ||
dataURLToBlob : dataURLToBlob, | ||
blobToBase64String : blobToBase64String, | ||
base64StringToBlob : base64StringToBlob, | ||
binaryStringToBlob : binaryStringToBlob, | ||
blobToBinaryString : blobToBinaryString, | ||
arrayBufferToBlob : arrayBufferToBlob, | ||
blobToArrayBuffer : blobToArrayBuffer | ||
}; | ||
},{"./utils":2,"blob":3}],2:[function(require,module,exports){ | ||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.blobUtil = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ | ||
(function (global){ | ||
'use strict'; | ||
var Promise = typeof global.Promise === 'function' ? global.Promise : require('lie'); | ||
exports.Promise = Promise; | ||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
},{"lie":7}],3:[function(require,module,exports){ | ||
(function (global){ | ||
/** | ||
@@ -410,3 +101,13 @@ * Create a blob builder even when vendor prefixes exist | ||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
},{}],4:[function(require,module,exports){ | ||
},{}],2:[function(_dereq_,module,exports){ | ||
},{}],3:[function(_dereq_,module,exports){ | ||
(function (global){ | ||
if (typeof global.Promise === 'function') { | ||
module.exports = global.Promise; | ||
} else { | ||
module.exports = _dereq_(7); | ||
} | ||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
},{"7":7}],4:[function(_dereq_,module,exports){ | ||
'use strict'; | ||
@@ -417,13 +118,13 @@ | ||
function INTERNAL() {} | ||
},{}],5:[function(require,module,exports){ | ||
},{}],5:[function(_dereq_,module,exports){ | ||
'use strict'; | ||
var Promise = require('./promise'); | ||
var reject = require('./reject'); | ||
var resolve = require('./resolve'); | ||
var INTERNAL = require('./INTERNAL'); | ||
var handlers = require('./handlers'); | ||
module.exports = all; | ||
function all(iterable) { | ||
var Promise = _dereq_(8); | ||
var reject = _dereq_(10); | ||
var resolve = _dereq_(11); | ||
var INTERNAL = _dereq_(4); | ||
var handlers = _dereq_(6); | ||
var noArray = reject(new TypeError('must be an array')); | ||
module.exports = function all(iterable) { | ||
if (Object.prototype.toString.call(iterable) !== '[object Array]') { | ||
return reject(new TypeError('must be an array')); | ||
return noArray; | ||
} | ||
@@ -461,8 +162,8 @@ | ||
} | ||
} | ||
},{"./INTERNAL":4,"./handlers":6,"./promise":8,"./reject":11,"./resolve":12}],6:[function(require,module,exports){ | ||
}; | ||
},{"10":10,"11":11,"4":4,"6":6,"8":8}],6:[function(_dereq_,module,exports){ | ||
'use strict'; | ||
var tryCatch = require('./tryCatch'); | ||
var resolveThenable = require('./resolveThenable'); | ||
var states = require('./states'); | ||
var tryCatch = _dereq_(14); | ||
var resolveThenable = _dereq_(12); | ||
var states = _dereq_(13); | ||
@@ -509,17 +210,16 @@ exports.resolve = function (self, value) { | ||
} | ||
},{"./resolveThenable":13,"./states":14,"./tryCatch":15}],7:[function(require,module,exports){ | ||
module.exports = exports = require('./promise'); | ||
},{"12":12,"13":13,"14":14}],7:[function(_dereq_,module,exports){ | ||
module.exports = exports = _dereq_(8); | ||
exports.resolve = require('./resolve'); | ||
exports.reject = require('./reject'); | ||
exports.all = require('./all'); | ||
exports.race = require('./race'); | ||
},{"./all":5,"./promise":8,"./race":10,"./reject":11,"./resolve":12}],8:[function(require,module,exports){ | ||
exports.resolve = _dereq_(11); | ||
exports.reject = _dereq_(10); | ||
exports.all = _dereq_(5); | ||
},{"10":10,"11":11,"5":5,"8":8}],8:[function(_dereq_,module,exports){ | ||
'use strict'; | ||
var unwrap = require('./unwrap'); | ||
var INTERNAL = require('./INTERNAL'); | ||
var resolveThenable = require('./resolveThenable'); | ||
var states = require('./states'); | ||
var QueueItem = require('./queueItem'); | ||
var unwrap = _dereq_(15); | ||
var INTERNAL = _dereq_(4); | ||
var resolveThenable = _dereq_(12); | ||
var states = _dereq_(13); | ||
var QueueItem = _dereq_(9); | ||
@@ -563,6 +263,6 @@ module.exports = Promise; | ||
},{"./INTERNAL":4,"./queueItem":9,"./resolveThenable":13,"./states":14,"./unwrap":16}],9:[function(require,module,exports){ | ||
},{"12":12,"13":13,"15":15,"4":4,"9":9}],9:[function(_dereq_,module,exports){ | ||
'use strict'; | ||
var handlers = require('./handlers'); | ||
var unwrap = require('./unwrap'); | ||
var handlers = _dereq_(6); | ||
var unwrap = _dereq_(15); | ||
@@ -593,49 +293,8 @@ module.exports = QueueItem; | ||
}; | ||
},{"./handlers":6,"./unwrap":16}],10:[function(require,module,exports){ | ||
},{"15":15,"6":6}],10:[function(_dereq_,module,exports){ | ||
'use strict'; | ||
var Promise = require('./promise'); | ||
var reject = require('./reject'); | ||
var resolve = require('./resolve'); | ||
var INTERNAL = require('./INTERNAL'); | ||
var handlers = require('./handlers'); | ||
module.exports = race; | ||
function race(iterable) { | ||
if (Object.prototype.toString.call(iterable) !== '[object Array]') { | ||
return reject(new TypeError('must be an array')); | ||
} | ||
var len = iterable.length; | ||
var called = false; | ||
if (!len) { | ||
return resolve([]); | ||
} | ||
var resolved = 0; | ||
var i = -1; | ||
var promise = new Promise(INTERNAL); | ||
while (++i < len) { | ||
resolver(iterable[i]); | ||
} | ||
return promise; | ||
function resolver(value) { | ||
resolve(value).then(function (response) { | ||
if (!called) { | ||
called = true; | ||
handlers.resolve(promise, response); | ||
} | ||
}, function (error) { | ||
if (!called) { | ||
called = true; | ||
handlers.reject(promise, error); | ||
} | ||
}); | ||
} | ||
} | ||
},{"./INTERNAL":4,"./handlers":6,"./promise":8,"./reject":11,"./resolve":12}],11:[function(require,module,exports){ | ||
'use strict'; | ||
var Promise = require('./promise'); | ||
var INTERNAL = require('./INTERNAL'); | ||
var handlers = require('./handlers'); | ||
var Promise = _dereq_(8); | ||
var INTERNAL = _dereq_(4); | ||
var handlers = _dereq_(6); | ||
module.exports = reject; | ||
@@ -647,8 +306,8 @@ | ||
} | ||
},{"./INTERNAL":4,"./handlers":6,"./promise":8}],12:[function(require,module,exports){ | ||
},{"4":4,"6":6,"8":8}],11:[function(_dereq_,module,exports){ | ||
'use strict'; | ||
var Promise = require('./promise'); | ||
var INTERNAL = require('./INTERNAL'); | ||
var handlers = require('./handlers'); | ||
var Promise = _dereq_(8); | ||
var INTERNAL = _dereq_(4); | ||
var handlers = _dereq_(6); | ||
module.exports = resolve; | ||
@@ -683,6 +342,6 @@ | ||
} | ||
},{"./INTERNAL":4,"./handlers":6,"./promise":8}],13:[function(require,module,exports){ | ||
},{"4":4,"6":6,"8":8}],12:[function(_dereq_,module,exports){ | ||
'use strict'; | ||
var handlers = require('./handlers'); | ||
var tryCatch = require('./tryCatch'); | ||
var handlers = _dereq_(6); | ||
var tryCatch = _dereq_(14); | ||
function safelyResolveThenable(self, thenable) { | ||
@@ -717,3 +376,3 @@ // Either fulfill, reject or reject with error | ||
exports.safely = safelyResolveThenable; | ||
},{"./handlers":6,"./tryCatch":15}],14:[function(require,module,exports){ | ||
},{"14":14,"6":6}],13:[function(_dereq_,module,exports){ | ||
// Lazy man's symbols for states | ||
@@ -724,3 +383,3 @@ | ||
exports.PENDING = ['PENDING']; | ||
},{}],15:[function(require,module,exports){ | ||
},{}],14:[function(_dereq_,module,exports){ | ||
'use strict'; | ||
@@ -741,7 +400,7 @@ | ||
} | ||
},{}],16:[function(require,module,exports){ | ||
},{}],15:[function(_dereq_,module,exports){ | ||
'use strict'; | ||
var immediate = require('immediate'); | ||
var handlers = require('./handlers'); | ||
var immediate = _dereq_(16); | ||
var handlers = _dereq_(6); | ||
module.exports = unwrap; | ||
@@ -764,28 +423,44 @@ | ||
} | ||
},{"./handlers":6,"immediate":17}],17:[function(require,module,exports){ | ||
},{"16":16,"6":6}],16:[function(_dereq_,module,exports){ | ||
'use strict'; | ||
var types = [ | ||
require('./nextTick'), | ||
require('./mutation.js'), | ||
require('./messageChannel'), | ||
require('./stateChange'), | ||
require('./timeout') | ||
_dereq_(2), | ||
_dereq_(18), | ||
_dereq_(17), | ||
_dereq_(19), | ||
_dereq_(20) | ||
]; | ||
var draining; | ||
var currentQueue; | ||
var queueIndex = -1; | ||
var queue = []; | ||
function cleanUpNextTick() { | ||
draining = false; | ||
if (currentQueue && currentQueue.length) { | ||
queue = currentQueue.concat(queue); | ||
} else { | ||
queueIndex = -1; | ||
} | ||
if (queue.length) { | ||
nextTick(); | ||
} | ||
} | ||
//named nextTick for less confusing stack traces | ||
function nextTick() { | ||
draining = true; | ||
var i, oldQueue; | ||
var len = queue.length; | ||
var timeout = setTimeout(cleanUpNextTick); | ||
while (len) { | ||
oldQueue = queue; | ||
currentQueue = queue; | ||
queue = []; | ||
i = -1; | ||
while (++i < len) { | ||
oldQueue[i](); | ||
while (++queueIndex < len) { | ||
currentQueue[queueIndex](); | ||
} | ||
queueIndex = -1; | ||
len = queue.length; | ||
} | ||
queueIndex = -1; | ||
draining = false; | ||
clearTimeout(timeout); | ||
} | ||
@@ -807,3 +482,3 @@ var scheduleDrain; | ||
} | ||
},{"./messageChannel":18,"./mutation.js":19,"./nextTick":22,"./stateChange":20,"./timeout":21}],18:[function(require,module,exports){ | ||
},{"17":17,"18":18,"19":19,"2":2,"20":20}],17:[function(_dereq_,module,exports){ | ||
(function (global){ | ||
@@ -829,3 +504,3 @@ 'use strict'; | ||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
},{}],19:[function(require,module,exports){ | ||
},{}],18:[function(_dereq_,module,exports){ | ||
(function (global){ | ||
@@ -855,3 +530,3 @@ 'use strict'; | ||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
},{}],20:[function(require,module,exports){ | ||
},{}],19:[function(_dereq_,module,exports){ | ||
(function (global){ | ||
@@ -883,3 +558,3 @@ 'use strict'; | ||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
},{}],21:[function(require,module,exports){ | ||
},{}],20:[function(_dereq_,module,exports){ | ||
'use strict'; | ||
@@ -895,5 +570,308 @@ exports.test = function () { | ||
}; | ||
},{}],22:[function(require,module,exports){ | ||
},{}],21:[function(_dereq_,module,exports){ | ||
'use strict'; | ||
},{}]},{},[1])(1) | ||
}); | ||
/* jshint -W079 */ | ||
var Blob = _dereq_(1); | ||
var Promise = _dereq_(3); | ||
// | ||
// PRIVATE | ||
// | ||
// From http://stackoverflow.com/questions/14967647/ (continues on next line) | ||
// encode-decode-image-with-base64-breaks-image (2013-04-21) | ||
function binaryStringToArrayBuffer(binary) { | ||
var length = binary.length; | ||
var buf = new ArrayBuffer(length); | ||
var arr = new Uint8Array(buf); | ||
var i = -1; | ||
while (++i < length) { | ||
arr[i] = binary.charCodeAt(i); | ||
} | ||
return buf; | ||
} | ||
// Can't find original post, but this is close | ||
// http://stackoverflow.com/questions/6965107/ (continues on next line) | ||
// converting-between-strings-and-arraybuffers | ||
function arrayBufferToBinaryString(buffer) { | ||
var binary = ''; | ||
var bytes = new Uint8Array(buffer); | ||
var length = bytes.byteLength; | ||
var i = -1; | ||
while (++i < length) { | ||
binary += String.fromCharCode(bytes[i]); | ||
} | ||
return binary; | ||
} | ||
// doesn't download the image more than once, because | ||
// browsers aren't dumb. uses the cache | ||
function loadImage(src, crossOrigin) { | ||
return new Promise(function (resolve, reject) { | ||
var img = new Image(); | ||
if (crossOrigin) { | ||
img.crossOrigin = crossOrigin; | ||
} | ||
img.onload = function () { | ||
resolve(img); | ||
}; | ||
img.onerror = reject; | ||
img.src = src; | ||
}); | ||
} | ||
function imgToCanvas(img) { | ||
var canvas = document.createElement('canvas'); | ||
canvas.width = img.width; | ||
canvas.height = img.height; | ||
// copy the image contents to the canvas | ||
var context = canvas.getContext('2d'); | ||
context.drawImage( | ||
img, | ||
0, 0, | ||
img.width, img.height, | ||
0, 0, | ||
img.width, img.height); | ||
return canvas; | ||
} | ||
// | ||
// PUBLIC | ||
// | ||
/** | ||
* Shim for | ||
* [new Blob()]{@link https://developer.mozilla.org/en-US/docs/Web/API/Blob.Blob} | ||
* to support | ||
* [older browsers that use the deprecated <code>BlobBuilder</code> API]{@link http://caniuse.com/blob}. | ||
* | ||
* @param {Array} parts - content of the <code>Blob</code> | ||
* @param {Object} options - usually just <code>{type: myContentType}</code> | ||
* @returns {Blob} | ||
*/ | ||
function createBlob(parts, options) { | ||
options = options || {}; | ||
if (typeof options === 'string') { | ||
options = {type: options}; // do you a solid here | ||
} | ||
return new Blob(parts, options); | ||
} | ||
/** | ||
* Shim for | ||
* [URL.createObjectURL()]{@link https://developer.mozilla.org/en-US/docs/Web/API/URL.createObjectURL} | ||
* to support browsers that only have the prefixed | ||
* <code>webkitURL</code> (e.g. Android <4.4). | ||
* @param {Blob} blob | ||
* @returns {string} url | ||
*/ | ||
function createObjectURL(blob) { | ||
return (window.URL || window.webkitURL).createObjectURL(blob); | ||
} | ||
/** | ||
* Shim for | ||
* [URL.revokeObjectURL()]{@link https://developer.mozilla.org/en-US/docs/Web/API/URL.revokeObjectURL} | ||
* to support browsers that only have the prefixed | ||
* <code>webkitURL</code> (e.g. Android <4.4). | ||
* @param {string} url | ||
*/ | ||
function revokeObjectURL(url) { | ||
return (window.URL || window.webkitURL).revokeObjectURL(url); | ||
} | ||
/** | ||
* Convert a <code>Blob</code> to a binary string. Returns a Promise. | ||
* | ||
* @param {Blob} blob | ||
* @returns {Promise} Promise that resolves with the binary string | ||
*/ | ||
function blobToBinaryString(blob) { | ||
return new Promise(function (resolve, reject) { | ||
var reader = new FileReader(); | ||
var hasBinaryString = typeof reader.readAsBinaryString === 'function'; | ||
reader.onloadend = function (e) { | ||
var result = e.target.result || ''; | ||
if (hasBinaryString) { | ||
return resolve(result); | ||
} | ||
resolve(arrayBufferToBinaryString(result)); | ||
}; | ||
reader.onerror = reject; | ||
if (hasBinaryString) { | ||
reader.readAsBinaryString(blob); | ||
} else { | ||
reader.readAsArrayBuffer(blob); | ||
} | ||
}); | ||
} | ||
/** | ||
* Convert a base64-encoded string to a <code>Blob</code>. Returns a Promise. | ||
* @param {string} base64 | ||
* @param {string|undefined} type - the content type (optional) | ||
* @returns {Promise} Promise that resolves with the <code>Blob</code> | ||
*/ | ||
function base64StringToBlob(base64, type) { | ||
return Promise.resolve().then(function () { | ||
var parts = [binaryStringToArrayBuffer(atob(base64))]; | ||
return type ? createBlob(parts, {type: type}) : createBlob(parts); | ||
}); | ||
} | ||
/** | ||
* Convert a binary string to a <code>Blob</code>. Returns a Promise. | ||
* @param {string} binary | ||
* @param {string|undefined} type - the content type (optional) | ||
* @returns {Promise} Promise that resolves with the <code>Blob</code> | ||
*/ | ||
function binaryStringToBlob(binary, type) { | ||
return Promise.resolve().then(function () { | ||
return base64StringToBlob(btoa(binary), type); | ||
}); | ||
} | ||
/** | ||
* Convert a <code>Blob</code> to a binary string. Returns a Promise. | ||
* @param {Blob} blob | ||
* @returns {Promise} Promise that resolves with the binary string | ||
*/ | ||
function blobToBase64String(blob) { | ||
return blobToBinaryString(blob).then(function (binary) { | ||
return btoa(binary); | ||
}); | ||
} | ||
/** | ||
* Convert a data URL string | ||
* (e.g. <code>'data:image/png;base64,iVBORw0KG...'</code>) | ||
* to a <code>Blob</code>. Returns a Promise. | ||
* @param {string} dataURL | ||
* @returns {Promise} Promise that resolves with the <code>Blob</code> | ||
*/ | ||
function dataURLToBlob(dataURL) { | ||
return Promise.resolve().then(function () { | ||
var type = dataURL.match(/data:([^;]+)/)[1]; | ||
var base64 = dataURL.replace(/^[^,]+,/, ''); | ||
var buff = binaryStringToArrayBuffer(atob(base64)); | ||
return createBlob([buff], {type: type}); | ||
}); | ||
} | ||
/** | ||
* Convert an image's <code>src</code> URL to a data URL by loading the image and painting | ||
* it to a <code>canvas</code>. Returns a Promise. | ||
* | ||
* <p/>Note: this will coerce the image to the desired content type, and it | ||
* will only paint the first frame of an animated GIF. | ||
* | ||
* @param {string} src | ||
* @param {string|undefined} type - the content type (optional, defaults to 'image/png') | ||
* @param {string|undefined} crossOrigin - for CORS-enabled images, set this to | ||
* 'Anonymous' to avoid "tainted canvas" errors | ||
* @returns {Promise} Promise that resolves with the data URL string | ||
*/ | ||
function imgSrcToDataURL(src, type, crossOrigin) { | ||
type = type || 'image/png'; | ||
return loadImage(src, crossOrigin).then(function (img) { | ||
return imgToCanvas(img); | ||
}).then(function (canvas) { | ||
return canvas.toDataURL(type); | ||
}); | ||
} | ||
/** | ||
* Convert a <code>canvas</code> to a <code>Blob</code>. Returns a Promise. | ||
* @param {string} canvas | ||
* @param {string|undefined} type - the content type (optional, defaults to 'image/png') | ||
* @returns {Promise} Promise that resolves with the <code>Blob</code> | ||
*/ | ||
function canvasToBlob(canvas, type) { | ||
return Promise.resolve().then(function () { | ||
if (typeof canvas.toBlob === 'function') { | ||
return new Promise(function (resolve) { | ||
canvas.toBlob(resolve, type); | ||
}); | ||
} | ||
return dataURLToBlob(canvas.toDataURL(type)); | ||
}); | ||
} | ||
/** | ||
* Convert an image's <code>src</code> URL to a <code>Blob</code> by loading the image and painting | ||
* it to a <code>canvas</code>. Returns a Promise. | ||
* | ||
* <p/>Note: this will coerce the image to the desired content type, and it | ||
* will only paint the first frame of an animated GIF. | ||
* | ||
* @param {string} src | ||
* @param {string|undefined} type - the content type (optional, defaults to 'image/png') | ||
* @param {string|undefined} crossOrigin - for CORS-enabled images, set this to | ||
* 'Anonymous' to avoid "tainted canvas" errors | ||
* @returns {Promise} Promise that resolves with the <code>Blob</code> | ||
*/ | ||
function imgSrcToBlob(src, type, crossOrigin) { | ||
type = type || 'image/png'; | ||
return loadImage(src, crossOrigin).then(function (img) { | ||
return imgToCanvas(img); | ||
}).then(function (canvas) { | ||
return canvasToBlob(canvas, type); | ||
}); | ||
} | ||
/** | ||
* Convert an <code>ArrayBuffer</code> to a <code>Blob</code>. Returns a Promise. | ||
* | ||
* @param {ArrayBuffer} buffer | ||
* @param {string|undefined} type - the content type (optional) | ||
* @returns {Promise} Promise that resolves with the <code>Blob</code> | ||
*/ | ||
function arrayBufferToBlob(buffer, type) { | ||
return Promise.resolve().then(function () { | ||
return createBlob([buffer], type); | ||
}); | ||
} | ||
/** | ||
* Convert a <code>Blob</code> to an <code>ArrayBuffer</code>. Returns a Promise. | ||
* @param {Blob} blob | ||
* @returns {Promise} Promise that resolves with the <code>ArrayBuffer</code> | ||
*/ | ||
function blobToArrayBuffer(blob) { | ||
return new Promise(function (resolve, reject) { | ||
var reader = new FileReader(); | ||
reader.onloadend = function (e) { | ||
var result = e.target.result || new ArrayBuffer(0); | ||
resolve(result); | ||
}; | ||
reader.onerror = reject; | ||
reader.readAsArrayBuffer(blob); | ||
}); | ||
} | ||
module.exports = { | ||
createBlob : createBlob, | ||
createObjectURL : createObjectURL, | ||
revokeObjectURL : revokeObjectURL, | ||
imgSrcToBlob : imgSrcToBlob, | ||
imgSrcToDataURL : imgSrcToDataURL, | ||
canvasToBlob : canvasToBlob, | ||
dataURLToBlob : dataURLToBlob, | ||
blobToBase64String : blobToBase64String, | ||
base64StringToBlob : base64StringToBlob, | ||
binaryStringToBlob : binaryStringToBlob, | ||
blobToBinaryString : blobToBinaryString, | ||
arrayBufferToBlob : arrayBufferToBlob, | ||
blobToArrayBuffer : blobToArrayBuffer | ||
}; | ||
},{"1":1,"3":3}]},{},[21])(21) | ||
}); |
@@ -1,1 +0,1 @@ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.blobUtil=e()}}(function(){return function e(t,n,r){function o(u,a){if(!n[u]){if(!t[u]){var s="function"==typeof require&&require;if(!a&&s)return s(u,!0);if(i)return i(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var c=n[u]={exports:{}};t[u][0].call(c.exports,function(e){var n=t[u][1][e];return o(n?n:e)},c,c.exports,e,t,n,r)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(e,t){"use strict";function n(e){for(var t=e.length,n=new ArrayBuffer(t),r=new Uint8Array(n),o=-1;++o<t;)r[o]=e.charCodeAt(o);return n}function r(e){for(var t="",n=new Uint8Array(e),r=n.byteLength,o=-1;++o<r;)t+=String.fromCharCode(n[o]);return t}function o(e,t){return new L(function(n,r){var o=new Image;t&&(o.crossOrigin=t),o.onload=function(){n(o)},o.onerror=r,o.src=e})}function i(e){var t=document.createElement("canvas");t.width=e.width,t.height=e.height;var n=t.getContext("2d");return n.drawImage(e,0,0,e.width,e.height,0,0,e.width,e.height),t}function u(e,t){return t=t||{},"string"==typeof t&&(t={type:t}),new m(e,t)}function a(e){return(window.URL||window.webkitURL).createObjectURL(e)}function s(e){return(window.URL||window.webkitURL).revokeObjectURL(e)}function f(e){return new L(function(t,n){var o=new FileReader,i="function"==typeof o.readAsBinaryString;o.onloadend=function(e){var n=e.target.result||"";return i?t(n):void t(r(n))},o.onerror=n,i?o.readAsBinaryString(e):o.readAsArrayBuffer(e)})}function c(e,t){return L.resolve().then(function(){var r=[n(atob(e))];return t?u(r,{type:t}):u(r)})}function l(e,t){return L.resolve().then(function(){return c(btoa(e),t)})}function d(e){return f(e).then(function(e){return btoa(e)})}function h(e){return L.resolve().then(function(){var t=e.match(/data:([^;]+)/)[1],r=e.replace(/^[^,]+,/,""),o=n(atob(r));return u([o],{type:t})})}function p(e,t,n){return t=t||"image/png",o(e,n).then(function(e){return i(e)}).then(function(e){return e.toDataURL(t)})}function v(e,t){return L.resolve().then(function(){return"function"==typeof e.toBlob?new L(function(n){e.toBlob(n,t)}):h(e.toDataURL(t))})}function y(e,t,n){return t=t||"image/png",o(e,n).then(function(e){return i(e)}).then(function(e){return v(e,t)})}function b(e,t){return L.resolve().then(function(){return u([e],t)})}function w(e){return f(e).then(function(e){return n(e)})}var g=e("./utils"),m=e("blob"),L=g.Promise;t.exports={createBlob:u,createObjectURL:a,revokeObjectURL:s,imgSrcToBlob:y,imgSrcToDataURL:p,canvasToBlob:v,dataURLToBlob:h,blobToBase64String:d,base64StringToBlob:c,binaryStringToBlob:l,blobToBinaryString:f,arrayBufferToBlob:b,blobToArrayBuffer:w}},{"./utils":2,blob:3}],2:[function(e,t,n){(function(t){"use strict";var r="function"==typeof t.Promise?t.Promise:e("lie");n.Promise=r}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{lie:7}],3:[function(e,t){(function(e){function n(e){for(var t=0;t<e.length;t++){var n=e[t];if(n.buffer instanceof ArrayBuffer){var r=n.buffer;if(n.byteLength!==r.byteLength){var o=new Uint8Array(n.byteLength);o.set(new Uint8Array(r,n.byteOffset,n.byteLength)),r=o.buffer}e[t]=r}}}function r(e,t){t=t||{};var r=new i;n(e);for(var o=0;o<e.length;o++)r.append(e[o]);return t.type?r.getBlob(t.type):r.getBlob()}function o(e,t){return n(e),new Blob(e,t||{})}var i=e.BlobBuilder||e.WebKitBlobBuilder||e.MSBlobBuilder||e.MozBlobBuilder,u=function(){try{var e=new Blob(["hi"]);return 2===e.size}catch(t){return!1}}(),a=u&&function(){try{var e=new Blob([new Uint8Array([1,2])]);return 2===e.size}catch(t){return!1}}(),s=i&&i.prototype.append&&i.prototype.getBlob;t.exports=function(){return u?a?e.Blob:o:s?r:void 0}()}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],4:[function(e,t){"use strict";function n(){}t.exports=n},{}],5:[function(e,t){"use strict";function n(e){function t(e,t){function r(e){f[t]=e,++c===n&!s&&(s=!0,a.resolve(d,f))}i(e).then(r,function(e){s||(s=!0,a.reject(d,e))})}if("[object Array]"!==Object.prototype.toString.call(e))return o(new TypeError("must be an array"));var n=e.length,s=!1;if(!n)return i([]);for(var f=new Array(n),c=0,l=-1,d=new r(u);++l<n;)t(e[l],l);return d}var r=e("./promise"),o=e("./reject"),i=e("./resolve"),u=e("./INTERNAL"),a=e("./handlers");t.exports=n},{"./INTERNAL":4,"./handlers":6,"./promise":8,"./reject":11,"./resolve":12}],6:[function(e,t,n){"use strict";function r(e){var t=e&&e.then;return e&&"object"==typeof e&&"function"==typeof t?function(){t.apply(e,arguments)}:void 0}var o=e("./tryCatch"),i=e("./resolveThenable"),u=e("./states");n.resolve=function(e,t){var a=o(r,t);if("error"===a.status)return n.reject(e,a.value);var s=a.value;if(s)i.safely(e,s);else{e.state=u.FULFILLED,e.outcome=t;for(var f=-1,c=e.queue.length;++f<c;)e.queue[f].callFulfilled(t)}return e},n.reject=function(e,t){e.state=u.REJECTED,e.outcome=t;for(var n=-1,r=e.queue.length;++n<r;)e.queue[n].callRejected(t);return e}},{"./resolveThenable":13,"./states":14,"./tryCatch":15}],7:[function(e,t,n){t.exports=n=e("./promise"),n.resolve=e("./resolve"),n.reject=e("./reject"),n.all=e("./all"),n.race=e("./race")},{"./all":5,"./promise":8,"./race":10,"./reject":11,"./resolve":12}],8:[function(e,t){"use strict";function n(e){if(!(this instanceof n))return new n(e);if("function"!=typeof e)throw new TypeError("reslover must be a function");this.state=u.PENDING,this.queue=[],this.outcome=void 0,e!==o&&i.safely(this,e)}var r=e("./unwrap"),o=e("./INTERNAL"),i=e("./resolveThenable"),u=e("./states"),a=e("./queueItem");t.exports=n,n.prototype["catch"]=function(e){return this.then(null,e)},n.prototype.then=function(e,t){if("function"!=typeof e&&this.state===u.FULFILLED||"function"!=typeof t&&this.state===u.REJECTED)return this;var i=new n(o);if(this.state!==u.PENDING){var s=this.state===u.FULFILLED?e:t;r(i,s,this.outcome)}else this.queue.push(new a(i,e,t));return i}},{"./INTERNAL":4,"./queueItem":9,"./resolveThenable":13,"./states":14,"./unwrap":16}],9:[function(e,t){"use strict";function n(e,t,n){this.promise=e,"function"==typeof t&&(this.onFulfilled=t,this.callFulfilled=this.otherCallFulfilled),"function"==typeof n&&(this.onRejected=n,this.callRejected=this.otherCallRejected)}var r=e("./handlers"),o=e("./unwrap");t.exports=n,n.prototype.callFulfilled=function(e){r.resolve(this.promise,e)},n.prototype.otherCallFulfilled=function(e){o(this.promise,this.onFulfilled,e)},n.prototype.callRejected=function(e){r.reject(this.promise,e)},n.prototype.otherCallRejected=function(e){o(this.promise,this.onRejected,e)}},{"./handlers":6,"./unwrap":16}],10:[function(e,t){"use strict";function n(e){function t(e){i(e).then(function(e){s||(s=!0,a.resolve(c,e))},function(e){s||(s=!0,a.reject(c,e))})}if("[object Array]"!==Object.prototype.toString.call(e))return o(new TypeError("must be an array"));var n=e.length,s=!1;if(!n)return i([]);for(var f=-1,c=new r(u);++f<n;)t(e[f]);return c}var r=e("./promise"),o=e("./reject"),i=e("./resolve"),u=e("./INTERNAL"),a=e("./handlers");t.exports=n},{"./INTERNAL":4,"./handlers":6,"./promise":8,"./reject":11,"./resolve":12}],11:[function(e,t){"use strict";function n(e){var t=new r(o);return i.reject(t,e)}var r=e("./promise"),o=e("./INTERNAL"),i=e("./handlers");t.exports=n},{"./INTERNAL":4,"./handlers":6,"./promise":8}],12:[function(e,t){"use strict";function n(e){if(e)return e instanceof r?e:i.resolve(new r(o),e);var t=typeof e;switch(t){case"boolean":return u;case"undefined":return s;case"object":return a;case"number":return f;case"string":return c}}var r=e("./promise"),o=e("./INTERNAL"),i=e("./handlers");t.exports=n;var u=i.resolve(new r(o),!1),a=i.resolve(new r(o),null),s=i.resolve(new r(o),void 0),f=i.resolve(new r(o),0),c=i.resolve(new r(o),"")},{"./INTERNAL":4,"./handlers":6,"./promise":8}],13:[function(e,t,n){"use strict";function r(e,t){function n(t){a||(a=!0,o.reject(e,t))}function r(t){a||(a=!0,o.resolve(e,t))}function u(){t(r,n)}var a=!1,s=i(u);"error"===s.status&&n(s.value)}var o=e("./handlers"),i=e("./tryCatch");n.safely=r},{"./handlers":6,"./tryCatch":15}],14:[function(e,t,n){n.REJECTED=["REJECTED"],n.FULFILLED=["FULFILLED"],n.PENDING=["PENDING"]},{}],15:[function(e,t){"use strict";function n(e,t){var n={};try{n.value=e(t),n.status="success"}catch(r){n.status="error",n.value=r}return n}t.exports=n},{}],16:[function(e,t){"use strict";function n(e,t,n){r(function(){var r;try{r=t(n)}catch(i){return o.reject(e,i)}r===e?o.reject(e,new TypeError("Cannot resolve promise with itself")):o.resolve(e,r)})}var r=e("immediate"),o=e("./handlers");t.exports=n},{"./handlers":6,immediate:17}],17:[function(e,t){"use strict";function n(){o=!0;for(var e,t,n=a.length;n;){for(t=a,a=[],e=-1;++e<n;)t[e]();n=a.length}o=!1}function r(e){1!==a.push(e)||o||i()}for(var o,i,u=[e("./nextTick"),e("./mutation.js"),e("./messageChannel"),e("./stateChange"),e("./timeout")],a=[],s=-1,f=u.length;++s<f;)if(u[s]&&u[s].test&&u[s].test()){i=u[s].install(n);break}t.exports=r},{"./messageChannel":18,"./mutation.js":19,"./nextTick":22,"./stateChange":20,"./timeout":21}],18:[function(e,t,n){(function(e){"use strict";n.test=function(){return e.setImmediate?!1:"undefined"!=typeof e.MessageChannel},n.install=function(t){var n=new e.MessageChannel;return n.port1.onmessage=t,function(){n.port2.postMessage(0)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],19:[function(e,t,n){(function(e){"use strict";var t=e.MutationObserver||e.WebKitMutationObserver;n.test=function(){return t},n.install=function(n){var r=0,o=new t(n),i=e.document.createTextNode("");return o.observe(i,{characterData:!0}),function(){i.data=r=++r%2}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],20:[function(e,t,n){(function(e){"use strict";n.test=function(){return"document"in e&&"onreadystatechange"in e.document.createElement("script")},n.install=function(t){return function(){var n=e.document.createElement("script");return n.onreadystatechange=function(){t(),n.onreadystatechange=null,n.parentNode.removeChild(n),n=null},e.document.documentElement.appendChild(n),t}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],21:[function(e,t,n){"use strict";n.test=function(){return!0},n.install=function(e){return function(){setTimeout(e,0)}}},{}],22:[function(){},{}]},{},[1])(1)}); | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.blobUtil=e()}}(function(){return function e(t,n,r){function o(u,f){if(!n[u]){if(!t[u]){var c="function"==typeof require&&require;if(!f&&c)return c(u,!0);if(i)return i(u,!0);var a=new Error("Cannot find module '"+u+"'");throw a.code="MODULE_NOT_FOUND",a}var s=n[u]={exports:{}};t[u][0].call(s.exports,function(e){var n=t[u][1][e];return o(n?n:e)},s,s.exports,e,t,n,r)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(e,t,n){(function(e){function n(e){for(var t=0;t<e.length;t++){var n=e[t];if(n.buffer instanceof ArrayBuffer){var r=n.buffer;if(n.byteLength!==r.byteLength){var o=new Uint8Array(n.byteLength);o.set(new Uint8Array(r,n.byteOffset,n.byteLength)),r=o.buffer}e[t]=r}}}function r(e,t){t=t||{};var r=new i;n(e);for(var o=0;o<e.length;o++)r.append(e[o]);return t.type?r.getBlob(t.type):r.getBlob()}function o(e,t){return n(e),new Blob(e,t||{})}var i=e.BlobBuilder||e.WebKitBlobBuilder||e.MSBlobBuilder||e.MozBlobBuilder,u=function(){try{var e=new Blob(["hi"]);return 2===e.size}catch(t){return!1}}(),f=u&&function(){try{var e=new Blob([new Uint8Array([1,2])]);return 2===e.size}catch(t){return!1}}(),c=i&&i.prototype.append&&i.prototype.getBlob;t.exports=function(){return u?f?e.Blob:o:c?r:void 0}()}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],2:[function(e,t,n){},{}],3:[function(e,t,n){(function(n){"function"==typeof n.Promise?t.exports=n.Promise:t.exports=e(7)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{7:7}],4:[function(e,t,n){"use strict";function r(){}t.exports=r},{}],5:[function(e,t,n){"use strict";var r=e(8),o=e(10),i=e(11),u=e(4),f=e(6),c=o(new TypeError("must be an array"));t.exports=function(e){function t(e,t){function r(e){a[t]=e,++s===n&!o&&(o=!0,f.resolve(d,a))}i(e).then(r,function(e){o||(o=!0,f.reject(d,e))})}if("[object Array]"!==Object.prototype.toString.call(e))return c;var n=e.length,o=!1;if(!n)return i([]);for(var a=new Array(n),s=0,l=-1,d=new r(u);++l<n;)t(e[l],l);return d}},{10:10,11:11,4:4,6:6,8:8}],6:[function(e,t,n){"use strict";function r(e){var t=e&&e.then;return e&&"object"==typeof e&&"function"==typeof t?function(){t.apply(e,arguments)}:void 0}var o=e(14),i=e(12),u=e(13);n.resolve=function(e,t){var f=o(r,t);if("error"===f.status)return n.reject(e,f.value);var c=f.value;if(c)i.safely(e,c);else{e.state=u.FULFILLED,e.outcome=t;for(var a=-1,s=e.queue.length;++a<s;)e.queue[a].callFulfilled(t)}return e},n.reject=function(e,t){e.state=u.REJECTED,e.outcome=t;for(var n=-1,r=e.queue.length;++n<r;)e.queue[n].callRejected(t);return e}},{12:12,13:13,14:14}],7:[function(e,t,n){t.exports=n=e(8),n.resolve=e(11),n.reject=e(10),n.all=e(5)},{10:10,11:11,5:5,8:8}],8:[function(e,t,n){"use strict";function r(e){if(!(this instanceof r))return new r(e);if("function"!=typeof e)throw new TypeError("reslover must be a function");this.state=f.PENDING,this.queue=[],this.outcome=void 0,e!==i&&u.safely(this,e)}var o=e(15),i=e(4),u=e(12),f=e(13),c=e(9);t.exports=r,r.prototype["catch"]=function(e){return this.then(null,e)},r.prototype.then=function(e,t){if("function"!=typeof e&&this.state===f.FULFILLED||"function"!=typeof t&&this.state===f.REJECTED)return this;var n=new r(i);if(this.state!==f.PENDING){var u=this.state===f.FULFILLED?e:t;o(n,u,this.outcome)}else this.queue.push(new c(n,e,t));return n}},{12:12,13:13,15:15,4:4,9:9}],9:[function(e,t,n){"use strict";function r(e,t,n){this.promise=e,"function"==typeof t&&(this.onFulfilled=t,this.callFulfilled=this.otherCallFulfilled),"function"==typeof n&&(this.onRejected=n,this.callRejected=this.otherCallRejected)}var o=e(6),i=e(15);t.exports=r,r.prototype.callFulfilled=function(e){o.resolve(this.promise,e)},r.prototype.otherCallFulfilled=function(e){i(this.promise,this.onFulfilled,e)},r.prototype.callRejected=function(e){o.reject(this.promise,e)},r.prototype.otherCallRejected=function(e){i(this.promise,this.onRejected,e)}},{15:15,6:6}],10:[function(e,t,n){"use strict";function r(e){var t=new o(i);return u.reject(t,e)}var o=e(8),i=e(4),u=e(6);t.exports=r},{4:4,6:6,8:8}],11:[function(e,t,n){"use strict";function r(e){if(e)return e instanceof o?e:u.resolve(new o(i),e);var t=typeof e;switch(t){case"boolean":return f;case"undefined":return a;case"object":return c;case"number":return s;case"string":return l}}var o=e(8),i=e(4),u=e(6);t.exports=r;var f=u.resolve(new o(i),!1),c=u.resolve(new o(i),null),a=u.resolve(new o(i),void 0),s=u.resolve(new o(i),0),l=u.resolve(new o(i),"")},{4:4,6:6,8:8}],12:[function(e,t,n){"use strict";function r(e,t){function n(t){f||(f=!0,o.reject(e,t))}function r(t){f||(f=!0,o.resolve(e,t))}function u(){t(r,n)}var f=!1,c=i(u);"error"===c.status&&n(c.value)}var o=e(6),i=e(14);n.safely=r},{14:14,6:6}],13:[function(e,t,n){n.REJECTED=["REJECTED"],n.FULFILLED=["FULFILLED"],n.PENDING=["PENDING"]},{}],14:[function(e,t,n){"use strict";function r(e,t){var n={};try{n.value=e(t),n.status="success"}catch(r){n.status="error",n.value=r}return n}t.exports=r},{}],15:[function(e,t,n){"use strict";function r(e,t,n){o(function(){var r;try{r=t(n)}catch(o){return i.reject(e,o)}r===e?i.reject(e,new TypeError("Cannot resolve promise with itself")):i.resolve(e,r)})}var o=e(16),i=e(6);t.exports=r},{16:16,6:6}],16:[function(e,t,n){"use strict";function r(){u=!1,f&&f.length?l=f.concat(l):s=-1,l.length&&o()}function o(){u=!0;for(var e=l.length,t=setTimeout(r);e;){for(f=l,l=[];++s<e;)f[s]();s=-1,e=l.length}s=-1,u=!1,clearTimeout(t)}function i(e){1!==l.push(e)||u||c()}for(var u,f,c,a=[e(2),e(18),e(17),e(19),e(20)],s=-1,l=[],d=-1,p=a.length;++d<p;)if(a[d]&&a[d].test&&a[d].test()){c=a[d].install(o);break}t.exports=i},{17:17,18:18,19:19,2:2,20:20}],17:[function(e,t,n){(function(e){"use strict";n.test=function(){return e.setImmediate?!1:"undefined"!=typeof e.MessageChannel},n.install=function(t){var n=new e.MessageChannel;return n.port1.onmessage=t,function(){n.port2.postMessage(0)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],18:[function(e,t,n){(function(e){"use strict";var t=e.MutationObserver||e.WebKitMutationObserver;n.test=function(){return t},n.install=function(n){var r=0,o=new t(n),i=e.document.createTextNode("");return o.observe(i,{characterData:!0}),function(){i.data=r=++r%2}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],19:[function(e,t,n){(function(e){"use strict";n.test=function(){return"document"in e&&"onreadystatechange"in e.document.createElement("script")},n.install=function(t){return function(){var n=e.document.createElement("script");return n.onreadystatechange=function(){t(),n.onreadystatechange=null,n.parentNode.removeChild(n),n=null},e.document.documentElement.appendChild(n),t}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],20:[function(e,t,n){"use strict";n.test=function(){return!0},n.install=function(e){return function(){setTimeout(e,0)}}},{}],21:[function(e,t,n){"use strict";function r(e){for(var t=e.length,n=new ArrayBuffer(t),r=new Uint8Array(n),o=-1;++o<t;)r[o]=e.charCodeAt(o);return n}function o(e){for(var t="",n=new Uint8Array(e),r=n.byteLength,o=-1;++o<r;)t+=String.fromCharCode(n[o]);return t}function i(e,t){return new B(function(n,r){var o=new Image;t&&(o.crossOrigin=t),o.onload=function(){n(o)},o.onerror=r,o.src=e})}function u(e){var t=document.createElement("canvas");t.width=e.width,t.height=e.height;var n=t.getContext("2d");return n.drawImage(e,0,0,e.width,e.height,0,0,e.width,e.height),t}function f(e,t){return t=t||{},"string"==typeof t&&(t={type:t}),new m(e,t)}function c(e){return(window.URL||window.webkitURL).createObjectURL(e)}function a(e){return(window.URL||window.webkitURL).revokeObjectURL(e)}function s(e){return new B(function(t,n){var r=new FileReader,i="function"==typeof r.readAsBinaryString;r.onloadend=function(e){var n=e.target.result||"";return i?t(n):void t(o(n))},r.onerror=n,i?r.readAsBinaryString(e):r.readAsArrayBuffer(e)})}function l(e,t){return B.resolve().then(function(){var n=[r(atob(e))];return t?f(n,{type:t}):f(n)})}function d(e,t){return B.resolve().then(function(){return l(btoa(e),t)})}function p(e){return s(e).then(function(e){return btoa(e)})}function h(e){return B.resolve().then(function(){var t=e.match(/data:([^;]+)/)[1],n=e.replace(/^[^,]+,/,""),o=r(atob(n));return f([o],{type:t})})}function v(e,t,n){return t=t||"image/png",i(e,n).then(function(e){return u(e)}).then(function(e){return e.toDataURL(t)})}function y(e,t){return B.resolve().then(function(){return"function"==typeof e.toBlob?new B(function(n){e.toBlob(n,t)}):h(e.toDataURL(t))})}function w(e,t,n){return t=t||"image/png",i(e,n).then(function(e){return u(e)}).then(function(e){return y(e,t)})}function b(e,t){return B.resolve().then(function(){return f([e],t)})}function g(e){return new B(function(t,n){var r=new FileReader;r.onloadend=function(e){var n=e.target.result||new ArrayBuffer(0);t(n)},r.onerror=n,r.readAsArrayBuffer(e)})}var m=e(1),B=e(3);t.exports={createBlob:f,createObjectURL:c,revokeObjectURL:a,imgSrcToBlob:w,imgSrcToDataURL:v,canvasToBlob:y,dataURLToBlob:h,blobToBase64String:p,base64StringToBlob:l,binaryStringToBlob:d,blobToBinaryString:s,arrayBufferToBlob:b,blobToArrayBuffer:g}},{1:1,3:3}]},{},[21])(21)}); |
'use strict'; | ||
var utils = require('./utils'); | ||
/* jshint -W079 */ | ||
var Blob = require('blob'); | ||
var Promise = utils.Promise; | ||
var Promise = require('pouchdb-promise'); | ||
@@ -279,4 +278,10 @@ // | ||
function blobToArrayBuffer(blob) { | ||
return blobToBinaryString(blob).then(function (binary) { | ||
return binaryStringToArrayBuffer(binary); | ||
return new Promise(function (resolve, reject) { | ||
var reader = new FileReader(); | ||
reader.onloadend = function (e) { | ||
var result = e.target.result || new ArrayBuffer(0); | ||
resolve(result); | ||
}; | ||
reader.onerror = reject; | ||
reader.readAsArrayBuffer(blob); | ||
}); | ||
@@ -283,0 +288,0 @@ } |
{ | ||
"name": "blob-util", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Utilities for working with Blob objects in the browser", | ||
@@ -27,3 +27,4 @@ "main": "lib/index.js", | ||
"test": "npm run jshint && ./bin/run-test.sh", | ||
"build": "mkdir -p dist && browserify lib/index.js -s blobUtil -o dist/blob-util.js && npm run min", | ||
"build": "mkdirp dist && npm run browserify && npm run min", | ||
"browserify": "browserify . -p bundle-collapser/plugin -s blobUtil | ./bin/es3ify.js | derequire > dist/blob-util.js", | ||
"min": "uglifyjs dist/blob-util.js -mc > dist/blob-util.min.js", | ||
@@ -38,11 +39,12 @@ "dev": "browserify test/test.js > test/test-bundle.js && npm run dev-server", | ||
"blob": "0.0.4", | ||
"es3ify": "^0.1.3", | ||
"jsdoc": "^3.3.0-alpha10", | ||
"lie": "^2.6.0" | ||
"pouchdb-promise": "0.0.0" | ||
}, | ||
"devDependencies": { | ||
"bluebird": "^1.0.7", | ||
"browserify": "~2.36.0", | ||
"browserify": "^9.0.3", | ||
"bundle-collapser": "^1.1.4", | ||
"chai": "~1.8.1", | ||
"chai-as-promised": "~4.1.0", | ||
"derequire": "^2.0.0", | ||
"es3ify": "^0.1.3", | ||
"http-server": "~0.5.5", | ||
@@ -53,2 +55,3 @@ "istanbul": "^0.2.7", | ||
"jshint": "~2.3.0", | ||
"mkdirp": "^0.5.0", | ||
"mocha": "~1.18", | ||
@@ -58,11 +61,7 @@ "phantomjs": "^1.9.7-5", | ||
"sauce-connect-launcher": "^0.4.2", | ||
"selenium-standalone": "3.0.2", | ||
"uglify-js": "^2.4.13", | ||
"watchify": "~0.4.1", | ||
"watchify": "^2.4.0", | ||
"wd": "^0.2.21" | ||
}, | ||
"browserify": { | ||
"transform": [ | ||
"es3ify" | ||
] | ||
} | ||
} |
185
README.md
@@ -8,6 +8,4 @@ blob-util | ||
If you want an easy way to work with binary data in the browser, or you don't even know what a Blob is, then this is the library for you. | ||
It offers a tiny (~4KB min+gz) set of cross-browser utilities for translating Blobs to and from different formats: | ||
`blob-util` offers a tiny (~4KB min+gz) set of cross-browser utilities for translating Blobs to and from different formats: | ||
* `<img/>` tags | ||
@@ -18,2 +16,3 @@ * base 64 strings | ||
* data URLs | ||
* canvas | ||
@@ -26,3 +25,4 @@ It's also a good pairing with the attachment API in [PouchDB](http://pouchdb.com). | ||
* [Usage](#usage) | ||
* [Install](#usage) | ||
* [Browser support](#browser-support) | ||
* [Tutorial](#tutorial) | ||
@@ -32,3 +32,3 @@ * [Playground](http://nolanlawson.github.io/blob-util) | ||
Usage | ||
Install | ||
------ | ||
@@ -56,2 +56,13 @@ | ||
Browser support | ||
----- | ||
* Firefox | ||
* Chrome | ||
* IE 10+ | ||
* Safari 6+ | ||
* iOS 6+ | ||
* Android 4+ | ||
* Any browser with either `Blob` or the older `BlobBuilder`; see [caniuse](http://caniuse.com/#search=blob) for details. | ||
Tutorial | ||
@@ -134,2 +145,9 @@ -------- | ||
**Returns**: `Blob` | ||
**Example**: | ||
```js | ||
var myBlob = blobUtil.createBlob(['hello world'], {type: 'text/plain'}); | ||
``` | ||
<a name="createObjectURL"></a> | ||
@@ -147,2 +165,9 @@ ###createObjectURL(blob) | ||
**Returns**: `string` - url | ||
**Example**: | ||
```js | ||
var myUrl = blobUtil.createObjectURL(blob); | ||
``` | ||
<a name="revokeObjectURL"></a> | ||
@@ -159,2 +184,8 @@ ###revokeObjectURL(url) | ||
**Example**: | ||
```js | ||
blobUtil.revokeObjectURL(myUrl); | ||
``` | ||
<a name="blobToBinaryString"></a> | ||
@@ -168,3 +199,14 @@ ###blobToBinaryString(blob) | ||
**Returns**: `Promise` - Promise that resolves with the binary string | ||
**Returns**: `Promise` - Promise that resolves with the binary string | ||
**Example**: | ||
```js | ||
blobUtil.blobToBinaryString(blob).then(function (binaryString) { | ||
// success | ||
}).catch(function (err) { | ||
// error | ||
}); | ||
``` | ||
<a name="base64StringToBlob"></a> | ||
@@ -180,2 +222,13 @@ ###base64StringToBlob(base64, type) | ||
**Returns**: `Promise` - Promise that resolves with the <code>Blob</code> | ||
**Example**: | ||
```js | ||
blobUtil.base64StringToBlob(base64String).then(function (blob) { | ||
// success | ||
}).catch(function (err) { | ||
// error | ||
}); | ||
``` | ||
<a name="binaryStringToBlob"></a> | ||
@@ -191,2 +244,13 @@ ###binaryStringToBlob(binary, type) | ||
**Returns**: `Promise` - Promise that resolves with the <code>Blob</code> | ||
**Example**: | ||
```js | ||
blobUtil.binaryStringToBlob(binaryString).then(function (blob) { | ||
// success | ||
}).catch(function (err) { | ||
// error | ||
}); | ||
``` | ||
<a name="blobToBase64String"></a> | ||
@@ -201,2 +265,14 @@ ###blobToBase64String(blob) | ||
**Returns**: `Promise` - Promise that resolves with the binary string | ||
**Example**: | ||
```js | ||
blobUtil.blobToBase64String(blob).then(function (base64String) { | ||
// success | ||
}).catch(function (err) { | ||
// error | ||
}); | ||
``` | ||
<a name="dataURLToBlob"></a> | ||
@@ -213,2 +289,13 @@ ###dataURLToBlob(dataURL) | ||
**Returns**: `Promise` - Promise that resolves with the <code>Blob</code> | ||
**Example**: | ||
```js | ||
blobUtil.dataURLToBlob(dataURL).then(function (blob) { | ||
// success | ||
}).catch(function (err) { | ||
// error | ||
}); | ||
``` | ||
<a name="imgSrcToDataURL"></a> | ||
@@ -230,2 +317,22 @@ ###imgSrcToDataURL(src, type, crossOrigin) | ||
**Returns**: `Promise` - Promise that resolves with the data URL string | ||
**Examples**: | ||
```js | ||
blobUtil.imgSrcToDataURL('http://mysite.com/img.png').then(function (dataURL) { | ||
// success | ||
}).catch(function (err) { | ||
// error | ||
}); | ||
``` | ||
```js | ||
blobUtil.imgSrcToDataURL('http://some-other-site.com/img.jpg', 'image/jpeg', | ||
{crossOrigin: 'Anonymous'}).then(function (dataURL) { | ||
// success | ||
}).catch(function (err) { | ||
// error | ||
}); | ||
``` | ||
<a name="canvasToBlob"></a> | ||
@@ -241,2 +348,25 @@ ###canvasToBlob(canvas, type) | ||
**Returns**: `Promise` - Promise that resolves with the <code>Blob</code> | ||
**Examples**: | ||
```js | ||
blobUtil.canvasToBlob(canvas).then(function (blob) { | ||
// success | ||
}).catch(function (err) { | ||
// error | ||
}); | ||
``` | ||
Most browsers support converting a canvas to both `'image/png'` and `'image/jpeg'`. You may | ||
also want to try `'image/webp'`, which will work in some browsers like Chrome (and in other browsers, will just fall back to `'image/png'`): | ||
```js | ||
blobUtil.canvasToBlob(canvas, 'image/webp').then(function (blob) { | ||
// success | ||
}).catch(function (err) { | ||
// error | ||
}); | ||
``` | ||
<a name="imgSrcToBlob"></a> | ||
@@ -258,2 +388,22 @@ ###imgSrcToBlob(src, type, crossOrigin) | ||
**Returns**: `Promise` - Promise that resolves with the <code>Blob</code> | ||
**Examples**: | ||
```js | ||
blobUtil.imgSrcToBlob('http://mysite.com/img.png').then(function (blob) { | ||
// success | ||
}).catch(function (err) { | ||
// error | ||
}); | ||
``` | ||
```js | ||
blobUtil.imgSrcToBlob('http://some-other-site.com/img.jpg', 'image/jpeg', | ||
{crossOrigin: 'Anonymous'}).then(function (blob) { | ||
// success | ||
}).catch(function (err) { | ||
// error | ||
}); | ||
``` | ||
<a name="arrayBufferToBlob"></a> | ||
@@ -269,2 +419,13 @@ ###arrayBufferToBlob(buffer, type) | ||
**Returns**: `Promise` - Promise that resolves with the <code>Blob</code> | ||
**Example**: | ||
```js | ||
blobUtil.arrayBufferToBlob(arrayBuff, 'audio/mpeg').then(function (blob) { | ||
// success | ||
}).catch(function (err) { | ||
// error | ||
}); | ||
``` | ||
<a name="blobToArrayBuffer"></a> | ||
@@ -280,2 +441,12 @@ ###blobToArrayBuffer(blob) | ||
**Example**: | ||
```js | ||
blobUtil.blobToArrayBuffer(blob).then(function (arrayBuff) { | ||
// success | ||
}).catch(function (err) { | ||
// error | ||
}); | ||
``` | ||
Credits | ||
@@ -307,2 +478,4 @@ ---- | ||
Update: I also manually added a bunch of code samples to `README.md` because jsdoc didn't seem to support that. So... yeah, jsdoc might not be so helpful anymore. | ||
Testing the library | ||
@@ -309,0 +482,0 @@ ---- |
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 too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
1566055
2
42
15435
479
20
5
21
+ Addedpouchdb-promise@0.0.0
+ Addedbluebird@1.2.4(transitive)
+ Addedimmediate@3.3.0(transitive)
+ Addedlie@2.7.7(transitive)
+ Addedpouchdb-promise@0.0.0(transitive)
- Removedes3ify@^0.1.3
- Removedjsdoc@^3.3.0-alpha10
- Removedlie@^2.6.0
- Removed@babel/helper-string-parser@7.24.8(transitive)
- Removed@babel/helper-validator-identifier@7.24.7(transitive)
- Removed@babel/parser@7.25.6(transitive)
- Removed@babel/types@7.25.6(transitive)
- Removed@types/linkify-it@5.0.0(transitive)
- Removed@types/markdown-it@12.2.3(transitive)
- Removed@types/mdurl@2.0.0(transitive)
- Removedacorn@1.2.2(transitive)
- Removedamdefine@1.0.1(transitive)
- Removedargparse@2.0.1(transitive)
- Removedast-types@0.8.15(transitive)
- Removedbase62@0.1.1(transitive)
- Removedbluebird@3.7.2(transitive)
- Removedcatharsis@0.9.0(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedentities@2.1.0(transitive)
- Removedes3ify@0.1.4(transitive)
- Removedescape-string-regexp@2.0.0(transitive)
- Removedesmangle-evaluator@1.0.1(transitive)
- Removedesprima-fb@15001.1001.0-dev-harmony-fb3001.1.0-dev-harmony-fb(transitive)
- Removedfalafel@1.2.0(transitive)
- Removedforeach@2.0.6(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedimmediate@3.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedinline-process-browser@1.0.0(transitive)
- Removedisarray@0.0.1(transitive)
- Removedjs2xmlparser@4.0.2(transitive)
- Removedjsdoc@3.6.11(transitive)
- Removedjstransform@3.0.0(transitive)
- Removedklaw@3.0.0(transitive)
- Removedlie@2.9.1(transitive)
- Removedlinkify-it@3.0.3(transitive)
- Removedlodash@4.17.21(transitive)
- Removedmarkdown-it@12.3.2(transitive)
- Removedmarkdown-it-anchor@8.6.7(transitive)
- Removedmarked@4.3.0(transitive)
- Removedmdurl@1.0.1(transitive)
- Removedmkdirp@1.0.4(transitive)
- Removedobject-keys@1.1.1(transitive)
- Removedprivate@0.1.8(transitive)
- Removedreadable-stream@1.0.34(transitive)
- Removedrecast@0.10.43(transitive)
- Removedrequizzle@0.2.4(transitive)
- Removedsource-map@0.1.310.5.7(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedstrip-json-comments@3.1.1(transitive)
- Removedtaffydb@2.6.2(transitive)
- Removedthrough@2.3.8(transitive)
- Removedthrough2@0.6.5(transitive)
- Removedto-fast-properties@2.0.0(transitive)
- Removeduc.micro@1.0.6(transitive)
- Removedunderscore@1.13.7(transitive)
- Removedunreachable-branch-transform@0.2.3(transitive)
- Removedxmlcreate@2.0.4(transitive)
- Removedxtend@4.0.2(transitive)