Get data from a local file.

Like lodash.get but for data held in JSON, YAML and HTML files.

import { utils } from '@reuters-graphics/graphics-bin';

// From a JSON file
utils.fs.get('./data/userData.json?people[0].name');

// ... YAML file
utils.fs.get('./data/userData.yaml?people[0].name');

// ... HTML file
utils.fs.get('dist/index.html?title');

HTML files return specially structured data, including the page's title, lang and canonical URL as well as meta tag values and json+ld data.

import { utils } from '@reuters-graphics/graphics-bin';

// Page title
utils.fs.get('dist/index.html?title');
// Page html lang attribute
utils.fs.get('dist/index.html?lang');
// Canonical URL
utils.fs.get('dist/index.html?canonical');

// Meta tag values
utils.fs.get('dist/index.html?meta.og:description');

// JSON-LD data (always in an array)
utils.fs.get('dist/index.html?jsonLd[0].headline');
utils.fs.get('dist/index.html?jsonLd[1].@type');
  • Type Parameters

    • T

    Parameters

    • key: string

      Key of the form "{filePath}?{propertyPath}"

    Returns undefined | T