Skip to content

Commit

Permalink
Require Node.js 12.20 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Aug 10, 2021
1 parent d8fd39d commit 0e64a6d
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 29 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,6 +17,4 @@ isAbsoluteUrl('foo/bar');
//=> false
```
*/
declare function isAbsoluteUrl(url: string): boolean;

export = isAbsoluteUrl;
export default function isAbsoluteUrl(url: string): boolean;
10 changes: 4 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expectType} from 'tsd';
import isAbsoluteUrl = require('.');
import isAbsoluteUrl from './index.js';

expectType<boolean>(isAbsoluteUrl('https://sindresorhus.com/foo/bar'));
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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:

Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
}
}
6 changes: 1 addition & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,12 +23,10 @@ isAbsoluteUrl('foo/bar');
//=> false
```


## Related

See [is-relative-url](https://github.com/sindresorhus/is-relative-url) for the inverse.


---

<div align="center">
Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -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'));
Expand Down

0 comments on commit 0e64a6d

Please sign in to comment.