Socket
Socket
Sign inDemoInstall

get-canonical-url

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-canonical-url - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

4

dist/get-canonical-url.cjs.js

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

/*! get-canonical-url v1.0.0 | MIT | https://github.com/jakejarvis/get-canonical-url */
/*! get-canonical-url v1.0.1 | MIT | https://github.com/jakejarvis/get-canonical-url */
'use strict';

@@ -12,3 +12,3 @@

function canonicalUrl(options) {
function canonicalUrl(options = {}) {
options = {

@@ -15,0 +15,0 @@ normalize: false,

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

/*! get-canonical-url v1.0.0 | MIT | https://github.com/jakejarvis/get-canonical-url */
/*! get-canonical-url v1.0.1 | MIT | https://github.com/jakejarvis/get-canonical-url */
import normalizeUrl from 'normalize-url';
function canonicalUrl(options) {
function canonicalUrl(options = {}) {
options = {

@@ -6,0 +6,0 @@ normalize: false,

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

/*! get-canonical-url v1.0.0 | MIT | https://github.com/jakejarvis/get-canonical-url */
/*! get-canonical-url v1.0.1 | MIT | https://github.com/jakejarvis/get-canonical-url */
(function (global, factory) {

@@ -302,3 +302,4 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :

function canonicalUrl(options) {
function canonicalUrl() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
options = _objectSpread2({

@@ -305,0 +306,0 @@ normalize: false,

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

/*! get-canonical-url v1.0.0 | MIT | https://github.com/jakejarvis/get-canonical-url */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).canonicalUrl=t()}(this,(function(){"use strict";function e(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,o)}return r}function t(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const r=(e,t)=>t.some((t=>t instanceof RegExp?t.test(e):t===e));function o(e,t){if(t={defaultProtocol:"http:",normalizeProtocol:!0,forceHttp:!1,forceHttps:!1,stripAuthentication:!0,stripHash:!1,stripTextFragment:!0,stripWWW:!0,removeQueryParameters:[/^utm_\w+/i],removeTrailingSlash:!0,removeSingleSlash:!0,removeDirectoryIndex:!1,sortQueryParameters:!0,...t},e=e.trim(),/^data:/i.test(e))return((e,{stripHash:t})=>{const r=/^data:(?<type>[^,]*?),(?<data>[^#]*?)(?:#(?<hash>.*))?$/.exec(e);if(!r)throw new Error(`Invalid URL: ${e}`);let{type:o,data:a,hash:n}=r.groups;const s=o.split(";");n=t?"":n;let i=!1;"base64"===s[s.length-1]&&(s.pop(),i=!0);const c=(s.shift()||"").toLowerCase(),p=[...s.map((e=>{let[t,r=""]=e.split("=").map((e=>e.trim()));return"charset"===t&&(r=r.toLowerCase(),"us-ascii"===r)?"":`${t}${r?`=${r}`:""}`})).filter(Boolean)];return i&&p.push("base64"),(p.length>0||c&&"text/plain"!==c)&&p.unshift(c),`data:${p.join(";")},${i?a.trim():a}${n?`#${n}`:""}`})(e,t);if(/^view-source:/i.test(e))throw new Error("`view-source:` is not supported as it is a non-standard protocol");const o=e.startsWith("//");!o&&/^\.*\//.test(e)||(e=e.replace(/^(?!(?:\w+:)?\/\/)|^\/\//,t.defaultProtocol));const a=new URL(e);if(t.forceHttp&&t.forceHttps)throw new Error("The `forceHttp` and `forceHttps` options cannot be used together");if(t.forceHttp&&"https:"===a.protocol&&(a.protocol="http:"),t.forceHttps&&"http:"===a.protocol&&(a.protocol="https:"),t.stripAuthentication&&(a.username="",a.password=""),t.stripHash?a.hash="":t.stripTextFragment&&(a.hash=a.hash.replace(/#?:~:text.*?$/i,"")),a.pathname){const e=/\b[a-z][a-z\d+\-.]{1,50}:\/\//g;let t=0,r="";for(;;){const o=e.exec(a.pathname);if(!o)break;const n=o[0],s=o.index;r+=a.pathname.slice(t,s).replace(/\/{2,}/g,"/"),r+=n,t=s+n.length}r+=a.pathname.slice(t,a.pathname.length).replace(/\/{2,}/g,"/"),a.pathname=r}if(a.pathname)try{a.pathname=decodeURI(a.pathname)}catch{}if(!0===t.removeDirectoryIndex&&(t.removeDirectoryIndex=[/^index\.[a-z]+$/]),Array.isArray(t.removeDirectoryIndex)&&t.removeDirectoryIndex.length>0){let e=a.pathname.split("/");const o=e[e.length-1];r(o,t.removeDirectoryIndex)&&(e=e.slice(0,-1),a.pathname=e.slice(1).join("/")+"/")}if(a.hostname&&(a.hostname=a.hostname.replace(/\.$/,""),t.stripWWW&&/^www\.(?!www\.)[a-z\-\d]{1,63}\.[a-z.\-\d]{2,63}$/.test(a.hostname)&&(a.hostname=a.hostname.replace(/^www\./,""))),Array.isArray(t.removeQueryParameters))for(const e of[...a.searchParams.keys()])r(e,t.removeQueryParameters)&&a.searchParams.delete(e);!0===t.removeQueryParameters&&(a.search=""),t.sortQueryParameters&&a.searchParams.sort(),t.removeTrailingSlash&&(a.pathname=a.pathname.replace(/\/$/,""));const n=e;return e=a.toString(),t.removeSingleSlash||"/"!==a.pathname||n.endsWith("/")||""!==a.hash||(e=e.replace(/\/$/,"")),(t.removeTrailingSlash||"/"===a.pathname)&&""===a.hash&&t.removeSingleSlash&&(e=e.replace(/\/$/,"")),o&&!t.normalizeProtocol&&(e=e.replace(/^http:\/\//,"//")),t.stripProtocol&&(e=e.replace(/^(?:https?:)?\/\//,"")),e}return function(r){r=function(r){for(var o=1;o<arguments.length;o++){var a=null!=arguments[o]?arguments[o]:{};o%2?e(Object(a),!0).forEach((function(e){t(r,e,a[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(a)):e(Object(a)).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(a,e))}))}return r}({normalize:!1,normalizeOptions:{stripWWW:!1,stripHash:!0,removeQueryParameters:!0,removeTrailingSlash:!1},guess:!1},r);var a=void 0,n=document.head.querySelector("link[rel='canonical']");return null!==n?a=n.href:r.guess&&(a=document.documentURI||document.URL||window.location.href),r.normalize&&(a=o(a,r.normalizeOptions)),a}}));
/*! get-canonical-url v1.0.1 | MIT | https://github.com/jakejarvis/get-canonical-url */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).canonicalUrl=t()}(this,(function(){"use strict";function e(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,o)}return r}function t(t){for(var o=1;o<arguments.length;o++){var a=null!=arguments[o]?arguments[o]:{};o%2?e(Object(a),!0).forEach((function(e){r(t,e,a[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):e(Object(a)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(a,e))}))}return t}function r(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const o=(e,t)=>t.some((t=>t instanceof RegExp?t.test(e):t===e));function a(e,t){if(t={defaultProtocol:"http:",normalizeProtocol:!0,forceHttp:!1,forceHttps:!1,stripAuthentication:!0,stripHash:!1,stripTextFragment:!0,stripWWW:!0,removeQueryParameters:[/^utm_\w+/i],removeTrailingSlash:!0,removeSingleSlash:!0,removeDirectoryIndex:!1,sortQueryParameters:!0,...t},e=e.trim(),/^data:/i.test(e))return((e,{stripHash:t})=>{const r=/^data:(?<type>[^,]*?),(?<data>[^#]*?)(?:#(?<hash>.*))?$/.exec(e);if(!r)throw new Error(`Invalid URL: ${e}`);let{type:o,data:a,hash:n}=r.groups;const s=o.split(";");n=t?"":n;let i=!1;"base64"===s[s.length-1]&&(s.pop(),i=!0);const c=(s.shift()||"").toLowerCase(),p=[...s.map((e=>{let[t,r=""]=e.split("=").map((e=>e.trim()));return"charset"===t&&(r=r.toLowerCase(),"us-ascii"===r)?"":`${t}${r?`=${r}`:""}`})).filter(Boolean)];return i&&p.push("base64"),(p.length>0||c&&"text/plain"!==c)&&p.unshift(c),`data:${p.join(";")},${i?a.trim():a}${n?`#${n}`:""}`})(e,t);if(/^view-source:/i.test(e))throw new Error("`view-source:` is not supported as it is a non-standard protocol");const r=e.startsWith("//");!r&&/^\.*\//.test(e)||(e=e.replace(/^(?!(?:\w+:)?\/\/)|^\/\//,t.defaultProtocol));const a=new URL(e);if(t.forceHttp&&t.forceHttps)throw new Error("The `forceHttp` and `forceHttps` options cannot be used together");if(t.forceHttp&&"https:"===a.protocol&&(a.protocol="http:"),t.forceHttps&&"http:"===a.protocol&&(a.protocol="https:"),t.stripAuthentication&&(a.username="",a.password=""),t.stripHash?a.hash="":t.stripTextFragment&&(a.hash=a.hash.replace(/#?:~:text.*?$/i,"")),a.pathname){const e=/\b[a-z][a-z\d+\-.]{1,50}:\/\//g;let t=0,r="";for(;;){const o=e.exec(a.pathname);if(!o)break;const n=o[0],s=o.index;r+=a.pathname.slice(t,s).replace(/\/{2,}/g,"/"),r+=n,t=s+n.length}r+=a.pathname.slice(t,a.pathname.length).replace(/\/{2,}/g,"/"),a.pathname=r}if(a.pathname)try{a.pathname=decodeURI(a.pathname)}catch{}if(!0===t.removeDirectoryIndex&&(t.removeDirectoryIndex=[/^index\.[a-z]+$/]),Array.isArray(t.removeDirectoryIndex)&&t.removeDirectoryIndex.length>0){let e=a.pathname.split("/");const r=e[e.length-1];o(r,t.removeDirectoryIndex)&&(e=e.slice(0,-1),a.pathname=e.slice(1).join("/")+"/")}if(a.hostname&&(a.hostname=a.hostname.replace(/\.$/,""),t.stripWWW&&/^www\.(?!www\.)[a-z\-\d]{1,63}\.[a-z.\-\d]{2,63}$/.test(a.hostname)&&(a.hostname=a.hostname.replace(/^www\./,""))),Array.isArray(t.removeQueryParameters))for(const e of[...a.searchParams.keys()])o(e,t.removeQueryParameters)&&a.searchParams.delete(e);!0===t.removeQueryParameters&&(a.search=""),t.sortQueryParameters&&a.searchParams.sort(),t.removeTrailingSlash&&(a.pathname=a.pathname.replace(/\/$/,""));const n=e;return e=a.toString(),t.removeSingleSlash||"/"!==a.pathname||n.endsWith("/")||""!==a.hash||(e=e.replace(/\/$/,"")),(t.removeTrailingSlash||"/"===a.pathname)&&""===a.hash&&t.removeSingleSlash&&(e=e.replace(/\/$/,"")),r&&!t.normalizeProtocol&&(e=e.replace(/^http:\/\//,"//")),t.stripProtocol&&(e=e.replace(/^(?:https?:)?\/\//,"")),e}return function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e=t({normalize:!1,normalizeOptions:{stripWWW:!1,stripHash:!0,removeQueryParameters:!0,removeTrailingSlash:!1},guess:!1},e);var r=void 0,o=document.head.querySelector("link[rel='canonical']");return null!==o?r=o.href:e.guess&&(r=document.documentURI||document.URL||window.location.href),e.normalize&&(r=a(r,e.normalizeOptions)),r}}));
{
"name": "get-canonical-url",
"version": "1.0.0",
"version": "1.0.1",
"description": "🔗 Determines the current page's canonical URL and optionally normalizes it for consistency.",

@@ -40,5 +40,5 @@ "license": "MIT",

"devDependencies": {
"@babel/core": "^7.15.5",
"@babel/eslint-parser": "^7.15.7",
"@babel/preset-env": "^7.15.6",
"@babel/core": "^7.15.8",
"@babel/eslint-parser": "^7.15.8",
"@babel/preset-env": "^7.15.8",
"@jakejarvis/eslint-config": "*",

@@ -55,5 +55,5 @@ "@rollup/plugin-babel": "^5.3.0",

"eslint-plugin-import": "~2.24.2",
"jsdom": "^17.0.0",
"jsdom": "^18.0.0",
"mocha": "^9.1.2",
"rollup": "^2.57.0",
"rollup": "^2.58.0",
"rollup-plugin-copy": "^3.4.0",

@@ -60,0 +60,0 @@ "rollup-plugin-delete": "^2.0.0",

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