Skip to content
This repository was archived by the owner on Jun 10, 2025. It is now read-only.

Commit de06f61

Browse files
committed
Fix boolean parsing
1 parent 98e0472 commit de06f61

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Fixed
11+
- Properties with `itemtype="http://schema.org/Boolean"` are parsed correctly.
12+
1013
### Added
1114
- Support for `track`, `data` and `meter` elements
1215

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@ function value(element: Element, extractValue: ExtractValue) {
101101
case 'https://schema.org/Integer':
102102
return Number(stringValue)
103103
case 'https://schema.org/Boolean':
104+
return stringValue === 'true'
104105
case 'https://schema.org/False':
106+
return false
105107
case 'https://schema.org/True':
106-
return Boolean(stringValue)
108+
return true
107109
default:
108110
throw new Error(
109111
`Unable to extract value. Change itemtype to a primitive type or add itemscope on element ${element.outerHTML}`

test/microdataTest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ type TreeList = {
2222
}
2323

2424
describe('microdata', () => {
25-
it('converts primitive types', () => {
25+
it.only('converts primitive types', () => {
2626
const dom = new JSDOM(`<!DOCTYPE html>
2727
<div itemscope itemtype="https://schema.org/Event">
2828
<div>
2929
Maximum attendees: <span itemprop="maximumAttendeeCapacity" itemtype="https://schema.org/Integer">35</span>.
30-
<meta itemprop="isAccessibleForFree" content="false"/>Ticket: pay at the entrance.
30+
<meta itemprop="isAccessibleForFree" itemtype="https://schema.org/Boolean" content="false"/>Ticket: pay at the entrance.
3131
</div>
3232
</div>
3333
`)

0 commit comments

Comments
 (0)