Skip to content

Commit

Permalink
simplifyClaims: remove empty claims arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlath committed Sep 22, 2022
1 parent c957953 commit e45a7e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/helpers/simplify_claims.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ const simplifyClaims = (claims, ...options) => {
if (propertyPrefix) {
id = propertyPrefix + ':' + id
}
simpleClaims[id] = simplifyPropertyClaims(propClaims, ...options)
const simplifiedPropertyClaims = simplifyPropertyClaims(propClaims, ...options)
if (simplifiedPropertyClaims.length > 0) {
simpleClaims[id] = simplifiedPropertyClaims
}
}
return simpleClaims
}
Expand Down
7 changes: 7 additions & 0 deletions test/simplify_claims.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ describe('simplifyPropertyClaims', () => {
simplified.should.deepEqual([ 'Q2044250' ])
})

it('should not return empty claims arrays', () => {
const deprecatedClaim = Q4115189.claims.P135[0]
const claims = { P135: [ deprecatedClaim ] }
const simplified = simplifyClaims(claims)
should(simplified.P135).not.be.ok()
})

it('should return non-truthy statements if requested', () => {
const options = { keepNonTruthy: true }
const simplified = simplifyPropertyClaims(Q4115189.claims.P135, options)
Expand Down

0 comments on commit e45a7e9

Please sign in to comment.