ChemPal Documentation - v1.6.0
    Preparing search index...

    Function isSchemaContext

    • Decide whether a JSON-LD @context denotes schema.org, tolerating every form seen in the wild: http/https, an optional trailing slash, an array of contexts, or an object whose values point at schema.org (e.g. an @vocab).

      Parameters

      • ctx: undefined | JsonValue

        The value of a node's @context (any JSON value or undefined).

      Returns boolean

      true if the context refers to schema.org, otherwise false.

      isSchemaContext('https://schema.org');                 // true
      isSchemaContext('https://schema.org/'); // true (trailing slash)
      isSchemaContext({ '@vocab': 'https://schema.org/' }); // true
      isSchemaContext('https://example.com'); // false
      export function isSchemaContext(ctx: JsonValue | undefined): boolean {
      if (typeof ctx === 'string') return SCHEMA_CONTEXT_RE.test(ctx);
      if (Array.isArray(ctx)) return ctx.some(isSchemaContext);
      if (isPlainObject(ctx)) {
      // e.g. { "@vocab": "https://schema.org/" } or a prefix map.
      return Object.values(ctx).some((v) => typeof v === 'string' && SCHEMA_CONTEXT_RE.test(v));
      }
      return false;
      }