Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jakejarvis/get-canonical-url
🔗 Determines the current page's canonical URL and optionally normalizes it for consistency.
https://github.com/jakejarvis/get-canonical-url
address browser canonical dom front-end javascript link normalize npm uri url
Last synced: 19 days ago
JSON representation
🔗 Determines the current page's canonical URL and optionally normalizes it for consistency.
- Host: GitHub
- URL: https://github.com/jakejarvis/get-canonical-url
- Owner: jakejarvis
- License: mit
- Created: 2021-09-29T15:39:16.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-28T04:02:35.000Z (over 1 year ago)
- Last Synced: 2024-10-20T06:22:47.485Z (24 days ago)
- Topics: address, browser, canonical, dom, front-end, javascript, link, normalize, npm, uri, url
- Language: TypeScript
- Homepage:
- Size: 368 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🔗 get-canonical-url
[![CI](https://github.com/jakejarvis/get-canonical-url/actions/workflows/ci.yml/badge.svg)](https://github.com/jakejarvis/get-canonical-url/actions/workflows/ci.yml)
[![npm](https://img.shields.io/npm/v/get-canonical-url)](https://www.npmjs.com/package/get-canonical-url)Determines the current page's canonical URL and optionally normalizes it via [normalize-url](https://github.com/sindresorhus/normalize-url) for consistency.
## Install
```sh
npm install get-canonical-url
# or...
yarn add get-canonical-url
```Or pull directly from [unpkg](https://unpkg.com/browse/get-canonical-url/) in-browser:
```html
```
## Usage
### With ``
```html
```
```js
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'
```### Without ``
```js
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`](https://github.com/sindresorhus/normalize-url/blob/main/index.d.ts)\
Default:```js
{
stripWWW: false,
stripHash: true,
removeQueryParameters: true,
removeTrailingSlash: false
}
```Options passed directly to [`normalize-url`](https://github.com/sindresorhus/normalize-url#options).
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 ``.
## License
MIT