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

@uppy/utils

Package Overview
Dependencies
Maintainers
5
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uppy/utils - npm Package Compare versions

Comparing version 0.27.1 to 0.28.0

3

lib/getFileTypeExtension.js

@@ -10,2 +10,3 @@ // TODO Check which types are actually supported in browsers. Chrome likes webm

'audio/webm': 'webm',
'video/x-matroska': 'mkv',
'video/mp4': 'mp4',

@@ -16,3 +17,5 @@ 'audio/mp3': 'mp3'

module.exports = function getFileTypeExtension(mimeType) {
// Remove the ; bit in 'video/x-matroska;codecs=avc1'
mimeType = mimeType.replace(/;.*$/, '');
return mimeToExtensions[mimeType] || null;
};

2

lib/isPreviewSupported.js

@@ -5,3 +5,3 @@ module.exports = function isPreviewSupported(fileType) {

// list of images that browsers can preview
if (/^(jpeg|gif|png|svg|svg\+xml|bmp)$/.test(fileTypeSpecific)) {
if (/^(jpe?g|gif|png|svg|svg\+xml|bmp)$/.test(fileTypeSpecific)) {
return true;

@@ -8,0 +8,0 @@ }

@@ -16,24 +16,41 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

*
* @param {object} opts
* @param {object|Array<object>} locale Locale or list of locales.
*/
module.exports = function () {
function Translator(opts) {
function Translator(locales) {
var _this = this;
_classCallCheck(this, Translator);
var defaultOptions = {
locale: {
strings: {},
pluralize: function pluralize(n) {
if (n === 1) {
return 0;
}
return 1;
this.locale = {
strings: {},
pluralize: function pluralize(n) {
if (n === 1) {
return 0;
}
return 1;
}
};
this.opts = _extends({}, defaultOptions, opts);
this.locale = _extends({}, defaultOptions.locale, opts.locale);
if (Array.isArray(locales)) {
locales.forEach(function (locale) {
return _this._apply(locale);
});
} else {
this._apply(locales);
}
}
Translator.prototype._apply = function _apply(locale) {
if (!locale || !locale.strings) {
return;
}
var prevLocale = this.locale;
this.locale = _extends({}, prevLocale, {
strings: _extends({}, prevLocale.strings, locale.strings)
});
this.locale.pluralize = locale.pluralize || prevLocale.pluralize;
};
/**

@@ -121,6 +138,6 @@ * Takes a string with placeholder variables like `%{smart_count} file selected`

var plural = this.locale.pluralize(options.smart_count);
return this.interpolate(this.opts.locale.strings[key][plural], options);
return this.interpolate(this.locale.strings[key][plural], options);
}
return this.interpolate(this.opts.locale.strings[key], options);
return this.interpolate(this.locale.strings[key], options);
};

@@ -127,0 +144,0 @@

{
"name": "@uppy/utils",
"description": "Shared utility functions for Uppy Core and plugins maintained by the Uppy team.",
"version": "0.27.1",
"version": "0.28.0",
"license": "MIT",

@@ -23,3 +23,4 @@ "main": "lib/index.js",

"lodash.throttle": "^4.1.1"
}
},
"gitHead": "47a68a6148a41c7b8a1e10e78b6cd6794a53f7e5"
}

@@ -10,2 +10,3 @@ // TODO Check which types are actually supported in browsers. Chrome likes webm

'audio/webm': 'webm',
'video/x-matroska': 'mkv',
'video/mp4': 'mp4',

@@ -16,3 +17,5 @@ 'audio/mp3': 'mp3'

module.exports = function getFileTypeExtension (mimeType) {
// Remove the ; bit in 'video/x-matroska;codecs=avc1'
mimeType = mimeType.replace(/;.*$/, '')
return mimeToExtensions[mimeType] || null
}

@@ -8,2 +8,5 @@ const getFileTypeExtension = require('./getFileTypeExtension')

expect(getFileTypeExtension('video/webm')).toEqual('webm')
// Supports mime types with additional data
expect(getFileTypeExtension('video/webm;codecs=vp8,opus')).toEqual('webm')
expect(getFileTypeExtension('video/x-matroska;codecs=avc1')).toEqual('mkv')
expect(getFileTypeExtension('audio/webm')).toEqual('webm')

@@ -10,0 +13,0 @@ expect(getFileTypeExtension('video/mp4')).toEqual('mp4')

@@ -5,3 +5,3 @@ module.exports = function isPreviewSupported (fileType) {

// list of images that browsers can preview
if (/^(jpeg|gif|png|svg|svg\+xml|bmp)$/.test(fileTypeSpecific)) {
if (/^(jpe?g|gif|png|svg|svg\+xml|bmp)$/.test(fileTypeSpecific)) {
return true

@@ -8,0 +8,0 @@ }

@@ -5,3 +5,3 @@ const isPreviewSupported = require('./isPreviewSupported')

it('should return true for any filetypes that browsers can preview', () => {
const supported = ['image/jpeg', 'image/gif', 'image/png', 'image/svg', 'image/svg+xml', 'image/bmp']
const supported = ['image/jpeg', 'image/gif', 'image/png', 'image/svg', 'image/svg+xml', 'image/bmp', 'image/jpg']
supported.forEach(ext => {

@@ -8,0 +8,0 @@ expect(isPreviewSupported(ext)).toEqual(true)

@@ -12,22 +12,35 @@ /**

*
* @param {object} opts
* @param {object|Array<object>} locale Locale or list of locales.
*/
module.exports = class Translator {
constructor (opts) {
const defaultOptions = {
locale: {
strings: {},
pluralize: function (n) {
if (n === 1) {
return 0
}
return 1
constructor (locales) {
this.locale = {
strings: {},
pluralize: function (n) {
if (n === 1) {
return 0
}
return 1
}
}
this.opts = Object.assign({}, defaultOptions, opts)
this.locale = Object.assign({}, defaultOptions.locale, opts.locale)
if (Array.isArray(locales)) {
locales.forEach((locale) => this._apply(locale))
} else {
this._apply(locales)
}
}
_apply (locale) {
if (!locale || !locale.strings) {
return
}
const prevLocale = this.locale
this.locale = Object.assign({}, prevLocale, {
strings: Object.assign({}, prevLocale.strings, locale.strings)
})
this.locale.pluralize = locale.pluralize || prevLocale.pluralize
}
/**

@@ -106,7 +119,7 @@ * Takes a string with placeholder variables like `%{smart_count} file selected`

var plural = this.locale.pluralize(options.smart_count)
return this.interpolate(this.opts.locale.strings[key][plural], options)
return this.interpolate(this.locale.strings[key][plural], options)
}
return this.interpolate(this.opts.locale.strings[key], options)
return this.interpolate(this.locale.strings[key], options)
}
}

@@ -9,3 +9,3 @@ const Translator = require('./Translator')

it('should translate a string', () => {
const translator = new Translator({ locale: russian })
const translator = new Translator(russian)
expect(translator.translate('chooseFile')).toEqual('Выберите файл')

@@ -16,7 +16,5 @@ })

const translator = new Translator({
locale: {
strings: {
test: 'Hello %{who}!',
test2: 'Hello %{who}'
}
strings: {
test: 'Hello %{who}!',
test2: 'Hello %{who}'
}

@@ -32,5 +30,33 @@ })

describe('translation strings inheritance / overriding', () => {
const launguagePackLoadedInCore = english
const defaultStrings = {
strings: {
youHaveChosen: 'You have chosen 123: %{fileName}'
}
}
const userSuppliedStrings = {
strings: {
youHaveChosen: 'Beep boop: %{fileName}'
}
}
it('should prioritize language pack strings from Core over default', () => {
const translator = new Translator([ defaultStrings, launguagePackLoadedInCore ])
expect(
translator.translate('youHaveChosen', { fileName: 'img.jpg' })
).toEqual('You have chosen: img.jpg')
})
it('should prioritize user-supplied strings over language pack from Core', () => {
const translator = new Translator([ defaultStrings, launguagePackLoadedInCore, userSuppliedStrings ])
expect(
translator.translate('youHaveChosen', { fileName: 'img.jpg' })
).toEqual('Beep boop: img.jpg')
})
})
describe('interpolation', () => {
it('should interpolate a string', () => {
const translator = new Translator({ locale: english })
const translator = new Translator(english)
expect(

@@ -44,3 +70,3 @@ translator.translate('youHaveChosen', { fileName: 'img.jpg' })

it('should translate a string', () => {
const translator = new Translator({ locale: russian })
const translator = new Translator(russian)
expect(

@@ -47,0 +73,0 @@ translator.translate('filesChosen', { smart_count: 18 })

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc