Skip to content

Commit

Permalink
Add types for extended WebP tags
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiasw committed Oct 21, 2023
1 parent f41e9a5 commit 18f507f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
24 changes: 22 additions & 2 deletions exif-reader.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ interface PngTextTags {
[name: string]: PngTextTag
}

interface RiffTags {
'Alpha'?: {
value: 0 | 1,
description: 'No' | 'Yes'
},
'Animation'?: {
value: 0 | 1,
description: 'No' | 'Yes'
},
'ImageWidth'?: {
value: number,
description: string
},
'ImageHeight'?: {
value: number,
description: string
}
}

interface NumberFileTag {
description: string,
value: number
Expand Down Expand Up @@ -153,6 +172,7 @@ interface ExpandedTags {
iptc?: ExifTags,
xmp?: { _raw: string } & XmpTags,
icc?: IccTags,
riff?: RiffTags,
Thumbnail?: ThumbnailTags,
gps?: GpsTags
}
Expand Down Expand Up @@ -453,9 +473,9 @@ interface IccTags {
[name: string]: ValueTag;
}

export type Tags = XmpTags & IccTags & PngTags & {
export type Tags = XmpTags & IccTags & PngTags & RiffTags & {
'Thumbnail'?: ThumbnailTags;
'Images'?: MPFImageTags[],
} & {
[K in keyof ExifTags]: ExifTags[K] | XmpTag;
}
}
34 changes: 34 additions & 0 deletions test/types/exif-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,37 @@ expandedTags.png?.["Pixel Units"]?.description === "meters";
// @ts-expect-error
expandedTags.png?.["Color Type"]?.description === "A non-color type value";
expandedTags.png?.["Custom Tag Name"]?.description === "Should work";

/////////
// RIFF
tags["Alpha"]?.value === 0;
tags["Alpha"]?.description === 'Yes';
tags["Alpha"]?.description === 'No';
// @ts-expect-error
tags["Alpha"]?.description === 'Maybe';
expandedTags["riff"]?.["Alpha"]?.value === 0;
expandedTags["riff"]?.["Alpha"]?.description === 'Yes';
expandedTags["riff"]?.["Alpha"]?.description === 'No';
// @ts-expect-error
expandedTags["riff"]?.["Alpha"]?.description === 'Maybe';

tags["Animation"]?.value === 0;
tags["Animation"]?.description === 'Yes';
tags["Animation"]?.description === 'No';
// @ts-expect-error
tags["Animation"]?.description === 'Maybe';
expandedTags["riff"]?.["Animation"]?.value === 0;
expandedTags["riff"]?.["Animation"]?.description === 'Yes';
expandedTags["riff"]?.["Animation"]?.description === 'No';
// @ts-expect-error
expandedTags["riff"]?.["Animation"]?.description === 'Maybe';

tags["ImageWidth"]?.value === 100;
tags["ImageWidth"]?.description === '100px';
expandedTags["riff"]?.["ImageWidth"]?.value === 100;
expandedTags["riff"]?.["ImageWidth"]?.description === '100px';

tags["ImageHeight"]?.value === 100;
tags["ImageHeight"]?.description === '100px';
expandedTags["riff"]?.["ImageHeight"]?.value === 100;
expandedTags["riff"]?.["ImageHeight"]?.description === '100px';

0 comments on commit 18f507f

Please sign in to comment.