@jsxtools/rollup-plugin-utils
Advanced tools
| export declare const every: <T>(value: unknown, predicate: Predicate<T>) => value is T[]; | ||
| export declare const from: <T, R extends T = NonNullable<T>>(items: From<T>, predicate?: Predicate<R>) => R[]; | ||
| export declare const isArray: (arg: any) => arg is any[]; | ||
| export declare const merge: <T>(a?: T[] | null, b?: T[] | null) => T[]; | ||
| export type From<T> = T | T[] | (T | null | undefined)[] | null | undefined; | ||
| export type Predicate<R> = (value: unknown) => value is R; |
| export const every = (value, predicate) => isArray(value) && value.every(predicate); | ||
| export const from = (items, predicate = __isNotNull) => (items == null ? [] : isArray(items) ? items : [items]).filter(predicate); | ||
| export const isArray = Array.isArray; | ||
| export const merge = (a, b) => [...(a ?? []), ...(b ?? [])]; | ||
| // #region Internals | ||
| const __isNotNull = (value) => value != null; | ||
| //# sourceMappingURL=array.js.map |
| {"version":3,"file":"array.js","sourceRoot":"","sources":["../src/array.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,KAAK,GAAG,CAAI,KAAc,EAAE,SAAuB,EAAgB,EAAE,CACjF,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;AAEzC,MAAM,CAAC,MAAM,IAAI,GAAG,CAAkC,KAAc,EAAE,YAAY,WAA2B,EAAO,EAAE,CACrH,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;AAE1E,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAA;AAEpC,MAAM,CAAC,MAAM,KAAK,GAAG,CAAI,CAAc,EAAE,CAAc,EAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;AAQ7F,oBAAoB;AAEpB,MAAM,WAAW,GAAG,CAAI,KAAQ,EAA2B,EAAE,CAAC,KAAK,IAAI,IAAI,CAAA"} |
| import { type Stats } from "node:fs"; | ||
| import type { PathLike } from "./path.js"; | ||
| export { readFile, stat as getFileStats, unlink as deleteFile, writeFile } from "node:fs/promises"; | ||
| /** Copies a file using the fastest method available. */ | ||
| export declare const copy: (src: PathLike, dest: PathLike) => Promise<void>; | ||
| /** Returns an async generator yielding file paths. */ | ||
| export declare const glob: (options?: GlobOptions) => AsyncGenerator<string, void, void>; | ||
| /** Options for `glob`. */ | ||
| export type GlobOptions = { | ||
| cwd?: PathLike; | ||
| include?: string | string[]; | ||
| exclude: string | string[]; | ||
| }; | ||
| /** Returns the SHA-256 hash of a file. */ | ||
| export declare const hash: (file: PathLike) => Promise<string>; | ||
| /** Creates a directory recursively. */ | ||
| export declare const mkdir: (path: PathLike) => Promise<string | undefined>; | ||
| /** Reads a file as parsed JSON. */ | ||
| export declare const readJSON: <T>(file: PathLike) => Promise<NonNullable<T>>; | ||
| export type FileStats = Stats; |
+41
| import { createHash } from "node:crypto"; | ||
| import { createReadStream } from "node:fs"; | ||
| import { constants, copyFile, glob as globWithNode, mkdir as mkdirWithNode, readFile as readFileWithNode, } from "node:fs/promises"; | ||
| import * as array from "./array.js"; | ||
| import * as json from "./json.js"; | ||
| export { readFile, stat as getFileStats, unlink as deleteFile, writeFile } from "node:fs/promises"; | ||
| /** Copies a file using the fastest method available. */ | ||
| export const copy = async (src, dest) => { | ||
| try { | ||
| return copyFile(src, dest, constants.COPYFILE_FICLONE); | ||
| } | ||
| catch { | ||
| return copyFile(src, dest); | ||
| } | ||
| }; | ||
| /** Returns an async generator yielding file paths. */ | ||
| export const glob = (options) => (async function* () { | ||
| const globPattern = array.from(options?.include); | ||
| const globOptions = { | ||
| cwd: options?.cwd, | ||
| exclude: array.from(options?.exclude), | ||
| }; | ||
| for await (const path of globWithNode(globPattern, globOptions)) { | ||
| yield new URL(path, globOptions.cwd).pathname; | ||
| } | ||
| })(); | ||
| /** Returns the SHA-256 hash of a file. */ | ||
| export const hash = async (file) => { | ||
| const hash = createHash("sha256"); | ||
| const stream = createReadStream(file); | ||
| stream.on("data", (chunk) => hash.update(chunk)); | ||
| return new Promise((resolve, reject) => { | ||
| stream.on("end", () => resolve(hash.digest("hex"))); | ||
| stream.on("error", reject); | ||
| }); | ||
| }; | ||
| /** Creates a directory recursively. */ | ||
| export const mkdir = async (path) => mkdirWithNode(path, { recursive: true }); | ||
| /** Reads a file as parsed JSON. */ | ||
| export const readJSON = (file) => readFileWithNode(file, "utf-8").then((data) => json.from(data)); | ||
| //# sourceMappingURL=file.js.map |
| {"version":3,"file":"file.js","sourceRoot":"","sources":["../src/file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAc,MAAM,SAAS,CAAA;AACtD,OAAO,EACN,SAAS,EACT,QAAQ,EACR,IAAI,IAAI,YAAY,EACpB,KAAK,IAAI,aAAa,EACtB,QAAQ,IAAI,gBAAgB,GAC5B,MAAM,kBAAkB,CAAA;AACzB,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAGjC,OAAO,EAAE,QAAQ,EAAE,IAAI,IAAI,YAAY,EAAE,MAAM,IAAI,UAAU,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAElG,wDAAwD;AACxD,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,EAAE,GAAa,EAAE,IAAc,EAAiB,EAAE;IAC1E,IAAI,CAAC;QACJ,OAAO,QAAQ,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC,gBAAgB,CAAC,CAAA;IACvD,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAC3B,CAAC;AACF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AA+B,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;AAEpH,mCAAmC;AACnC,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAI,IAAc,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAI,IAAI,CAAE,CAAC,CAAA"} |
| export declare const to: (value: unknown, replacer?: Replacer, space?: Space) => string; | ||
| export declare const from: <T>(json: string, reviver?: Reviver) => T | undefined; | ||
| export type Reviver = (this: any, key: string, value: any) => any; | ||
| export type Replacer = (this: any, key: string, value: any) => any; | ||
| export type Space = string | number; |
+10
| export const to = (value, replacer, space) => JSON.stringify(value, replacer, space); | ||
| export const from = (json, reviver) => { | ||
| try { | ||
| return JSON.parse(json, reviver); | ||
| } | ||
| catch { | ||
| // do nothing and return undefined | ||
| } | ||
| }; | ||
| //# sourceMappingURL=json.js.map |
| {"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAc,EAAE,QAAmB,EAAE,KAAa,EAAU,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAA;AAExH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAI,IAAY,EAAE,OAAiB,EAAiB,EAAE;IACzE,IAAI,CAAC;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IACjC,CAAC;IAAC,MAAM,CAAC;QACR,kCAAkC;IACnC,CAAC;AACF,CAAC,CAAA"} |
| /** Returns the value as a string. */ | ||
| export declare const from: (value: unknown) => string; | ||
| /** Returns the value as a trimmed string. */ | ||
| export declare const trim: (value: unknown) => string; | ||
| /** Returns whether the value is a non-empty string. */ | ||
| export declare const hasTrimmedValue: <T>(value: T) => value is HasValue<T>; | ||
| export type HasValue<T> = T extends string ? (T extends "" ? never : T) : never; |
| /** Returns the value as a string. */ | ||
| export const from = (value) => String(value ?? ""); | ||
| /** Returns the value as a trimmed string. */ | ||
| export const trim = (value) => from(value).trim(); | ||
| /** Returns whether the value is a non-empty string. */ | ||
| export const hasTrimmedValue = (value) => trim(value) !== ""; | ||
| //# sourceMappingURL=string.js.map |
| {"version":3,"file":"string.js","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,KAAc,EAAU,EAAE,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAA;AAEnE,6CAA6C;AAC7C,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,KAAc,EAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAA;AAElE,uDAAuD;AACvD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAI,KAAQ,EAAwB,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA"} |
@@ -1,3 +0,6 @@ | ||
| export declare const toMergedArray: <T>(a?: T[] | null, b?: T[] | null) => T[]; | ||
| export declare const toArray: <T>(items: T | T[] | null | undefined) => NonNullable<T>[]; | ||
| import type { RollupOptions } from "rollup"; | ||
| export declare const assignInput: <T extends string[] | Record<string, string>>(input: T, id: string) => T; | ||
| export declare const getDirs: (options: RollupOptions) => { | ||
| distDir: string | undefined; | ||
| rootDir: string | undefined; | ||
| }; |
+5
-2
@@ -1,3 +0,2 @@ | ||
| export const toMergedArray = (a, b) => [...(a ?? []), ...(b ?? [])]; | ||
| export const toArray = (items) => [].concat(items ?? []).filter((item) => item != null); | ||
| import * as array from "./array.js"; | ||
| export const assignInput = (input, id) => { | ||
@@ -12,2 +11,6 @@ if (Array.isArray(input)) { | ||
| }; | ||
| export const getDirs = (options) => ({ | ||
| distDir: array.from(options.output).find((output) => output.dir)?.dir, | ||
| rootDir: array.from(options.output).find((output) => output.preserveModulesRoot)?.preserveModulesRoot, | ||
| }); | ||
| //# sourceMappingURL=options.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,CAAI,CAAc,EAAE,CAAc,EAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;AAErG,MAAM,CAAC,MAAM,OAAO,GAAG,CAAI,KAAiC,EAAoB,EAAE,CAChF,EAAU,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,IAAI,CAAC,CAAA;AAE/D,MAAM,CAAC,MAAM,WAAW,GAAG,CAA8C,KAAQ,EAAE,EAAU,EAAK,EAAE;IACnG,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACf,CAAC;SAAM,CAAC;QACP,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,CAAA;IACf,CAAC;IAED,OAAO,KAAK,CAAA;AACb,CAAC,CAAA"} | ||
| {"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC,MAAM,CAAC,MAAM,WAAW,GAAG,CAA8C,KAAQ,EAAE,EAAU,EAAK,EAAE;IACnG,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACf,CAAC;SAAM,CAAC;QACP,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,CAAA;IACf,CAAC;IAED,OAAO,KAAK,CAAA;AACb,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAsB,EAAE,EAAE,CAAC,CAAC;IACnD,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG;IACrE,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,EAAE,mBAAmB;CACrG,CAAC,CAAA"} |
+16
-3
@@ -1,3 +0,16 @@ | ||
| import { relative, resolve } from "node:path"; | ||
| export { relative, resolve }; | ||
| export declare const resolveDir: (...paths: string[]) => string; | ||
| /** Returns the file path with a trailing slash. */ | ||
| export declare const toDirPath: (path: PathLike, ...parts: PathLike[]) => string; | ||
| /** Returns a resolved URL of a directory from any path. */ | ||
| export declare const toDirURL: (path: PathLike, ...parts: PathLike[]) => URL; | ||
| /** Returns the parent directory path of the given path. */ | ||
| export declare const toParentPath: (path: PathLike) => string; | ||
| /** Returns the parent directory URL of the given path. */ | ||
| export declare const toParentURL: (path: PathLike) => URL; | ||
| /** Returns a resolved, posix path from any path. */ | ||
| export declare const toPath: (path: PathLike, ...parts: PathLike[]) => string; | ||
| /** Returns a URL from any path. */ | ||
| export declare const toURL: (path: PathLike, ...parts: PathLike[]) => URL; | ||
| /** Returns the given path relative to the base path. */ | ||
| export declare const toRelativePath: (base: PathLike, path: PathLike, matchOS?: boolean) => string; | ||
| export declare const toPathWithoutBase: (path: PathLike, base: PathLike) => string; | ||
| export type PathLike = string | URL; |
+53
-3
@@ -1,4 +0,54 @@ | ||
| import { relative, resolve, sep } from "node:path"; | ||
| export { relative, resolve }; | ||
| export const resolveDir = (...paths) => resolve(...paths) + sep; | ||
| import { isAbsolute as isAbsoluteByOS, sep as sepByOS } from "node:path"; | ||
| import { resolve, sep } from "node:path/posix"; | ||
| import { pathToFileURL } from "node:url"; | ||
| /** Returns the file path with a trailing slash. */ | ||
| export const toDirPath = (path, ...parts) => toDirURL(path, ...parts).pathname; | ||
| /** Returns a resolved URL of a directory from any path. */ | ||
| export const toDirURL = (path, ...parts) => __toDirURL(toURL(path, ...parts)); | ||
| /** Returns the parent directory path of the given path. */ | ||
| export const toParentPath = (path) => toParentURL(path).pathname; | ||
| /** Returns the parent directory URL of the given path. */ | ||
| export const toParentURL = (path) => toURL(path, "./"); | ||
| /** Returns a resolved, posix path from any path. */ | ||
| export const toPath = (path, ...parts) => toURL(path, ...parts).pathname; | ||
| /** Returns a URL from any path. */ | ||
| export const toURL = (path, ...parts) => __withURLParts(__toURL(path), parts); | ||
| /** Returns the given path relative to the base path. */ | ||
| export const toRelativePath = (base, path, matchOS = false) => { | ||
| base = __toURL(base); | ||
| path = __withURLParts(base, [path]); | ||
| const baseParts = base.pathname.slice(1).split("/"); | ||
| const pathParts = path.pathname.slice(1).split("/"); // <-- use path, not base | ||
| // Remove the trailing "" segment if base ends with a slash | ||
| if (base.pathname.endsWith("/")) { | ||
| baseParts.pop(); | ||
| } | ||
| let shared = 0; | ||
| const max = Math.min(baseParts.length, pathParts.length); | ||
| while (shared < max && baseParts[shared] === pathParts[shared]) { | ||
| ++shared; | ||
| } | ||
| const up = baseParts.length - shared; | ||
| const dir = matchOS ? sepByOS : sep; | ||
| const tail = pathParts.slice(shared).join(dir); | ||
| return (up ? `..${dir}`.repeat(up) : `.${dir}`) + tail; | ||
| }; | ||
| export const toPathWithoutBase = (path, base) => ((base = __toDirURL(__toURL(base))), | ||
| (path = __withURLParts(base, [path]).pathname), | ||
| path.startsWith(base.pathname) ? path.slice(base.pathname.length) : path); | ||
| // #region Internals | ||
| const __toURL = (path) => path instanceof URL | ||
| ? path | ||
| : path.startsWith("file:") | ||
| ? new URL(path) | ||
| : isAbsoluteByOS(path) | ||
| ? pathToFileURL(path) | ||
| : pathToFileURL(resolve(path)); | ||
| const __toDirURL = (url) => url.pathname.endsWith("/") ? url : new URL(`${url.pathname}/${url.search}${url.hash}`, url); | ||
| const __withURLParts = (url, parts) => { | ||
| for (const part of parts) { | ||
| url = new URL(part, url); | ||
| } | ||
| return url; | ||
| }; | ||
| //# sourceMappingURL=path.js.map |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"path.js","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAElD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAA;AAE5B,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAG,KAAe,EAAU,EAAE,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,GAAG,GAAG,CAAA"} | ||
| {"version":3,"file":"path.js","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,WAAW,CAAA;AACxE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,mDAAmD;AACnD,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAc,EAAE,GAAG,KAAiB,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAA;AAEpG,2DAA2D;AAC3D,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAc,EAAE,GAAG,KAAiB,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,CAAC,CAAA;AAEnG,2DAA2D;AAC3D,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IA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,CAAC;YACrB,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC;YACrB,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;AAElC,MAAM,UAAU,GAAG,CAAC,GAAQ,EAAE,EAAE,CAC/B,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,IAAI,EAAE,EAAE,GAAG,CAAC,CAAA;AAE5F,MAAM,cAAc,GAAG,CAAC,GAAQ,EAAE,KAAiB,EAAE,EAAE;IACtD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;IACzB,CAAC;IAED,OAAO,GAAG,CAAA;AACX,CAAC,CAAA"} |
+6
-3
| { | ||
| "name": "@jsxtools/rollup-plugin-utils", | ||
| "version": "0.1.0", | ||
| "version": "0.2.0", | ||
| "type": "module", | ||
| "exports": { | ||
| "./get-file-hash": "./dist/get-file-hash.js", | ||
| "./array": "./dist/array.js", | ||
| "./file": "./dist/file.js", | ||
| "./json": "./dist/json.js", | ||
| "./options": "./dist/options.js", | ||
| "./path": "./dist/path.js", | ||
| "./string": "./dist/string.js", | ||
| "./virtual-asset": "./dist/virtual-asset.js" | ||
@@ -30,3 +33,3 @@ }, | ||
| "devDependencies": { | ||
| "@types/node": "^24.5.2", | ||
| "@types/node": "^24.6.2", | ||
| "rollup": "^4.6.0", | ||
@@ -33,0 +36,0 @@ "typescript": "^5.4.5" |
| /** Returns a SHA-1 hash of the given file path. */ | ||
| export declare const getFileHash: (filePath: string) => Promise<string | null>; | ||
| /** Returns both a SHA-1 hash and the file content from a single file read. */ | ||
| export declare const getFileHashAndData: (filePath: string) => Promise<FileHashAndData>; | ||
| export type FileHashAndData = { | ||
| hash: string; | ||
| data: Buffer; | ||
| } | { | ||
| hash: null; | ||
| data: null; | ||
| }; |
| import { createHash } from "node:crypto"; | ||
| import { createReadStream } from "node:fs"; | ||
| import { readFile } from "node:fs/promises"; | ||
| /** Returns a SHA-1 hash of the given file path. */ | ||
| export const getFileHash = async (filePath) => new Promise((resolve) => { | ||
| const sha1Hash = createHash("sha1"); | ||
| const stream = createReadStream(filePath); | ||
| stream.on("data", (chunk) => sha1Hash.update(chunk)); | ||
| stream.on("error", () => resolve(null)); | ||
| stream.on("end", () => resolve(sha1Hash.digest("hex"))); | ||
| }); | ||
| /** Returns both a SHA-1 hash and the file content from a single file read. */ | ||
| export const getFileHashAndData = async (filePath) => { | ||
| try { | ||
| const data = await readFile(filePath); | ||
| const hash = createHash("sha1").update(data).digest("hex"); | ||
| return { hash, data }; | ||
| } | ||
| catch { | ||
| return { hash: null, data: null }; | ||
| } | ||
| }; | ||
| //# sourceMappingURL=get-file-hash.js.map |
| {"version":3,"file":"get-file-hash.js","sourceRoot":"","sources":["../src/get-file-hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE3C,mDAAmD;AACnD,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAAE,QAAgB,EAA0B,EAAE,CAC7E,IAAI,OAAO,CAAgB,CAAC,OAAO,EAAE,EAAE;IACtC,MAAM,QAAQ,GAAG,UAAU,CAAC,MAAM,CAAC,CAAA;IACnC,MAAM,MAAM,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAA;IAEzC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IACpD,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;IACvC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AACxD,CAAC,CAAC,CAAA;AAEH,8EAA8E;AAC9E,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EAAE,QAAgB,EAA4B,EAAE;IACtF,IAAI,CAAC;QACJ,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAA;QACrC,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAE1D,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;IACtB,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;IAClC,CAAC;AACF,CAAC,CAAA"} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
27896
79.65%23
64.29%267
102.27%1
Infinity%