Skip to content

Commit 0eb3fc7

Browse files
committed
Update context shortcuts to support JSON-LD 1.1
1 parent 362f2a8 commit 0eb3fc7

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

lib/serialize/ContextConstructor.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ export class ContextConstructor {
5959
// Shortcut name for a class contains no special characters
6060
// Regex will always match
6161
const match = <RegExpExecArray> (/[a-z0-9]*$/iu.exec(component['@id']));
62-
shortcuts[match[0]] = component['@id'];
62+
shortcuts[match[0]] = <any> {
63+
'@id': component['@id'],
64+
'@prefix': true,
65+
};
6366
}
6467
}
6568
return shortcuts;

test/serialize/ContextConstructor.test.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,17 @@ describe('ContextConstructor', () => {
8585
'@context': [
8686
'https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^3.0.0/components/context.jsonld',
8787
{
88-
npmd: 'https://linkedsoftwaredependencies.org/bundles/npm/',
89-
mp: 'npmd:my-package/',
88+
MyClass1: {
89+
'@id': 'mp:file1#MyClass1',
90+
'@prefix': true,
91+
},
92+
MyClass2: {
93+
'@id': 'mp:b/file2#MyClass2',
94+
'@prefix': true,
95+
},
9096
'files-mp': 'mp:^1.0.0/',
91-
92-
MyClass1: 'mp:file1#MyClass1',
93-
MyClass2: 'mp:b/file2#MyClass2',
97+
mp: 'npmd:my-package/',
98+
npmd: 'https://linkedsoftwaredependencies.org/bundles/npm/',
9499
},
95100
],
96101
});
@@ -135,8 +140,14 @@ describe('ContextConstructor', () => {
135140
],
136141
},
137142
})).toEqual({
138-
MyClass1: 'mp:file1#MyClass1',
139-
MyClass2: 'mp:b/file2#MyClass2',
143+
MyClass1: {
144+
'@id': 'mp:file1#MyClass1',
145+
'@prefix': true,
146+
},
147+
MyClass2: {
148+
'@id': 'mp:b/file2#MyClass2',
149+
'@prefix': true,
150+
},
140151
});
141152
});
142153
});

0 commit comments

Comments
 (0)