From 089ff380ad8169bc0cbe6dde0b2192b41a6801b6 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Mon, 23 Nov 2026 06:50:00 +0800 Subject: [PATCH] fs: add static `Stats.isStats()` method Signed-off-by: LiviaMedeiros --- doc/api/fs.md | 41 +++++++++++++++++ lib/internal/fs/utils.js | 9 ++++ test/parallel/test-fs-stats-isstats.mjs | 61 +++++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 test/parallel/test-fs-stats-isstats.mjs diff --git a/doc/api/fs.md b/doc/api/fs.md index 186ab76c0989..266242fcdc42 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -7994,6 +7994,9 @@ i.e. before the `'ready'` event is emitted. + +* `value` {any} +* Returns: {boolean} + +Returns `true` if `value` is a `fs.Stats` object, including objects returned +when `bigint` option was set to `true`. Returns `false` otherwise. + +Prefer this method over `value instanceof fs.Stats`. + +```mjs +import { statSync, Stats } from 'node:fs'; + +const stats = statSync('/etc/hosts'); +const statsBigInt = statSync('/etc/hosts', { bigint: true }); + +Stats.isStats(stats); // true +Stats.isStats(statsBigInt); // true +stats instanceof Stats; // true +statsBigInt instanceof Stats; // false +``` + +```cjs +const { statSync, Stats } = require('node:fs'); + +const stats = statSync('/etc/hosts'); +const statsBigInt = statSync('/etc/hosts', { bigint: true }); + +Stats.isStats(stats); // true +Stats.isStats(statsBigInt); // true +stats instanceof Stats; // true +statsBigInt instanceof Stats; // false +``` + #### `stats.isBlockDevice()`