From 390ccc5bc5bb006d2a393c84c0282b805e290897 Mon Sep 17 00:00:00 2001 From: Borewit Date: Thu, 18 Oct 2018 08:40:48 +0200 Subject: [PATCH] Type define music-metadata-browser lazy-load-require function. Add comment to type music-metadata-browser imports. --- js/fileUtils.ts | 4 +--- js/types.ts | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/js/fileUtils.ts b/js/fileUtils.ts index 22004fe9..8e6891b0 100644 --- a/js/fileUtils.ts +++ b/js/fileUtils.ts @@ -1,7 +1,5 @@ import invariant from "invariant"; -import { IAudioMetadata, IOptions } from 'music-metadata-browser'; - -type JsMediaTagsFile = string | ArrayBuffer | Blob; +import { IAudioMetadata } from 'music-metadata-browser'; // Import music-metadata type definitions type MediaDataType = string | ArrayBuffer | Blob; diff --git a/js/types.ts b/js/types.ts index 68b6801b..57605171 100644 --- a/js/types.ts +++ b/js/types.ts @@ -8,6 +8,7 @@ import { EqualizerState } from "./reducers/equalizer"; import { NetworkState } from "./reducers/network"; import { SerializedStateV1 } from "./serializedStates/v1Types"; import { TracksState } from "./reducers/tracks"; +import { IAudioMetadata, IOptions } from 'music-metadata-browser'; export { WebampWindow, @@ -517,9 +518,41 @@ export interface AppState { tracks: TracksState; } +/** + * Type definition of the music-metadata-browser module. + * Ref: https://github.com/Borewit/music-metadata-browser/blob/master/src/index.ts + */ +export interface IMusicMetadataBrowserApi { + + /** + * Parse Web API File + * @param {Blob} blob + * @param {IOptions} options Parsing options + * @returns {Promise} + */ + parseBlob(blob: Blob, options?: IOptions): Promise; + + /** + * Parse fetched file, using the Web Fetch API + * @param {string} audioTrackUrl URL to download the audio track from + * @param {IOptions} options Parsing options + * @returns {Promise} + */ + fetchFromUrl(audioTrackUrl: string, options?: IOptions): Promise; + + /** + * Parse audio from Node Buffer + * @param {Stream.Readable} stream Audio input stream + * @param {string} mimeType Content specification MIME-type, e.g.: 'audio/mpeg' + * @param {IOptions} options Parsing options + * @returns {Promise} + */ + parseBuffer(buf: Buffer, mimeType?: string, options?: IOptions): Promise; +} + export interface Extras { requireJSZip: () => Promise; - requireMusicMetadata: () => Promise; + requireMusicMetadata: () => Promise; } export type GetState = () => AppState;