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 12, 2021
1 parent 03c718b commit 9d6eb53
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 31 deletions.
3 changes: 0 additions & 3 deletions .github/funding.yml

This file was deleted.

7 changes: 2 additions & 5 deletions .github/workflows/main.yml
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
Expand Up @@ -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;
18 changes: 10 additions & 8 deletions 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);
}
2 changes: 1 addition & 1 deletion index.test-d.ts
@@ -1,4 +1,4 @@
import {expectType} from 'tsd';
import tildify = require('.');
import tildify from './index.js';

expectType<string>(tildify('/Users/sindresorhus/dev'));
10 changes: 6 additions & 4 deletions package.json
Expand Up @@ -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"
Expand All @@ -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"
}
}
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -11,7 +11,7 @@ $ npm install tildify
## Usage

```js
const tildify = require('tildify');
import tildify from 'tildify';

tildify('/Users/sindresorhus/dev');
//=> '~/dev'
Expand Down
9 changes: 4 additions & 5 deletions 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();

Expand Down

0 comments on commit 9d6eb53

Please sign in to comment.