Socket
Socket
Sign inDemoInstall

@nodelib/fs.stat

Package Overview
Dependencies
0
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.3 to 2.0.0

out/providers/async.d.ts

2

out/adapters/fs.d.ts

@@ -10,3 +10,3 @@ /// <reference types="node" />

export declare const FILE_SYSTEM_ADAPTER: FileSystemAdapter;
export declare function getFileSystemAdapter(fsMethods?: Partial<FileSystemAdapter>): FileSystemAdapter;
export declare function createFileSystemAdapter(fsMethods?: Partial<FileSystemAdapter>): FileSystemAdapter;
//# sourceMappingURL=fs.d.ts.map

@@ -10,3 +10,3 @@ "use strict";

};
function getFileSystemAdapter(fsMethods) {
function createFileSystemAdapter(fsMethods) {
if (!fsMethods) {

@@ -17,2 +17,2 @@ return exports.FILE_SYSTEM_ADAPTER;

}
exports.getFileSystemAdapter = getFileSystemAdapter;
exports.createFileSystemAdapter = createFileSystemAdapter;

@@ -1,22 +0,13 @@

/// <reference types="node" />
import * as fs from 'fs';
import { FileSystemAdapter } from './adapters/fs';
import { Options } from './managers/options';
import { AsyncCallback } from './providers/stat';
/**
* Asynchronous API.
*/
export declare function stat(path: fs.PathLike, opts?: Options): Promise<fs.Stats>;
/**
* Callback API.
*/
export declare function statCallback(path: fs.PathLike, callback: AsyncCallback): void;
export declare function statCallback(path: fs.PathLike, opts: Options, callback: AsyncCallback): void;
/**
* Synchronous API.
*/
export declare function statSync(path: fs.PathLike, opts?: Options): fs.Stats;
export declare type Options = Options;
export declare type StatAsyncCallback = AsyncCallback;
export declare type FileSystemAdapter = FileSystemAdapter;
import * as async from './providers/async';
import Settings, { Options } from './settings';
import { Stats } from './types/index';
declare type AsyncCallback = async.AsyncCallback;
declare function stat(path: string, callback: AsyncCallback): void;
declare function stat(path: string, optionsOrSettings: Options | Settings, callback: AsyncCallback): void;
declare namespace stat {
function __promisify__(path: string, optionsOrSettings?: Options | Settings): Promise<Stats>;
}
declare function statSync(path: string, optionsOrSettings?: Options | Settings): Stats;
export { Settings, stat, statSync, AsyncCallback, FileSystemAdapter, Options, Stats };
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const optionsManager = require("./managers/options");
const statProvider = require("./providers/stat");
/**
* Asynchronous API.
*/
function stat(path, opts) {
return new Promise((resolve, reject) => {
statProvider.async(path, optionsManager.prepare(opts), (err, stats) => err ? reject(err) : resolve(stats));
});
const async = require("./providers/async");
const sync = require("./providers/sync");
const settings_1 = require("./settings");
exports.Settings = settings_1.default;
function stat(path, optionsOrSettingsOrCallback, callback) {
if (typeof optionsOrSettingsOrCallback === 'function') {
return async.read(path, getSettings(), optionsOrSettingsOrCallback);
}
async.read(path, getSettings(optionsOrSettingsOrCallback), callback);
}
exports.stat = stat;
function statCallback(path, optsOrCallback, callback) {
if (typeof optsOrCallback === 'function') {
callback = optsOrCallback; /* tslint:disable-line: no-parameter-reassignment */
optsOrCallback = undefined; /* tslint:disable-line: no-parameter-reassignment */
function statSync(path, optionsOrSettings) {
const settings = getSettings(optionsOrSettings);
return sync.read(path, settings);
}
exports.statSync = statSync;
function getSettings(settingsOrOptions = {}) {
if (settingsOrOptions instanceof settings_1.default) {
return settingsOrOptions;
}
if (typeof callback === 'undefined') {
throw new TypeError('The "callback" argument must be of type Function.');
}
statProvider.async(path, optionsManager.prepare(optsOrCallback), callback);
return new settings_1.default(settingsOrOptions);
}
exports.statCallback = statCallback;
/**
* Synchronous API.
*/
function statSync(path, opts) {
return statProvider.sync(path, optionsManager.prepare(opts));
}
exports.statSync = statSync;
{
"name": "@nodelib/fs.stat",
"version": "1.1.3",
"version": "2.0.0",
"description": "Get the status of a file with some features",

@@ -15,3 +15,3 @@ "license": "MIT",

"engines": {
"node": ">= 6"
"node": ">= 8"
},

@@ -21,3 +21,3 @@ "main": "out/index.js",

"scripts": {
"clean": "rimraf out",
"clean": "rimraf {tsconfig.tsbuildinfo,out}",
"lint": "tslint \"src/**/*.ts\" -p . -t stylish",

@@ -27,5 +27,5 @@ "compile": "tsc -b .",

"test": "mocha \"out/**/*.spec.js\" -s 0",
"build": "npm run clean && npm run lint && npm run compile && npm test",
"build": "npm run clean && npm run compile && npm run lint && npm test",
"watch": "npm run clean && npm run compile:watch"
}
}

@@ -7,21 +7,19 @@ # @nodelib/fs.stat

Wrapper over standard methods ([`fs.lstat`](https://nodejs.org/dist/latest/docs/api/fs.html#fs_fs_lstat_path_callback), [`fs.stat`](https://nodejs.org/dist/latest/docs/api/fs.html#fs_fs_stat_path_callback)) with some features.
Wrapper around standard method `fs.lstat` and `fs.stat` with some features.
* :beginner: Normally follows symlinks.
* :gear: Can safely work with broken symlinks (returns information about symlink instead of generating an error).
* :beginner: Normally follows symbolic link.
* :gear: Can safely work with broken symbolic link.
## Install
```console
npm install @nodelib/fs.stat
```
$ npm install @nodelib/fs.stat
```
## Usage
```js
const fsStat = require('@nodelib/fs.stat');
```ts
import * as fsStat from '@nodelib/fs.stat';
fsStat.stat('path').then((stat) => {
console.log(stat); // => fs.Stats
});
fsStat.stat('path', (error, stats) => { /* … */ });
```

@@ -31,49 +29,81 @@

### fsStat.stat(path, [options])
### .stat(path, [optionsOrSettings], callback)
Returns a [`Promise<fs.Stats>`](https://nodejs.org/dist/latest/docs/api/fs.html#fs_class_fs_stats) for provided path.
Returns an instance of `fs.Stats` class for provided path with standard callback-style.
### fsStat.statSync(path, [options])
```ts
fsStat.stat('path', (error, stats) => { /* … */ });
fsStat.stat('path', {}, (error, stats) => { /* … */ });
fsStat.stat('path', new fsStat.Settings(), (error, stats) => { /* … */ });
```
Returns a [`fs.Stats`](https://nodejs.org/dist/latest/docs/api/fs.html#fs_class_fs_stats) for provided path.
### .statSync(path, [optionsOrSettings])
### fsStat.statCallback(path, [options], callback)
Returns an instance of `fs.Stats` class for provided path.
Returns a [`fs.Stats`](https://nodejs.org/dist/latest/docs/api/fs.html#fs_class_fs_stats) for provided path with standard callback-style.
```ts
const stats = fsStat.stat('path');
const stats = fsStat.stat('path', {});
const stats = fsStat.stat('path', new fsStat.Settings());
```
#### path
* Type: `string | Buffer | URL`
* Required: `true`
* Type: `string | Buffer | URL`
The `path` argument for [`fs.lstat`](https://nodejs.org/dist/latest/docs/api/fs.html#fs_fs_lstat_path_callback) or [`fs.stat`](https://nodejs.org/dist/latest/docs/api/fs.html#fs_fs_stat_path_callback) method.
A path to a file. If a URL is provided, it must use the `file:` protocol.
#### options
#### optionsOrSettings
* Type: `Object`
* Required: `false`
* Type: `Options | Settings`
* Default: An instance of `Settings` class
See [options](#options-1) section for more detailed information.
An [`Options`](#options) object or an instance of [`Settings`](#settings) class.
> :book: When you pass a plain object, an instance of the `Settings` class will be created automatically. If you plan to call the method frequently, use a pre-created instance of the `Settings` class.
### Settings([options])
A class of full settings of the package.
```ts
const settings = new fsStat.Settings({ followSymbolicLink: false });
const stats = fsStat.stat('path', settings);
```
## Options
### throwErrorOnBrokenSymlinks
### `followSymbolicLink`
* Type: `boolean`
* Default: `true`
* Type: `boolean`
* Default: `true`
Throw an error or return information about symlink, when symlink is broken. When `false`, methods will be return lstat call for broken symlinks.
Follow symbolic link or not. Call `fs.stat` on symbolic link if `true`.
### followSymlinks
### `markSymbolicLink`
* Type: `boolean`
* Default: `true`
* Type: `boolean`
* Default: `false`
By default, the methods of this package follows symlinks. If you do not want it, set this option to `false` or use the standard method [`fs.lstat`](https://nodejs.org/dist/latest/docs/api/fs.html#fs_fs_lstat_path_callback).
Mark symbolic link by setting the return value of `isSymbolicLink` function to always `true` (even after `fs.stat`).
### fs
> :book: Can be used if you want to know what is hidden behind a symbolic link, but still continue to know that it is a symbolic link.
* Type: `FileSystemAdapter`
* Default: `built-in FS methods`
### `throwErrorOnBrokenSymbolicLink`
By default, the built-in Node.js module (`fs`) is used to work with the file system. You can replace each method with your own.
* Type: `boolean`
* Default: `true`
Throw an error when symbolic link is broken if `true` or safely return `lstat` call if `false`.
### `fs`
* Type: [`FileSystemAdapter`](./src/adapters/fs.ts)
* Default: A default FS methods
By default, the built-in Node.js module (`fs`) is used to work with the file system. You can replace any method with your own.
```ts

@@ -86,2 +116,6 @@ interface FileSystemAdapter {

}
const settings = new fsStat.Settings({
fs: { lstat: fakeLstat }
});
```

@@ -91,3 +125,3 @@

See the [Releases section of our GitHub project](https://github.com/nodelib/nodelib/releases) for changelogs for each release version.
See the [Releases section of our GitHub project](https://github.com/nodelib/nodelib/releases) for changelog for each release version.

@@ -94,0 +128,0 @@ ## License

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc