diff --git a/.gitignore b/.gitignore index 8ce7441..c110f9d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,3 @@ test/test-bundle.js npm-debug.log dist api.md -doc/global.html -doc/index.html diff --git a/README.md b/README.md index ed44d28..17e3359 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,7 @@ Warning: this API uses [Promises](https://promisesaplus.com/), because it's not * [binaryStringToBlob(binary, type)](#binaryStringToBlob) * [blobToBase64String(blob)](#blobToBase64String) * [dataURLToBlob(dataURL)](#dataURLToBlob) +* [blobToDataURL(blob)](#blobToDataURL) * [imgSrcToDataURL(src, type, crossOrigin, quality)](#imgSrcToDataURL) * [canvasToBlob(canvas, type, quality)](#canvasToBlob) * [imgSrcToBlob(src, type, crossOrigin, quality)](#imgSrcToBlob) @@ -284,7 +285,27 @@ blobUtil.dataURLToBlob(dataURL).then(function (blob) { // error }); ``` + +###blobToDataURL(blob) +Convert a Blob to a data URL string +(e.g. 'data:image/png;base64,iVBORw0KG...'). +Returns a Promise. +**Params** + +- blob `Blob` + +**Returns**: `Promise` - Promise that resolves with the data URL string + +**Example**: + +```js +blobUtil.blobToDataURL(blob).then(function (dataURL) { + // success +}).catch(function (err) { + // error +}); +``` ### imgSrcToDataURL(src, type, crossOrigin, quality) Convert an image's src URL to a data URL by loading the image and painting @@ -460,10 +481,8 @@ The playground is just `jsdoc` with some extra text containing Kirby and the cod So unfortunately you will need to do a manual diff to get the docs up to date. You'll need to diff: -* `api.md` to `README.md` -* `index.html` to `doc/global.html` - -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. +* `README.md` to its previous version (make sure to keep the code samples, which were manually added) +* `docs` to its previous version Testing the library ---- diff --git a/doc/blob-util.gif b/doc/blob-util.gif deleted file mode 100644 index d580688..0000000 Binary files a/doc/blob-util.gif and /dev/null differ diff --git a/doc/fonts/OpenSans-Bold-webfont.eot b/docs/fonts/OpenSans-Bold-webfont.eot similarity index 100% rename from doc/fonts/OpenSans-Bold-webfont.eot rename to docs/fonts/OpenSans-Bold-webfont.eot diff --git a/doc/fonts/OpenSans-Bold-webfont.svg b/docs/fonts/OpenSans-Bold-webfont.svg similarity index 100% rename from doc/fonts/OpenSans-Bold-webfont.svg rename to docs/fonts/OpenSans-Bold-webfont.svg diff --git a/doc/fonts/OpenSans-Bold-webfont.woff b/docs/fonts/OpenSans-Bold-webfont.woff similarity index 100% rename from doc/fonts/OpenSans-Bold-webfont.woff rename to docs/fonts/OpenSans-Bold-webfont.woff diff --git a/doc/fonts/OpenSans-BoldItalic-webfont.eot b/docs/fonts/OpenSans-BoldItalic-webfont.eot similarity index 100% rename from doc/fonts/OpenSans-BoldItalic-webfont.eot rename to docs/fonts/OpenSans-BoldItalic-webfont.eot diff --git a/doc/fonts/OpenSans-BoldItalic-webfont.svg b/docs/fonts/OpenSans-BoldItalic-webfont.svg similarity index 100% rename from doc/fonts/OpenSans-BoldItalic-webfont.svg rename to docs/fonts/OpenSans-BoldItalic-webfont.svg diff --git a/doc/fonts/OpenSans-BoldItalic-webfont.woff b/docs/fonts/OpenSans-BoldItalic-webfont.woff similarity index 100% rename from doc/fonts/OpenSans-BoldItalic-webfont.woff rename to docs/fonts/OpenSans-BoldItalic-webfont.woff diff --git a/doc/fonts/OpenSans-Italic-webfont.eot b/docs/fonts/OpenSans-Italic-webfont.eot similarity index 100% rename from doc/fonts/OpenSans-Italic-webfont.eot rename to docs/fonts/OpenSans-Italic-webfont.eot diff --git a/doc/fonts/OpenSans-Italic-webfont.svg b/docs/fonts/OpenSans-Italic-webfont.svg similarity index 100% rename from doc/fonts/OpenSans-Italic-webfont.svg rename to docs/fonts/OpenSans-Italic-webfont.svg diff --git a/doc/fonts/OpenSans-Italic-webfont.woff b/docs/fonts/OpenSans-Italic-webfont.woff similarity index 100% rename from doc/fonts/OpenSans-Italic-webfont.woff rename to docs/fonts/OpenSans-Italic-webfont.woff diff --git a/doc/fonts/OpenSans-Light-webfont.eot b/docs/fonts/OpenSans-Light-webfont.eot similarity index 100% rename from doc/fonts/OpenSans-Light-webfont.eot rename to docs/fonts/OpenSans-Light-webfont.eot diff --git a/doc/fonts/OpenSans-Light-webfont.svg b/docs/fonts/OpenSans-Light-webfont.svg similarity index 100% rename from doc/fonts/OpenSans-Light-webfont.svg rename to docs/fonts/OpenSans-Light-webfont.svg diff --git a/doc/fonts/OpenSans-Light-webfont.woff b/docs/fonts/OpenSans-Light-webfont.woff similarity index 100% rename from doc/fonts/OpenSans-Light-webfont.woff rename to docs/fonts/OpenSans-Light-webfont.woff diff --git a/doc/fonts/OpenSans-LightItalic-webfont.eot b/docs/fonts/OpenSans-LightItalic-webfont.eot similarity index 100% rename from doc/fonts/OpenSans-LightItalic-webfont.eot rename to docs/fonts/OpenSans-LightItalic-webfont.eot diff --git a/doc/fonts/OpenSans-LightItalic-webfont.svg b/docs/fonts/OpenSans-LightItalic-webfont.svg similarity index 100% rename from doc/fonts/OpenSans-LightItalic-webfont.svg rename to docs/fonts/OpenSans-LightItalic-webfont.svg diff --git a/doc/fonts/OpenSans-LightItalic-webfont.woff b/docs/fonts/OpenSans-LightItalic-webfont.woff similarity index 100% rename from doc/fonts/OpenSans-LightItalic-webfont.woff rename to docs/fonts/OpenSans-LightItalic-webfont.woff diff --git a/doc/fonts/OpenSans-Regular-webfont.eot b/docs/fonts/OpenSans-Regular-webfont.eot similarity index 100% rename from doc/fonts/OpenSans-Regular-webfont.eot rename to docs/fonts/OpenSans-Regular-webfont.eot diff --git a/doc/fonts/OpenSans-Regular-webfont.svg b/docs/fonts/OpenSans-Regular-webfont.svg similarity index 100% rename from doc/fonts/OpenSans-Regular-webfont.svg rename to docs/fonts/OpenSans-Regular-webfont.svg diff --git a/doc/fonts/OpenSans-Regular-webfont.woff b/docs/fonts/OpenSans-Regular-webfont.woff similarity index 100% rename from doc/fonts/OpenSans-Regular-webfont.woff rename to docs/fonts/OpenSans-Regular-webfont.woff diff --git a/index.html b/docs/index.html similarity index 84% rename from index.html rename to docs/index.html index c488b95..1c1fc99 100644 --- a/index.html +++ b/docs/index.html @@ -4,49 +4,27 @@ Playground for blob-util - - + + - - + +
-

blob-util

- - +

Playground for blob-util

- - -
- -
- -

- -

- - -
- -
-
- - -

Playground for blob-util

- - -

Welcome to the docs and playground for blob-util!

-

Below you'll find API documentation, as well as a little Kirby GIF you can play around with.

-

Kirby

-

Here's some code to get you started. Copy-paste this into your console:

-
+  

Welcome to the docs and playground for blob-util!

+

Below you'll find API documentation, as well as a little Kirby GIF you can play around with.

+

Kirby

+

Here's some code to get you started. Copy-paste this into your console:

+
 
 var img = document.getElementById('kirby');
 
@@ -59,7 +37,26 @@ blobUtil.imgSrcToBlob(img.src).then(function (blob) {
   img.parentNode.appendChild(newImg);
 });
 
-

If you see two Kirbys, you're on your way!

+

If you see two Kirbys, you're on your way!

+ + + + +
+ +
+ +

+ + +
+ +
+
+ + + +
@@ -108,7 +105,9 @@ blobUtil.imgSrcToBlob(img.src).then(function (blob) { - + + + @@ -122,7 +121,9 @@ blobUtil.imgSrcToBlob(img.src).then(function (blob) { +

arrayBufferToBlob(buffer, type) → {Promise}

+ @@ -248,7 +249,7 @@ blobUtil.imgSrcToBlob(img.src).then(function (blob) {
Source:
@@ -296,12 +297,16 @@ blobUtil.imgSrcToBlob(img.src).then(function (blob) { + + +

base64StringToBlob(base64, type) → {Promise}

+ @@ -427,7 +432,7 @@ blobUtil.imgSrcToBlob(img.src).then(function (blob) {
Source:
@@ -475,12 +480,16 @@ blobUtil.imgSrcToBlob(img.src).then(function (blob) { + + +

binaryStringToBlob(binary, type) → {Promise}

+ @@ -606,7 +615,7 @@ blobUtil.imgSrcToBlob(img.src).then(function (blob) {
Source:
@@ -654,12 +663,16 @@ blobUtil.imgSrcToBlob(img.src).then(function (blob) { + + +

blobToArrayBuffer(blob) → {Promise}

+ @@ -759,7 +772,7 @@ blobUtil.imgSrcToBlob(img.src).then(function (blob) {
Source:
@@ -807,12 +820,16 @@ blobUtil.imgSrcToBlob(img.src).then(function (blob) { + + +

blobToBase64String(blob) → {Promise}

+ @@ -912,7 +929,7 @@ blobUtil.imgSrcToBlob(img.src).then(function (blob) {
Source:
@@ -960,12 +977,16 @@ blobUtil.imgSrcToBlob(img.src).then(function (blob) { + + +

blobToBinaryString(blob) → {Promise}

+ @@ -1065,7 +1086,7 @@ blobUtil.imgSrcToBlob(img.src).then(function (blob) {
Source:
@@ -1113,12 +1134,175 @@ blobUtil.imgSrcToBlob(img.src).then(function (blob) { + + + +

blobToDataURL(blob) → {Promise}

+ + + + + + +
+ Convert a Blob to a data URL string +(e.g. 'data:image/png;base64,iVBORw0KG...'). +Returns a Promise. +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blob + + +Blob + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+ Promise that resolves with the data URL string +
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + + + +

canvasToBlob(canvas, type, quality) → {Promise}

+ @@ -1271,7 +1455,7 @@ blobUtil.imgSrcToBlob(img.src).then(function (blob) {
Source:
@@ -1319,12 +1503,16 @@ blobUtil.imgSrcToBlob(img.src).then(function (blob) { + + +

createBlob(parts, options) → {Blob}

+ @@ -1450,7 +1638,7 @@ to support
Source:
@@ -1494,12 +1682,16 @@ to support + + +

createObjectURL(blob) → {string}

+ @@ -1602,7 +1794,7 @@ to support browsers that only have the prefixed
Source:
@@ -1650,12 +1842,16 @@ to support browsers that only have the prefixed + + +

dataURLToBlob(dataURL) → {Promise}

+ @@ -1757,7 +1953,7 @@ to a Blob. Returns a Promise.
Source:
@@ -1805,12 +2001,16 @@ to a Blob. Returns a Promise. + + +

imgSrcToBlob(src, type, crossOrigin, quality) → {Promise}

+ @@ -1994,7 +2194,7 @@ will only paint the first frame of an animated GIF.
Source:
@@ -2042,12 +2242,16 @@ will only paint the first frame of an animated GIF. + + +

imgSrcToDataURL(src, type, crossOrigin, quality) → {Promise}

+ @@ -2231,7 +2435,7 @@ will only paint the first frame of an animated GIF.
Source:
@@ -2279,12 +2483,16 @@ will only paint the first frame of an animated GIF. + + +

revokeObjectURL(url)

+ @@ -2387,7 +2595,7 @@ to support browsers that only have the prefixed
Source:
@@ -2413,6 +2621,8 @@ to support browsers that only have the prefixed + + @@ -2429,17 +2639,17 @@ to support browsers that only have the prefixed

- Documentation generated by JSDoc 3.3.0-beta3 on Sat Jan 16 2016 14:43:19 GMT-0500 (EST) + Documentation generated by JSDoc 3.5.3 on Tue Aug 08 2017 13:21:18 GMT-0700 (PDT)
- + - + \ No newline at end of file diff --git a/doc/index.js.html b/docs/index.js.html similarity index 88% rename from doc/index.js.html rename to docs/index.js.html index 5aed6d9..542a18d 100644 --- a/doc/index.js.html +++ b/docs/index.js.html @@ -30,7 +30,7 @@ /* jshint -W079 */ var Blob = require('blob'); -var Promise = require('pouchdb-promise'); +var Promise = require('native-or-lie'); // // PRIVATE @@ -221,6 +221,19 @@ function dataURLToBlob(dataURL) { }); } +/** + * Convert a <code>Blob</code> to a data URL string + * (e.g. <code>'data:image/png;base64,iVBORw0KG...'</code>). + * Returns a Promise. + * @param {Blob} blob + * @returns {Promise} Promise that resolves with the data URL string + */ +function blobToDataURL(blob) { + return blobToBase64String(blob).then(function (base64String) { + return 'data:' + blob.type + ';base64,' + base64String; + }); +} + /** * 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. @@ -328,6 +341,7 @@ module.exports = { imgSrcToDataURL : imgSrcToDataURL, canvasToBlob : canvasToBlob, dataURLToBlob : dataURLToBlob, + blobToDataURL : blobToDataURL, blobToBase64String : blobToBase64String, base64StringToBlob : base64StringToBlob, binaryStringToBlob : binaryStringToBlob, @@ -345,13 +359,13 @@ module.exports = {

- Documentation generated by JSDoc 3.3.0-beta3 on Sat Jan 16 2016 14:43:19 GMT-0500 (EST) + Documentation generated by JSDoc 3.5.3 on Tue Aug 08 2017 13:21:18 GMT-0700 (PDT)
diff --git a/docs/kirby.gif b/docs/kirby.gif new file mode 100644 index 0000000..862bb7d Binary files /dev/null and b/docs/kirby.gif differ diff --git a/doc/scripts/linenumber.js b/docs/scripts/linenumber.js similarity index 100% rename from doc/scripts/linenumber.js rename to docs/scripts/linenumber.js diff --git a/doc/scripts/prettify/Apache-License-2.0.txt b/docs/scripts/prettify/Apache-License-2.0.txt similarity index 100% rename from doc/scripts/prettify/Apache-License-2.0.txt rename to docs/scripts/prettify/Apache-License-2.0.txt diff --git a/doc/scripts/prettify/lang-css.js b/docs/scripts/prettify/lang-css.js similarity index 100% rename from doc/scripts/prettify/lang-css.js rename to docs/scripts/prettify/lang-css.js diff --git a/doc/scripts/prettify/prettify.js b/docs/scripts/prettify/prettify.js similarity index 100% rename from doc/scripts/prettify/prettify.js rename to docs/scripts/prettify/prettify.js diff --git a/doc/styles/jsdoc-default.css b/docs/styles/jsdoc-default.css similarity index 93% rename from doc/styles/jsdoc-default.css rename to docs/styles/jsdoc-default.css index 24aa20f..9207bc8 100644 --- a/doc/styles/jsdoc-default.css +++ b/docs/styles/jsdoc-default.css @@ -78,6 +78,10 @@ article dl { margin-bottom: 40px; } +article img { + max-width: 100%; +} + section { display: block; @@ -153,7 +157,7 @@ h1 margin: 12px 24px 20px; } -h2, h3 +h2, h3.subsection-title { font-size: 30px; font-weight: 700; @@ -161,6 +165,13 @@ h2, h3 margin-bottom: 12px; } +h3 +{ + font-size: 24px; + letter-spacing: -0.5px; + margin-bottom: 12px; +} + h4 { font-size: 18px; @@ -185,8 +196,34 @@ h6 font-style: italic; } -.ancestors { color: #999; } -.ancestors a +table +{ + border-spacing: 0; + border: 0; + border-collapse: collapse; +} + +td, th +{ + border: 1px solid #ddd; + margin: 0px; + text-align: left; + vertical-align: top; + padding: 4px 6px; + display: table-cell; +} + +thead tr +{ + background-color: #ddd; + font-weight: bold; +} + +th { border-right: 1px solid #aaa; } +tr > th:last-child { border-right: 1px solid #ddd; } + +.ancestors, .attribs { color: #999; } +.ancestors a, .attribs a { color: #999 !important; text-decoration: none; @@ -296,44 +333,12 @@ h6 user-select: text; } -.params, .props -{ - border-spacing: 0; - border: 0; - border-collapse: collapse; -} - .params .name, .props .name, .name code { color: #4D4E53; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 100%; } -.params td, .params th, .props td, .props th -{ - border: 1px solid #ddd; - margin: 0px; - text-align: left; - vertical-align: top; - padding: 4px 6px; - display: table-cell; -} - -.params thead tr, .props thead tr -{ - background-color: #ddd; - font-weight: bold; -} - -.params .params thead tr, .props .props thead tr -{ - background-color: #fff; - font-weight: bold; -} - -.params th, .props th { border-right: 1px solid #aaa; } -.params thead .last, .props thead .last { border-right: 1px solid #ddd; } - .params td.description > p:first-child, .props td.description > p:first-child { diff --git a/doc/styles/prettify-jsdoc.css b/docs/styles/prettify-jsdoc.css similarity index 100% rename from doc/styles/prettify-jsdoc.css rename to docs/styles/prettify-jsdoc.css diff --git a/doc/styles/prettify-tomorrow.css b/docs/styles/prettify-tomorrow.css similarity index 100% rename from doc/styles/prettify-tomorrow.css rename to docs/styles/prettify-tomorrow.css diff --git a/package.json b/package.json index 76ea2d1..7989ffe 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,8 @@ "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", - "jsdoc2md": "jsdoc2md --heading-depth 3 ./lib/index.js > api.md", - "jsdoc": "jsdoc -d doc ./lib/index.js" + "jsdoc2md": "jsdoc2md --heading-depth 3 ./lib/index.js > README.md", + "jsdoc": "jsdoc -d docs ./lib/index.js && mv -f docs/global.html docs/index.html" }, "dependencies": { "blob": "0.0.4",