forked from isaacs/rimraf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1a59d7
commit cfee0e1
Showing
11 changed files
with
349 additions
and
70 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
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,17 +1,28 @@ | ||
export const Codes = { | ||
EPERM: 'EPERM', | ||
ENOENT: 'ENOENT', | ||
EMFILE: 'EMFILE', | ||
ENFILE: 'ENFILE', | ||
EBUSY: 'EBUSY', | ||
ENOTDIR: 'ENOTDIR', | ||
ENOTEMPTY: 'ENOTEMPTY', | ||
} as const | ||
|
||
export type Code = (typeof Codes)[keyof typeof Codes] | ||
export type CodeSet = Set<Code> | ||
const codes: CodeSet = new Set(Object.values(Codes)) | ||
|
||
const isRecord = (o: unknown): o is Record<string, unknown> => | ||
!!o && typeof o === 'object' | ||
|
||
const hasString = (o: Record<string, unknown>, key: string) => | ||
key in o && typeof o[key] === 'string' | ||
const isString = (v: unknown): v is string => typeof v === 'string' | ||
|
||
const isCode = (v: unknown): v is Code => isString(v) && codes.has(v as Code) | ||
|
||
export const isFsError = ( | ||
o: unknown, | ||
): o is NodeJS.ErrnoException & { | ||
code: string | ||
path: string | ||
} => isRecord(o) && hasString(o, 'code') && hasString(o, 'path') | ||
export const isError = (o: unknown): o is { code: Code; path: string } => | ||
isRecord(o) && isCode(o.code) && isString(o.path) | ||
|
||
export const errorCode = (er: unknown) => | ||
isRecord(er) && hasString(er, 'code') ? er.code : null | ||
export const errorCode = (er: unknown): Code | null => | ||
isRecord(er) && isCode(er.code) ? er.code : null | ||
|
||
export const asFsError = (er: unknown) => er as NodeJS.ErrnoException |
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
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
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
Oops, something went wrong.