@uppy/core
Advanced tools
Comparing version 4.0.0-beta.9 to 4.0.0-beta.10
@@ -58,2 +58,3 @@ declare const _default: { | ||
additionalRestrictionsFailed: string; | ||
unnamed: string; | ||
}; | ||
@@ -60,0 +61,0 @@ }; |
@@ -58,4 +58,5 @@ export default { | ||
}, | ||
additionalRestrictionsFailed: '%{count} additional restrictions were not fulfilled' | ||
additionalRestrictionsFailed: '%{count} additional restrictions were not fulfilled', | ||
unnamed: 'Unnamed' | ||
} | ||
}; |
@@ -180,3 +180,3 @@ /// <reference types="lodash" /> | ||
*/ | ||
export declare class Uppy<M extends Meta, B extends Body> { | ||
export declare class Uppy<M extends Meta, B extends Body = Record<string, never>> { | ||
#private; | ||
@@ -294,3 +294,3 @@ static VERSION: any; | ||
*/ | ||
getPlugin(id: string): UnknownPlugin<M, B> | undefined; | ||
getPlugin<T extends UnknownPlugin<M, B> = UnknownPlugin<M, B>>(id: string): T | undefined; | ||
/** | ||
@@ -297,0 +297,0 @@ * Iterate through all `use`d plugins. |
@@ -24,3 +24,3 @@ function _classPrivateFieldLooseBase(e, t) { if (!{}.hasOwnProperty.call(e, t)) throw new TypeError("attempted to use private field on non-instance"); return e; } | ||
const packageJson = { | ||
"version": "4.0.0-beta.9" | ||
"version": "4.0.0-beta.10" | ||
}; | ||
@@ -27,0 +27,0 @@ import locale from "./locale.js"; |
{ | ||
"name": "@uppy/core", | ||
"description": "Core module for the extensible JavaScript file upload widget with support for drag&drop, resumable uploads, previews, restrictions, file processing/encoding, remote providers like Instagram, Dropbox, Google Drive, S3 and more :dog:", | ||
"version": "4.0.0-beta.9", | ||
"version": "4.0.0-beta.10", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "main": "lib/index.js", |
@@ -65,3 +65,4 @@ export default { | ||
'%{count} additional restrictions were not fulfilled', | ||
unnamed: 'Unnamed', | ||
}, | ||
} |
import { expectTypeOf, test } from 'vitest' | ||
import type { Body, InternalMetadata, Meta } from '@uppy/utils/lib/UppyFile' | ||
import Uppy from './Uppy' | ||
import Uppy, { type UnknownPlugin } from './Uppy' | ||
import UIPlugin, { type UIPluginOptions } from './UIPlugin' | ||
@@ -20,3 +20,3 @@ | ||
const core = new Uppy() | ||
expectTypeOf(core).toEqualTypeOf<Uppy<Meta, Body>>() | ||
expectTypeOf(core).toEqualTypeOf<Uppy<Meta, Record<string, never>>>() | ||
}) | ||
@@ -26,5 +26,17 @@ | ||
const core = new Uppy().use(TestPlugin) | ||
expectTypeOf(core).toEqualTypeOf<Uppy<Meta, Body>>() | ||
expectTypeOf(core).toEqualTypeOf<Uppy<Meta, Record<string, never>>>() | ||
}) | ||
test('can .getPlugin() with a generic', async () => { | ||
const core = new Uppy().use(TestPlugin) | ||
const plugin = core.getPlugin<TestPlugin<any, any>>('TestPlugin') | ||
const plugin2 = core.getPlugin('TestPlugin') | ||
expectTypeOf(plugin).toEqualTypeOf<TestPlugin<any, any> | undefined>() | ||
expectTypeOf(plugin2).toEqualTypeOf< | ||
// The default type | ||
| UnknownPlugin<Meta, Record<string, never>, Record<string, unknown>> | ||
| undefined | ||
>() | ||
}) | ||
test('Meta and Body generic move through the Uppy class', async () => { | ||
@@ -31,0 +43,0 @@ type M = { foo: string } |
@@ -311,3 +311,3 @@ /* eslint-disable max-classes-per-file */ | ||
*/ | ||
export class Uppy<M extends Meta, B extends Body> { | ||
export class Uppy<M extends Meta, B extends Body = Record<string, never>> { | ||
static VERSION = packageJson.version | ||
@@ -1728,6 +1728,8 @@ | ||
*/ | ||
getPlugin(id: string): UnknownPlugin<M, B> | undefined { | ||
getPlugin<T extends UnknownPlugin<M, B> = UnknownPlugin<M, B>>( | ||
id: string, | ||
): T | undefined { | ||
for (const plugins of Object.values(this.#plugins)) { | ||
const foundPlugin = plugins.find((plugin) => plugin.id === id) | ||
if (foundPlugin != null) return foundPlugin | ||
if (foundPlugin != null) return foundPlugin as T | ||
} | ||
@@ -1734,0 +1736,0 @@ return undefined |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
506952
8234