Socket
Socket
Sign inDemoInstall

get-canonical-url

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    get-canonical-url

🔗 Determines the current page's canonical URL and optionally normalizes it for consistency.


Version published
Weekly downloads
21
increased by133.33%
Maintainers
1
Install size
60.1 kB
Created
Weekly downloads
 

Readme

Source

🔗 get-canonical-url

CI npm

Determines the current page's canonical URL and optionally normalizes it via normalize-url for consistency.

Install

npm install get-canonical-url
# or...
yarn add get-canonical-url

Or pull directly from unpkg in-browser:

<script src="https://unpkg.com/get-canonical-url/dist/get-canonical-url.min.js"></script>

Usage

<!doctype html>
<html>
<head>
  <link rel="canonical" href="https://www.example.com/this/doesnt/exist.aspx?no=really&it=doesnt#gocheck">
</head>
</html>
import canonicalUrl from "get-canonical-url";

canonicalUrl();
//=> 'https://www.example.com/this/doesnt/exist.aspx?no=really&it=doesnt#gocheck'

canonicalUrl({
  normalize: true,
  normalizeOptions: {
    stripProtocol: true,
    stripWWW: true,
    stripHash: true
  }
})
//=> 'example.com/this/doesnt/exist.aspx?it=doesnt&no=really'
import canonicalUrl from "get-canonical-url";

canonicalUrl({
  guess: true,
  normalize: true
});
//=> Determined via the individual user's window.location.href or other similar browser hints. Normalizing is recommended.

API

canonicalUrl(options?)

options

Type: object

normalize

Type: boolean
Default: false

Clean-up and normalize the determined canonical URL.

normalizeOptions

Type: NormalizeOptions
Default:

{
  stripWWW: false,
  stripHash: true,
  removeQueryParameters: true,
  removeTrailingSlash: false
}

Options passed directly to normalize-url.

Requires options.normalize = true.

guess

Type: boolean
Default: false

Make an educated guess using other clues if canonical isn't explicitly set in the page's <head>.

License

MIT

Keywords

FAQs

Last updated on 11 Nov 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc