From 0e64a6d252a7fc4a5b2c46245783ed0490a1d419 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 11 Aug 2021 00:59:01 +0200 Subject: [PATCH] Require Node.js 12.20 and move to ESM --- .github/workflows/main.yml | 7 ++----- index.d.ts | 6 ++---- index.js | 10 ++++------ index.test-d.ts | 2 +- license | 2 +- package.json | 14 ++++++++------ readme.md | 6 +----- test.js | 2 +- 8 files changed, 20 insertions(+), 29 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 18531b3..441975c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,13 +10,10 @@ jobs: fail-fast: false matrix: node-version: - - 14 - - 12 - - 10 - - 8 + - 16 steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/index.d.ts b/index.d.ts index cdb7b34..824ba79 100644 --- a/index.d.ts +++ b/index.d.ts @@ -5,7 +5,7 @@ Check if a URL is absolute. @example ``` -import isAbsoluteUrl = require('is-absolute-url'); +import isAbsoluteUrl from 'is-absolute-url'; isAbsoluteUrl('http://sindresorhus.com/foo/bar'); //=> true @@ -17,6 +17,4 @@ isAbsoluteUrl('foo/bar'); //=> false ``` */ -declare function isAbsoluteUrl(url: string): boolean; - -export = isAbsoluteUrl; +export default function isAbsoluteUrl(url: string): boolean; diff --git a/index.js b/index.js index 25dca66..886dfdf 100644 --- a/index.js +++ b/index.js @@ -1,16 +1,14 @@ -'use strict'; - -module.exports = url => { +export default function isAbsoluteUrl(url) { if (typeof url !== 'string') { throw new TypeError(`Expected a \`string\`, got \`${typeof url}\``); } - // Don't match Windows paths `c:\` + // Don't match Windows paths `c:\`. if (/^[a-zA-Z]:\\/.test(url)) { return false; } // Scheme: https://tools.ietf.org/html/rfc3986#section-3.1 // Absolute URL: https://tools.ietf.org/html/rfc3986#section-4.3 - return /^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(url); -}; + return /^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(url); +} diff --git a/index.test-d.ts b/index.test-d.ts index 6ad483a..43d0b83 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,4 +1,4 @@ import {expectType} from 'tsd'; -import isAbsoluteUrl = require('.'); +import isAbsoluteUrl from './index.js'; expectType(isAbsoluteUrl('https://sindresorhus.com/foo/bar')); diff --git a/license b/license index e7af2f7..fa7ceba 100644 --- a/license +++ b/license @@ -1,6 +1,6 @@ MIT License -Copyright (c) Sindre Sorhus (sindresorhus.com) +Copyright (c) Sindre Sorhus (https://sindresorhus.com) 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: diff --git a/package.json b/package.json index 9cb5d68..bfc0cc6 100644 --- a/package.json +++ b/package.json @@ -4,13 +4,16 @@ "description": "Check if a URL is absolute", "license": "MIT", "repository": "sindresorhus/is-absolute-url", + "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" + "url": "https://sindresorhus.com" }, + "type": "module", + "exports": "./index.js", "engines": { - "node": ">=8" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, "scripts": { "test": "xo && ava && tsd" @@ -23,13 +26,12 @@ "url", "absolute", "relative", - "uri", "is", "check" ], "devDependencies": { - "ava": "^1.4.1", - "tsd": "^0.7.2", - "xo": "^0.24.0" + "ava": "^3.15.0", + "tsd": "^0.17.0", + "xo": "^0.44.0" } } diff --git a/readme.md b/readme.md index 17b3525..fc89fca 100644 --- a/readme.md +++ b/readme.md @@ -2,18 +2,16 @@ > Check if a URL is absolute - ## Install ``` $ npm install is-absolute-url ``` - ## Usage ```js -const isAbsoluteUrl = require('is-absolute-url'); +import isAbsoluteUrl from 'is-absolute-url'; isAbsoluteUrl('https://sindresorhus.com/foo/bar'); //=> true @@ -25,12 +23,10 @@ isAbsoluteUrl('foo/bar'); //=> false ``` - ## Related See [is-relative-url](https://github.com/sindresorhus/is-relative-url) for the inverse. - ---
diff --git a/test.js b/test.js index f68537b..662ad83 100644 --- a/test.js +++ b/test.js @@ -1,5 +1,5 @@ import test from 'ava'; -import isAbsoluteUrl from '.'; +import isAbsoluteUrl from './index.js'; test('main', t => { t.true(isAbsoluteUrl('http://sindresorhus.com'));