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

mokuji.js

Package Overview
Dependencies
Maintainers
0
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mokuji.js - npm Package Compare versions

Comparing version 4.4.1 to 4.5.0

dist/index.d.cts

4

dist/index.d.ts

@@ -6,3 +6,5 @@ type AnchorContainerTagNameProps = 'ul' | 'ol';

anchorLinkSymbol?: string;
/** @deprecated use anchorLinkPosition */
anchorLinkBefore?: boolean;
anchorLinkPosition?: 'before' | 'after';
anchorLinkClassName?: string;

@@ -15,2 +17,2 @@ anchorContainerTagName?: AnchorContainerTagNameProps;

export { Destroy, Mokuji, MokujiOption };
export { Destroy, Mokuji, type MokujiOption };

@@ -1,5 +0,5 @@

var g=(t,n)=>!t||!n?!1:n.contains(t),u=t=>t.querySelectorAll("h1, h2, h3, h4, h5, h6"),h=t=>document.createElement(t);var L=new Set,E=t=>t.replaceAll(/\s+/g,"_"),A=t=>encodeURIComponent(t).replaceAll(/%+/g,"."),T=(t,n="")=>{let e=n,o=1;for(;o<=t.length;){let r=o===1?e:`${e}_${o}`;if(!L.has(r)){e=r,L.add(e);break}o++;}return e},M=(t,n)=>{let e=E(t);return e=e.replaceAll(/&+/g,"").replaceAll(/&amp;+/g,""),n&&(e=A(e)),e};var H="data-mokuji-anchor",k={anchorType:!0,anchorLink:!1,anchorLinkSymbol:"#",anchorLinkBefore:!0,anchorLinkClassName:"",anchorContainerTagName:"ol"},N=t=>{let n=new Map;for(let e=0;e<t.length;e++){let o=t[e].hash.replace("#","");n.set(o,t[e]);}return n},x=(t,n,e)=>{let o=h("a");o.setAttribute(H,""),e.anchorLinkClassName&&o.classList.add(e.anchorLinkClassName);for(let r=0;r<t.length;r++){let c=t[r],l=n.get(c.id);if(!l)continue;let s=o.cloneNode(!1);s.setAttribute("href",l.hash),e.anchorLinkSymbol&&(s.textContent=e.anchorLinkSymbol),e.anchorLinkBefore?c.insertBefore(s,c.firstChild):c.append(s);}},y=(t,n)=>{for(let e=0;e<n.length;e++){let o=n[e],r=o.textContent,c=o.hash,l=t.filter(a=>a.id===r);if(l.length===1)continue;let s=0;for(let a=0;a<l.length;a++){let f=l[a],m=`${f.id}-${s}`;for(let i=0;i<n.length;i++){let d=n[i];if(d.hash===c){d.href=`#${m}`;break}}f.id=m,s++;}}},C=(t,n,e)=>{let o=0,r=h("li"),c=h("a");for(let l=0;l<t.length;l++){let s=t[l],a=Number(s.tagName[1]);if(o!==0&&o<a){let p=h("ol");n.lastChild.append(p),n=p;}else if(o!==0&&o>a)for(let p=0;p<o-a;p++)g(n,n.parentNode)&&(n=n.parentNode?.parentNode);let f=T(t,s.textContent||""),m=M(f,e);s.id=m;let i=c.cloneNode(!1);i.href=`#${m}`,i.textContent=s.textContent;let d=r.cloneNode(!1);d.append(i),n.append(d),o=a;}},I=(t,n)=>{if(!t)return;let e={...k,...n},o=[...u(t)];if(o.length===0)return;let r=h(e.anchorContainerTagName);C(o,r,e.anchorType);let c=[...r.querySelectorAll("a")];if(c.length!==0){if(y(o,c),e.anchorLink){let l=N(c);x(o,l,e);}return r}},_=()=>{let t=document.querySelectorAll(`[${H}]`);for(let n=t.length-1;n>=0;n--)t[n].remove();};
var g=(e,t)=>!e||!t?!1:t.contains(e),u=e=>e.querySelectorAll("h1, h2, h3, h4, h5, h6"),i=e=>document.createElement(e);var L=new Set,E=e=>e.replaceAll(/\s+/g,"_"),A=e=>encodeURIComponent(e).replaceAll(/%+/g,"."),T=(e,t="")=>{let n=t,o=1;for(;o<=e.length;){let r=o===1?n:`${n}_${o}`;if(!L.has(r)){n=r,L.add(n);break}o++;}return n},M=(e,t)=>{let n=E(e);return n=n.replaceAll(/&+/g,"").replaceAll(/&amp;+/g,""),t&&(n=A(n)),n};var H="data-mokuji-anchor",N={anchorType:!0,anchorLink:!1,anchorLinkSymbol:"#",anchorLinkPosition:"before",anchorLinkClassName:"",anchorContainerTagName:"ol"},k=e=>{let t=new Map;for(let n=0;n<e.length;n++){let o=e[n].hash.replace("#","");t.set(o,e[n]);}return t},x=(e,t,n)=>{let o=i("a");o.setAttribute(H,""),n.anchorLinkClassName&&o.classList.add(n.anchorLinkClassName);for(let r=0;r<e.length;r++){let s=e[r],c=t.get(encodeURIComponent(s.id));if(!c)continue;let a=o.cloneNode(!1);a.setAttribute("href",c.hash),n.anchorLinkSymbol&&(a.textContent=n.anchorLinkSymbol),n.anchorLinkPosition==="before"?s.insertBefore(a,s.firstChild):s.append(a);}},b=(e,t)=>{let n=new Map,o=new Map;for(let r of t){let s=r.hash.slice(1),c=o.get(s)||[];c.push(r),o.set(s,c);}for(let r of e){let s=r.id,c=n.get(s)||0;if(c>0){let a=`${s}-${c}`;r.id=a;let l=o.get(s)||[];for(let m of l)m.href=`#${a}`;}n.set(s,c+1);}},y=(e,t,n)=>{let o=0,r=i("li"),s=i("a");for(let c=0;c<e.length;c++){let a=e[c],l=Number(a.tagName[1]);if(o!==0&&o<l){let h=i("ol");t.lastChild.append(h),t=h;}else if(o!==0&&o>l)for(let h=0;h<o-l;h++)g(t,t.parentNode)&&(t=t.parentNode?.parentNode);let m=T(e,a.textContent||""),p=M(m,n);a.id=p;let d=s.cloneNode(!1);d.href=`#${p}`,d.textContent=a.textContent;let f=r.cloneNode(!1);f.append(d),t.append(f),o=l;}},j=(e,t)=>{if(!e)return;let n={...N,...t},o=[...u(e)];if(o.length===0)return;let r=i(n.anchorContainerTagName);y(o,r,n.anchorType);let s=[...r.querySelectorAll("a")];if(s.length!==0){if(b(o,s),n.anchorLink){let c=k(s);x(o,c,n);}return r}},U=()=>{let e=document.querySelectorAll(`[${H}]`);for(let t=e.length-1;t>=0;t--)e[t].remove();};
export { _ as Destroy, I as Mokuji };
//# sourceMappingURL=out.js.map
export { U as Destroy, j as Mokuji };
//# sourceMappingURL=index.js.map
//# sourceMappingURL=index.js.map
{
"name": "mokuji.js",
"version": "4.4.1",
"version": "4.5.0",
"description": "A table of content JavaScript Library",

@@ -55,3 +55,3 @@ "scripts": {

"devDependencies": {
"@types/node": "~20.2.3",
"@types/node": "~20.4.1",
"@typescript-eslint/eslint-plugin": "^5.59.7",

@@ -62,7 +62,7 @@ "eslint": "^8.41.0",

"husky": "^8.0.3",
"lint-staged": "^13.2.2",
"prettier": "^2.8.8",
"tsup": "^6.7.0",
"lint-staged": "^15.2.8",
"prettier": "^3.3.3",
"tsup": "^8.2.4",
"typescript": "~5.0.4"
}
}

@@ -33,3 +33,3 @@ mokuji.js

anchorLinkSymbol: '#',
anchorLinkBefore: true,
anchorLinkPosition: 'before',
anchorLinkClassName: '',

@@ -60,9 +60,11 @@ }

### `anchorLinkBefore`
### `anchorLinkPosition`
(default: `true`)
(default: `'before`)
set position (before/after) the anchor link in headings.
Set the position of the anchor link with 'before' or 'after'.
### `anchorLinkClassName`

@@ -69,0 +71,0 @@

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