UNPKG

notion-page-tree

Version:

Recursively fetch nested Notion pages from the root page/database/block node.

34 lines (33 loc) 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.convertNotionId = exports.convertNotionId2 = void 0; var convertNotionId2 = function (id, convertTo) { if (convertTo === 'dashed' && id.length === 32) { return [8, 4, 4, 4, 16].reduce(function (acc, val, idx) { return ({ i: acc.i + val, v: (acc.v !== '' && idx !== 5 ? acc.v + '-' : acc.v) + id.slice(acc.i, acc.i + val) }); }, { i: 0, v: '' }).v; } if (convertTo === 'plain' && id.length === 36) { return id.split('-').join(); } return false; }; exports.convertNotionId2 = convertNotionId2; var convertNotionId = function (id, convertTo) { return id.length === 32 ? convertTo === 'dashed' ? [8, 4, 4, 4, 16].reduce(function (acc, val, idx) { return ({ i: acc.i + val, v: (acc.v !== '' && idx !== 5 ? acc.v + '-' : acc.v) + id.slice(acc.i, acc.i + val) }); }, { i: 0, v: '' }).v : id : id.length === 36 ? convertTo === 'plain' ? id.split('-').join() : id : id; }; exports.convertNotionId = convertNotionId;