Skip to content

Commit

Permalink
Merge branch 'main' of github.com:photostructure/exiftool-vendored.js
Browse files Browse the repository at this point in the history
  • Loading branch information
mceachen committed Sep 22, 2024
2 parents 59c7f5a + 5ee6469 commit c678ec2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"premktags": "npm run compile",
"mktags": "node dist/update/mktags.js",
"prelint": "npm run compile",
"prepare": "npm run compile",
"lint": "eslint src --ext .ts",
"prettier": "prettier --write src/*.ts src/**/*.ts **/*.yml **/*.json **/*.md",
"pretest": "npm run compile",
Expand Down
4 changes: 2 additions & 2 deletions src/Struct.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isDateOrTime } from "./DateTime"

export type Struct = {
[k: string]: number | string | Struct
[k: string]: number | string | Struct | Array<Struct|number|string>
}

export function isStruct(o: any): o is Struct {
Expand All @@ -10,7 +10,7 @@ export function isStruct(o: any): o is Struct {
o.constructor?.name === "Object" &&
Object.values(o).every((v) => {
const t = typeof v
return t === "string" || t === "number" || isDateOrTime(v) || isStruct(v)
return t === "string" || t === "number" || isDateOrTime(v) || isStruct(v) || Array.isArray(v)
})
)
}
27 changes: 27 additions & 0 deletions src/WriteTask.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -836,5 +836,32 @@ describe("WriteTask", function () {
// const missing = Object.keys(before).filter((k) => !(k in after))
// console.log({ missing })
})

it("supports creating arrays in structs", async () => {
const f = await testImg()
const regionData = {
RegionInfo: {
AppliedToDimensions: { W: 10, H: 10, Unit: "pixel" },
RegionList: [
{
Area: { X: 0.5, Y: 0.5, W: 0.1, H: 0.1, Unit: "normalized" },
Rotation: 0,
Type: "Face",
Name: "randomName1",
},
{
Area: { X: 0.5, Y: 0.5, W: 0.1, H: 0.1, Unit: "normalized" },
Rotation: 0,
Type: "Face",
Name: "randomName2",
},
],
},
}

await exiftool.write(f, regionData)
const after = await exiftool.read(f)
expect(after).to.containSubset(regionData)
})
})
})

0 comments on commit c678ec2

Please sign in to comment.