@uppy/utils
Advanced tools
Comparing version 5.6.0 to 5.7.0
# @uppy/utils | ||
## 5.7.0 | ||
Released: 2023-12-12 | ||
Included in: Uppy v3.21.0 | ||
- @uppy/utils: fix import in test files (Antoine du Hamel / #4806) | ||
## 5.6.0 | ||
@@ -4,0 +11,0 @@ |
function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } | ||
var id = 0; | ||
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } | ||
import has from "./hasProperty.js"; | ||
// We're using a generic because languages have different plural rules. | ||
@@ -64,2 +62,5 @@ | ||
} | ||
const defaultOnMissingKey = key => { | ||
throw new Error(`missing string: ${key}`); | ||
}; | ||
@@ -77,8 +78,16 @@ /** | ||
*/ | ||
var _onMissingKey = /*#__PURE__*/_classPrivateFieldLooseKey("onMissingKey"); | ||
var _apply = /*#__PURE__*/_classPrivateFieldLooseKey("apply"); | ||
export default class Translator { | ||
constructor(locales) { | ||
constructor(locales, _temp) { | ||
let { | ||
onMissingKey = defaultOnMissingKey | ||
} = _temp === void 0 ? {} : _temp; | ||
Object.defineProperty(this, _apply, { | ||
value: _apply2 | ||
}); | ||
Object.defineProperty(this, _onMissingKey, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
this.locale = { | ||
@@ -98,2 +107,3 @@ strings: {}, | ||
} | ||
_classPrivateFieldLooseBase(this, _onMissingKey)[_onMissingKey] = onMissingKey; | ||
} | ||
@@ -117,6 +127,7 @@ /** | ||
translateArray(key, options) { | ||
if (!has(this.locale.strings, key)) { | ||
throw new Error(`missing string: ${key}`); | ||
let string = this.locale.strings[key]; | ||
if (string == null) { | ||
_classPrivateFieldLooseBase(this, _onMissingKey)[_onMissingKey](key); | ||
string = key; | ||
} | ||
const string = this.locale.strings[key]; | ||
const hasPluralForms = typeof string === 'object'; | ||
@@ -130,2 +141,5 @@ if (hasPluralForms) { | ||
} | ||
if (typeof string !== 'string') { | ||
throw new Error(`string was not a string`); | ||
} | ||
return interpolate(string, options); | ||
@@ -132,0 +146,0 @@ } |
{ | ||
"name": "@uppy/utils", | ||
"description": "Shared utility functions for Uppy Core and plugins maintained by the Uppy team.", | ||
"version": "5.6.0", | ||
"version": "5.7.0", | ||
"license": "MIT", | ||
@@ -68,3 +68,4 @@ "types": "types/index.d.ts", | ||
"./lib/VirtualList": "./lib/VirtualList.js", | ||
"./src/microtip.scss": "./src/microtip.scss" | ||
"./src/microtip.scss": "./src/microtip.scss", | ||
"./lib/UserFacingApiError": "./lib/UserFacingApiError.js" | ||
}, | ||
@@ -71,0 +72,0 @@ "dependencies": { |
import { describe, expect, it } from 'vitest' | ||
import dataURItoBlob from './dataURItoBlob.ts' | ||
import sampleImageDataURI from './sampleImageDataURI.js' | ||
import sampleImageDataURI from './sampleImageDataURI.ts' | ||
@@ -5,0 +5,0 @@ describe('dataURItoBlob', () => { |
import { describe, expect, it } from 'vitest' | ||
import dataURItoFile from './dataURItoFile.ts' | ||
import sampleImageDataURI from './sampleImageDataURI.js' | ||
import sampleImageDataURI from './sampleImageDataURI.ts' | ||
@@ -5,0 +5,0 @@ describe('dataURItoFile', () => { |
@@ -1,3 +0,1 @@ | ||
import has from './hasProperty.ts' | ||
// We're using a generic because languages have different plural rules. | ||
@@ -87,2 +85,6 @@ export interface Locale<T extends number = number> { | ||
const defaultOnMissingKey = (key: string): void => { | ||
throw new Error(`missing string: ${key}`) | ||
} | ||
/** | ||
@@ -102,3 +104,6 @@ * Translates strings with interpolation & pluralization support. | ||
constructor(locales: Locale | Locale[]) { | ||
constructor( | ||
locales: Locale | Locale[], | ||
{ onMissingKey = defaultOnMissingKey } = {}, | ||
) { | ||
this.locale = { | ||
@@ -119,4 +124,8 @@ strings: {}, | ||
} | ||
this.#onMissingKey = onMissingKey | ||
} | ||
#onMissingKey | ||
#apply(locale?: Locale): void { | ||
@@ -152,7 +161,7 @@ if (!locale?.strings) { | ||
translateArray(key: string, options?: Options): Array<string | unknown> { | ||
if (!has(this.locale.strings, key)) { | ||
throw new Error(`missing string: ${key}`) | ||
let string = this.locale.strings[key] | ||
if (string == null) { | ||
this.#onMissingKey(key) | ||
string = key | ||
} | ||
const string = this.locale.strings[key] | ||
const hasPluralForms = typeof string === 'object' | ||
@@ -170,4 +179,8 @@ | ||
if (typeof string !== 'string') { | ||
throw new Error(`string was not a string`) | ||
} | ||
return interpolate(string, options) | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
310602
199
4260
101
2
2
1
23
291289