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 3001e88..0fd7011 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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'; diff --git a/index.js b/index.js index 88b7157..6d5a8ad 100644 --- a/index.js +++ b/index.js @@ -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; +} diff --git a/index.test-d.ts b/index.test-d.ts index 09a0e7e..21a2739 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,7 +1,7 @@ import {expectType} from 'tsd'; -import filenamifyUrl = require('.'); +import filenamifyUrl from './index.js'; expectType(filenamifyUrl('http://sindresorhus.com/foo?bar=baz')); expectType( - filenamifyUrl('http://sindresorhus.com/foo', {replacement: '🐴'}) + filenamifyUrl('http://sindresorhus.com/foo', {replacement: '🐴'}), ); 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 17183ee..7e1d415 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,10 @@ "email": "sindresorhus@gmail.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" @@ -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" } } diff --git a/readme.md b/readme.md index 043660d..336f2bb 100644 --- a/readme.md +++ b/readme.md @@ -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' diff --git a/test.js b/test.js index 04ebc13..999b2af 100644 --- a/test.js +++ b/test.js @@ -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');