diff --git a/.github/funding.yml b/.github/funding.yml deleted file mode 100644 index 1a630e9..0000000 --- a/.github/funding.yml +++ /dev/null @@ -1,3 +0,0 @@ -github: sindresorhus -open_collective: sindresorhus -custom: https://sindresorhus.com/donate 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 4e34bd6..a1fd61d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -3,12 +3,10 @@ Convert an absolute path to a tilde path: `/Users/sindresorhus/dev` → `~/dev`. @example ``` -import tildify = require('tildify'); +import tildify from 'tildify'; tildify('/Users/sindresorhus/dev'); //=> '~/dev' ``` */ -declare function tildify(absolutePath: string): string; - -export = tildify; +export default function tildify(absolutePath: string): string; diff --git a/index.js b/index.js index 78b53fb..017aa9e 100644 --- a/index.js +++ b/index.js @@ -1,13 +1,15 @@ -'use strict'; -const path = require('path'); -const os = require('os'); +import path from 'node:path'; +import os from 'node:os'; const homeDirectory = os.homedir(); -module.exports = absolutePath => { +export default function tildify(absolutePath) { const normalizedPath = path.normalize(absolutePath) + path.sep; - return (normalizedPath.indexOf(homeDirectory) === 0 ? - normalizedPath.replace(homeDirectory + path.sep, `~${path.sep}`) : - normalizedPath).slice(0, -1); -}; + return ( + normalizedPath.startsWith(homeDirectory) + ? normalizedPath.replace(homeDirectory + path.sep, `~${path.sep}`) + : normalizedPath + ) + .slice(0, -1); +} diff --git a/index.test-d.ts b/index.test-d.ts index 4c97b08..715e0cf 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,4 +1,4 @@ import {expectType} from 'tsd'; -import tildify = require('.'); +import tildify from './index.js'; expectType(tildify('/Users/sindresorhus/dev')); diff --git a/package.json b/package.json index a037143..8dcff95 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" @@ -34,8 +36,8 @@ "convert" ], "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 b44d613..179df93 100644 --- a/readme.md +++ b/readme.md @@ -11,7 +11,7 @@ $ npm install tildify ## Usage ```js -const tildify = require('tildify'); +import tildify from 'tildify'; tildify('/Users/sindresorhus/dev'); //=> '~/dev' diff --git a/test.js b/test.js index 6a08be7..e34ae08 100644 --- a/test.js +++ b/test.js @@ -1,8 +1,7 @@ -'use strict'; -const path = require('path'); -const os = require('os'); -const test = require('ava'); -const tildify = require('.'); +import path from 'node:path'; +import os from 'node:os'; +import test from 'ava'; +import tildify from './index.js'; const homeDirectory = os.homedir();