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 Jun 12, 2021
1 parent 733a374 commit 440412d
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 50 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
6 changes: 2 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ jobs:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
- 10
- 8
- 6
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
15 changes: 9 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
'use strict';
const normalizeUrl = require('normalize-url');
import normalizeUrl from 'normalize-url';

module.exports = (a, b) => {
if (a === b) {
export default function compareUrls(firstUrl, secondUrl) {
if (firstUrl === secondUrl) {
return true;
}

return normalizeUrl(a) === normalizeUrl(b);
};
const options = {
defaultProtocol: 'https:'
};

return normalizeUrl(firstUrl, options) === normalizeUrl(secondUrl, options);
}
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 <[email protected]> (sindresorhus.com)
Copyright (c) Sindre Sorhus <[email protected]> (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
71 changes: 37 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
{
"name": "compare-urls",
"version": "2.0.0",
"description": "Compare URLs by first normalizing them",
"license": "MIT",
"repository": "sindresorhus/compare-urls",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
},
"scripts": {
"test": "ava"
},
"files": [
"index.js"
],
"keywords": [
"compare",
"equal",
"same",
"url",
"uri",
"normalize"
],
"dependencies": {
"normalize-url": "^2.0.1"
},
"devDependencies": {
"ava": "*",
"xo": "*"
}
"name": "compare-urls",
"version": "2.0.0",
"description": "Compare URLs by first normalizing them",
"license": "MIT",
"repository": "sindresorhus/compare-urls",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=12.20"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"compare",
"equal",
"same",
"url",
"uri",
"normalize"
],
"dependencies": {
"normalize-url": "^6.0.1"
},
"devDependencies": {
"ava": "^3.15.0",
"xo": "^0.40.2"
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $ npm install compare-urls
## Usage

```js
const compareUrls = require('compare-urls');
import compareUrls from 'compare-urls';

compareUrls('HTTPS://sindresorhus.com/?b=b&a=a', 'sindresorhus.com/?a=a&b=b');
//=> true
Expand Down
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import test from 'ava';
import compareUrls from '.';
import compareUrls from './index.js';

test('main', t => {
t.true(compareUrls('https://sindresorhus.com', 'https://sindresorhus.com/'));
t.true(compareUrls('http://sindresorhus.com', '//sindresorhus.com'));
t.true(compareUrls('https://sindresorhus.com', '//sindresorhus.com'));
t.true(compareUrls('https://sindresorhus.com', 'sindresorhus.com'));
t.true(compareUrls('HTTPS://sindresorhus.com/?b=b&a=a', 'sindresorhus.com/?a=a&b=b'));
});

0 comments on commit 440412d

Please sign in to comment.