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 🙏

© 2025 – Pkg Stats / Ryan Hefner

notion2content

v0.4.1

Published

Notion のデータベースを変換しダウンロードするライブラリーとサンプル実装としての CLI ツール。

Downloads

31

Readme

notion2content

Notion のデータベースを変換しダウンロードするライブラリーとサンプル実装としての CLI ツール。

  • Properties は Frontmatter で扱いやすい JSON へ変換
  • Blocks は hast へ変換(CLI ツールでは hast から HTML/Markdown へ変換)

実装中。

Install

CLI ツールとしてインストール。

npm install -g notion2content

ライブラリーとしてインストール。

npm install --save notion2content

Usage

データベースを ndjson(JSON Lines) として出力。

$ export NOTION2CONTENT_API_KEY=<NOTION API KEY>
$ notion2content dist/main.js --database-id <DATABASE ID>
{"id":"*****","props":{ ... },"content":{"type":"root","children":[ ... ]}}
{"id":"*****","props":{ ... },"content":{"type":"root","children":[ ... ]}}
{"id":"*****","props":{ ... },"content":{"type":"root","children":[ ... ]}}

ページ別にファイルへ保存。HTML と Markdown の場合は Propery が Frontmatter となる。

$ notion2content dist/main.js --database-id <DATABASE ID> --save-dir ./tmp --save-format md
$ ll tmp
total 20
drwxrwxrwx+  2 vscode vscode 4096 Sep 30 16:15 ./
drwxrwxrwx+ 12 vscode root   4096 Sep 30 15:16 ../
-rw-rw-rw-   1 vscode vscode   41 Sep 30 16:15 *****.md
-rw-rw-rw-   1 vscode vscode   38 Sep 30 16:15 *****.md
-rw-rw-rw-   1 vscode vscode   48 Sep 30 16:15 *****.md

API

Client abstract class

@notionhq/client を使った実装方法。

import { Client as NotionClient } from '@notionhq/client'
import { ClientOptions } from '@notionhq/client/build/src/Client'
import { Client } from 'notion2content'

class CliClient extends Client {
  private client: NotionClient
  constructor(options?: ClientOptions) {
    super()
    this.client = new NotionClient(options)
  }
  queryDatabases(
    ...args: Parameters<NotionClient['databases']['query']>
  ): ReturnType<NotionClient['databases']['query']> {
    return this.client.databases.query(...args)
  }
  listBlockChildren(
    ...args: Parameters<NotionClient['blocks']['children']['list']>
  ): ReturnType<NotionClient['blocks']['children']['list']> {
    return this.client.blocks.children.list(...args)
  }
}

const client = new CliClient({
  auth: 'youre api key'
})

toContent function

import { toContent } from 'notion2content'
const client = new CliClient({
  auth: 'youre api key'
})
const ite = toContent(client, {
  target: ['props', 'content'],
  query: { database_id: '*****' },
  toItemsOpts: {},
  toHastOpts: {}
})
for await (const content of ite) {
  console.log(`${JSON.stringify(content)}\n`)
}

Options

inOpts.target

propscontent のどちらを変換するか配列で指定(同時にどちらも指定可能)

inOpts.workersNum

content の変換(child ブロックのフェッチ)を並行で行う数。

inOpts.query

Notion Clinet の databases.query へ渡す引数。

inOpts.skip

query で取得したデータをスキップする数。

inOpts.limit

query で取得したデータを制限する数。

inOpts.toItemsOpts.initialIndex

props に追加する index の初期値。

index とは toContent が返す iterator から取得したときに props に追加する連番。

inOpts.toItemsOpts.indexName

props に追加する index 名。

inOpts.toItemsOpts.toHastOpts

notion2hastblockToHast へ渡すオプション.

対応状況

Properties

  • [x] number - null0 へ変換される
  • [x] url - plain text へ変換される
  • [x] select - null はブランクへ変換される
  • [x] multi_select
  • [x] status - plain text へ変換される
  • [x] date - Date property values を出力(null は '' へ変換される)
  • [x] email - plain text へ変換される
  • [x] phone_number - plain text へ変換される
  • [x] checkbox - boolean へ変換される
  • [ ] files
  • [x] created_by - Created by property valuesを出力(person のみ対応、nullundefined'' へ変換される)
  • [x] created_time - plain text へ変換される
  • [x] last_edited_by - Last edited by property valuesを出力(person のみ対応、nullundefined'' へ変換される)
  • [x] last_edited_time - plain text へ変換される
  • [ ] formula
  • [x] title - plain text へ変換される
  • [x] rich_text - plain text へ変換される
  • [x] people - People property valuesを出力(person のみ対応、nullundefined'' へ変換される)
  • [x] relation - id の配列へ変換
  • [ ] rollup

Blocks

Blocks の変換は notion2hast で対応。

License

MIT License

Copyright (c) 2022 hankei6km