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

mokuji.js

Package Overview
Dependencies
Maintainers
1
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 3.0.0 to 3.0.1

2

dist/mokuji.modern.js

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

const e=(e,t)=>{for(;e;){if(e===t)return!0;e=e.parentNode}return!1},t=e=>{const t=e.match(/\d/g).join("");return Number(t)};export default class{constructor(e,t){return this.storeIds=[],this.options=Object.assign({anchorType:!0,anchorLink:!1,anchorLinkSymbol:"#",anchorLinkBefore:!0,anchorLinkClassName:"",anchorContainerTagName:"ol"},t),this.headings=(e=>e.querySelectorAll("h1, h2, h3, h4, h5, h6"))(e),this.render()}render(){const e=this.generateMokuji();if(this.options.anchorLink){const t=null==e?void 0:e.querySelectorAll("a");this.renderAnchorLink(t)}return e}generateMokuji(){let e=document.createElement(this.options.anchorContainerTagName);this.generateHierarchyList(e);const t=e.getElementsByTagName("a");return this.removeDuplicateIds(t),e}generateHierarchyList(n){let o=0;const r=document.createElement("li"),s=document.createElement("a");for(let i=0;i<this.headings.length;i++){const a=this.headings[i],c=t(a.tagName);if(0!==o&&o<c){const e=document.createElement("ol");n.lastChild.appendChild(e),n=e}else if(0!==o&&o>c)for(let t=0;t<o-c;t++)e(n,n.parentNode)&&(n=n.parentNode.parentNode);const h=this.censorshipId(a.textContent);a.id=this.setAnchor(h,this.options.anchorType);const l=s.cloneNode(!1);l.href="#"+a.id,l.textContent=a.textContent;const d=r.cloneNode(!1);d.appendChild(l),n.appendChild(d),o=c}}censorshipId(e){let t=e||"",n=1;for(;n<=this.headings.length;){const e=1===n?t:`${t}_${n}`;if(-1===this.storeIds.indexOf(e)){t=e,this.storeIds.push(t);break}n++}return t}setAnchor(e,t){let n=(e=>e.replace(/\s+/g,"_"))(e);return n=n.replace(/\&+/g,"").replace(/\&amp;+/g,""),!0===t&&(n=(e=>(e=encodeURIComponent(e)).replace(/\%+/g,"."))(n)),n}renderAnchorLink(e){if(!e)return;const t=document.createElement("a");t.classList.add(this.options.anchorLinkClassName);for(let n=0;n<e.length;n++){const o=e[n].hash,r=document.querySelector(`[id="${o.replace("#","")}"]`);if(!r)continue;const s=t.cloneNode(!1);s.setAttribute("href",o),s.textContent=this.options.anchorLinkSymbol,this.options.anchorLinkBefore?r.insertBefore(s,r.firstChild):r.appendChild(s)}}removeDuplicateIds(e){for(let t=0;t<e.length;t++){const n=e[t].hash,o=document.querySelectorAll(`[id="${e[t].innerText}"]`);if(1===o.length)continue;let r=0;for(const t of Array.from(o)){const o=`${t.id}-${r}`;for(const t of Array.from(e))if(t.hash===n){t.href="#"+o;break}t.id=o,r++}}}}
const e=(e,t)=>{for(;e;){if(e===t)return!0;e=e.parentNode}return!1},t=e=>{const t=e.match(/\d/g).join("");return Number(t)};export default class{constructor(e,t){return this.storeIds=[],this.options=Object.assign({anchorType:!0,anchorLink:!1,anchorLinkSymbol:"#",anchorLinkBefore:!0,anchorLinkClassName:"",anchorContainerTagName:"ol"},t),this.headings=(e=>e.querySelectorAll("h1, h2, h3, h4, h5, h6"))(e),this.render()}render(){const e=this.generateMokuji();if(this.options.anchorLink){const t=null==e?void 0:e.querySelectorAll("a");this.renderAnchorLink(t)}return e}generateMokuji(){let e=document.createElement(this.options.anchorContainerTagName);this.generateHierarchyList(e);const t=e.getElementsByTagName("a");return this.removeDuplicateIds(t),e}generateHierarchyList(n){let o=0;const r=document.createElement("li"),s=document.createElement("a");for(let i=0;i<this.headings.length;i++){const a=this.headings[i],c=t(a.tagName);if(0!==o&&o<c){const e=document.createElement("ol");n.lastChild.appendChild(e),n=e}else if(0!==o&&o>c)for(let t=0;t<o-c;t++)e(n,n.parentNode)&&(n=n.parentNode.parentNode);const h=this.censorshipId(a.textContent);a.id=this.setAnchor(h,this.options.anchorType);const l=s.cloneNode(!1);l.href="#"+a.id,l.textContent=a.textContent;const d=r.cloneNode(!1);d.appendChild(l),n.appendChild(d),o=c}}censorshipId(e){let t=e||"",n=1;for(;n<=this.headings.length;){const e=1===n?t:`${t}_${n}`;if(-1===this.storeIds.indexOf(e)){t=e,this.storeIds.push(t);break}n++}return t}setAnchor(e,t){let n=(e=>e.replace(/\s+/g,"_"))(e);return n=n.replace(/\&+/g,"").replace(/\&amp;+/g,""),!0===t&&(n=(e=>(e=encodeURIComponent(e)).replace(/\%+/g,"."))(n)),n}renderAnchorLink(e){if(!e)return;const t=document.createElement("a");t.classList.add(this.options.anchorLinkClassName);for(let n=0;n<e.length;n++){const o=e[n].hash,r=document.querySelector(`[id="${o.replace("#","")}"]`);if(!r)continue;const s=t.cloneNode(!1);s.setAttribute("href",o),s.textContent=this.options.anchorLinkSymbol,this.options.anchorLinkBefore?r.insertBefore(s,r.firstChild):r.appendChild(s)}}removeDuplicateIds(e){for(let t=0;t<e.length;t++){const n=e[t].hash,o=document.querySelectorAll(`[id="${e[t].innerText}"]`);if(1===o.length)continue;let r=0;for(const t of Array.from(o)){const o=`${t.id}-${r}`;for(const t of Array.from(e))if(t.hash===n){t.href=`#${o}`;break}t.id=o,r++}}}}
//# sourceMappingURL=mokuji.modern.js.map

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

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).mokujiJs=n()}(this,function(){var e=function(e,n){for(;e;){if(e===n)return!0;e=e.parentNode}return!1},n=function(e){var n=e.match(/\d/g).join("");return Number(n)};return function(){function r(e,n){return this.storeIds=[],this.options=Object.assign({anchorType:!0,anchorLink:!1,anchorLinkSymbol:"#",anchorLinkBefore:!0,anchorLinkClassName:"",anchorContainerTagName:"ol"},n),this.headings=function(e){return e.querySelectorAll("h1, h2, h3, h4, h5, h6")}(e),this.render()}var t=r.prototype;return t.render=function(){var e=this.generateMokuji();if(this.options.anchorLink){var n=null==e?void 0:e.querySelectorAll("a");this.renderAnchorLink(n)}return e},t.generateMokuji=function(){var e=document.createElement(this.options.anchorContainerTagName);this.generateHierarchyList(e);var n=e.getElementsByTagName("a");return this.removeDuplicateIds(n),e},t.generateHierarchyList=function(r){for(var t=0,o=document.createElement("li"),i=document.createElement("a"),a=0;a<this.headings.length;a++){var h=this.headings[a],s=n(h.tagName);if(0!==t&&t<s){var c=document.createElement("ol");r.lastChild.appendChild(c),r=c}else if(0!==t&&t>s)for(var d=0;d<t-s;d++)e(r,r.parentNode)&&(r=r.parentNode.parentNode);var l=this.censorshipId(h.textContent);h.id=this.setAnchor(l,this.options.anchorType);var u=i.cloneNode(!1);u.href="#"+h.id,u.textContent=h.textContent;var f=o.cloneNode(!1);f.appendChild(u),r.appendChild(f),t=s}},t.censorshipId=function(e){for(var n=e||"",r=1;r<=this.headings.length;){var t=1===r?n:n+"_"+r;if(-1===this.storeIds.indexOf(t)){this.storeIds.push(n=t);break}r++}return n},t.setAnchor=function(e,n){var r=function(e){return e.replace(/\s+/g,"_")}(e);return r=r.replace(/\&+/g,"").replace(/\&amp;+/g,""),!0===n&&(r=function(e){return(e=encodeURIComponent(e)).replace(/\%+/g,".")}(r)),r},t.renderAnchorLink=function(e){if(e){var n=document.createElement("a");n.classList.add(this.options.anchorLinkClassName);for(var r=0;r<e.length;r++){var t=e[r].hash,o=document.querySelector('[id="'+t.replace("#","")+'"]');if(o){var i=n.cloneNode(!1);i.setAttribute("href",t),i.textContent=this.options.anchorLinkSymbol,this.options.anchorLinkBefore?o.insertBefore(i,o.firstChild):o.appendChild(i)}}}},t.removeDuplicateIds=function(e){for(var n=0;n<e.length;n++){var r=e[n].hash,t=document.querySelectorAll('[id="'+e[n].innerText+'"]');if(1!==t.length)for(var o=0,i=0,a=Array.from(t);i<a.length;i++){for(var h=a[i],s=h.id+"-"+o,c=0,d=Array.from(e);c<d.length;c++){var l=d[c];if(l.hash===r){l.href="#"+s;break}}h.id=s,o++}}},r}()});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e||self).mokujiJs=n()}(this,function(){var e=function(e,n){for(;e;){if(e===n)return!0;e=e.parentNode}return!1},n=function(e){var n=e.match(/\d/g).join("");return Number(n)};return function(){function t(e,n){return this.storeIds=[],this.options=Object.assign({anchorType:!0,anchorLink:!1,anchorLinkSymbol:"#",anchorLinkBefore:!0,anchorLinkClassName:"",anchorContainerTagName:"ol"},n),this.headings=function(e){return e.querySelectorAll("h1, h2, h3, h4, h5, h6")}(e),this.render()}var r=t.prototype;return r.render=function(){var e=this.generateMokuji();if(this.options.anchorLink){var n=null==e?void 0:e.querySelectorAll("a");this.renderAnchorLink(n)}return e},r.generateMokuji=function(){var e=document.createElement(this.options.anchorContainerTagName);this.generateHierarchyList(e);var n=e.getElementsByTagName("a");return this.removeDuplicateIds(n),e},r.generateHierarchyList=function(t){for(var r=0,o=document.createElement("li"),i=document.createElement("a"),a=0;a<this.headings.length;a++){var h=this.headings[a],s=n(h.tagName);if(0!==r&&r<s){var c=document.createElement("ol");t.lastChild.appendChild(c),t=c}else if(0!==r&&r>s)for(var d=0;d<r-s;d++)e(t,t.parentNode)&&(t=t.parentNode.parentNode);var l=this.censorshipId(h.textContent);h.id=this.setAnchor(l,this.options.anchorType);var f=i.cloneNode(!1);f.href="#"+h.id,f.textContent=h.textContent;var u=o.cloneNode(!1);u.appendChild(f),t.appendChild(u),r=s}},r.censorshipId=function(e){for(var n=e||"",t=1;t<=this.headings.length;){var r=1===t?n:n+"_"+t;if(-1===this.storeIds.indexOf(r)){this.storeIds.push(n=r);break}t++}return n},r.setAnchor=function(e,n){var t=function(e){return e.replace(/\s+/g,"_")}(e);return t=t.replace(/\&+/g,"").replace(/\&amp;+/g,""),!0===n&&(t=function(e){return(e=encodeURIComponent(e)).replace(/\%+/g,".")}(t)),t},r.renderAnchorLink=function(e){if(e){var n=document.createElement("a");n.classList.add(this.options.anchorLinkClassName);for(var t=0;t<e.length;t++){var r=e[t].hash,o=document.querySelector('[id="'+r.replace("#","")+'"]');if(o){var i=n.cloneNode(!1);i.setAttribute("href",r),i.textContent=this.options.anchorLinkSymbol,this.options.anchorLinkBefore?o.insertBefore(i,o.firstChild):o.appendChild(i)}}}},r.removeDuplicateIds=function(e){for(var n=0;n<e.length;n++){var t=e[n].hash,r=document.querySelectorAll('[id="'+e[n].innerText+'"]');if(1!==r.length)for(var o=0,i=0,a=Array.from(r);i<a.length;i++){for(var h=a[i],s=h.id+"-"+o,c=0,d=Array.from(e);c<d.length;c++){var l=d[c];if(l.hash===t){l.href="#"+s;break}}h.id=s,o++}}},t}()});
//# sourceMappingURL=mokuji.umd.js.map
{
"name": "mokuji.js",
"version": "3.0.0",
"version": "3.0.1",
"description": "A table of content JavaScript Library",

@@ -54,12 +54,12 @@ "scripts": {

"devDependencies": {
"@babel/plugin-proposal-optional-chaining": "^7.10.4",
"@babel/plugin-proposal-optional-chaining": "^7.13.12",
"@hiro0218/prettier-config": "^1.0.2",
"@types/node": "~14.0.18",
"@types/node": "~14.14.41",
"cross-env": "^5.2.0",
"husky": "^4.2.5",
"lint-staged": "^10.2.11",
"microbundle": "^0.12.2",
"microbundle": "^0.13.0",
"prettier": "^2.0.5",
"rimraf": "^3.0.2",
"typescript": "~3.9.6"
"typescript": "~4.2.4"
},

@@ -66,0 +66,0 @@ "husky": {

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