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 26, 2021
1 parent 70c5abd commit 0a2693b
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 52 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
43 changes: 16 additions & 27 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
import {Options as FilenamifyOptions} from 'filenamify';
import {Options} from 'filenamify';

declare namespace filenamifyUrl {
type Options = FilenamifyOptions;
}
/**
Convert a URL to a valid filename.
declare const filenamifyUrl: {
/**
Convert a URL to a valid filename.
@param url - A URL to convert to a valid filename.
@returns A valid filename for `url`.
@param url - A URL to convert to a valid filename.
@returns A valid filename for `url`.
@example
```
import filenamifyUrl from 'filenamify-url';
@example
```
import filenamifyUrl = require('filenamify-url');
filenamifyUrl('http://sindresorhus.com/foo?bar=baz');
//=> 'sindresorhus.com!foo!bar=baz'
filenamifyUrl('http://sindresorhus.com/foo?bar=baz');
//=> 'sindresorhus.com!foo!bar=baz'
filenamifyUrl('http://sindresorhus.com/foo', {replacement: '🐴'});
//=> 'sindresorhus.com🐴foo'
```
*/
export default function filenamifyUrl(url: string, options?: Options): string;

filenamifyUrl('http://sindresorhus.com/foo', {replacement: '🐴'});
//=> 'sindresorhus.com🐴foo'
```
*/
(url: string, options?: filenamifyUrl.Options): string;

// TODO: Remove this for the next major release, refactor the whole definition to:
// declare function filenamifyUrl(url: string, options?: Options): string;
// export = filenamifyUrl;
default: typeof filenamifyUrl;
};

export = filenamifyUrl;
export {Options} from 'filenamify';
13 changes: 4 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
'use strict';
const filenamify = require('filenamify');
const humanizeUrl = require('humanize-url');
import filenamify from 'filenamify';
import humanizeUrl from 'humanize-url';

const filenamifyUrl = (string, options) => {
export default function filenamifyUrl(string, options) {
if (typeof string !== 'string') {
throw new TypeError('Expected a string');
}

return filenamify(decodeURIComponent(humanizeUrl(string)), options);
};

module.exports = filenamifyUrl;
// TODO: Remove this for the next major release
module.exports.default = filenamifyUrl;
}
4 changes: 2 additions & 2 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {expectType} from 'tsd';
import filenamifyUrl = require('.');
import filenamifyUrl from './index.js';

expectType<string>(filenamifyUrl('http://sindresorhus.com/foo?bar=baz'));
expectType<string>(
filenamifyUrl('http://sindresorhus.com/foo', {replacement: '🐴'})
filenamifyUrl('http://sindresorhus.com/foo', {replacement: '🐴'}),
);
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
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
"email": "[email protected]",
"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 @@ -31,12 +33,12 @@
"url"
],
"dependencies": {
"filenamify": "^4.3.0",
"humanize-url": "^2.1.1"
"filenamify": "^5.0.1",
"humanize-url": "^3.0.0"
},
"devDependencies": {
"ava": "^2.4.0",
"tsd": "^0.11.0",
"xo": "^0.25.3"
"ava": "^3.15.0",
"tsd": "^0.17.0",
"xo": "^0.44.0"
}
}
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 filenamify-url
## Usage

```js
const filenamifyUrl = require('filenamify-url');
import filenamifyUrl from 'filenamify-url';

filenamifyUrl('http://sindresorhus.com/foo?bar=baz');
//=> 'sindresorhus.com!foo!bar=baz'
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 filenamifyUrl from '.';
import filenamifyUrl from './index.js';

test('main', t => {
t.is(filenamifyUrl('sindresorhus.com'), 'sindresorhus.com');
Expand Down

0 comments on commit 0a2693b

Please sign in to comment.