@wordpress/blob
Advanced tools
Comparing version 1.0.0-alpha.1 to 1.0.0-alpha.2
@@ -1,7 +0,4 @@ | ||
import _Promise from "babel-runtime/core-js/promise"; | ||
/** | ||
* Browser dependencies | ||
*/ | ||
var _window = window, | ||
fetch = _window.fetch; | ||
var _window$URL = window.URL, | ||
@@ -14,26 +11,41 @@ createObjectURL = _window$URL.createObjectURL, | ||
export function createBlobURL(blob) { | ||
var url = createObjectURL(blob); | ||
/** | ||
* Create a blob URL from a file. | ||
* | ||
* @param {File} file The file to create a blob URL for. | ||
* | ||
* @return {string} The blob URL. | ||
*/ | ||
export function createBlobURL(file) { | ||
var url = createObjectURL(file); | ||
cache[url] = blob; | ||
cache[url] = file; | ||
return url; | ||
return url; | ||
} | ||
/** | ||
* Retrieve a file based on a blob URL. The file must have been created by | ||
* `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return | ||
* `undefined`. | ||
* | ||
* @param {string} url The blob URL. | ||
* | ||
* @return {?File} The file for the blob URL. | ||
*/ | ||
export function getBlobByURL(url) { | ||
if (cache[url]) { | ||
return _Promise.resolve(cache[url]); | ||
} | ||
return fetch(url).then(function (response) { | ||
return response.blob(); | ||
}); | ||
return cache[url]; | ||
} | ||
/** | ||
* Remove the resource and file cache from memory. | ||
* | ||
* @param {string} url The blob URL. | ||
*/ | ||
export function revokeBlobURL(url) { | ||
if (cache[url]) { | ||
revokeObjectURL(url); | ||
} | ||
if (cache[url]) { | ||
revokeObjectURL(url); | ||
} | ||
delete cache[url]; | ||
delete cache[url]; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
var _promise = require("babel-runtime/core-js/promise"); | ||
var _promise2 = _interopRequireDefault(_promise); | ||
exports.createBlobURL = createBlobURL; | ||
exports.getBlobByURL = getBlobByURL; | ||
exports.revokeBlobURL = revokeBlobURL; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
* Browser dependencies | ||
*/ | ||
var _window = window, | ||
fetch = _window.fetch; | ||
var _window$URL = window.URL, | ||
@@ -29,26 +19,41 @@ createObjectURL = _window$URL.createObjectURL, | ||
function createBlobURL(blob) { | ||
var url = createObjectURL(blob); | ||
/** | ||
* Create a blob URL from a file. | ||
* | ||
* @param {File} file The file to create a blob URL for. | ||
* | ||
* @return {string} The blob URL. | ||
*/ | ||
function createBlobURL(file) { | ||
var url = createObjectURL(file); | ||
cache[url] = blob; | ||
cache[url] = file; | ||
return url; | ||
return url; | ||
} | ||
/** | ||
* Retrieve a file based on a blob URL. The file must have been created by | ||
* `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return | ||
* `undefined`. | ||
* | ||
* @param {string} url The blob URL. | ||
* | ||
* @return {?File} The file for the blob URL. | ||
*/ | ||
function getBlobByURL(url) { | ||
if (cache[url]) { | ||
return _promise2.default.resolve(cache[url]); | ||
} | ||
return fetch(url).then(function (response) { | ||
return response.blob(); | ||
}); | ||
return cache[url]; | ||
} | ||
/** | ||
* Remove the resource and file cache from memory. | ||
* | ||
* @param {string} url The blob URL. | ||
*/ | ||
function revokeBlobURL(url) { | ||
if (cache[url]) { | ||
revokeObjectURL(url); | ||
} | ||
if (cache[url]) { | ||
revokeObjectURL(url); | ||
} | ||
delete cache[url]; | ||
delete cache[url]; | ||
} |
{ | ||
"name": "@wordpress/blob", | ||
"version": "1.0.0-alpha.1", | ||
"version": "1.0.0-alpha.2", | ||
"description": "Blob utils for WordPress", | ||
@@ -5,0 +5,0 @@ "author": "The WordPress Contributors", |
/** | ||
* Browser dependencies | ||
*/ | ||
const { fetch } = window; | ||
const { createObjectURL, revokeObjectURL } = window.URL; | ||
@@ -9,6 +8,13 @@ | ||
export function createBlobURL( blob ) { | ||
const url = createObjectURL( blob ); | ||
/** | ||
* Create a blob URL from a file. | ||
* | ||
* @param {File} file The file to create a blob URL for. | ||
* | ||
* @return {string} The blob URL. | ||
*/ | ||
export function createBlobURL( file ) { | ||
const url = createObjectURL( file ); | ||
cache[ url ] = blob; | ||
cache[ url ] = file; | ||
@@ -18,10 +24,20 @@ return url; | ||
/** | ||
* Retrieve a file based on a blob URL. The file must have been created by | ||
* `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return | ||
* `undefined`. | ||
* | ||
* @param {string} url The blob URL. | ||
* | ||
* @return {?File} The file for the blob URL. | ||
*/ | ||
export function getBlobByURL( url ) { | ||
if ( cache[ url ] ) { | ||
return Promise.resolve( cache[ url ] ); | ||
} | ||
return fetch( url ).then( ( response ) => response.blob() ); | ||
return cache[ url ]; | ||
} | ||
/** | ||
* Remove the resource and file cache from memory. | ||
* | ||
* @param {string} url The blob URL. | ||
*/ | ||
export function revokeBlobURL( url ) { | ||
@@ -28,0 +44,0 @@ if ( cache[ url ] ) { |
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
3860
129
0