How to use the jsonld-context-parser.ContextParser.compactIri function in jsonld-context-parser

To help you get started, we’ve selected a few jsonld-context-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rubensworks / jsonld-streaming-serializer.js / lib / Util.ts View on Github external
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 };

jsonld-context-parser

Parses JSON-LD contexts

MIT
Latest version published 5 months ago

Package Health Score

67 / 100
Full package analysis