Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mdx-extract-export

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdx-extract-export

Extract named exports from MDX files using Babel

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

mdx-extract-export

Extract named exports from MDX files using Babel.


code example:

const fs = require('fs')
const extract = require('mdx-extract-export')
const sample = fs.readFileSync('/path/to/file.mdx')

main()
async function main() {
  const res = await extract(sample)
  console.log(res) // { [...]: { ... } }
}

Optionally, pass a search array option to select keys you want to extract:

  const { meta } = await extract(sample, { search: ['meta'] })
When would you use this?

Storing stuctured data along with MDX files, and accessing this data at runtime, is a fairly common case. Think of configuration objects you would pass to react-helmet for example.

Now imagine that you want to create a small API / display info out of a bunch of MDX files. You would have to actually import each of these files in order to acces their metadata. No thanks 🙅‍♀️: use this package instead!

See a (WIP) example here: https://github.com/trycereals/next, where a Netlify plugin uses mdx-extract-export to create a JSON index file. It then can be directly accessed by a Netlify function ✌️

FAQs

Package last updated on 27 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc