package/package.json000644 000765 000024 0000001211 13125245465013017 0ustar00000000 000000 { "name": "isurl", "description": "Checks whether a value is a WHATWG URL.", "version": "1.0.0", "license": "MIT", "author": "Steven Vachon (https://www.svachon.com/)", "repository": "stevenvachon/isurl", "dependencies": { "has-to-string-tag-x": "^1.2.0", "is-object": "^1.0.1" }, "devDependencies": { "chai": "^4.0.2", "mocha": "^3.4.2", "semver": "^5.3.0", "universal-url": "^1.0.0" }, "engines": { "node": ">= 4" }, "scripts": { "test": "mocha test --check-leaks --bail" }, "files": [ "index.js" ], "keywords": [ "uri", "url", "whatwg" ] } package/README.md000644 000765 000024 0000002002 13120651100011765 0ustar00000000 000000 # isurl [![NPM Version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] > Checks whether a value is a WHATWG [`URL`](https://developer.mozilla.org/en/docs/Web/API/URL). Works cross-realm/iframe and despite @@toStringTag. ## Installation [Node.js](http://nodejs.org/) `>= 4` is required. To install, type this at the command line: ```shell npm install isurl ``` ## Usage ```js const isURL = require('isurl'); isURL('http://domain/'); //-> false isURL(new URL('http://domain/')); //-> true ``` Optionally, acceptance can be extended to incomplete `URL` implementations that lack `searchParams` (which are common in many modern web browsers): ```js const url = new URL('http://domain/?query'); console.log(url.searchParams); //-> undefined isURL.lenient(url); //-> true ``` [npm-image]: https://img.shields.io/npm/v/isurl.svg [npm-url]: https://npmjs.org/package/isurl [travis-image]: https://img.shields.io/travis/stevenvachon/isurl.svg [travis-url]: https://travis-ci.org/stevenvachon/isurl package/LICENSE000644 000765 000024 0000002056 13053115050011530 0ustar00000000 000000 MIT License Copyright (c) 2017 Steven Vachon Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package/index.js000644 000765 000024 0000002400 13125241131012161 0ustar00000000 000000 "use strict"; const hasToStringTag = require("has-to-string-tag-x"); const isObject = require("is-object"); const toString = Object.prototype.toString; const urlClass = "[object URL]"; const hash = "hash"; const host = "host"; const hostname = "hostname"; const href = "href"; const password = "password"; const pathname = "pathname"; const port = "port"; const protocol = "protocol"; const search = "search"; const username = "username"; const isURL = (url, supportIncomplete/*=false*/) => { if (!isObject(url)) return false; // Native implementation in older browsers if (!hasToStringTag && toString.call(url) === urlClass) return true; if (!(href in url)) return false; if (!(protocol in url)) return false; if (!(username in url)) return false; if (!(password in url)) return false; if (!(hostname in url)) return false; if (!(port in url)) return false; if (!(host in url)) return false; if (!(pathname in url)) return false; if (!(search in url)) return false; if (!(hash in url)) return false; if (supportIncomplete !== true) { if (!isObject(url.searchParams)) return false; // TODO :: write a separate isURLSearchParams ? } return true; } isURL.lenient = url => { return isURL(url, true); }; module.exports = isURL;