@jitl/notion-api
Version:
The missing companion library for the official Notion public API.
44 lines • 1.49 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const __1 = require("..");
function getBlockTextContentBefore(block) {
switch (block.type) {
case 'paragraph':
return block.paragraph.rich_text;
case 'heading_1':
return block.heading_1.rich_text;
case 'heading_2':
return block.heading_2.rich_text;
// ... etc, for many more block types
default:
throw new Error(`unknown block type: ${block.type}`);
}
}
function getBlockTextContentAfter(block) {
const blockData = (0, __1.getBlockData)(block);
const results = [];
if ('rich_text' in blockData) {
results.push(blockData.rich_text);
}
if ('caption' in blockData) {
results.push(blockData.caption);
}
// Done.
return results;
}
function getBlockTextContentAfterExhaustive(block) {
switch (block.type) {
case 'paragraph': // Fall-through for blocks with only rich_text
case 'heading_1':
case 'heading_2': // ... etc
return (0, __1.getBlockData)(block).rich_text;
case 'image':
return (0, __1.getBlockData)(block).caption;
case 'code':
return [(0, __1.getBlockData)(block).rich_text, (0, __1.getBlockData)(block).caption];
// ... etc, for many more block types
default:
throw new Error(`unknown block type: ${block.type}`);
}
}
//# sourceMappingURL=blockData.js.map
;