taglib-wasm 0.3.13 → 0.3.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +22 -35
  2. package/dist/index.d.ts +10 -10
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +117 -134
  5. package/dist/index.js.map +1 -0
  6. package/dist/src/constants.js +211 -0
  7. package/dist/src/constants.js.map +1 -0
  8. package/dist/src/errors.js +180 -0
  9. package/dist/src/errors.js.map +1 -0
  10. package/dist/src/file-utils.d.ts +2 -2
  11. package/dist/src/file-utils.d.ts.map +1 -1
  12. package/dist/src/file-utils.js +394 -0
  13. package/dist/src/file-utils.js.map +1 -0
  14. package/dist/src/mod.d.ts +4 -4
  15. package/dist/src/mod.d.ts.map +1 -1
  16. package/dist/src/mod.js +7 -0
  17. package/dist/src/mod.js.map +1 -0
  18. package/dist/src/simple.d.ts +4 -4
  19. package/dist/src/simple.d.ts.map +1 -1
  20. package/dist/src/{simple.ts → simple.js} +193 -311
  21. package/dist/src/simple.js.map +1 -0
  22. package/dist/src/taglib.d.ts +3 -3
  23. package/dist/src/taglib.d.ts.map +1 -1
  24. package/dist/src/taglib.js +516 -0
  25. package/dist/src/taglib.js.map +1 -0
  26. package/dist/src/types.d.ts +2 -2
  27. package/dist/src/types.d.ts.map +1 -1
  28. package/dist/src/types.js +239 -0
  29. package/dist/src/types.js.map +1 -0
  30. package/dist/src/utils/file.js +65 -0
  31. package/dist/src/utils/file.js.map +1 -0
  32. package/dist/src/utils/write.js +49 -0
  33. package/dist/src/utils/write.js.map +1 -0
  34. package/dist/src/wasm-workers.d.ts +1 -1
  35. package/dist/src/wasm-workers.d.ts.map +1 -1
  36. package/dist/src/wasm-workers.js +148 -0
  37. package/dist/src/wasm-workers.js.map +1 -0
  38. package/dist/src/wasm.js +6 -0
  39. package/dist/src/wasm.js.map +1 -0
  40. package/dist/src/web-utils.d.ts +2 -2
  41. package/dist/src/web-utils.d.ts.map +1 -1
  42. package/{src/web-utils.ts → dist/src/web-utils.js} +102 -184
  43. package/dist/src/web-utils.js.map +1 -0
  44. package/dist/src/workers.d.ts +2 -2
  45. package/dist/src/workers.d.ts.map +1 -1
  46. package/dist/src/workers.js +389 -0
  47. package/dist/src/workers.js.map +1 -0
  48. package/dist/taglib-wrapper.js +8 -2528
  49. package/package.json +7 -10
  50. package/dist/index.ts +0 -221
  51. package/dist/src/constants.ts +0 -227
  52. package/dist/src/errors.ts +0 -254
  53. package/dist/src/file-utils.ts +0 -483
  54. package/dist/src/file.js +0 -52
  55. package/dist/src/global.d.ts +0 -12
  56. package/dist/src/mod.ts +0 -19
  57. package/dist/src/taglib.ts +0 -961
  58. package/dist/src/types.ts +0 -538
  59. package/dist/src/utils/file.ts +0 -86
  60. package/dist/src/utils/write.ts +0 -66
  61. package/dist/src/wasm-workers.ts +0 -176
  62. package/dist/src/wasm.ts +0 -133
  63. package/dist/src/web-utils.ts +0 -347
  64. package/dist/src/workers.ts +0 -461
  65. package/dist/src/write.js +0 -33
  66. package/index.ts +0 -221
  67. package/lib/taglib/COPYING.LGPL +0 -502
  68. package/lib/taglib/COPYING.MPL +0 -470
  69. package/lib/taglib/README.md +0 -24
  70. package/src/constants.ts +0 -227
  71. package/src/errors.ts +0 -254
  72. package/src/file-utils.ts +0 -483
  73. package/src/global.d.ts +0 -12
  74. package/src/mod.ts +0 -19
  75. package/src/simple.ts +0 -667
  76. package/src/taglib.ts +0 -961
  77. package/src/types.ts +0 -538
  78. package/src/utils/file.ts +0 -86
  79. package/src/utils/write.ts +0 -66
  80. package/src/wasm-workers.ts +0 -176
  81. package/src/wasm.ts +0 -133
  82. package/src/workers.ts +0 -461
