How to use the jsonld.promises.expand function in jsonld

To help you get started, we’ve selected a few jsonld 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 wikibus / Alcaeus / src / MediaTypeProcessors / RdfProcessor.ts View on Github external
async function flatten (json, url): Promise {
    const opts: FlattenOptions = {}
    if (url) {
        opts.base = url
    }

    const expanded = await jsonld.expand(json, opts)
    const flattened = await jsonld.flatten(expanded, {})

    return flattened[Constants.JsonLd.Graph]
}
github blakeembrey / node-scrappy / src / scrape / plugins / html.ts View on Github external
if (result.encodingFormat !== 'text/html') {
    return next(stream)
  }

  const [parsed] = await Promise.all([
    parseHtml(stream.pipe(new PassThrough()), url),
    next(stream.pipe(new PassThrough()))
  ])

  const { twitter, html, icons, dublincore, applinks, sailthru, alternate } = parsed

  const [jsonld, rdfa, microdata] = await Promise.all([
    parsed.jsonld ? Jsonld.expand(parsed.jsonld, { base: url }).catch(() => undefined) : undefined,
    parsed.rdfa ? Jsonld.expand(parsed.rdfa, { base: url }).catch(() => undefined) : undefined,
    parsed.microdata ? Jsonld.expand(parsed.microdata, { base: url }).catch(() => undefined) : undefined
  ])

  return Object.assign(result, {
    jsonld,
    rdfa,
    microdata,
    twitter,
    html,
    icons,
    dublincore,
    applinks,
    sailthru,
    alternate
  })
}
github blakeembrey / node-scrappy / src / scrape / plugins / html.ts View on Github external
): Promise {
  const { url } = result

  if (result.encodingFormat !== 'text/html') {
    return next(stream)
  }

  const [parsed] = await Promise.all([
    parseHtml(stream.pipe(new PassThrough()), url),
    next(stream.pipe(new PassThrough()))
  ])

  const { twitter, html, icons, dublincore, applinks, sailthru, alternate } = parsed

  const [jsonld, rdfa, microdata] = await Promise.all([
    parsed.jsonld ? Jsonld.expand(parsed.jsonld, { base: url }).catch(() => undefined) : undefined,
    parsed.rdfa ? Jsonld.expand(parsed.rdfa, { base: url }).catch(() => undefined) : undefined,
    parsed.microdata ? Jsonld.expand(parsed.microdata, { base: url }).catch(() => undefined) : undefined
  ])

  return Object.assign(result, {
    jsonld,
    rdfa,
    microdata,
    twitter,
    html,
    icons,
    dublincore,
    applinks,
    sailthru,
    alternate
  })
github api-platform / admin / src / hydra / fetchHydra.js View on Github external
}).then(data => {
    const status = data.response.status;

    if (status < 200 || status >= 300) {
      return promises
        .expand(data.body, {
          base: getDocumentationUrlFromHeaders(data.response.headers),
        })
        .then(json => {
          return Promise.reject(
            new HttpError(
              json[0]['http://www.w3.org/ns/hydra/core#description'][0][
                '@value'
              ],
              status,
            ),
          );
        })
        .catch(e => {
          if (e.hasOwnProperty('body')) {
            return Promise.reject(e);
github AudienceHero / AudienceHero / src / AudienceHero / Bundle / CoreBundle / Resources / modules / common / client / fetchHydra.js View on Github external
}).then(data => {
        const status = data.response.status;

        if (status < 200 || status >= 300) {
            return promises
                .expand(data.body, {
                    base: getDocumentationUrlFromHeaders(data.response.headers),
                })
                .then(json => {
                    const e = new HttpError(
                        json[0][
                            'http://www.w3.org/ns/hydra/core#description'
                        ][0]['@value'],
                        status,
                        json[0]
                    );
                    return Promise.reject(e);
                })
                .catch(e => {
                    if (e instanceof HttpError) {
                        return Promise.reject(e);
github blakeembrey / node-scrappy / src / scrape / plugins / html.ts View on Github external
const { url } = result

  if (result.encodingFormat !== 'text/html') {
    return next(stream)
  }

  const [parsed] = await Promise.all([
    parseHtml(stream.pipe(new PassThrough()), url),
    next(stream.pipe(new PassThrough()))
  ])

  const { twitter, html, icons, dublincore, applinks, sailthru, alternate } = parsed

  const [jsonld, rdfa, microdata] = await Promise.all([
    parsed.jsonld ? Jsonld.expand(parsed.jsonld, { base: url }).catch(() => undefined) : undefined,
    parsed.rdfa ? Jsonld.expand(parsed.rdfa, { base: url }).catch(() => undefined) : undefined,
    parsed.microdata ? Jsonld.expand(parsed.microdata, { base: url }).catch(() => undefined) : undefined
  ])

  return Object.assign(result, {
    jsonld,
    rdfa,
    microdata,
    twitter,
    html,
    icons,
    dublincore,
    applinks,
    sailthru,
    alternate
  })
}