is-url-to-anchor

Check if the URL indicates an anchor of the document


Keywords
location, hash, url, fragment, identifier
License
MIT
Install
bower install is-url-to-anchor

Documentation

is-url-to-anchor.js

Bower version NPM version Build Status devDependency Status

browser support

A client-side library to check if the URL indicates an anchor of the document

// On http://yoursite.com/foo/bar

isUrlToAnchor('#buz'); //=> true
isUrlToAnchor('/foo/bar#buz'); //=> true
isUrlToAnchor('bar#buz'); //=> true
isUrlToAnchor('http://yoursite.com/foo/bar#buz'); //=> true

Installation

Install with package manager

Bower

bower i --save is-url-to-anchor

Component

component install shinnn/is-url-to-anchor.js

npm (Use with Browserify etc.)

npm i --save is-url-to-anchor

Standalone

Download the script file directly.

API

isUrlToAnchor(url[, options])

Return: Boolean

Check if the String of the url argument indicates an anchored element of the document (that is, the string contains a hash# character).

By default, the samePage option and the emptyId option are both enabled. You can disable them by passing an Object to the options argument.

options.samePage

Type: Boolean Default: true

Validate the URL indicates an anchor of the same document.

// On http://yoursite.com/foo

isUrlToAnchor('bar#buz'); //=> false
isUrlToAnchor('bar#buz', {samePage: false}); //=> true

options.emptyId

Type: Boolean Default: true

Allow the URL to have no characters after hash character.

isUrlToAnchor('#'); //=> true
isUrlToAnchor('#', {emptyId: false}); //=> false

License

Copyright (c) 2014 Shinnosuke Watanabe

Licensed under the MIT LIcense.