New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

anchor-js

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anchor-js - npm Package Compare versions

Comparing version 3.2.2 to 4.0.0

banner.js

20

anchor.js

@@ -1,7 +0,1 @@

/**
* AnchorJS - v3.2.2 - 2016-10-05
* https://github.com/bryanbraun/anchorjs
* Copyright (c) 2016 Bryan Braun; Licensed MIT
*/
/* eslint-env amd, node */

@@ -91,3 +85,3 @@

if (!selector) {
selector = 'h1, h2, h3, h4, h5, h6';
selector = 'h2, h3, h4, h5, h6';
}

@@ -98,3 +92,3 @@

if (elements.length === 0) {
return false;
return this;
}

@@ -118,2 +112,4 @@

elementID = elements[i].getAttribute('id');
} else if (elements[i].hasAttribute('data-anchor-id')) {
elementID = elements[i].getAttribute('data-anchor-id');
} else {

@@ -189,3 +185,3 @@ tidyText = this.urlify(elements[i].textContent);

* @param {String|Array|Nodelist} selector - A CSS selector string targeting elements with anchor links,
* OR a nodeList / array containing the DOM elements.
* OR a nodeList / array containing the DOM elements.
* @return {this} - The AnchorJS object

@@ -230,4 +226,4 @@ */

this.urlify = function(text) {
// Regex for finding the nonsafe URL characters (many need escaping): & +$,:;=?@"#{}|^~[`%!']./()*\
var nonsafeChars = /[& +$,:;=?@"#{}|^~[`%!'\]\.\/\(\)\*\\]/g,
// Regex for finding the nonsafe URL characters (many need escaping): & +$,:;=?@"#{}|^~[`%!'<>]./()*\
var nonsafeChars = /[& +$,:;=?@"#{}|^~[`%!'<>\]\.\/\(\)\*\\]/g,
urlText;

@@ -271,3 +267,3 @@

* @param {String|Array|Nodelist} input - A CSS selector string targeting elements with anchor links,
* OR a nodeList / array containing the DOM elements.
* OR a nodeList / array containing the DOM elements.
* @return {Array} - An array containing the elements we want.

@@ -274,0 +270,0 @@ */

6

anchor.min.js
/**
* AnchorJS - v3.2.2 - 2016-10-05
* AnchorJS - v4.0.0 - 2017-06-02
* https://github.com/bryanbraun/anchorjs
* Copyright (c) 2016 Bryan Braun; Licensed MIT
* Copyright (c) 2017 Bryan Braun; Licensed MIT
*/
!function(A,e){"use strict";"function"==typeof define&&define.amd?define([],e):"object"==typeof module&&module.exports?module.exports=e():(A.AnchorJS=e(),A.anchors=new A.AnchorJS)}(this,function(){"use strict";function A(A){function e(A){A.icon=A.hasOwnProperty("icon")?A.icon:"",A.visible=A.hasOwnProperty("visible")?A.visible:"hover",A.placement=A.hasOwnProperty("placement")?A.placement:"right",A.class=A.hasOwnProperty("class")?A.class:"",A.truncate=A.hasOwnProperty("truncate")?Math.floor(A.truncate):64}function t(A){var e;if("string"==typeof A||A instanceof String)e=[].slice.call(document.querySelectorAll(A));else{if(!(Array.isArray(A)||A instanceof NodeList))throw new Error("The selector provided to AnchorJS was invalid.");e=[].slice.call(A)}return e}function n(){if(null===document.head.querySelector("style.anchorjs")){var A,e=document.createElement("style"),t=" .anchorjs-link { opacity: 0; text-decoration: none; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }",n=" *:hover > .anchorjs-link, .anchorjs-link:focus { opacity: 1; }",i=' @font-face { font-family: "anchorjs-icons"; src: url(data:n/a;base64,AAEAAAALAIAAAwAwT1MvMg8yG2cAAAE4AAAAYGNtYXDp3gC3AAABpAAAAExnYXNwAAAAEAAAA9wAAAAIZ2x5ZlQCcfwAAAH4AAABCGhlYWQHFvHyAAAAvAAAADZoaGVhBnACFwAAAPQAAAAkaG10eASAADEAAAGYAAAADGxvY2EACACEAAAB8AAAAAhtYXhwAAYAVwAAARgAAAAgbmFtZQGOH9cAAAMAAAAAunBvc3QAAwAAAAADvAAAACAAAQAAAAEAAHzE2p9fDzz1AAkEAAAAAADRecUWAAAAANQA6R8AAAAAAoACwAAAAAgAAgAAAAAAAAABAAADwP/AAAACgAAA/9MCrQABAAAAAAAAAAAAAAAAAAAAAwABAAAAAwBVAAIAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAMCQAGQAAUAAAKZAswAAACPApkCzAAAAesAMwEJAAAAAAAAAAAAAAAAAAAAARAAAAAAAAAAAAAAAAAAAAAAQAAg//0DwP/AAEADwABAAAAAAQAAAAAAAAAAAAAAIAAAAAAAAAIAAAACgAAxAAAAAwAAAAMAAAAcAAEAAwAAABwAAwABAAAAHAAEADAAAAAIAAgAAgAAACDpy//9//8AAAAg6cv//f///+EWNwADAAEAAAAAAAAAAAAAAAAACACEAAEAAAAAAAAAAAAAAAAxAAACAAQARAKAAsAAKwBUAAABIiYnJjQ3NzY2MzIWFxYUBwcGIicmNDc3NjQnJiYjIgYHBwYUFxYUBwYGIwciJicmNDc3NjIXFhQHBwYUFxYWMzI2Nzc2NCcmNDc2MhcWFAcHBgYjARQGDAUtLXoWOR8fORYtLTgKGwoKCjgaGg0gEhIgDXoaGgkJBQwHdR85Fi0tOAobCgoKOBoaDSASEiANehoaCQkKGwotLXoWOR8BMwUFLYEuehYXFxYugC44CQkKGwo4GkoaDQ0NDXoaShoKGwoFBe8XFi6ALjgJCQobCjgaShoNDQ0NehpKGgobCgoKLYEuehYXAAAADACWAAEAAAAAAAEACAAAAAEAAAAAAAIAAwAIAAEAAAAAAAMACAAAAAEAAAAAAAQACAAAAAEAAAAAAAUAAQALAAEAAAAAAAYACAAAAAMAAQQJAAEAEAAMAAMAAQQJAAIABgAcAAMAAQQJAAMAEAAMAAMAAQQJAAQAEAAMAAMAAQQJAAUAAgAiAAMAAQQJAAYAEAAMYW5jaG9yanM0MDBAAGEAbgBjAGgAbwByAGoAcwA0ADAAMABAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAH//wAP) format("truetype"); }',o=" [data-anchorjs-icon]::after { content: attr(data-anchorjs-icon); }";e.className="anchorjs",e.appendChild(document.createTextNode("")),A=document.head.querySelector('[rel="stylesheet"], style'),void 0===A?document.head.appendChild(e):document.head.insertBefore(e,A),e.sheet.insertRule(t,e.sheet.cssRules.length),e.sheet.insertRule(n,e.sheet.cssRules.length),e.sheet.insertRule(o,e.sheet.cssRules.length),e.sheet.insertRule(i,e.sheet.cssRules.length)}}this.options=A||{},this.elements=[],e(this.options),this.isTouchDevice=function(){return!!("ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch)},this.add=function(A){var i,o,s,c,r,a,h,l,u,d,f,p,w=[];if(e(this.options),p=this.options.visible,"touch"===p&&(p=this.isTouchDevice()?"always":"hover"),A||(A="h1, h2, h3, h4, h5, h6"),i=t(A),0===i.length)return!1;for(n(),o=document.querySelectorAll("[id]"),s=[].map.call(o,function(A){return A.id}),r=0;r<i.length;r++)if(this.hasAnchorJSLink(i[r]))w.push(r);else{if(i[r].hasAttribute("id"))c=i[r].getAttribute("id");else{l=this.urlify(i[r].textContent),u=l,h=0;do void 0!==a&&(u=l+"-"+h),a=s.indexOf(u),h+=1;while(-1!==a);a=void 0,s.push(u),i[r].setAttribute("id",u),c=u}d=c.replace(/-/g," "),f=document.createElement("a"),f.className="anchorjs-link "+this.options.class,f.href="#"+c,f.setAttribute("aria-label","Anchor link for: "+d),f.setAttribute("data-anchorjs-icon",this.options.icon),"always"===p&&(f.style.opacity="1"),""===this.options.icon&&(f.style.font="1em/1 anchorjs-icons","left"===this.options.placement&&(f.style.lineHeight="inherit")),"left"===this.options.placement?(f.style.position="absolute",f.style.marginLeft="-1em",f.style.paddingRight="0.5em",i[r].insertBefore(f,i[r].firstChild)):(f.style.paddingLeft="0.375em",i[r].appendChild(f))}for(r=0;r<w.length;r++)i.splice(w[r]-r,1);return this.elements=this.elements.concat(i),this},this.remove=function(A){for(var e,n,i=t(A),o=0;o<i.length;o++)n=i[o].querySelector(".anchorjs-link"),n&&(e=this.elements.indexOf(i[o]),-1!==e&&this.elements.splice(e,1),i[o].removeChild(n));return this},this.removeAll=function(){this.remove(this.elements)},this.urlify=function(A){var t,n=/[& +$,:;=?@"#{}|^~[`%!'\]\.\/\(\)\*\\]/g;return this.options.truncate||e(this.options),t=A.trim().replace(/\'/gi,"").replace(n,"-").replace(/-{2,}/g,"-").substring(0,this.options.truncate).replace(/^-+|-+$/gm,"").toLowerCase()},this.hasAnchorJSLink=function(A){var e=A.firstChild&&(" "+A.firstChild.className+" ").indexOf(" anchorjs-link ")>-1,t=A.lastChild&&(" "+A.lastChild.className+" ").indexOf(" anchorjs-link ")>-1;return e||t||!1}}return A});
!function(A,e){"use strict";"function"==typeof define&&define.amd?define([],e):"object"==typeof module&&module.exports?module.exports=e():(A.AnchorJS=e(),A.anchors=new A.AnchorJS)}(this,function(){"use strict";function A(A){function e(A){A.icon=A.hasOwnProperty("icon")?A.icon:"",A.visible=A.hasOwnProperty("visible")?A.visible:"hover",A.placement=A.hasOwnProperty("placement")?A.placement:"right",A.class=A.hasOwnProperty("class")?A.class:"",A.truncate=A.hasOwnProperty("truncate")?Math.floor(A.truncate):64}function t(A){var e;if("string"==typeof A||A instanceof String)e=[].slice.call(document.querySelectorAll(A));else{if(!(Array.isArray(A)||A instanceof NodeList))throw new Error("The selector provided to AnchorJS was invalid.");e=[].slice.call(A)}return e}function n(){if(null===document.head.querySelector("style.anchorjs")){var A,e=document.createElement("style");e.className="anchorjs",e.appendChild(document.createTextNode("")),void 0===(A=document.head.querySelector('[rel="stylesheet"], style'))?document.head.appendChild(e):document.head.insertBefore(e,A),e.sheet.insertRule(" .anchorjs-link { opacity: 0; text-decoration: none; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }",e.sheet.cssRules.length),e.sheet.insertRule(" *:hover > .anchorjs-link, .anchorjs-link:focus { opacity: 1; }",e.sheet.cssRules.length),e.sheet.insertRule(" [data-anchorjs-icon]::after { content: attr(data-anchorjs-icon); }",e.sheet.cssRules.length),e.sheet.insertRule(' @font-face { font-family: "anchorjs-icons"; src: url(data:n/a;base64,AAEAAAALAIAAAwAwT1MvMg8yG2cAAAE4AAAAYGNtYXDp3gC3AAABpAAAAExnYXNwAAAAEAAAA9wAAAAIZ2x5ZlQC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QQJAAQAEAAMAAMAAQQJAAUAAgAiAAMAAQQJAAYAEAAMYW5jaG9yanM0MDBAAGEAbgBjAGgAbwByAGoAcwA0ADAAMABAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAH//wAP) format("truetype"); }',e.sheet.cssRules.length)}}this.options=A||{},this.elements=[],e(this.options),this.isTouchDevice=function(){return!!("ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch)},this.add=function(A){var i,o,s,c,r,a,h,l,u,d,f,g,p=[];if(e(this.options),"touch"===(g=this.options.visible)&&(g=this.isTouchDevice()?"always":"hover"),A||(A="h2, h3, h4, h5, h6"),0===(i=t(A)).length)return this;for(n(),o=document.querySelectorAll("[id]"),s=[].map.call(o,function(A){return A.id}),r=0;r<i.length;r++)if(this.hasAnchorJSLink(i[r]))p.push(r);else{if(i[r].hasAttribute("id"))c=i[r].getAttribute("id");else if(i[r].hasAttribute("data-anchor-id"))c=i[r].getAttribute("data-anchor-id");else{u=l=this.urlify(i[r].textContent),h=0;do{void 0!==a&&(u=l+"-"+h),a=s.indexOf(u),h+=1}while(-1!==a);a=void 0,s.push(u),i[r].setAttribute("id",u),c=u}d=c.replace(/-/g," "),(f=document.createElement("a")).className="anchorjs-link "+this.options.class,f.href="#"+c,f.setAttribute("aria-label","Anchor link for: "+d),f.setAttribute("data-anchorjs-icon",this.options.icon),"always"===g&&(f.style.opacity="1"),""===this.options.icon&&(f.style.font="1em/1 anchorjs-icons","left"===this.options.placement&&(f.style.lineHeight="inherit")),"left"===this.options.placement?(f.style.position="absolute",f.style.marginLeft="-1em",f.style.paddingRight="0.5em",i[r].insertBefore(f,i[r].firstChild)):(f.style.paddingLeft="0.375em",i[r].appendChild(f))}for(r=0;r<p.length;r++)i.splice(p[r]-r,1);return this.elements=this.elements.concat(i),this},this.remove=function(A){for(var e,n,i=t(A),o=0;o<i.length;o++)(n=i[o].querySelector(".anchorjs-link"))&&(-1!==(e=this.elements.indexOf(i[o]))&&this.elements.splice(e,1),i[o].removeChild(n));return this},this.removeAll=function(){this.remove(this.elements)},this.urlify=function(A){var t=/[& +$,:;=?@"#{}|^~[`%!'<>\]\.\/\(\)\*\\]/g;return this.options.truncate||e(this.options),A.trim().replace(/\'/gi,"").replace(t,"-").replace(/-{2,}/g,"-").substring(0,this.options.truncate).replace(/^-+|-+$/gm,"").toLowerCase()},this.hasAnchorJSLink=function(A){var e=A.firstChild&&(" "+A.firstChild.className+" ").indexOf(" anchorjs-link ")>-1,t=A.lastChild&&(" "+A.lastChild.className+" ").indexOf(" anchorjs-link ")>-1;return e||t||!1}}return A});
{
"name": "anchor-js",
"version": "3.2.2",
"version": "4.0.0",
"authors": [

@@ -5,0 +5,0 @@ "Bryan Braun"

{
"name": "anchor-js",
"version": "3.2.2",
"version": "4.0.0",
"main": "anchor.js",

@@ -19,15 +19,17 @@ "author": "bryanbraun (https://github.com/bryanbraun)",

"jasmine": "karma start test/config.js --single-run",
"release": "uglifyjs anchor.js --compress --mangle --screw-ie8 --comments \"/Copyright/\" -o anchor.min.js",
"release": "npm run uglify && npm run add-banner && cp anchor.js docs/anchor.js",
"add-banner": "node banner.js",
"uglify": "uglifyjs anchor.js --compress --mangle --screw-ie8 --comments \"/Copyright/\" -o anchor.min.js",
"test": "npm run lint && npm run jasmine"
},
"devDependencies": {
"eslint": "~3.7.1",
"jasmine-core": "~2.5.2",
"karma": "~1.3.0",
"eslint": "~3.19.0",
"jasmine-core": "~2.6.2",
"karma": "~1.7.0",
"karma-cli": "~1.0.1",
"karma-jasmine": "~1.0.2",
"karma-jasmine": "~1.1.0",
"karma-phantomjs-launcher": "~1.0.2",
"phantomjs-prebuilt": "~2.1.13",
"uglify-js": "~2.7.3"
"phantomjs-prebuilt": "~2.1.14",
"uglify-js": "~3.0.15"
}
}

@@ -7,3 +7,3 @@ # AnchorJS [![Build Status](https://img.shields.io/travis/bryanbraun/anchorjs/master.svg?style=flat)](https://travis-ci.org/bryanbraun/anchorjs)

![Anchoring links](http://bryanbraun.com/sites/default/files/anchoring-links_0.png)
![Anchoring links](docs/img/anchoring-links.png)

@@ -34,3 +34,3 @@ ## Installation

##Usage
## Usage
See **[the Documentation](http://bryanbraun.github.io/anchorjs#basic-usage)** for detailed instructions.

@@ -37,0 +37,0 @@

@@ -31,9 +31,39 @@ /* eslint-env jasmine */

it('should add an anchor link to an h1 by default', function() {
it('should not add an anchor link to an h1 by default', function() {
var anchorLink;
anchors.add();
anchorLink = document.querySelector('h1 > .anchorjs-link');
expect(anchorLink).not.toBe(null);
expect(anchorLink).toBe(null);
});
it('should add an anchor link to an h2-h6 by default', function() {
var anchorLink2, anchorLink3, anchorLink4, anchorLink5, anchorLink6,
el2 = appendElementToBody('h2', 'Example Title'),
el3 = appendElementToBody('h3', 'Example Title'),
el4 = appendElementToBody('h4', 'Example Title'),
el5 = appendElementToBody('h5', 'Example Title'),
el6 = appendElementToBody('h6', 'Example Title');
anchors.add();
anchorLink2 = document.querySelector('h2 > .anchorjs-link');
anchorLink3 = document.querySelector('h3 > .anchorjs-link');
anchorLink4 = document.querySelector('h4 > .anchorjs-link');
anchorLink5 = document.querySelector('h5 > .anchorjs-link');
anchorLink6 = document.querySelector('h6 > .anchorjs-link');
expect(anchorLink2).not.toBe(null);
expect(anchorLink3).not.toBe(null);
expect(anchorLink4).not.toBe(null);
expect(anchorLink5).not.toBe(null);
expect(anchorLink6).not.toBe(null);
document.body.removeChild(el2);
document.body.removeChild(el3);
document.body.removeChild(el4);
document.body.removeChild(el5);
document.body.removeChild(el6);
});
it('add/remove accepts a string (selector), nodelist, or array of els', function() {

@@ -98,3 +128,3 @@ var el2 = appendElementToBody('h2', 'Example Title');

anchorObj = new AnchorJS();
anchorObj.add();
anchorObj.add('h1');
anchorLink = document.querySelector('h1 > .anchorjs-link');

@@ -117,3 +147,3 @@ expect(anchorLink).not.toBe(null);

anchorLinkAfter;
anchors.add();
anchors.add('h1');
anchorLinkBefore = document.querySelector('h1 > .anchorjs-link');

@@ -175,2 +205,16 @@ expect(anchorLinkBefore).not.toBe(null);

it('should leave existing data-anchor-IDs in place without injecting a superfluous id, and use them as the href for anchors.', function() {
var href,
dataId,
id;
document.getElementsByTagName('h1')[0].setAttribute('data-anchor-id', 'test-id');
anchors.add('h1');
href = document.querySelector('.anchorjs-link').getAttribute('href');
dataId = document.getElementsByTagName('h1')[0].getAttribute('data-anchor-id');
id = document.getElementsByTagName('h1')[0].getAttribute('id');
expect(href).toEqual('#test-id');
expect(dataId).toEqual('test-id');
expect(id).toBe(null);
});
it('should increment new IDs if multiple IDs are found on a page.', function() {

@@ -220,2 +264,3 @@ var el2 = appendElementToBody('h2', 'Example Title'),

anchorLinkList2;
anchors.add('h1');

@@ -291,3 +336,4 @@

text2Before = 'one@two"three#four{five}six|seven^eight~nine[ten',
text3Before = 'one`two%three!four]five.six/seven(eight)nine*ten\\',
text3Before = 'one`two%three!four]five.six/seven(eight)nine*ten',
text4Before = 'one\\two<three>four-five-six-seven-eight-nine-ten',
after = 'one-two-three-four-five-six-seven-eight-nine-ten';

@@ -298,2 +344,3 @@

expect(anchors.urlify(text3Before)).toEqual(after);
expect(anchors.urlify(text4Before)).toEqual(after);
});

@@ -300,0 +347,0 @@

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