npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

notion2json

v0.3.2

Published

A library built with Bun and Notion API client to extract and parse data from a Notion database.

Downloads

38

Readme

notion2json

A library built with Bun and Notion API client to extract and parse data from a Notion database.

NotionQuerier

This class needs a NOTION_API_SECRET environment variable in your project.

Query a database's pages

const querier = new NotionQuerier()

// Query pages sequentially: uses Notion's `next_cursor` after each call
const pages = await querier.queryAllDatabasePages('478cb452-7694-467a-9470-1934dc35ca87')

// Query pages bidirectionally: uses 2 threads, one querying from the oldest created page upward and one from the most recent page downward
const pages = await querier.queryDatabaseBidirectionally('478cb452-7694-467a-9470-1934dc35ca87')

// Query pages by partition: partitions the database based on the creation date and queries all segments concurrently
const pages = await querier.queryAllDatabasePagesByPartition('478cb452-7694-467a-9470-1934dc35ca87', { decreaseRatio: 2, count: 10 })

// Add options to queried pages (uses NotionClient options)
const pages = await querier.queryAllDatabasePages('478cb452-7694-467a-9470-1934dc35ca87', { filter_properties: ['%3BVB%3D', '%3Caie'] })

Retrieve property configurations

const querier = new NotionQuerier()

// Retrieve id, type and related databaseId (for relation properties only) of every property in the database
const propertyConfigs = await querier.fetchDatabasePropertyConfigs('478cb452-7694-467a-9470-1934dc35ca87')

NotionFormatter

This class needs to be initiated with the pages and propertyConfigs, which can be fetched by the NotionQuerier.

Format database pages

const formatter = new NotionFormatter({ '478cb452-7694-467a-9470-1934dc35ca87': { pages, propertyConfigs } })

// Format all pages in the given database to JSON objects with property ids as keys and property content as values
const formattedPages = formatter.formatDatabase('478cb452-7694-467a-9470-1934dc35ca87')

[!WARNING] You must provide the NotionFormatter with all databases that will be needed to format the pages' properties. This means that if one of the properties in the formatted database is a relation prop towards another database, you will need to provide the NotionFormatter the pointed database as well.

Example

The return value of the formatDatabase() method will be an array of pages. Each of these pages will be an object where keys are property IDs and values are formatted values from the Notion page. For instance, a formatted page would look like:

{
  id:
  qPsw: "Done",
  "qby%3F": [""],
  "s%3C%3Fk": 1,
  "s%5Cxn": ["John Doe"],
  "s_~%7C": [{ text: "[email protected]", url: "mailto:[email protected]" }],
  tgaC: ["1550 Notion Street"],
  tkIR: "",
  ugTi: [],
  vJrh: 1,
  "vm%7Cc": "",
  "z%5EUR": 2023-03-02T13:07:00.000Z,
  "zvJ~": "IDF",
  "%7BXp%5C": [2024-02-26T00:00:00.000Z],
  "%7BloJ": [],
  "%7DsuD": "",
  "~OYv": "",
  title: ["John's Todo List"],
  id: { text: "06cae4ca-5542-444c-adde-b48a2dcca40b", url: "https://www.notion.so/06cae4ca5542444caddeb48a2dcca40b" }
}