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
Fixes #14
  • Loading branch information
sindresorhus committed Jun 8, 2021
1 parent ab28ad1 commit b2d7c44
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 36 deletions.
3 changes: 0 additions & 3 deletions .github/funding.yml

This file was deleted.

5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ jobs:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
- 10
- 8
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Get a random temporary file path.
@example
```
import tempfile = require('tempfile');
import tempfile from 'tempfile';
tempfile('.png');
//=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4049f192-43e7-43b2-98d9-094e6760861b.png'
Expand All @@ -14,6 +14,4 @@ tempfile();
//=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/6271e235-13b9-4138-8b9b-ee2f26c09ce3'
```
*/
declare function tempfile(extension?: string): string;

export = tempfile;
export default function tempfile(extension?: string): string;
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const path = require('path');
const uuid = require('uuid');
const tempDirectory = require('temp-dir');
import path from 'node:path';
import {v4 as uuidv4} from 'uuid';
import tempDirectory from 'temp-dir';

module.exports = (extension = '') => path.join(tempDirectory, uuid.v4() + extension);
export default function tempfile(extension = '') {
return path.join(tempDirectory, uuidv4() + extension);
}
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import tempfile = require('.');
import tempfile from './index.js';

expectType<string>(tempfile());
expectType<string>(tempfile('.png'));
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 <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
"description": "Get a random temporary file path",
"license": "MIT",
"repository": "sindresorhus/tempfile",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=8"
"node": ">=12.20"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -30,11 +33,11 @@
],
"dependencies": {
"temp-dir": "^2.0.0",
"uuid": "^3.3.2"
"uuid": "^8.3.2"
},
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^3.15.0",
"tsd": "^0.17.0",
"xo": "^0.40.2"
}
}
13 changes: 2 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@
**Checkout out [`tempy`](https://github.com/sindresorhus/tempy) which is a better take on this module.**


## Install

```
$ npm install tempfile
```


## Usage

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

tempfile('.png');
//=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4049f192-43e7-43b2-98d9-094e6760861b.png'
Expand All @@ -24,24 +22,17 @@ tempfile();
//=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/6271e235-13b9-4138-8b9b-ee2f26c09ce3'
```


## API

### tempfile([extension])
### tempfile(extension?)

#### extension

Type: `string`

Extension to append to the path.


## Related

- [tempy](https://github.com/sindresorhus/tempy) - Get a random temporary file or directory path
- [temp-write](https://github.com/sindresorhus/temp-write) - Write string/buffer/stream to a random temp file


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {tmpdir} from 'os';
import {tmpdir} from 'node:os';
import test from 'ava';
import tempfile from '.';
import tempfile from './index.js';

test('main', t => {
t.true(tempfile().includes(tmpdir()));
Expand Down

0 comments on commit b2d7c44

Please sign in to comment.