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 16, 2021
1 parent 88d24c1 commit 541155e
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 62 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ jobs:
fail-fast: false
matrix:
node-version:
- 14
- 12
- 10
- 8
- 6
- 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
37 changes: 14 additions & 23 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
declare const validFilename: {
/**
Check if a string is a [valid filename](https://github.com/sindresorhus/filename-reserved-regex).
/**
Check if a string is a [valid filename](https://github.com/sindresorhus/filename-reserved-regex).
@param input - The string to check.
@returns Whether `input` is a valid filename.
@param input - The string to check.
@returns Whether `input` is a valid filename.
@example
```
import validFilename = require('valid-filename');
@example
```
import isValidFilename from 'valid-filename';
validFilename('foo/bar');
//=> false
isValidFilename('foo/bar');
//=> false
validFilename('foo-bar');
//=> true
```
*/
(input: string): boolean;

// TODO: Remove this for the next major release, refactor the whole definition to:
// declare function validFilename(input: string): boolean;
// export = validFilename;
default: typeof validFilename;
};

export = validFilename;
isValidFilename('foo-bar');
//=> true
```
*/
export default function isValidFilename(input: string): boolean;
15 changes: 5 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
'use strict';
const filenameReservedRegex = require('filename-reserved-regex');
import filenameReservedRegex, {windowsReservedNameRegex} from 'filename-reserved-regex';

const validFilename = string => {
export default function isValidFilename(string) {
if (!string || string.length > 255) {
return false;
}

if (filenameReservedRegex().test(string) || filenameReservedRegex.windowsNames().test(string)) {
if (filenameReservedRegex().test(string) || windowsReservedNameRegex().test(string)) {
return false;
}

if (/^\.\.?$/.test(string)) {
if (string === '.' || string === '..') {
return false;
}

return true;
};

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

expectType<boolean>(validFilename('foo/bar'));
expectType<boolean>(isValidFilename('foo/bar'));
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
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": "Check if a string is a valid filename",
"license": "MIT",
"repository": "sindresorhus/valid-filename",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=6"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -31,11 +34,11 @@
"string"
],
"dependencies": {
"filename-reserved-regex": "^2.0.0"
"filename-reserved-regex": "^3.0.0"
},
"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"
}
}
17 changes: 4 additions & 13 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,27 @@

> Check if a string is a [valid filename](https://github.com/sindresorhus/filename-reserved-regex)

## Install

```
$ npm install valid-filename
```


## Usage

```js
const validFilename = require('valid-filename');
import isValidFilename from 'valid-filename';

validFilename('foo/bar');
isValidFilename('foo/bar');
//=> false

validFilename('foo-bar');
isValidFilename('foo-bar');
//=> true
```


## API

### validFilename(input)
### isValidFilename(input)

Returns a `boolean` of whether `input` is a valid filename.

Expand All @@ -35,12 +32,6 @@ Type: `string`

The string to check.


## Related

- [filenamify](https://github.com/sindresorhus/filenamify) - Convert a string to a valid safe filename


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)
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 validFilename from '.';
import validFilename from './index.js';

test('main', t => {
t.true(validFilename('foo-bar'));
Expand Down

0 comments on commit 541155e

Please sign in to comment.