diff --git a/lib/node_modules/@stdlib/fs/stat/README.md b/lib/node_modules/@stdlib/fs/stat/README.md new file mode 100644 index 000000000000..fff3df2cb97c --- /dev/null +++ b/lib/node_modules/@stdlib/fs/stat/README.md @@ -0,0 +1,243 @@ + + +# Stat + +> Get full details on a file or directory. + +
+ +## Usage + +```javascript +var stat = require( '@stdlib/fs/stat' ); +``` + +#### stat( path, clbk ) + +Asynchronously returns file system statistics for a file or directory. + +The callback is invoked with an [`fs.Stats`][node-fs-stats] object containing methods and values describing the target path. + +```javascript +stat( __filename, onStat ); + +function onStat( error, stats ) { + if ( error ) { + throw error; + } + console.log( stats.isFile() ); + console.log( stats.isDirectory() ); + console.log( stats.isSymbolicLink() ); + console.log( stats.size ); + console.log( stats.mode ); + console.log( stats.atime ); +} +``` + +#### stat( path, options, clbk ) + +Asynchronously returns file system statistics for a file or directory with options. + +```javascript +stat( __filename, { + 'bigint': true +}, onStat ); + +function onStat( error, stats ) { + if ( error ) { + throw error; + } + console.log( stats.size ); + console.log( stats.atimeNs ); +} +``` + +Options: + +- **bigint**: `boolean` flag indicating whether numeric values should be returned as [`bigint`][@stdlib/bigint/ctor]. Default: `false`. + +```javascript +stat( __filename, onStat ); + +function onStat( error, stats ) { + if ( error ) { + throw error; + } + console.log( stats.isFile() ); +} +``` + +#### stat.sync( path ) + +Synchronously returns file system statistics for a file or directory. + +```javascript +var out = stat.sync( __filename ); +if ( out instanceof Error ) { + throw out; +} +console.log( out.isFile() ); +console.log( out.isSocket() ); +console.log( out.size ); +console.log( out.mtimeMs ); +``` + +#### stat.sync( path, options ) + +Synchronously returns file system statistics for a file or directory with options. + +```javascript +var out = stat.sync( __filename, { + 'bigint': true +}); +if ( out instanceof Error ) { + throw out; +} +console.log( out.size ); +console.log( out.birthtimeNs ); +``` + +The returned `fs.Stats` instance provides these type-check methods: + +- `isFile()` +- `isDirectory()` +- `isBlockDevice()` +- `isCharacterDevice()` +- `isFIFO()` +- `isSocket()` +- `isSymbolicLink()` + +The returned `fs.Stats` instance also provides values such as [`fs.Stats`][node-fs-stats]: + +- `dev`, `ino`, `mode`, `nlink`, `uid`, `gid`, `rdev`, `size`, `blksize`, `blocks` +- `atime`, `mtime`, `ctime`, `birthtime` +- `atimeMs`, `mtimeMs`, `ctimeMs`, `birthtimeMs` +- `atimeNs`, `mtimeNs`, `ctimeNs`, `birthtimeNs` (available when `bigint: true`) + +```javascript +var out = stat.sync( __filename ); +if ( out instanceof Error ) { + throw out; +} +console.log( out.isFile() ); +``` + +
+ + + +
+ +## Examples + + + +```javascript +var stat = require( '@stdlib/fs/stat' ); + +var out = stat.sync( __filename ); +if ( out instanceof Error ) { + throw out; +} +console.log( out.isFile() ); + +stat( __filename, onStat ); + +function onStat( error, stats ) { + if ( error ) { + throw error; + } + console.log( stats.isFile() ); + console.log( stats.isDirectory() ); + console.log( stats.isBlockDevice() ); + console.log( stats.isCharacterDevice() ); + console.log( stats.isFIFO() ); + console.log( stats.isSocket() ); + console.log( stats.isSymbolicLink() ); + console.log( stats.size ); + console.log( stats.mode ); + console.log( stats.uid ); + console.log( stats.gid ); + console.log( stats.atimeMs ); + console.log( stats.mtimeMs ); + console.log( stats.ctimeMs ); + console.log( stats.birthtimeMs ); +} +``` + +
+ + + +* * * + +
+ +## CLI + +
+ +### Usage + +```text +Usage: stat [options] + +Options: + + -h, --help Print this message. + -V, --version Print the package version. +``` + +
+ + + +
+ +### Notes + +- Relative paths are resolved relative to the current working directory. +- Errors are written to `stderr`. +- Results are written to `stdout` as JSON. + +
+ + + +
+ + + + + + + + diff --git a/lib/node_modules/@stdlib/fs/stat/benchmark/benchmark.js b/lib/node_modules/@stdlib/fs/stat/benchmark/benchmark.js new file mode 100644 index 000000000000..53340d1284cc --- /dev/null +++ b/lib/node_modules/@stdlib/fs/stat/benchmark/benchmark.js @@ -0,0 +1,44 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var bench = require( '@stdlib/bench' ); +var stat = require( './../lib' ).sync; + +bench( 'stat.sync', function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = stat( __filename ); + if ( out instanceof Error ) { + b.fail( out.message ); + } + if ( typeof out.isFile !== 'function' ) { + b.fail( 'unexpected return value' ); + } + } + b.toc(); + if ( out instanceof Error ) { + b.fail( out.message ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/fs/stat/bin/cli b/lib/node_modules/@stdlib/fs/stat/bin/cli new file mode 100644 index 000000000000..0652b1a967f4 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/stat/bin/cli @@ -0,0 +1,84 @@ +#!/usr/bin/env node + +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var readFileSync = require( '@stdlib/fs/read-file' ).sync; +var CLI = require( '@stdlib/cli/ctor' ); +var cwd = require( '@stdlib/process/cwd' ); +var stat = require( './../lib' ); + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +* @returns {void} +*/ +function main() { + var flags; + var fpath; + var args; + var cli; + + // Create a command-line interface: + cli = new CLI({ + 'pkg': require( './../package.json' ), + 'options': require( './../etc/cli_opts.json' ), + 'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { + 'encoding': 'utf8' + }) + }); + + // Get any provided command-line options: + flags = cli.flags(); + if ( flags.help || flags.version ) { + return; + } + + // Get any provided command-line arguments: + args = cli.args(); + fpath = resolve( cwd(), args[ 0 ] ); + + stat( fpath, onStat ); + + /** + * Callback invoked upon retrieving file statistics. + * + * @private + * @param {(Error|null)} error - error object + * @param {Stats} stats - file statistics + * @returns {void} + */ + function onStat( error, stats ) { + if ( error ) { + return cli.error( error ); + } + // Print a JSON representation to enable stable testing: + console.log( JSON.stringify( stats, null, 2 ) ); // eslint-disable-line no-console + } +} + +main(); diff --git a/lib/node_modules/@stdlib/fs/stat/docs/types/index.d.ts b/lib/node_modules/@stdlib/fs/stat/docs/types/index.d.ts new file mode 100644 index 000000000000..3857c981bd3e --- /dev/null +++ b/lib/node_modules/@stdlib/fs/stat/docs/types/index.d.ts @@ -0,0 +1,137 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Stats, BigIntStats } from 'fs'; + +/** +* Options for retrieving file statistics. +*/ +interface Options { + /** + * Whether the numeric values in the returned Stats object should be bigint. + * + * Default: false + */ + bigint?: boolean; +} + +/** +* Options for retrieving file statistics with bigint numeric values. +*/ +interface BigIntOptions { + /** + * Whether the numeric values in the returned Stats object should be bigint. + */ + bigint: true; +} + +/** +* Callback invoked after retrieving file statistics. +* +* @param err - error argument +* @param stats - file statistics +*/ +type Callback = ( err: Error | null, stats: Stats ) => void; + +/** +* Callback invoked after retrieving file statistics with bigint numeric values. +* +* @param err - error argument +* @param stats - file statistics +*/ +type BigIntCallback = ( err: Error | null, stats: BigIntStats ) => void; + +/** +* Interface for retrieving file statistics. +*/ +interface Stat { + /** + * Asynchronously returns file system statistics for a file or directory. + * + * @param path - file path + * @param clbk - callback to invoke after retrieving file statistics + */ + ( path: string | Buffer, clbk: Callback ): void; + + /** + * Asynchronously returns file system statistics for a file or directory. + * + * @param path - file path + * @param options - function options + * @param clbk - callback to invoke after retrieving file statistics + */ + ( path: string | Buffer, options: Options, clbk: Callback ): void; + + /** + * Asynchronously returns file system statistics for a file or directory. + * + * @param path - file path + * @param options - function options + * @param clbk - callback to invoke after retrieving file statistics + */ + ( path: string | Buffer, options: BigIntOptions, clbk: BigIntCallback ): void; + + /** + * Synchronously returns file system statistics for a file or directory. + * + * @param path - file path + * @param options - function options + * @returns file statistics or an error + */ + sync( path: string | Buffer, options?: Options ): Stats | Error; + + /** + * Synchronously returns file system statistics for a file or directory. + * + * @param path - file path + * @param options - function options + * @returns file statistics or an error + */ + sync( path: string | Buffer, options: BigIntOptions ): BigIntStats | Error; +} + +/** +* Asynchronously returns file system statistics for a file or directory. +* +* @param path - file path +* @param clbk - callback to invoke after retrieving file statistics +* +* @example +* +* stat( __filename, onStat ); +* stat( __dirname, onStat ); +* +* function onStat( error, stats ) { +* if ( error ) { +* throw error; +* } +* console.log( stats.isFile() ); +* console.log( stats.isDirectory() ); +* console.log( stats ); +* } +*/ +declare var stat: Stat; + + +// EXPORTS // + +export = stat; diff --git a/lib/node_modules/@stdlib/fs/stat/docs/types/test.ts b/lib/node_modules/@stdlib/fs/stat/docs/types/test.ts new file mode 100644 index 000000000000..6316cec0084d --- /dev/null +++ b/lib/node_modules/@stdlib/fs/stat/docs/types/test.ts @@ -0,0 +1,119 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import { Stats } from 'fs'; +import stat = require( './index' ); + +const done = ( error: Error | null, stats: Stats ) => { + if ( error ) { + throw error; + } + if ( stats.isFile() !== true && stats.isFile() !== false ) { + throw new Error( 'unexpected stats object' ); + } +}; + + +// TESTS // + +// The function does not have a return value... +{ + stat( 'beepboop', done ); // $ExpectType void +} + +// The function supports options... +{ + stat( 'beepboop', { 'bigint': false }, done ); // $ExpectType void +} + +// The compiler throws an error if the function is provided a first argument of an unsupported type... +{ + stat( false, done ); // $ExpectError + stat( true, done ); // $ExpectError + stat( null, done ); // $ExpectError + stat( undefined, done ); // $ExpectError + stat( [], done ); // $ExpectError + stat( {}, done ); // $ExpectError + stat( ( x: number ): number => x, done ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not either an options object or callback... +{ + stat( 'beepboop', 123, done ); // $ExpectError + stat( 'beepboop', false, done ); // $ExpectError + stat( 'beepboop', true, done ); // $ExpectError + stat( 'beepboop', null, done ); // $ExpectError + stat( 'beepboop', undefined, done ); // $ExpectError + stat( 'beepboop', [], done ); // $ExpectError + stat( 'beepboop', ( x: number ): number => x, done ); // $ExpectError +} + +// The compiler throws an error if the function is provided a callback argument which is not a function with the expected signature... +{ + stat( 'beepboop', 1 ); // $ExpectError + stat( 'beepboop', 'abc' ); // $ExpectError + stat( 'beepboop', false ); // $ExpectError + stat( 'beepboop', true ); // $ExpectError + stat( 'beepboop', null ); // $ExpectError + stat( 'beepboop', undefined ); // $ExpectError + stat( 'beepboop', [] ); // $ExpectError + stat( 'beepboop', {} ); // $ExpectError + stat( 'beepboop', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + stat(); // $ExpectError + stat( 'beepboop' ); // $ExpectError +} + +// Attached to main export is a `sync` method which returns either a Stats object or an error... +{ + stat.sync( 'beepboop' ); // $ExpectType Error | Stats +} + +// The `sync` method supports options... +{ + stat.sync( 'beepboop', { 'bigint': false } ); // $ExpectType Error | Stats +} + +// The compiler throws an error if the `sync` method is provided a first argument of an unsupported type... +{ + stat.sync( false ); // $ExpectError + stat.sync( true ); // $ExpectError + stat.sync( null ); // $ExpectError + stat.sync( undefined ); // $ExpectError + stat.sync( [] ); // $ExpectError + stat.sync( {} ); // $ExpectError + stat.sync( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `sync` method is provided an options argument which is not an object... +{ + stat.sync( 'beepboop', 123 ); // $ExpectError + stat.sync( 'beepboop', false ); // $ExpectError + stat.sync( 'beepboop', true ); // $ExpectError + stat.sync( 'beepboop', null ); // $ExpectError + stat.sync( 'beepboop', [] ); // $ExpectError + stat.sync( 'beepboop', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `sync` method is provided an unsupported number of arguments... +{ + stat.sync(); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/fs/stat/docs/usage.txt b/lib/node_modules/@stdlib/fs/stat/docs/usage.txt new file mode 100644 index 000000000000..a2eebe5e0db7 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/stat/docs/usage.txt @@ -0,0 +1,7 @@ + +Usage: stat [options] + +Options: + + -h, --help Print this message. + -V, --version Print the package version. diff --git a/lib/node_modules/@stdlib/fs/stat/etc/cli_opts.json b/lib/node_modules/@stdlib/fs/stat/etc/cli_opts.json new file mode 100644 index 000000000000..f245a17e6317 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/stat/etc/cli_opts.json @@ -0,0 +1,14 @@ +{ + "boolean": [ + "help", + "version" + ], + "alias": { + "help": [ + "h" + ], + "version": [ + "V" + ] + } +} diff --git a/lib/node_modules/@stdlib/fs/stat/examples/index.js b/lib/node_modules/@stdlib/fs/stat/examples/index.js new file mode 100644 index 000000000000..3efcee2afc61 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/stat/examples/index.js @@ -0,0 +1,100 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var stat = require( './../lib' ); + +/* Sync */ + +var out = stat.sync( __filename ); +if ( out instanceof Error ) { + throw out; +} +console.log( out.isFile() ); +console.log( out.isDirectory() ); +console.log( out.isBlockDevice() ); +console.log( out.isCharacterDevice() ); +console.log( out.isFIFO() ); +console.log( out.isSocket() ); +console.log( out.isSymbolicLink() ); +console.log( out.size ); +console.log( out.mode ); +console.log( out.uid ); +console.log( out.gid ); +console.log( out.atime ); +console.log( out.mtime ); +console.log( out.ctime ); +console.log( out.birthtime ); +console.log( out ); + +out = stat.sync( __dirname ); +if ( out instanceof Error ) { + throw out; +} +console.log( out.isDirectory() ); +console.log( out.isFile() ); +console.log( out.isBlockDevice() ); +console.log( out.isCharacterDevice() ); +console.log( out.isFIFO() ); +console.log( out.isSocket() ); +console.log( out.isSymbolicLink() ); +console.log( out.size ); +console.log( out ); + +/* Async */ + +stat( __filename, onStat ); +stat( __dirname, onStat ); + +function onStat( error, stats ) { + if ( error ) { + throw error; + } + console.log( stats.isFile() ); + console.log( stats.isDirectory() ); + console.log( stats.isBlockDevice() ); + console.log( stats.isCharacterDevice() ); + console.log( stats.isFIFO() ); + console.log( stats.isSocket() ); + console.log( stats.isSymbolicLink() ); + console.log( stats.size ); + console.log( stats.mode ); + console.log( stats.uid ); + console.log( stats.gid ); + console.log( stats.atimeMs ); + console.log( stats.mtimeMs ); + console.log( stats.ctimeMs ); + console.log( stats.birthtimeMs ); + console.log( stats ); +} + +stat( __filename, { + 'bigint': true +}, onBigIntStat ); + +function onBigIntStat( error, stats ) { + if ( error ) { + throw error; + } + console.log( stats.size ); + console.log( stats.atimeNs ); + console.log( stats.mtimeNs ); + console.log( stats.ctimeNs ); + console.log( stats.birthtimeNs ); +} diff --git a/lib/node_modules/@stdlib/fs/stat/lib/async.js b/lib/node_modules/@stdlib/fs/stat/lib/async.js new file mode 100644 index 000000000000..c5b3b167d582 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/stat/lib/async.js @@ -0,0 +1,91 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var stat = require( 'fs' ).stat; +var isFunction = require( '@stdlib/assert/is-function' ); +var isObject = require( '@stdlib/assert/is-plain-object' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Asynchronously returns full details on the statistics of a file or directory. +* +* @param {(string|Buffer)} path - file path +* @param {Object} [options] - function options (Node >=10.5.0) +* @param {boolean} [options.bigint=false] - whether to return `BigInt` numeric values +* @param {Function} clbk - callback to invoke after retrieving file statistics +* @throws {TypeError} callback argument must be a function +* @throws {TypeError} options argument must be an object +* @throws {TypeError} options are not supported by the current environment +* @returns {(Stats|Error)} file statistics or an error +* +* @example +* stat( __filename, onStat ); +* stat( __dirname, onStat ); +* +* function onStat( error, stats ) { +* if ( error ) { +* throw error; +* } +* console.log( stats.isFile() ); +* console.log( stats.isDirectory() ); +* console.log( stats.isSocket() ); +* console.log( stats.isSymbolicLink() ); +* console.log( stats.size ); +* console.log( stats.mode ); +* console.log( stats.atimeMs ); +* console.log( stats ); +* } +*/ +function statWrapper( path, options, clbk ) { + var nargs; + var cb; + + nargs = arguments.length; + if ( nargs === 2 ) { + cb = options; + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', cb ) ); + } + return stat( path, cb ); + } + if ( nargs > 2 ) { + cb = clbk; + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', cb ) ); + } + if ( !isObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + // Note: we attempt to pass options directly and rely on the runtime to handle + // them, as checking `stat.length` is not a reliable indicator of options support. + return stat( path, options, cb ); + } + throw new TypeError( 'invalid invocation. Must provide a file path and a callback.' ); +} + + +// EXPORTS // + +module.exports = statWrapper; diff --git a/lib/node_modules/@stdlib/fs/stat/lib/index.js b/lib/node_modules/@stdlib/fs/stat/lib/index.js new file mode 100644 index 000000000000..4b0ae98a23d1 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/stat/lib/index.js @@ -0,0 +1,84 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return full details on the statistics of a file or directory. For more information, see the [archive][1]. +* +* [1]: https://github.com/nodejs/node-v0.x-archive/blob/d8baf8a2a4481940bfed0196308ae6189ca18eee/lib/fs.js#L782 +* +* @module @stdlib/fs/stat +* +* @example +* var stat = require( '@stdlib/fs/stat' ); +* +* stat( __filename, onStat ); +* stat( __dirname, onStat ); +* +* function onStat( error, stats ) { +* if ( error ) { +* throw error; +* } +* console.log( stats.isFile() ); +* console.log( stats.isDirectory() ); +* console.log( stats.isSocket() ); +* console.log( stats.isSymbolicLink() ); +* console.log( stats.size ); +* console.log( stats.mode ); +* console.log( stats.atimeMs ); +* console.log( stats ); +* } +* +* @example +* var stat = require( '@stdlib/fs/stat' ); +* +* var out = stat.sync( __filename ); +* if ( out instanceof Error ) { +* throw out; +* } +* console.log( out.isFile() ); +* console.log( out.isSocket() ); +* console.log( out.size ); +* console.log( out ); +* +* out = stat.sync( __dirname ); +* if ( out instanceof Error ) { +* throw out; +* } +* console.log( out.isDirectory() ); +* console.log( out.isSymbolicLink() ); +* console.log( out.mode ); +* console.log( out ); +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var stat = require( './async.js' ); +var sync = require( './sync.js' ); + + +// MAIN // + +setReadOnly( stat, 'sync', sync ); + + +// EXPORTS // + +module.exports = stat; diff --git a/lib/node_modules/@stdlib/fs/stat/lib/sync.js b/lib/node_modules/@stdlib/fs/stat/lib/sync.js new file mode 100644 index 000000000000..74cfbaaeb1b5 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/stat/lib/sync.js @@ -0,0 +1,88 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var stat = require( 'fs' ).statSync; // eslint-disable-line node/no-sync +var isObject = require( '@stdlib/assert/is-plain-object' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Synchronously returns full details on the statistics of a file or directory. +* +* @param {(string|Buffer)} path - file path +* @param {Object} [options] - function options (Node >=10.5.0) +* @param {boolean} [options.bigint=false] - whether to return `BigInt` numeric values +* @throws {TypeError} options argument must be an object +* @throws {TypeError} options are not supported by the current environment +* @returns {(Stats|Error)} file statistics or an error +* +* @example +* var stat = require( '@stdlib/fs/stat' ); +* +* var out = stat.sync( __filename ); +* if ( out instanceof Error ) { +* throw out; +* } +* console.log( out.isFile() ); +* console.log( out.isSocket() ); +* console.log( out.size ); +* console.log( out ); +* +* out = stat.sync( __dirname ); +* if ( out instanceof Error ) { +* throw out; +* } +* console.log( out.isDirectory() ); +* console.log( out.isSymbolicLink() ); +* console.log( out.mode ); +* console.log( out ); +*/ +function statSync( path, options ) { + var nargs; + var out; + + nargs = arguments.length; + try { + if ( nargs === 1 ) { + out = stat( path ); + } else { + if ( !isObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + // Only pass options if supported by the runtime: + if ( stat.length < 2 ) { + throw new TypeError( 'invalid argument. Options argument is not supported by the current runtime.' ); + } + out = stat( path, options ); + } + } catch ( err ) { + return err; + } + return out; +} + + +// EXPORTS // + +module.exports = statSync; diff --git a/lib/node_modules/@stdlib/fs/stat/package.json b/lib/node_modules/@stdlib/fs/stat/package.json new file mode 100644 index 000000000000..2d5dc591791e --- /dev/null +++ b/lib/node_modules/@stdlib/fs/stat/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/fs/stat", + "version": "0.0.0", + "description": "Get full details on a file or directory.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "bin": { + "stat": "./bin/cli" + }, + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdfs", + "fs", + "stat", + "stats", + "filesystem", + "file", + "directory", + "async", + "sync", + "node" + ] +} diff --git a/lib/node_modules/@stdlib/fs/stat/test/test.async.js b/lib/node_modules/@stdlib/fs/stat/test/test.async.js new file mode 100644 index 000000000000..ad7648c65651 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/stat/test/test.async.js @@ -0,0 +1,249 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var BigInt = require( '@stdlib/bigint/ctor' ); +var stat = require( './../lib/async.js' ); + + +// VARIABLES // + +// Don't run tests in the browser...for now... +var opts = { + 'skip': IS_BROWSER // FIXME +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof stat, 'function', 'export is a function' ); + t.end(); +}); + +tape( 'the function returns file stats (success)', opts, function test( t ) { + stat( __filename, onStat ); + + function onStat( error, stats ) { + t.strictEqual( error, null, 'error is null' ); + t.strictEqual( typeof stats.isFile, 'function', 'returns a Stats-like object' ); + t.strictEqual( stats.isFile(), true, 'returns expected value' ); + t.end(); + } +}); + +tape( 'the function returns directory stats (success)', opts, function test( t ) { + stat( __dirname, onStat ); + + function onStat( error, stats ) { + t.strictEqual( error, null, 'error is null' ); + t.strictEqual( typeof stats.isDirectory, 'function', 'returns a Stats-like object' ); + t.strictEqual( stats.isDirectory(), true, 'returns expected value' ); + t.strictEqual( stats.isFile(), false, 'returns expected value' ); + t.end(); + } +}); + +tape( 'the function returns an error (failure)', opts, function test( t ) { + stat( 'beepboopbebop', onStat ); + + function onStat( error ) { + t.ok( error instanceof Error, 'returns an error' ); + t.end(); + } +}); + +tape( 'the function throws if provided an invalid callback', function test( t ) { + t.throws( badValue, TypeError, 'throws a type error' ); + t.end(); + + function badValue() { + stat( __filename, 'beep' ); + } +}); + +tape( 'the function throws if provided options which are not an object', function test( t ) { + t.throws( badValue, TypeError, 'throws a type error' ); + t.end(); + + function badValue() { + stat( __filename, 'beep', function noop() {} ); + } +}); + +tape( 'the function passes options through when supported', function test( t ) { + var called = false; + var stat = proxyquire( './../lib/async.js', { + 'fs': { + 'stat': function stub( path, opts, cb ) { + called = true; + t.strictEqual( path, __filename, 'path argument' ); + t.deepEqual( opts, { + 'bigint': false + }, 'options argument' ); + t.strictEqual( typeof cb, 'function', 'callback argument' ); + cb( null, { + 'isFile': function isFile() { return true; } + }); + } + } + }); + stat( __filename, { + 'bigint': false + }, done ); + + function done( error, stats ) { + t.strictEqual( error, null, 'error is null' ); + t.strictEqual( stats.isFile(), true, 'returns expected value' ); + t.strictEqual( called, true, 'invoked underlying stat' ); + t.end(); + } +}); + +tape( 'the function throws if options are provided and options are unsupported', function test( t ) { + var stat = proxyquire( './../lib/async.js', { + 'fs': { + // If a function only accepts (path, cb), its `.length` will be 2: + 'stat': function stat2( path, cb ) { + return cb( null, {} ); + } + } + }); + + t.throws( badValue, TypeError, 'throws a type error' ); + t.end(); + + function badValue() { + stat( __filename, { + 'bigint': false + }, function noop() {} ); + } +}); + +tape( 'the function returns file stats methods', opts, function test( t ) { + stat( __filename, onStat ); + + function onStat( error, stats ) { + t.strictEqual( error, null, 'error is null' ); + t.strictEqual( typeof stats.isBlockDevice, 'function', 'has expected method' ); + t.strictEqual( typeof stats.isCharacterDevice, 'function', 'has expected method' ); + t.strictEqual( typeof stats.isFIFO, 'function', 'has expected method' ); + t.strictEqual( typeof stats.isSocket, 'function', 'has expected method' ); + t.strictEqual( typeof stats.isSymbolicLink, 'function', 'has expected method' ); + t.strictEqual( stats.isBlockDevice(), false, 'returns expected value' ); + t.strictEqual( stats.isCharacterDevice(), false, 'returns expected value' ); + t.strictEqual( stats.isFIFO(), false, 'returns expected value' ); + t.strictEqual( stats.isSocket(), false, 'returns expected value' ); + t.strictEqual( stats.isSymbolicLink(), false, 'returns expected value' ); + t.end(); + } +}); + +tape( 'the function returns file stats properties', opts, function test( t ) { + stat( __filename, onStat ); + + function onStat( error, stats ) { + t.strictEqual( error, null, 'error is null' ); + t.strictEqual( typeof stats.dev, 'number', 'has expected property' ); + t.strictEqual( typeof stats.ino, 'number', 'has expected property' ); + t.strictEqual( typeof stats.mode, 'number', 'has expected property' ); + t.strictEqual( typeof stats.nlink, 'number', 'has expected property' ); + t.strictEqual( typeof stats.uid, 'number', 'has expected property' ); + t.strictEqual( typeof stats.gid, 'number', 'has expected property' ); + t.strictEqual( typeof stats.rdev, 'number', 'has expected property' ); + t.strictEqual( typeof stats.size, 'number', 'has expected property' ); + t.strictEqual( typeof stats.blksize, 'number', 'has expected property' ); + t.strictEqual( typeof stats.blocks, 'number', 'has expected property' ); + t.ok( stats.atime instanceof Date, 'has expected property' ); + t.ok( stats.mtime instanceof Date, 'has expected property' ); + t.ok( stats.ctime instanceof Date, 'has expected property' ); + t.ok( stats.birthtime instanceof Date, 'has expected property' ); + t.strictEqual( typeof stats.atimeMs, 'number', 'has expected property' ); + t.strictEqual( typeof stats.mtimeMs, 'number', 'has expected property' ); + t.strictEqual( typeof stats.ctimeMs, 'number', 'has expected property' ); + t.strictEqual( typeof stats.birthtimeMs, 'number', 'has expected property' ); + t.end(); + } +}); + +tape( 'the function supports the bigint option', opts, function test( t ) { + var stat = proxyquire( './../lib/async.js', { + 'fs': { + 'stat': function stub( path, opts, cb ) { + t.strictEqual( path, __filename, 'path argument' ); + t.deepEqual( opts, { + 'bigint': true + }, 'options argument' ); + cb( null, { + 'dev': BigInt( '1' ), + 'ino': BigInt( '2' ), + 'mode': BigInt( '3' ), + 'nlink': BigInt( '4' ), + 'uid': BigInt( '5' ), + 'gid': BigInt( '6' ), + 'rdev': BigInt( '7' ), + 'size': BigInt( '8' ), + 'blksize': BigInt( '9' ), + 'blocks': BigInt( '10' ), + 'atimeMs': BigInt( '11' ), + 'mtimeMs': BigInt( '12' ), + 'ctimeMs': BigInt( '13' ), + 'birthtimeMs': BigInt( '14' ), + 'atimeNs': BigInt( '15' ), + 'mtimeNs': BigInt( '16' ), + 'ctimeNs': BigInt( '17' ), + 'birthtimeNs': BigInt( '18' ) + }); + } + } + }); + + stat( __filename, { + 'bigint': true + }, onStat ); + + function onStat( error, stats ) { + t.strictEqual( error, null, 'error is null' ); + t.strictEqual( typeof stats.dev, 'bigint', 'has expected property' ); + t.strictEqual( typeof stats.ino, 'bigint', 'has expected property' ); + t.strictEqual( typeof stats.mode, 'bigint', 'has expected property' ); + t.strictEqual( typeof stats.nlink, 'bigint', 'has expected property' ); + t.strictEqual( typeof stats.uid, 'bigint', 'has expected property' ); + t.strictEqual( typeof stats.gid, 'bigint', 'has expected property' ); + t.strictEqual( typeof stats.rdev, 'bigint', 'has expected property' ); + t.strictEqual( typeof stats.size, 'bigint', 'has expected property' ); + t.strictEqual( typeof stats.blksize, 'bigint', 'has expected property' ); + t.strictEqual( typeof stats.blocks, 'bigint', 'has expected property' ); + t.strictEqual( typeof stats.atimeMs, 'bigint', 'has expected property' ); + t.strictEqual( typeof stats.mtimeMs, 'bigint', 'has expected property' ); + t.strictEqual( typeof stats.ctimeMs, 'bigint', 'has expected property' ); + t.strictEqual( typeof stats.birthtimeMs, 'bigint', 'has expected property' ); + t.strictEqual( typeof stats.atimeNs, 'bigint', 'has expected property' ); + t.strictEqual( typeof stats.mtimeNs, 'bigint', 'has expected property' ); + t.strictEqual( typeof stats.ctimeNs, 'bigint', 'has expected property' ); + t.strictEqual( typeof stats.birthtimeNs, 'bigint', 'has expected property' ); + t.end(); + } +}); diff --git a/lib/node_modules/@stdlib/fs/stat/test/test.cli.js b/lib/node_modules/@stdlib/fs/stat/test/test.cli.js new file mode 100644 index 000000000000..0381b5cc256a --- /dev/null +++ b/lib/node_modules/@stdlib/fs/stat/test/test.cli.js @@ -0,0 +1,183 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var exec = require( 'child_process' ).exec; +var tape = require( 'tape' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var IS_WINDOWS = require( '@stdlib/assert/is-windows' ); +var EXEC_PATH = require( '@stdlib/process/exec-path' ); +var readFileSync = require( '@stdlib/fs/read-file' ).sync; + + +// VARIABLES // + +var fpath = resolve( __dirname, '..', 'bin', 'cli' ); +var opts = { + 'skip': IS_BROWSER || IS_WINDOWS +}; + + +// FIXTURES // + +var PKG_VERSION = require( './../package.json' ).version; + + +// TESTS // + +tape( 'command-line interface', function test( t ) { + t.ok( true, __filename ); + t.end(); +}); + +tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { + var expected; + var cmd; + + expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { + 'encoding': 'utf8' + }); + cmd = [ + EXEC_PATH, + fpath, + '--help' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); + } + t.end(); + } +}); + +tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { + var expected; + var cmd; + + expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { + 'encoding': 'utf8' + }); + cmd = [ + EXEC_PATH, + fpath, + '-h' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); + } + t.end(); + } +}); + +tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { + var cmd = [ + EXEC_PATH, + fpath, + '--version' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); + } + t.end(); + } +}); + +tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { + var cmd = [ + EXEC_PATH, + fpath, + '-V' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); + } + t.end(); + } +}); + +tape( 'the command-line interface prints file statistics as JSON', opts, function test( t ) { + var cmd = [ + EXEC_PATH, + fpath, + __filename + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + var out; + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); + out = JSON.parse( stdout.toString() ); + t.strictEqual( typeof out.size, 'number', 'contains expected fields' ); + t.strictEqual( typeof out.mode, 'number', 'contains expected fields' ); + t.strictEqual( typeof out.mtimeMs, 'number', 'contains expected fields' ); + } + t.end(); + } +}); + +tape( 'when provided a non-existent path, the command-line interface prints an error to `stderr`', opts, function test( t ) { + var cmd = [ + EXEC_PATH, + fpath, + 'beepboopbebop' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + t.ok( error, 'returns an error' ); + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.ok( stderr.toString().length > 0, 'prints to `stderr`' ); + t.end(); + } +}); diff --git a/lib/node_modules/@stdlib/fs/stat/test/test.js b/lib/node_modules/@stdlib/fs/stat/test/test.js new file mode 100644 index 000000000000..c84604161a93 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/stat/test/test.js @@ -0,0 +1,47 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var stat = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof stat, 'function', 'export is a function' ); + t.end(); +}); + +tape( 'export includes a function to stat synchronously', function test( t ) { + t.strictEqual( typeof stat.sync, 'function', 'export is a function' ); + t.end(); +}); + +tape( 'attached `sync` property is non-enumerable and read-only', function test( t ) { + var desc = Object.getOwnPropertyDescriptor( stat, 'sync' ); + t.strictEqual( typeof desc, 'object', 'returns a descriptor' ); + t.strictEqual( desc.enumerable, false, 'non-enumerable' ); + t.strictEqual( desc.configurable, false, 'non-configurable' ); + t.strictEqual( desc.writable, false, 'read-only' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/fs/stat/test/test.sync.js b/lib/node_modules/@stdlib/fs/stat/test/test.sync.js new file mode 100644 index 000000000000..f4b249050045 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/stat/test/test.sync.js @@ -0,0 +1,217 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var BigInt = require( '@stdlib/bigint/ctor' ); +var stat = require( './../lib/sync.js' ); + + +// VARIABLES // + +// Don't run tests in the browser...for now... +var opts = { + 'skip': IS_BROWSER // FIXME +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof stat, 'function', 'export is a function' ); + t.end(); +}); + +tape( 'the function returns file stats (success)', opts, function test( t ) { + var out = stat( __filename ); + t.strictEqual( out instanceof Error, false, 'does not return an error' ); + t.strictEqual( typeof out.isFile, 'function', 'returns a Stats-like object' ); + t.strictEqual( out.isFile(), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns directory stats (success)', opts, function test( t ) { + var out = stat( __dirname ); + t.strictEqual( out instanceof Error, false, 'does not return an error' ); + t.strictEqual( typeof out.isDirectory, 'function', 'returns a Stats-like object' ); + t.strictEqual( out.isDirectory(), true, 'returns expected value' ); + t.strictEqual( out.isFile(), false, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an error (failure)', opts, function test( t ) { + var out = stat( 'beepboopbebop' ); + t.strictEqual( out instanceof Error, true, 'returns an error' ); + t.end(); +}); + +tape( 'the function returns an error if provided options which are not an object', function test( t ) { + var out = stat( __filename, 'beep' ); + t.strictEqual( out instanceof Error, true, 'returns an error' ); + t.strictEqual( out.name, 'TypeError', 'returns a type error' ); + t.end(); +}); + +tape( 'the function passes options through when supported', function test( t ) { + var called = false; + var stat = proxyquire( './../lib/sync.js', { + 'fs': { + 'statSync': function stub( path, opts ) { + called = true; + t.strictEqual( path, __filename, 'path argument' ); + t.deepEqual( opts, { + 'bigint': false + }, 'options argument' ); + return { + 'isFile': function isFile() { + return true; + } + }; + } + } + }); + + var out = stat( __filename, { + 'bigint': false + }); + t.strictEqual( out instanceof Error, false, 'does not return an error' ); + t.strictEqual( out.isFile(), true, 'returns expected value' ); + t.strictEqual( called, true, 'invoked underlying statSync' ); + t.end(); +}); + +tape( 'the function returns an error if options are provided and options are unsupported', function test( t ) { + var stat = proxyquire( './../lib/sync.js', { + 'fs': { + // If a function only accepts (path), its `.length` will be 1: + 'statSync': function stat1( path ) { // eslint-disable-line no-unused-vars + return {}; + } + } + }); + + var out = stat( __filename, { + 'bigint': false + }); + t.strictEqual( out instanceof Error, true, 'returns an error' ); + t.strictEqual( out.name, 'TypeError', 'returns a type error' ); + t.end(); +}); + +tape( 'the function returns file stats methods', opts, function test( t ) { + var out = stat( __filename ); + t.strictEqual( out instanceof Error, false, 'does not return an error' ); + t.strictEqual( typeof out.isBlockDevice, 'function', 'has expected method' ); + t.strictEqual( typeof out.isCharacterDevice, 'function', 'has expected method' ); + t.strictEqual( typeof out.isFIFO, 'function', 'has expected method' ); + t.strictEqual( typeof out.isSocket, 'function', 'has expected method' ); + t.strictEqual( typeof out.isSymbolicLink, 'function', 'has expected method' ); + t.strictEqual( out.isBlockDevice(), false, 'returns expected value' ); + t.strictEqual( out.isCharacterDevice(), false, 'returns expected value' ); + t.strictEqual( out.isFIFO(), false, 'returns expected value' ); + t.strictEqual( out.isSocket(), false, 'returns expected value' ); + t.strictEqual( out.isSymbolicLink(), false, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns file stats properties', opts, function test( t ) { + var out = stat( __filename ); + t.strictEqual( out instanceof Error, false, 'does not return an error' ); + t.strictEqual( typeof out.dev, 'number', 'has expected property' ); + t.strictEqual( typeof out.ino, 'number', 'has expected property' ); + t.strictEqual( typeof out.mode, 'number', 'has expected property' ); + t.strictEqual( typeof out.nlink, 'number', 'has expected property' ); + t.strictEqual( typeof out.uid, 'number', 'has expected property' ); + t.strictEqual( typeof out.gid, 'number', 'has expected property' ); + t.strictEqual( typeof out.rdev, 'number', 'has expected property' ); + t.strictEqual( typeof out.size, 'number', 'has expected property' ); + t.strictEqual( typeof out.blksize, 'number', 'has expected property' ); + t.strictEqual( typeof out.blocks, 'number', 'has expected property' ); + t.ok( out.atime instanceof Date, 'has expected property' ); + t.ok( out.mtime instanceof Date, 'has expected property' ); + t.ok( out.ctime instanceof Date, 'has expected property' ); + t.ok( out.birthtime instanceof Date, 'has expected property' ); + t.strictEqual( typeof out.atimeMs, 'number', 'has expected property' ); + t.strictEqual( typeof out.mtimeMs, 'number', 'has expected property' ); + t.strictEqual( typeof out.ctimeMs, 'number', 'has expected property' ); + t.strictEqual( typeof out.birthtimeMs, 'number', 'has expected property' ); + t.end(); +}); + +tape( 'the function supports the bigint option', opts, function test( t ) { + var stat = proxyquire( './../lib/sync.js', { + 'fs': { + 'statSync': function stub( path, opts ) { + t.strictEqual( path, __filename, 'path argument' ); + t.deepEqual( opts, { + 'bigint': true + }, 'options argument' ); + return { + 'dev': BigInt( '1' ), + 'ino': BigInt( '2' ), + 'mode': BigInt( '3' ), + 'nlink': BigInt( '4' ), + 'uid': BigInt( '5' ), + 'gid': BigInt( '6' ), + 'rdev': BigInt( '7' ), + 'size': BigInt( '8' ), + 'blksize': BigInt( '9' ), + 'blocks': BigInt( '10' ), + 'atimeMs': BigInt( '11' ), + 'mtimeMs': BigInt( '12' ), + 'ctimeMs': BigInt( '13' ), + 'birthtimeMs': BigInt( '14' ), + 'atimeNs': BigInt( '15' ), + 'mtimeNs': BigInt( '16' ), + 'ctimeNs': BigInt( '17' ), + 'birthtimeNs': BigInt( '18' ) + }; + } + } + }); + + var out = stat( __filename, { + 'bigint': true + }); + t.strictEqual( out instanceof Error, false, 'does not return an error' ); + t.strictEqual( typeof out.dev, 'bigint', 'has expected property' ); + t.strictEqual( typeof out.ino, 'bigint', 'has expected property' ); + t.strictEqual( typeof out.mode, 'bigint', 'has expected property' ); + t.strictEqual( typeof out.nlink, 'bigint', 'has expected property' ); + t.strictEqual( typeof out.uid, 'bigint', 'has expected property' ); + t.strictEqual( typeof out.gid, 'bigint', 'has expected property' ); + t.strictEqual( typeof out.rdev, 'bigint', 'has expected property' ); + t.strictEqual( typeof out.size, 'bigint', 'has expected property' ); + t.strictEqual( typeof out.blksize, 'bigint', 'has expected property' ); + t.strictEqual( typeof out.blocks, 'bigint', 'has expected property' ); + t.strictEqual( typeof out.atimeMs, 'bigint', 'has expected property' ); + t.strictEqual( typeof out.mtimeMs, 'bigint', 'has expected property' ); + t.strictEqual( typeof out.ctimeMs, 'bigint', 'has expected property' ); + t.strictEqual( typeof out.birthtimeMs, 'bigint', 'has expected property' ); + t.strictEqual( typeof out.atimeNs, 'bigint', 'has expected property' ); + t.strictEqual( typeof out.mtimeNs, 'bigint', 'has expected property' ); + t.strictEqual( typeof out.ctimeNs, 'bigint', 'has expected property' ); + t.strictEqual( typeof out.birthtimeNs, 'bigint', 'has expected property' ); + t.end(); +});