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.9.2 to 6.9.3-6.10.0-alpha.0.0

2

build/index.js

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

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

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

},
"gitHead": "efc5dc018efa2791e4a39f6609ce1cb151c907ff"
"gitHead": "3efb2dff8bea12930ee2b0536e848727d080724a"
}

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