package/src/constants.ts DELETED
@@ -1,227 +0,0 @@
1
- /**
2
- * Standard tag property names used by TagLib.
3
- * These constants provide type-safe access to tag properties with IDE autocomplete.
4
- *
5
- * @example
6
- * ```typescript
7
- * import { Tags } from 'taglib-wasm';
8
- *
9
- * // Read tags
10
- * const title = file.tag.properties.get(Tags.Title);
11
- * const artist = file.tag.properties.get(Tags.Artist);
12
- *
13
- * // Write tags
14
- * file.tag.properties.set(Tags.Album, "Dark Side of the Moon");
15
- * file.tag.properties.set(Tags.Year, "1973");
16
- * ```
17
- */
18
- export const Tags = {
19
- // Basic Properties
20
- /** Track/song title */
21
- Title: "TITLE",
22
- /** Primary performer(s) */
23
- Artist: "ARTIST",
24
- /** Album/collection name */
25
- Album: "ALBUM",
26
- /** Date of recording (year) */
27
- Date: "DATE",
28
- /** Track number on album */
29
- TrackNumber: "TRACKNUMBER",
30
- /** Musical genre */
31
- Genre: "GENRE",
32
- /** Comments/notes */
33
- Comment: "COMMENT",
34
-
35
- // Extended Properties
36
- /** Band/orchestra/ensemble */
37
- AlbumArtist: "ALBUMARTIST",
38
- /** Original composer(s) */
39
- Composer: "COMPOSER",
40
- /** Copyright information */
41
- Copyright: "COPYRIGHT",
42
- /** Encoding software/person */
43
- EncodedBy: "ENCODEDBY",
44
- /** Disc number for multi-disc sets */
45
- DiscNumber: "DISCNUMBER",
46
- /** Beats per minute */
47
- Bpm: "BPM",
48
- /** Lyrics/text writer(s) */
49
- Lyricist: "LYRICIST",
50
- /** Conductor */
51
- Conductor: "CONDUCTOR",
52
- /** Person who remixed */
53
- Remixer: "REMIXEDBY",
54
- /** Language of vocals/lyrics */
55
- Language: "LANGUAGE",
56
- /** Publisher */
57
- Publisher: "PUBLISHER",
58
- /** Mood/atmosphere */
59
- Mood: "MOOD",
60
- /** Media type (CD, vinyl, etc.) */
61
- Media: "MEDIA",
62
- /** Radio station owner */
63
- RadioStationOwner: "RADIOSTATIONOWNER",
64
- /** Producer */
65
- Producer: "PRODUCER",
66
- /** Album subtitle */
67
- Subtitle: "SUBTITLE",
68
- /** Release label */
69
- Label: "LABEL",
70
-
71
- // Sorting Properties
72
- /** Sort name for title */
73
- TitleSort: "TITLESORT",
74
- /** Sort name for artist */
75
- ArtistSort: "ARTISTSORT",
76
- /** Sort name for album artist */
77
- AlbumArtistSort: "ALBUMARTISTSORT",
78
- /** Sort name for album */
79
- AlbumSort: "ALBUMSORT",
80
- /** Sort name for composer */
81
- ComposerSort: "COMPOSERSORT",
82
-
83
- // Identifiers
84
- /** International Standard Recording Code */
85
- Isrc: "ISRC",
86
- /** Amazon Standard Identification Number */
87
- Asin: "ASIN",
88
- /** Catalog number */
89
- CatalogNumber: "CATALOGNUMBER",
90
- /** Barcode (EAN/UPC) */
91
- Barcode: "BARCODE",
92
-
93
- // MusicBrainz Identifiers
94
- /** MusicBrainz Artist ID */
95
- MusicBrainzArtistId: "MUSICBRAINZ_ARTISTID",
96
- /** MusicBrainz Release Artist ID */
97
- MusicBrainzReleaseArtistId: "MUSICBRAINZ_ALBUMARTISTID",
98
- /** MusicBrainz Work ID */
99
- MusicBrainzWorkId: "MUSICBRAINZ_WORKID",
100
- /** MusicBrainz Release ID */
101
- MusicBrainzReleaseId: "MUSICBRAINZ_ALBUMID",
102
- /** MusicBrainz Recording ID */
103
- MusicBrainzRecordingId: "MUSICBRAINZ_TRACKID",
104
- /** MusicBrainz Track ID (deprecated, use RecordingId) */
105
- MusicBrainzTrackId: "MUSICBRAINZ_TRACKID",
106
- /** MusicBrainz Release Group ID */
107
- MusicBrainzReleaseGroupId: "MUSICBRAINZ_RELEASEGROUPID",
108
- /** MusicBrainz Release Track ID */
109
- MusicBrainzReleaseTrackId: "MUSICBRAINZ_RELEASETRACKID",
110
-
111
- // Podcast Properties
112
- /** Podcast identifier */
113
- PodcastId: "PODCASTID",
114
- /** Podcast URL */
115
- PodcastUrl: "PODCASTURL",
116
-
117
- // Grouping and Work
118
- /** Content group/work */
119
- Grouping: "GROUPING",
120
- /** Work name */
121
- Work: "WORK",
122
-
123
- // Additional Metadata
124
- /** Lyrics content */
125
- Lyrics: "LYRICS",
126
- /** Album gain (ReplayGain) */
127
- AlbumGain: "REPLAYGAIN_ALBUM_GAIN",
128
- /** Album peak (ReplayGain) */
129
- AlbumPeak: "REPLAYGAIN_ALBUM_PEAK",
130
- /** Track gain (ReplayGain) */
131
- TrackGain: "REPLAYGAIN_TRACK_GAIN",
132
- /** Track peak (ReplayGain) */
133
- TrackPeak: "REPLAYGAIN_TRACK_PEAK",
134
-
135
- // Special handling
136
- /** Original artist for covers */
137
- OriginalArtist: "ORIGINALARTIST",
138
- /** Original album */
139
- OriginalAlbum: "ORIGINALALBUM",
140
- /** Original release date */
141
- OriginalDate: "ORIGINALDATE",
142
- /** Script/writing system */
143
- Script: "SCRIPT",
144
- /** Involved people list */
145
- InvolvedPeopleList: "INVOLVEDPEOPLELIST",
146
-
147
- // Technical Properties
148
- /** Encoder settings/software */
149
- EncoderSettings: "ENCODERSETTINGS",
150
- /** Source media */
151
- SourceMedia: "SOURCEMEDIA",
152
- } as const;
153
-
154
- /**
155
- * Type representing all valid tag property names
156
- */
157
- export type TagName = typeof Tags[keyof typeof Tags];
158
-
159
- /**
160
- * Type guard to check if a string is a valid tag name
161
- */
162
- export function isValidTagName(name: string): name is TagName {
163
- return Object.values(Tags).includes(name as TagName);
164
- }
165
-
166
- /**
167
- * Get all available tag names as an array
168
- */
169
- export function getAllTagNames(): readonly TagName[] {
170
- return Object.values(Tags);
171
- }
172
-
173
- /**
174
- * Format-specific tag mappings (for reference only - TagLib handles these automatically)
175
- * This shows how standard property names map to format-specific identifiers.
176
- */
177
- export const FormatMappings = {
178
- Title: {
179
- id3v2: "TIT2",
180
- mp4: "©nam",
181
- vorbis: "TITLE",
182
- ape: "Title",
183
- riff: "INAM",
184
- },
185
- Artist: {
186
- id3v2: "TPE1",
187
- mp4: "©ART",
188
- vorbis: "ARTIST",
189
- ape: "Artist",
190
- riff: "IART",
191
- },
192
- Album: {
193
- id3v2: "TALB",
194
- mp4: "©alb",
195
- vorbis: "ALBUM",
196
- ape: "Album",
197
- riff: "IPRD",
198
- },
199
- Date: {
200
- id3v2: "TDRC",
201
- mp4: "©day",
202
- vorbis: "DATE",
203
- ape: "Year",
204
- riff: "ICRD",
205
- },
206
- Genre: {
207
- id3v2: "TCON",
208
- mp4: "©gen",
209
- vorbis: "GENRE",
210
- ape: "Genre",
211
- riff: "IGNR",
212
- },
213
- Comment: {
214
- id3v2: "COMM",
215
- mp4: "©cmt",
216
- vorbis: "COMMENT",
217
- ape: "Comment",
218
- riff: "ICMT",
219
- },
220
- TrackNumber: {
221
- id3v2: "TRCK",
222
- mp4: "trkn",
223
- vorbis: "TRACKNUMBER",
224
- ape: "Track",
225
- riff: "ITRK",
226
- },
227
- } as const;
package/src/errors.ts DELETED
@@ -1,254 +0,0 @@
1
- /**
2
- * Custom error types for taglib-wasm with enhanced context and debugging information
3
- */
4
-
5
- /**
6
- * List of audio formats supported by taglib-wasm
7
- */
8
- export const SUPPORTED_FORMATS = [
9
- "MP3",
10
- "MP4",
11
- "M4A",
12
- "FLAC",
13
- "OGG",
14
- "WAV",
15
- ] as const;
16
-
17
- /**
18
- * Error codes for programmatic error handling
19
- */
20
- export enum TagLibErrorCode {
21
- INITIALIZATION_FAILED = "INITIALIZATION_FAILED",
22
- INVALID_FORMAT = "INVALID_FORMAT",
23
- UNSUPPORTED_FORMAT = "UNSUPPORTED_FORMAT",
24
- FILE_OPERATION_FAILED = "FILE_OPERATION_FAILED",
25
- METADATA_ERROR = "METADATA_ERROR",
26
- MEMORY_ERROR = "MEMORY_ERROR",
27
- ENVIRONMENT_ERROR = "ENVIRONMENT_ERROR",
28
- }
29
-
30
- /**
31
- * Base error class for all taglib-wasm errors
32
- */
33
- export class TagLibError extends Error {
34
- constructor(
35
- message: string,
36
- public readonly code: TagLibErrorCode,
37
- public readonly context?: Record<string, unknown>,
38
- ) {
39
- super(message);
40
- this.name = "TagLibError";
41
- Object.setPrototypeOf(this, TagLibError.prototype);
42
- }
43
- }
44
-
45
- /**
46
- * Error thrown when the Wasm module fails to initialize
47
- */
48
- export class TagLibInitializationError extends TagLibError {
49
- constructor(message: string, context?: Record<string, unknown>) {
50
- super(
51
- createErrorMessage("Failed to initialize TagLib Wasm module", message),
52
- TagLibErrorCode.INITIALIZATION_FAILED,
53
- context,
54
- );
55
- this.name = "TagLibInitializationError";
56
- Object.setPrototypeOf(this, TagLibInitializationError.prototype);
57
- }
58
- }
59
-
60
- /**
61
- * Error thrown when an audio file format is invalid or corrupted
62
- */
63
- export class InvalidFormatError extends TagLibError {
64
- constructor(
65
- message: string,
66
- public readonly bufferSize?: number,
67
- context?: Record<string, unknown>,
68
- ) {
69
- const details = [`Invalid audio file format: ${message}`];
70
-
71
- if (bufferSize !== undefined) {
72
- details.push(`Buffer size: ${formatFileSize(bufferSize)}`);
73
- if (bufferSize < 1024) {
74
- details.push(
75
- "Audio files must be at least 1KB to contain valid headers.",
76
- );
77
- }
78
- }
79
-
80
- super(
81
- details.join(". "),
82
- TagLibErrorCode.INVALID_FORMAT,
83
- { ...context, bufferSize },
84
- );
85
- this.name = "InvalidFormatError";
86
- Object.setPrototypeOf(this, InvalidFormatError.prototype);
87
- }
88
- }
89
-
90
- /**
91
- * Error thrown when an audio format is recognized but not supported
92
- */
93
- export class UnsupportedFormatError extends TagLibError {
94
- constructor(
95
- public readonly format: string,
96
- public readonly supportedFormats: readonly string[] = SUPPORTED_FORMATS,
97
- context?: Record<string, unknown>,
98
- ) {
99
- super(
100
- `Unsupported audio format: ${format}. Supported formats: ${
101
- supportedFormats.join(", ")
102
- }`,
103
- TagLibErrorCode.UNSUPPORTED_FORMAT,
104
- { ...context, format, supportedFormats },
105
- );
106
- this.name = "UnsupportedFormatError";
107
- Object.setPrototypeOf(this, UnsupportedFormatError.prototype);
108
- }
109
- }
110
-
111
- /**
112
- * Error thrown during file operations (read, write, save)
113
- */
114
- export class FileOperationError extends TagLibError {
115
- constructor(
116
- public readonly operation: "read" | "write" | "save",
117
- message: string,
118
- public readonly path?: string,
119
- context?: Record<string, unknown>,
120
- ) {
121
- const details = [`Failed to ${operation} file`];
122
- if (path) {
123
- details.push(`Path: ${path}`);
124
- }
125
- details.push(message);
126
-
127
- super(
128
- details.join(". "),
129
- TagLibErrorCode.FILE_OPERATION_FAILED,
130
- { ...context, operation, path },
131
- );
132
- this.name = "FileOperationError";
133
- Object.setPrototypeOf(this, FileOperationError.prototype);
134
- }
135
- }
136
-
137
- /**
138
- * Error thrown when metadata operations fail
139
- */
140
- export class MetadataError extends TagLibError {
141
- constructor(
142
- public readonly operation: "read" | "write",
143
- message: string,
144
- public readonly field?: string,
145
- context?: Record<string, unknown>,
146
- ) {
147
- const details = [`Failed to ${operation} metadata`];
148
- if (field) {
149
- details.push(`Field: ${field}`);
150
- }
151
- details.push(message);
152
-
153
- super(
154
- details.join(". "),
155
- TagLibErrorCode.METADATA_ERROR,
156
- { ...context, operation, field },
157
- );
158
- this.name = "MetadataError";
159
- Object.setPrototypeOf(this, MetadataError.prototype);
160
- }
161
- }
162
-
163
- /**
164
- * Error thrown when Wasm memory operations fail
165
- */
166
- export class MemoryError extends TagLibError {
167
- constructor(message: string, context?: Record<string, unknown>) {
168
- super(
169
- createErrorMessage("Memory allocation failed", message),
170
- TagLibErrorCode.MEMORY_ERROR,
171
- context,
172
- );
173
- this.name = "MemoryError";
174
- Object.setPrototypeOf(this, MemoryError.prototype);
175
- }
176
- }
177
-
178
- /**
179
- * Error thrown when the environment doesn't support required features
180
- */
181
- export class EnvironmentError extends TagLibError {
182
- constructor(
183
- public readonly environment: string,
184
- message: string,
185
- public readonly requiredFeature?: string,
186
- context?: Record<string, unknown>,
187
- ) {
188
- const details = [`Environment '${environment}' ${message}`];
189
- if (requiredFeature) {
190
- details.push(`Required feature: ${requiredFeature}`);
191
- }
192
-
193
- super(
194
- details.join(". "),
195
- TagLibErrorCode.ENVIRONMENT_ERROR,
196
- { ...context, environment, requiredFeature },
197
- );
198
- this.name = "EnvironmentError";
199
- Object.setPrototypeOf(this, EnvironmentError.prototype);
200
- }
201
- }
202
-
203
- /**
204
- * Helper function to create consistent error messages
205
- */
206
- function createErrorMessage(prefix: string, details: string): string {
207
- return `${prefix}: ${details}`;
208
- }
209
-
210
- /**
211
- * Format file size in human-readable format
212
- */
213
- function formatFileSize(bytes: number): string {
214
- if (bytes < 1024) return `${bytes} bytes`;
215
- if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
216
- return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
217
- }
218
-
219
- /**
220
- * Type guards for error handling
221
- */
222
- export function isTagLibError(error: unknown): error is TagLibError {
223
- return error instanceof TagLibError;
224
- }
225
-
226
- export function isInvalidFormatError(
227
- error: unknown,
228
- ): error is InvalidFormatError {
229
- return error instanceof InvalidFormatError;
230
- }
231
-
232
- export function isUnsupportedFormatError(
233
- error: unknown,
234
- ): error is UnsupportedFormatError {
235
- return error instanceof UnsupportedFormatError;
236
- }
237
-
238
- export function isFileOperationError(
239
- error: unknown,
240
- ): error is FileOperationError {
241
- return error instanceof FileOperationError;
242
- }
243
-
244
- export function isMetadataError(error: unknown): error is MetadataError {
245
- return error instanceof MetadataError;
246
- }
247
-
248
- export function isMemoryError(error: unknown): error is MemoryError {
249
- return error instanceof MemoryError;
250
- }
251
-
252
- export function isEnvironmentError(error: unknown): error is EnvironmentError {
253
- return error instanceof EnvironmentError;
254
- }