@texonom/nutils
v1.5.8
Published
Useful utilities for working with Notion data. Isomorphic.
Readme
nutils
Useful utilities for working with Notion data. Runs in Node.js and the browser.
Features
- Convert between page IDs and UUIDs
- Map and normalize Notion URLs
- Helpers for reading page metadata
Install
pnpm i @texonom/nutilsUsage
import { parsePageId } from '@texonom/nutils'
parsePageId('https://www.notion.so/Notion-Tests-067dd719a912471ea9a3ac10710e7fdf')
// '067dd719-a912-471e-a9a3-ac10710e7fdf'
parsePageId('About-d9ae0c6e7cad49a78e21d240cf2e3d04', { uuid: false })
// 'd9ae0c6e7cad49a78e21d240cf2e3d04'
import { normalizeUrl } from '@texonom/nutils'
normalizeUrl('https://test.com/foo/bar?foo=bar')
import { defaultMapPageUrl, defaultMapImageUrl } from '@texonom/nutils'
const mapPage = defaultMapPageUrl('root')('067dd719a912471ea9a3ac10710e7fdf')
const mapImage = defaultMapImageUrl('/image.png', { id: 'id', parent_table: 'block' } as any)
import { getCanonicalPageId } from '@texonom/nutils'
getCanonicalPageId('067dd719-a912-471e-a9a3-ac10710e7fdf', recordMap)See the full docs for more helpers.
API
The library exports many helpers. Each function works both in Node.js and the browser.
getTextContent(value)– extract plain text from rich text valuesgetBlockTitle(block, recordMap)– title of a blockgetBlockIcon(block, recordMap)– icon for a blockgetBlockCollectionId(block, recordMap)– collection id for collection view blocksgetPageTitle(recordMap)– page title from a record mapgetPageProperty(name, block, recordMap)– any page propertygetDateValue(value)– normalize Notion date valuesgetBlockParentPage(block, recordMap)– parent page blockgetPageTableOfContents(recordMap)– extract headers and linksgetPageContentBlockIds(recordMap)– list of block ids contained in a pageparsePageId(id, opts?)– convert Notion URLs and idsidToUuid(id)– add dashes to a notion iduuidToId(uuid)– remove dashes from a uuidgetAllInSpace(api, spaceId)– fetch every page in a workspacegetCanonicalPageId(pageId, recordMap)– canonical slug for a pagegetPageBreadcrumbs(block, recordMap)– breadcrumb labelsgetPageImageUrls(recordMap)– all images used on a pageisUrl(value)– check if a string is a URLnormalizeUrl(url)– remove tracking paramsnormalizeTitle(title)– cleanup page titlesmergeRecordMaps(a, b)– combine multiple record mapsformatDate(value)– format ISO date stringformatNotionDateTime(value)– format Notion timestampsfindAncestors(blockId, recordMap)– walk up the block treeestimatePageReadTime(recordMap)– count words for read timemapImageUrl(url, block)– default image URL mappermapPageUrl(id)– default page URL mapper
