-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require Node.js 12.20 and move to ESM
- Loading branch information
1 parent
88d24c1
commit 541155e
Showing
8 changed files
with
38 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters