diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 972e2cb..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -167,6 +167,15 @@ } /** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** * RegExp for SVG size. * * @static @@ -177,4 +186,3 @@ * @example <svg width="100" height="100"></svg> */ SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len - diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 972e2cb..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -167,6 +167,15 @@ } /** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** * RegExp for SVG size. * * @static @@ -177,4 +186,3 @@ * @example <svg width="100" height="100"></svg> */ SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len - diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index dc9d3b9..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -261,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 972e2cb..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -167,6 +167,15 @@ } /** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** * RegExp for SVG size. * * @static @@ -177,4 +186,3 @@ * @example <svg width="100" height="100"></svg> */ SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len - diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index dc9d3b9..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -261,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 972e2cb..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -167,6 +167,15 @@ } /** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** * RegExp for SVG size. * * @static @@ -177,4 +186,3 @@ * @example <svg width="100" height="100"></svg> */ SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len - diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index dc9d3b9..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -261,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/utils/src/const.js b/packages/utils/src/const.js index b96767b..c66c82d 100644 --- a/packages/utils/src/const.js +++ b/packages/utils/src/const.js @@ -1,15 +1,4 @@ /** - * Regexp for image type by extension. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `image.png` - */ -export const URL_FILE_EXTENSION = /\.(\w{3,4})(?:$|\?|#)/i; - -/** * Regexp for data URI. * Based on: {@link https://github.com/ragingwind/data-uri-regex} * diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 972e2cb..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -167,6 +167,15 @@ } /** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** * RegExp for SVG size. * * @static @@ -177,4 +186,3 @@ * @example <svg width="100" height="100"></svg> */ SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len - diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index dc9d3b9..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -261,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/utils/src/const.js b/packages/utils/src/const.js index b96767b..c66c82d 100644 --- a/packages/utils/src/const.js +++ b/packages/utils/src/const.js @@ -1,15 +1,4 @@ /** - * Regexp for image type by extension. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `image.png` - */ -export const URL_FILE_EXTENSION = /\.(\w{3,4})(?:$|\?|#)/i; - -/** * Regexp for data URI. * Based on: {@link https://github.com/ragingwind/data-uri-regex} * diff --git a/packages/utils/src/network/getUrlFileExtension.js b/packages/utils/src/network/getUrlFileExtension.js deleted file mode 100644 index 407f689..0000000 --- a/packages/utils/src/network/getUrlFileExtension.js +++ /dev/null @@ -1,21 +0,0 @@ -import { URL_FILE_EXTENSION } from '../const'; - -/** - * Get type of the image by regexp for extension. Returns undefined for unknown extensions. - * - * @memberof PIXI.utils - * @function getUrlFileExtension - * @param {string} url - the image path - * @return {string|undefined} image extension - */ -export function getUrlFileExtension(url) -{ - const extension = URL_FILE_EXTENSION.exec(url); - - if (extension) - { - return extension[1].toLowerCase(); - } - - return undefined; -} diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 972e2cb..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -167,6 +167,15 @@ } /** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** * RegExp for SVG size. * * @static @@ -177,4 +186,3 @@ * @example <svg width="100" height="100"></svg> */ SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len - diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index dc9d3b9..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -261,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/utils/src/const.js b/packages/utils/src/const.js index b96767b..c66c82d 100644 --- a/packages/utils/src/const.js +++ b/packages/utils/src/const.js @@ -1,15 +1,4 @@ /** - * Regexp for image type by extension. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `image.png` - */ -export const URL_FILE_EXTENSION = /\.(\w{3,4})(?:$|\?|#)/i; - -/** * Regexp for data URI. * Based on: {@link https://github.com/ragingwind/data-uri-regex} * diff --git a/packages/utils/src/network/getUrlFileExtension.js b/packages/utils/src/network/getUrlFileExtension.js deleted file mode 100644 index 407f689..0000000 --- a/packages/utils/src/network/getUrlFileExtension.js +++ /dev/null @@ -1,21 +0,0 @@ -import { URL_FILE_EXTENSION } from '../const'; - -/** - * Get type of the image by regexp for extension. Returns undefined for unknown extensions. - * - * @memberof PIXI.utils - * @function getUrlFileExtension - * @param {string} url - the image path - * @return {string|undefined} image extension - */ -export function getUrlFileExtension(url) -{ - const extension = URL_FILE_EXTENSION.exec(url); - - if (extension) - { - return extension[1].toLowerCase(); - } - - return undefined; -} diff --git a/packages/utils/src/network/index.js b/packages/utils/src/network/index.js index 3bb2549..f2f5430 100644 --- a/packages/utils/src/network/index.js +++ b/packages/utils/src/network/index.js @@ -1,4 +1,3 @@ export * from './decomposeDataUri'; export * from './determineCrossOrigin'; export * from './getResolutionOfUrl'; -export * from './getUrlFileExtension'; diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 972e2cb..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -167,6 +167,15 @@ } /** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** * RegExp for SVG size. * * @static @@ -177,4 +186,3 @@ * @example <svg width="100" height="100"></svg> */ SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len - diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index dc9d3b9..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -261,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/utils/src/const.js b/packages/utils/src/const.js index b96767b..c66c82d 100644 --- a/packages/utils/src/const.js +++ b/packages/utils/src/const.js @@ -1,15 +1,4 @@ /** - * Regexp for image type by extension. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `image.png` - */ -export const URL_FILE_EXTENSION = /\.(\w{3,4})(?:$|\?|#)/i; - -/** * Regexp for data URI. * Based on: {@link https://github.com/ragingwind/data-uri-regex} * diff --git a/packages/utils/src/network/getUrlFileExtension.js b/packages/utils/src/network/getUrlFileExtension.js deleted file mode 100644 index 407f689..0000000 --- a/packages/utils/src/network/getUrlFileExtension.js +++ /dev/null @@ -1,21 +0,0 @@ -import { URL_FILE_EXTENSION } from '../const'; - -/** - * Get type of the image by regexp for extension. Returns undefined for unknown extensions. - * - * @memberof PIXI.utils - * @function getUrlFileExtension - * @param {string} url - the image path - * @return {string|undefined} image extension - */ -export function getUrlFileExtension(url) -{ - const extension = URL_FILE_EXTENSION.exec(url); - - if (extension) - { - return extension[1].toLowerCase(); - } - - return undefined; -} diff --git a/packages/utils/src/network/index.js b/packages/utils/src/network/index.js index 3bb2549..f2f5430 100644 --- a/packages/utils/src/network/index.js +++ b/packages/utils/src/network/index.js @@ -1,4 +1,3 @@ export * from './decomposeDataUri'; export * from './determineCrossOrigin'; export * from './getResolutionOfUrl'; -export * from './getUrlFileExtension'; diff --git a/packages/utils/test/index.js b/packages/utils/test/index.js index 340361f..bf8041e 100755 --- a/packages/utils/test/index.js +++ b/packages/utils/test/index.js @@ -99,87 +99,6 @@ }); }); - describe('getUrlFileExtension', function () - { - it('should exist', function () - { - expect(utils.getUrlFileExtension) - .to.be.a('function'); - }); - - it('should return extension of URL in lower case', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should return extension of URL when absolute', function () - { - const imageType = utils.getUrlFileExtension('/you/baz.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should return extension of URL when relative', function () - { - const imageType = utils.getUrlFileExtension('me/baz.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should return extension of URL when just an extension', function () - { - const imageType = utils.getUrlFileExtension('.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG#derp'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash path on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG#derp/this/is/a/path/me.jpg'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a query string on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG?v=1&file=me.jpg'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash and query string on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG?v=1&file=me.jpg#not-today'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash path and query string on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG?v=1&file=me.jpg#path/s/not-today.svg'); - - expect(imageType) - .to.equal('png'); - }); - }); - describe('sayHello', function () { it('should exist', function ()