Skip to content

Commit

Permalink
Refactor parseShapes function to simplify property checks and improve…
Browse files Browse the repository at this point in the history
… readability

- Combined checks for properties.P and properties.L into a single conditional statement.
- Replaced separate blocks for properties.P and properties.L with a ternary operator to set the type (0x01 for P, 0x02 for L).
- Updated the loop to start from 0 instead of 1 for consistency and clarity.
- Preserved the logic for reading buffer values and updating the buffer position after each iteration.

These changes streamline the function without altering its core behavior.
  • Loading branch information
Ayoub-Mabrouk committed Nov 14, 2024
1 parent ea475b0 commit 9e08a95
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions lib/udt.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,14 @@ const parseShapes = (buffer, count, properties) => {
return shapes
}

if (properties.P) {
if (properties.P || properties.L) {
shapes.push({
parentOffset: -1,
figureOffset: 0,
type: 0x01
})
} else if (properties.L) {
shapes.push({
parentOffset: -1,
figureOffset: 0,
type: 0x02
type: properties.P ? 0x01 : 0x02
})
} else {
for (let i = 1; i <= count; i++) {
for (let i = 0; i < count; i++) {
shapes.push({
parentOffset: buffer.readInt32LE(buffer.position),
figureOffset: buffer.readInt32LE(buffer.position + 4),
Expand Down

0 comments on commit 9e08a95

Please sign in to comment.