Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public static termToValue(term: RDF.Term, context: IJsonLdContextNormalized, options: ITermToValueOptions = {
compactIds: false,
useNativeTypes: false,
}): any {
switch (term.termType) {
case 'NamedNode':
const compacted = ContextParser.compactIri(term.value, context, options.vocab);
return options.compactIds ? compacted : { '@id': compacted };
case 'DefaultGraph':
return options.compactIds ? term.value : { '@id': term.value };
case 'BlankNode':
const id = `_:${term.value}`;
return options.compactIds ? id : { '@id': id };
case 'Literal':
const stringType = term.datatype.value === Util.XSD_STRING;
const rawValue = {
'@value': !stringType && options.useNativeTypes
? Util.stringToNativeType(term.value, term.datatype.value) : term.value,
};
if (term.language) {
return { ...rawValue, '@language': term.language };
} else if (!stringType && typeof rawValue['@value'] === 'string') {
return { ...rawValue, '@type': term.datatype.value };