normalize-notion-database
v1.0.1
Published
Normalize Notion database entries into a simple key-value object
Maintainers
Keywords
Readme
normalize-notion-database
A lightweight utility to normalize Notion database entries into a simple key-value object.
It is specifically built to work with data retrieved using the @notionhq/client package.
Installation
Install the package with your package manager of choice:
# npm
npm install normalize-notion-database
# yarn
yarn add normalize-notion-database
# pnpm
pnpm add normalize-notion-databaseUsage
Here’s a quick example to get you started:
import { Client } from "@notionhq/client";
import { normalizeNotionDatabase } from 'normalize-notion-database';
// 1. Initialize the Notion client.
const notion = new Client({
auth: process.env.NOTION_AUTH_TOKEN,
});
// 2. Query the Notion database.
const database = await notion.databases.query({
database_id: process.env.NOTION_DATABASE_ID,
});
// 3. Normalize the data into a usable format.
const normalizedData = await normalizeNotionDatabase(notionData, { camelcase: true });
console.log(normalizedData);
// => [{ projectTitle: 'My Project', currentStatus: 'In Progress', tags: ['Tag1', 'Tag2'] }]API
normalizeNotionDatabase(db, options)
Normalizes a Notion database object into an array of simplified JavaScript objects.
Parameters
db
Type:
NotionDatabase(orRecord<string, any>)
The raw Notion database object containing aresultsarray of pages withproperties.
options
Type:
{ camelcase?: boolean }
Optional configuration object.
camelcase: Iftrue, converts property keys to camelCase (e.g.,Start DatebecomesstartDate). Defaults tofalse.
Returns
Type:
Promise<Record<string, string | string[] | boolean | number | Record<string, string> | null>[]>
A promise that resolves to an array of normalized objects, where each object represents a Notion page with simplified property values.
Supported Property Types
The package normalizes the following Notion property types into simple values:
title→string | nullrich_text→string | nullurl→string | nullselect→string | nullmulti_select→string[]checkbox→booleannumber→number | nulldate→string | null(returns thestartdate)status→string | nullemail→string | nullphone_number→string | nullcreated_time→string | nullcreated_by→Record<string, string> | nulllast_edited_time→string | nulllast_edited_by→Record<string, string> | nullid→string | null
License
MIT License © Rocktim Saikia 2025
