@@ -113,7 +113,8 @@ api.compact = ({
113
113
114
114
// recursively compact object
115
115
if ( _isObject ( element ) ) {
116
- if ( options . link && '@id' in element && element [ '@id' ] in options . link ) {
116
+ if ( options . link && '@id' in element &&
117
+ options . link . hasOwnProperty ( element [ '@id' ] ) ) {
117
118
// check for a linked element to reuse
118
119
const linked = options . link [ element [ '@id' ] ] ;
119
120
for ( let i = 0 ; i < linked . length ; ++ i ) {
@@ -129,7 +130,7 @@ api.compact = ({
129
130
api . compactValue ( { activeCtx, activeProperty, value : element , options} ) ;
130
131
if ( options . link && _isSubjectReference ( element ) ) {
131
132
// store linked element
132
- if ( ! ( element [ '@id' ] in options . link ) ) {
133
+ if ( ! ( options . link . hasOwnProperty ( element [ '@id' ] ) ) ) {
133
134
options . link [ element [ '@id' ] ] = [ ] ;
134
135
}
135
136
options . link [ element [ '@id' ] ] . push ( { expanded : element , compacted : rval } ) ;
@@ -144,7 +145,7 @@ api.compact = ({
144
145
145
146
if ( options . link && '@id' in element ) {
146
147
// store linked element
147
- if ( ! ( element [ '@id' ] in options . link ) ) {
148
+ if ( ! options . link . hasOwnProperty ( element [ '@id' ] ) ) {
148
149
options . link [ element [ '@id' ] ] = [ ] ;
149
150
}
150
151
options . link [ element [ '@id' ] ] . push ( { expanded : element , compacted : rval } ) ;
@@ -208,8 +209,8 @@ api.compact = ({
208
209
209
210
// handle double-reversed properties
210
211
for ( const compactedProperty in compactedValue ) {
211
- if ( activeCtx . mappings [ compactedProperty ] &&
212
- activeCtx . mappings [ compactedProperty ] . reverse ) {
212
+ if ( activeCtx . mappings . has ( compactedProperty ) &&
213
+ activeCtx . mappings . get ( compactedProperty ) . reverse ) {
213
214
const value = compactedValue [ compactedProperty ] ;
214
215
const container = _getContextValue (
215
216
activeCtx , compactedProperty , '@container' ) || [ ] ;
@@ -297,8 +298,8 @@ api.compact = ({
297
298
relativeTo : { vocab : true } ,
298
299
reverse : insideReverse
299
300
} ) ;
300
- const nestProperty = ( itemActiveProperty in activeCtx . mappings ) ?
301
- activeCtx . mappings [ itemActiveProperty ] [ '@nest' ] : null ;
301
+ const nestProperty = activeCtx . mappings . has ( itemActiveProperty ) ?
302
+ activeCtx . mappings . get ( itemActiveProperty ) [ '@nest' ] : null ;
302
303
let nestResult = rval ;
303
304
if ( nestProperty ) {
304
305
_checkNestProperty ( activeCtx , nestProperty , options ) ;
@@ -326,8 +327,8 @@ api.compact = ({
326
327
327
328
// if itemActiveProperty is a @nest property, add values to nestResult,
328
329
// otherwise rval
329
- const nestProperty = ( itemActiveProperty in activeCtx . mappings ) ?
330
- activeCtx . mappings [ itemActiveProperty ] [ '@nest' ] : null ;
330
+ const nestProperty = activeCtx . mappings . has ( itemActiveProperty ) ?
331
+ activeCtx . mappings . get ( itemActiveProperty ) [ '@nest' ] : null ;
331
332
let nestResult = rval ;
332
333
if ( nestProperty ) {
333
334
_checkNestProperty ( activeCtx , nestProperty , options ) ;
@@ -384,7 +385,7 @@ api.compact = ({
384
385
relativeTo : { vocab : true }
385
386
} ) ] = expandedItem [ '@index' ] ;
386
387
}
387
- } else if ( itemActiveProperty in nestResult ) {
388
+ } else if ( nestResult . hasOwnProperty ( itemActiveProperty ) ) {
388
389
// can't use @list container for more than 1 list
389
390
throw new JsonLdError (
390
391
'JSON-LD compact error; property has a "@list" @container ' +
@@ -401,7 +402,7 @@ api.compact = ({
401
402
container . includes ( '@index' ) && _isSimpleGraph ( expandedItem ) ) ) {
402
403
// get or create the map object
403
404
let mapObject ;
404
- if ( itemActiveProperty in nestResult ) {
405
+ if ( nestResult . hasOwnProperty ( itemActiveProperty ) ) {
405
406
mapObject = nestResult [ itemActiveProperty ] ;
406
407
} else {
407
408
nestResult [ itemActiveProperty ] = mapObject = { } ;
@@ -472,7 +473,7 @@ api.compact = ({
472
473
// handle language and index maps
473
474
// get or create the map object
474
475
let mapObject ;
475
- if ( itemActiveProperty in nestResult ) {
476
+ if ( nestResult . hasOwnProperty ( itemActiveProperty ) ) {
476
477
mapObject = nestResult [ itemActiveProperty ] ;
477
478
} else {
478
479
nestResult [ itemActiveProperty ] = mapObject = { } ;
@@ -736,7 +737,7 @@ api.compactIri = ({
736
737
if ( iri . indexOf ( vocab ) === 0 && iri !== vocab ) {
737
738
// use suffix as relative iri if it is not a term in the active context
738
739
const suffix = iri . substr ( vocab . length ) ;
739
- if ( ! ( suffix in activeCtx . mappings ) ) {
740
+ if ( ! activeCtx . mappings . has ( suffix ) ) {
740
741
return suffix ;
741
742
}
742
743
}
@@ -767,9 +768,9 @@ api.compactIri = ({
767
768
// 2. value is null, which means we're not compacting an @value, AND
768
769
// the mapping matches the IRI
769
770
const curie = term + ':' + iri . substr ( entry . iri . length ) ;
770
- const isUsableCurie = ( activeCtx . mappings [ term ] . _prefix &&
771
- ( ! ( curie in activeCtx . mappings ) ||
772
- ( value === null && activeCtx . mappings [ curie ] [ '@id' ] === iri ) ) ) ;
771
+ const isUsableCurie = ( activeCtx . mappings . get ( term ) . _prefix &&
772
+ ( ! activeCtx . mappings . has ( curie ) ||
773
+ ( value === null && activeCtx . mappings . get ( curie ) [ '@id' ] === iri ) ) ) ;
773
774
774
775
// select curie if it is shorter or the same length but lexicographically
775
776
// less than the current choice
@@ -834,8 +835,8 @@ api.compactValue = ({activeCtx, activeProperty, value, options}) => {
834
835
( keyCount === 2 && '@index' in value && ! preserveIndex ) ) ;
835
836
const hasDefaultLanguage = ( '@language' in activeCtx ) ;
836
837
const isValueString = _isString ( value [ '@value' ] ) ;
837
- const hasNullMapping = ( activeCtx . mappings [ activeProperty ] &&
838
- activeCtx . mappings [ activeProperty ] [ '@language' ] === null ) ;
838
+ const hasNullMapping = ( activeCtx . mappings . has ( activeProperty ) &&
839
+ activeCtx . mappings . get ( activeProperty ) [ '@language' ] === null ) ;
839
840
if ( isValueOnlyKey &&
840
841
( ! hasDefaultLanguage || ! isValueString || hasNullMapping ) ) {
841
842
return value [ '@value' ] ;
@@ -948,9 +949,9 @@ api.removePreserve = (ctx, input, options) => {
948
949
iri : '@id' ,
949
950
relativeTo : { vocab : true }
950
951
} ) ;
951
- if ( idAlias in input ) {
952
+ if ( input . hasOwnProperty ( idAlias ) ) {
952
953
const id = input [ idAlias ] ;
953
- if ( id in options . link ) {
954
+ if ( options . link . hasOwnProperty ( id ) ) {
954
955
const idx = options . link [ id ] . indexOf ( input ) ;
955
956
if ( idx !== - 1 ) {
956
957
// already visited
@@ -1020,9 +1021,9 @@ function _selectTerm(
1020
1021
// try to compact value to a term
1021
1022
const term = api . compactIri (
1022
1023
{ activeCtx, iri : value [ '@id' ] , relativeTo : { vocab : true } } ) ;
1023
- if ( term in activeCtx . mappings &&
1024
- activeCtx . mappings [ term ] &&
1025
- activeCtx . mappings [ term ] [ '@id' ] === value [ '@id' ] ) {
1024
+ if ( activeCtx . mappings . has ( term ) &&
1025
+ activeCtx . mappings . get ( term ) &&
1026
+ activeCtx . mappings . get ( term ) [ '@id' ] === value [ '@id' ] ) {
1026
1027
// prefer @vocab
1027
1028
prefs . push . apply ( prefs , [ '@vocab' , '@id' ] ) ;
1028
1029
} else {
0 commit comments