Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

notion-utils

Package Overview
Dependencies
Maintainers
2
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

notion-utils - npm Package Compare versions

Comparing version 6.7.0-alpha.1 to 6.7.0-alpha.2

build/is-url.d.ts

1

build/index.d.ts

@@ -18,4 +18,5 @@ export * from './get-text-content';

export * from './get-page-image-urls';
export * from './is-url';
export * from './normalize-url';
export * from './normalize-title';
//# sourceMappingURL=index.d.ts.map

2

build/index.js

@@ -1,2 +0,2 @@

var h=(e,t,n)=>new Promise((o,i)=>{var r=a=>{try{p(n.next(a))}catch(s){i(s)}},c=a=>{try{p(n.throw(a))}catch(s){i(s)}},p=a=>a.done?o(a.value):Promise.resolve(a.value).then(r,c);p((n=n.apply(e,t)).next())});var x=e=>{var t;return e?Array.isArray(e)?(t=e==null?void 0:e.reduce((n,o)=>n+(o[0]!=="\u204D"&&o[0]!=="\u2023"?o[0]:""),""))!=null?t:"":e:""};function T(e){var t,n;return e.collection_id||((n=(t=e.format)==null?void 0:t.collection_pointer)==null?void 0:n.id)||null}function _(e,t){var n,o;if((n=e.properties)!=null&&n.title)return x(e.properties.title);if(e.type==="collection_view_page"||e.type==="collection_view"){let i=(o=t.collection[T(e)])==null?void 0:o.value;if(i)return x(i.name)}return""}function P(e,t){var n,o,i;if((n=e.format)!=null&&n.page_icon)return(o=e.format)==null?void 0:o.page_icon;if(e.type==="collection_view_page"||e.type==="collection_view"){let r=T(e);if(r){let c=(i=t.collection[r])==null?void 0:i.value;if(c)return c.icon}}return null}function J(e){var n;let t=(n=e.block[Object.keys(e.block)[0]])==null?void 0:n.value;return t?_(t,e):null}function w(e,t,n){var o;try{if(!t.properties||!Object.keys(n.collection))return null;let i=(o=n.collection[t.parent_id])==null?void 0:o.value;if(i){let r=Object.keys(i.schema).find(a=>{var s;return((s=i.schema[a])==null?void 0:s.name)===e});if(!r)return null;let{type:c}=i.schema[r],p=x(t.properties[r]);switch(c){case"created_time":return t.created_time;case"multi_select":return p.split(",");case"date":{let s=t.properties[r][0][1][0][1];if(s.type=="datetime")return new Date(`${s.start_date} ${s.start_time}`).getTime();if(s.type=="date")return new Date(s.start_date).getTime();if(s.type=="datetimerange"){let{start_date:f,start_time:d,end_date:m,end_time:l}=s,y=new Date(`${f} ${d}`).getTime(),g=new Date(`${m} ${l}`).getTime();return[y,g]}else{let f=new Date(s.start_date).getTime(),d=new Date(s.end_date).getTime();return[f,d]}}case"checkbox":return p=="Yes";case"last_edited_time":return t.last_edited_time;default:return p}}}catch(i){}return null}var D=e=>{if(e&&Array.isArray(e)){if(e[0]==="d")return e[1];for(let t of e){let n=D(t);if(n)return n}}return null};var E=(e,t,{inclusive:n=!1}={})=>{var i,r;let o=e;for(;o!=null;){if(n&&(o==null?void 0:o.type)==="page")return o;let c=o.parent_id,p=o.parent_table;if(!c)break;if(p==="collection")o=(i=t.collection[c])==null?void 0:i.value;else if(o=(r=t.block[c])==null?void 0:r.value,(o==null?void 0:o.type)==="page")return o}return null};var O={header:0,sub_header:1,sub_sub_header:2},ne=(e,t)=>{var i;let n=((i=e.content)!=null?i:[]).map(r=>{var p,a;let c=(p=t.block[r])==null?void 0:p.value;if(c){let{type:s}=c;if(s==="header"||s==="sub_header"||s==="sub_sub_header")return{id:r,type:s,text:x((a=c.properties)==null?void 0:a.title),indentLevel:O[s]}}return null}).filter(Boolean),o=[{actual:-1,effective:-1}];for(let r of n){let{indentLevel:c}=r,p=c;do{let a=o[o.length-1],{actual:s,effective:f}=a;if(p>s)r.indentLevel=f+1,o.push({actual:p,effective:r.indentLevel});else if(p===s){r.indentLevel=f;break}else o.pop()}while(!0)}return n};var ie=(e,t)=>{var r,c,p;let n=t||Object.keys(e.block)[0],o=new Set;function i(a){var m;if(o.has(a))return;o.add(a);let s=(m=e.block[a])==null?void 0:m.value;if(!s)return;let{content:f,type:d}=s;if(!!f&&!(d==="page"&&a!==n))for(let l of f)i(l)}i(n);for(let a of Object.keys(e.block)){let s=(r=e.block[a])==null?void 0:r.value;if(!s)continue;let{properties:f}=s;if(f)for(let d of Object.keys(f)){let m=f[d];m.map(y=>{var u,k;let g=(k=(u=y==null?void 0:y[0])==null?void 0:u[1])==null?void 0:k[0];(g==null?void 0:g[0])==="p"&&g[1]&&o.add(g[1])});let l=(p=(c=m==null?void 0:m[0])==null?void 0:c[1])==null?void 0:p[0];(l==null?void 0:l[0])==="p"&&l[1]&&o.add(l[1])}}return Array.from(o)};var C=(e="")=>`${e.substr(0,8)}-${e.substr(8,4)}-${e.substr(12,4)}-${e.substr(16,4)}-${e.substr(20)}`;var A=/\b([a-f0-9]{32})\b/,j=/\b([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})\b/,R=(e="",{uuid:t=!0}={})=>{if(!e)return null;e=e.split("?")[0];let n=e.match(A);if(n)return t?C(n[1]):n[1];let o=e.match(j);return o?t?o[1]:o[1].replace(/-/g,""):null};var I=e=>e.replace(/-/g,"");import L from"p-queue";function ge(c,p,a){return h(this,arguments,function*(e,t,n,{concurrency:o=4,traverseCollections:i=!0,targetPageId:r=null}={}){let s={},f=new Set,d=new L({concurrency:o});function m(l){return h(this,null,function*(){r&&f.has(r)||(l=R(l),l&&!s[l]&&!f.has(l)&&(f.add(l),d.add(()=>h(this,null,function*(){var y,g;try{if(r&&f.has(r)&&l!==r)return;let u=yield n(l);if(!u)return;let k=(g=(y=u.block[l])==null?void 0:y.value)==null?void 0:g.space_id;if(k){if(!t)t=k;else if(t!==k)return}if(Object.keys(u.block).filter(v=>{var B;let b=(B=u.block[v])==null?void 0:B.value;return!(!b||b.type!=="page"&&b.type!=="collection_view_page"||t&&b.space_id&&b.space_id!==t)}).forEach(v=>m(v)),i)for(let v of Object.values(u.collection_query))for(let b of Object.values(v)){let{blockIds:B}=b;if(B)for(let $ of B)m($)}s[l]=u}catch(u){console.warn("page load error",{pageId:l,spaceId:t},u.statusCode,u.message),s[l]=null}f.delete(l)}))))})}return yield m(e),yield d.onIdle(),s})}var U=e=>(e||"").replace(/ /g,"-").replace(/[^a-zA-Z0-9-\u4e00-\u9fa5]/g,"").replace(/--/g,"-").replace(/-$/,"").replace(/^-/,"").trim().toLowerCase();var ve=(e,t,{uuid:n=!0}={})=>{var r;if(!e||!t)return null;let o=I(e),i=(r=t.block[e])==null?void 0:r.value;if(i){let c=w("slug",i,t)||w("Slug",i,t)||U(_(i,t));if(c)return n?`${c}-${o}`:c}return o};var we=(e,t)=>{var r;let n=e.block,o=[],i=t;do{let c=(r=n[i])==null?void 0:r.value;if(!c)break;let p=_(c,e),a=P(c,e);if(!(p||a))break;o.push({block:c,active:i===t,pageId:i,title:p,icon:a});let s=E(c,e),f=s==null?void 0:s.id;if(!f)break;i=f}while(!0);return o.reverse(),o};import M from"is-url-superb";var Ie=(e,{mapImageUrl:t})=>{let o=Object.keys(e.block).flatMap(i=>{var p,a,s,f,d,m,l,y;let r=(p=e.block[i])==null?void 0:p.value,c=[];if(r){if(r.type==="image"){let k=((a=e.signed_urls)==null?void 0:a[r.id])||((d=(f=(s=r.properties)==null?void 0:s.source)==null?void 0:f[0])==null?void 0:d[0]);k&&c.push({block:r,url:k})}if((m=r.format)!=null&&m.page_cover){let u=r.format.page_cover;c.push({block:r,url:u})}if((l=r.format)!=null&&l.bookmark_cover){let u=r.format.bookmark_cover;c.push({block:r,url:u})}if((y=r.format)!=null&&y.bookmark_icon){let u=r.format.bookmark_icon;c.push({block:r,url:u})}let g=P(r,e);g&&M(g)&&c.push({block:r,url:g})}return c}).filter(Boolean).map(({block:i,url:r})=>t(r,i)).filter(Boolean);return Array.from(new Set(o))};import z from"normalize-url";import F from"mem";var W=F(e=>{if(!e)return"";try{if(e.startsWith("https://www.notion.so/image/")){let t=new URL(e),n=decodeURIComponent(t.pathname.substr(7)),o=W(n);t.pathname=`/image/${encodeURIComponent(o)}`,e=t.toString()}return z(e,{stripProtocol:!0,stripWWW:!0,stripHash:!0,stripTextFragment:!0,removeQueryParameters:!0})}catch(t){return""}});export{ge as getAllPagesInSpace,T as getBlockCollectionId,P as getBlockIcon,E as getBlockParentPage,_ as getBlockTitle,ve as getCanonicalPageId,D as getDateValue,we as getPageBreadcrumbs,ie as getPageContentBlockIds,Ie as getPageImageUrls,w as getPageProperty,ne as getPageTableOfContents,J as getPageTitle,x as getTextContent,C as idToUuid,U as normalizeTitle,W as normalizeUrl,R as parsePageId,I as uuidToId};
var h=(e,t,n)=>new Promise((r,i)=>{var o=a=>{try{p(n.next(a))}catch(s){i(s)}},c=a=>{try{p(n.throw(a))}catch(s){i(s)}},p=a=>a.done?r(a.value):Promise.resolve(a.value).then(o,c);p((n=n.apply(e,t)).next())});var x=e=>{var t;return e?Array.isArray(e)?(t=e==null?void 0:e.reduce((n,r)=>n+(r[0]!=="\u204D"&&r[0]!=="\u2023"?r[0]:""),""))!=null?t:"":e:""};function T(e){var t,n;return e.collection_id||((n=(t=e.format)==null?void 0:t.collection_pointer)==null?void 0:n.id)||null}function _(e,t){var n,r;if((n=e.properties)!=null&&n.title)return x(e.properties.title);if(e.type==="collection_view_page"||e.type==="collection_view"){let i=(r=t.collection[T(e)])==null?void 0:r.value;if(i)return x(i.name)}return""}function P(e,t){var n,r,i;if((n=e.format)!=null&&n.page_icon)return(r=e.format)==null?void 0:r.page_icon;if(e.type==="collection_view_page"||e.type==="collection_view"){let o=T(e);if(o){let c=(i=t.collection[o])==null?void 0:i.value;if(c)return c.icon}}return null}function J(e){var n;let t=(n=e.block[Object.keys(e.block)[0]])==null?void 0:n.value;return t?_(t,e):null}function w(e,t,n){var r;try{if(!t.properties||!Object.keys(n.collection))return null;let i=(r=n.collection[t.parent_id])==null?void 0:r.value;if(i){let o=Object.keys(i.schema).find(a=>{var s;return((s=i.schema[a])==null?void 0:s.name)===e});if(!o)return null;let{type:c}=i.schema[o],p=x(t.properties[o]);switch(c){case"created_time":return t.created_time;case"multi_select":return p.split(",");case"date":{let s=t.properties[o][0][1][0][1];if(s.type=="datetime")return new Date(`${s.start_date} ${s.start_time}`).getTime();if(s.type=="date")return new Date(s.start_date).getTime();if(s.type=="datetimerange"){let{start_date:f,start_time:d,end_date:m,end_time:l}=s,y=new Date(`${f} ${d}`).getTime(),g=new Date(`${m} ${l}`).getTime();return[y,g]}else{let f=new Date(s.start_date).getTime(),d=new Date(s.end_date).getTime();return[f,d]}}case"checkbox":return p=="Yes";case"last_edited_time":return t.last_edited_time;default:return p}}}catch(i){}return null}var O=e=>{if(e&&Array.isArray(e)){if(e[0]==="d")return e[1];for(let t of e){let n=O(t);if(n)return n}}return null};var E=(e,t,{inclusive:n=!1}={})=>{var i,o;let r=e;for(;r!=null;){if(n&&(r==null?void 0:r.type)==="page")return r;let c=r.parent_id,p=r.parent_table;if(!c)break;if(p==="collection")r=(i=t.collection[c])==null?void 0:i.value;else if(r=(o=t.block[c])==null?void 0:o.value,(r==null?void 0:r.type)==="page")return r}return null};var A={header:0,sub_header:1,sub_sub_header:2},ne=(e,t)=>{var i;let n=((i=e.content)!=null?i:[]).map(o=>{var p,a;let c=(p=t.block[o])==null?void 0:p.value;if(c){let{type:s}=c;if(s==="header"||s==="sub_header"||s==="sub_sub_header")return{id:o,type:s,text:x((a=c.properties)==null?void 0:a.title),indentLevel:A[s]}}return null}).filter(Boolean),r=[{actual:-1,effective:-1}];for(let o of n){let{indentLevel:c}=o,p=c;do{let a=r[r.length-1],{actual:s,effective:f}=a;if(p>s)o.indentLevel=f+1,r.push({actual:p,effective:o.indentLevel});else if(p===s){o.indentLevel=f;break}else r.pop()}while(!0)}return n};var ie=(e,t)=>{var o,c,p;let n=t||Object.keys(e.block)[0],r=new Set;function i(a){var m;if(r.has(a))return;r.add(a);let s=(m=e.block[a])==null?void 0:m.value;if(!s)return;let{content:f,type:d}=s;if(!!f&&!(d==="page"&&a!==n))for(let l of f)i(l)}i(n);for(let a of Object.keys(e.block)){let s=(o=e.block[a])==null?void 0:o.value;if(!s)continue;let{properties:f}=s;if(f)for(let d of Object.keys(f)){let m=f[d];m.map(y=>{var u,k;let g=(k=(u=y==null?void 0:y[0])==null?void 0:u[1])==null?void 0:k[0];(g==null?void 0:g[0])==="p"&&g[1]&&r.add(g[1])});let l=(p=(c=m==null?void 0:m[0])==null?void 0:c[1])==null?void 0:p[0];(l==null?void 0:l[0])==="p"&&l[1]&&r.add(l[1])}}return Array.from(r)};var C=(e="")=>`${e.substr(0,8)}-${e.substr(8,4)}-${e.substr(12,4)}-${e.substr(16,4)}-${e.substr(20)}`;var j=/\b([a-f0-9]{32})\b/,L=/\b([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})\b/,R=(e="",{uuid:t=!0}={})=>{if(!e)return null;e=e.split("?")[0];let n=e.match(j);if(n)return t?C(n[1]):n[1];let r=e.match(L);return r?t?r[1]:r[1].replace(/-/g,""):null};var I=e=>e.replace(/-/g,"");import M from"p-queue";function ge(c,p,a){return h(this,arguments,function*(e,t,n,{concurrency:r=4,traverseCollections:i=!0,targetPageId:o=null}={}){let s={},f=new Set,d=new M({concurrency:r});function m(l){return h(this,null,function*(){o&&f.has(o)||(l=R(l),l&&!s[l]&&!f.has(l)&&(f.add(l),d.add(()=>h(this,null,function*(){var y,g;try{if(o&&f.has(o)&&l!==o)return;let u=yield n(l);if(!u)return;let k=(g=(y=u.block[l])==null?void 0:y.value)==null?void 0:g.space_id;if(k){if(!t)t=k;else if(t!==k)return}if(Object.keys(u.block).filter(v=>{var B;let b=(B=u.block[v])==null?void 0:B.value;return!(!b||b.type!=="page"&&b.type!=="collection_view_page"||t&&b.space_id&&b.space_id!==t)}).forEach(v=>m(v)),i)for(let v of Object.values(u.collection_query))for(let b of Object.values(v)){let{blockIds:B}=b;if(B)for(let D of B)m(D)}s[l]=u}catch(u){console.warn("page load error",{pageId:l,spaceId:t},u.statusCode,u.message),s[l]=null}f.delete(l)}))))})}return yield m(e),yield d.onIdle(),s})}var U=e=>(e||"").replace(/ /g,"-").replace(/[^a-zA-Z0-9-\u4e00-\u9fa5]/g,"").replace(/--/g,"-").replace(/-$/,"").replace(/^-/,"").trim().toLowerCase();var ve=(e,t,{uuid:n=!0}={})=>{var o;if(!e||!t)return null;let r=I(e),i=(o=t.block[e])==null?void 0:o.value;if(i){let c=w("slug",i,t)||w("Slug",i,t)||U(_(i,t));if(c)return n?`${c}-${r}`:c}return r};var we=(e,t)=>{var o;let n=e.block,r=[],i=t;do{let c=(o=n[i])==null?void 0:o.value;if(!c)break;let p=_(c,e),a=P(c,e);if(!(p||a))break;r.push({block:c,active:i===t,pageId:i,title:p,icon:a});let s=E(c,e),f=s==null?void 0:s.id;if(!f)break;i=f}while(!0);return r.reverse(),r};import $ from"is-url-superb";var $e=(e,{mapImageUrl:t})=>{let r=Object.keys(e.block).flatMap(i=>{var p,a,s,f,d,m,l,y;let o=(p=e.block[i])==null?void 0:p.value,c=[];if(o){if(o.type==="image"){let k=((a=e.signed_urls)==null?void 0:a[o.id])||((d=(f=(s=o.properties)==null?void 0:s.source)==null?void 0:f[0])==null?void 0:d[0]);k&&c.push({block:o,url:k})}if((m=o.format)!=null&&m.page_cover){let u=o.format.page_cover;c.push({block:o,url:u})}if((l=o.format)!=null&&l.bookmark_cover){let u=o.format.bookmark_cover;c.push({block:o,url:u})}if((y=o.format)!=null&&y.bookmark_icon){let u=o.format.bookmark_icon;c.push({block:o,url:u})}let g=P(o,e);g&&$(g)&&c.push({block:o,url:g})}return c}).filter(Boolean).map(({block:i,url:o})=>t(o,i)).filter(Boolean);return Array.from(new Set(r))};import z from"normalize-url";import F from"mem";var W=F(e=>{if(!e)return"";try{if(e.startsWith("https://www.notion.so/image/")){let t=new URL(e),n=decodeURIComponent(t.pathname.substr(7)),r=W(n);t.pathname=`/image/${encodeURIComponent(r)}`,e=t.toString()}return z(e,{stripProtocol:!0,stripWWW:!0,stripHash:!0,stripTextFragment:!0,removeQueryParameters:!0})}catch(t){return""}});export{ge as getAllPagesInSpace,T as getBlockCollectionId,P as getBlockIcon,E as getBlockParentPage,_ as getBlockTitle,ve as getCanonicalPageId,O as getDateValue,we as getPageBreadcrumbs,ie as getPageContentBlockIds,$e as getPageImageUrls,w as getPageProperty,ne as getPageTableOfContents,J as getPageTitle,x as getTextContent,C as idToUuid,$ as isUrl,U as normalizeTitle,W as normalizeUrl,R as parsePageId,I as uuidToId};
//# sourceMappingURL=index.js.map
{
"name": "notion-utils",
"version": "6.7.0-alpha.1",
"version": "6.7.0-alpha.2",
"type": "module",

@@ -48,3 +48,3 @@ "description": "Useful utilities for working with Notion data. Isomorphic.",

},
"gitHead": "d3c54174fff8659294f9bd06486a20603d222f7e"
"gitHead": "1214df762c0e66565e019afc1dc95563475c1bb8"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc