From 62619dcbc5384852e7e139d7eb14f1336b68df62 Mon Sep 17 00:00:00 2001 From: Hridyanshu7 Date: Wed, 20 Mar 2024 18:28:42 +0530 Subject: [PATCH 01/23] added append-file utility in stdlib/fs --- .../@stdlib/fs/append-file/README.md | 247 ++++++++++++++++ .../fs/append-file/benchmark/benchmark.js | 80 ++++++ .../@stdlib/fs/append-file/bin/cli | 109 +++++++ .../@stdlib/fs/append-file/docs/repl.txt | 65 +++++ .../fs/append-file/docs/types/index.d.ts | 142 +++++++++ .../@stdlib/fs/append-file/docs/types/test.ts | 218 ++++++++++++++ .../@stdlib/fs/append-file/docs/usage.txt | 10 + .../@stdlib/fs/append-file/etc/cli_opts.json | 22 ++ .../@stdlib/fs/append-file/examples/index.js | 42 +++ .../@stdlib/fs/append-file/lib/async.js | 56 ++++ .../@stdlib/fs/append-file/lib/index.js | 60 ++++ .../@stdlib/fs/append-file/lib/sync.js | 58 ++++ .../@stdlib/fs/append-file/package.json | 69 +++++ .../@stdlib/fs/append-file/test/test.async.js | 219 ++++++++++++++ .../@stdlib/fs/append-file/test/test.cli.js | 270 ++++++++++++++++++ .../@stdlib/fs/append-file/test/test.js | 40 +++ .../@stdlib/fs/append-file/test/test.sync.js | 221 ++++++++++++++ 17 files changed, 1928 insertions(+) create mode 100644 lib/node_modules/@stdlib/fs/append-file/README.md create mode 100644 lib/node_modules/@stdlib/fs/append-file/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/fs/append-file/bin/cli create mode 100644 lib/node_modules/@stdlib/fs/append-file/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/fs/append-file/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/fs/append-file/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/fs/append-file/docs/usage.txt create mode 100644 lib/node_modules/@stdlib/fs/append-file/etc/cli_opts.json create mode 100644 lib/node_modules/@stdlib/fs/append-file/examples/index.js create mode 100644 lib/node_modules/@stdlib/fs/append-file/lib/async.js create mode 100644 lib/node_modules/@stdlib/fs/append-file/lib/index.js create mode 100644 lib/node_modules/@stdlib/fs/append-file/lib/sync.js create mode 100644 lib/node_modules/@stdlib/fs/append-file/package.json create mode 100644 lib/node_modules/@stdlib/fs/append-file/test/test.async.js create mode 100644 lib/node_modules/@stdlib/fs/append-file/test/test.cli.js create mode 100644 lib/node_modules/@stdlib/fs/append-file/test/test.js create mode 100644 lib/node_modules/@stdlib/fs/append-file/test/test.sync.js diff --git a/lib/node_modules/@stdlib/fs/append-file/README.md b/lib/node_modules/@stdlib/fs/append-file/README.md new file mode 100644 index 000000000000..bb6cd9a478d4 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/append-file/README.md @@ -0,0 +1,247 @@ + + +# Append File + +> Append data to a file. + +
+ +## Usage + +```javascript +var appendFile = require("@stdlib/fs/append-file"); +``` + +#### appendFile( file, data\[, options], clbk ) + +Asynchronously appends `data` to a `file`. + +```javascript +var join = require("path").join; + +var fpath = join(__dirname, "examples", "fixtures", "file.txt"); + +appendFile(fpath, "beep boop\n", onAppend); + +function onAppend(error) { + if (error) { + throw error; + } +} +``` + +The `data` argument may be either a `string` or a [`Buffer`][@stdlib/buffer/ctor]. + +```javascript +var join = require("path").join; +var string2buffer = require("@stdlib/buffer/from-string"); + +var fpath = join(__dirname, "examples", "fixtures", "file.txt"); + +appendFile(fpath, string2buffer("beep boop\n"), onAppend); + +function onAppend(error) { + if (error) { + throw error; + } +} +``` + +The function accepts the same `options` and has the same defaults as [`fs.appendFile()`][node-fs]. + +#### appendFile.sync( file, data\[, options] ) + +Synchronously appends `data` to a `file`. + +```javascript +var join = require("path").join; + +var fpath = join(__dirname, "examples", "fixtures", "file.txt"); + +var err = appendFile.sync(fpath, "beep boop\n"); +if (err instanceof Error) { + throw err; +} +``` + +The function accepts the same `options` and has the same defaults as [`fs.appendFileSync()`][node-fs]. + +
+ + + +
+ +## Notes + + + + ```javascript + var fs = require( 'fs' ); + + // Check for directory path existence to prevent an error being thrown... + if ( fs.existsSync( '/path/to' ) ) { + fs.appendFileSync( '/path/to/file.txt', 'beep boop\n' ); + } + ``` + + can be replaced by an approach which addresses existence via `error` handling. + + + + ```javascript + var appendFile = require( '@stdlib/fs/append-file' ); + + // Explicitly handle the error... + try{ + appendFile.sync( '/path/to/file.txt', 'beep boop\n' ); + } catch(err) { + throw err + } + ``` + +
+ + + +
+ +## Examples + + + +```javascript +var join = require("path").join; +var appendFile = require("@stdlib/fs/append-file"); + +var fpath = join(__dirname, "examples", "fixtures", "file.txt"); + +// Synchronously append data to a file: +try { + appendFile.sync(fpath, "beep boop\n", "utf8"); + // throws no errors +} catch (err) { + console.log(err instanceof Error); + // => false +} + +// Asynchronously append data to a file: +appendFile(fpath, "beep boop\n", onAppend); + +function onAppend(error) { + if (error) { + console.error("Error: %s", error.message); + } + console.log("Success!"); +} +``` + +
+ + + +--- + +
+ +## CLI + +
+ +### Usage + +```text +Usage: append-file [options] + +Options: + + -h, --help Print this message. + -V, --version Print the package version. + --enc, --encoding encoding Encoding. Default: 'utf8'. + --flag flag Flag. Default: 'a'. + --mode mode Mode. Default: 0o666. +``` + +
+ + + +
+ +### Notes + +- Relative output file paths are resolved relative to the current working directory. +- Errors are written to `stderr`. +- File contents should be provided over `stdin` as part of a [standard stream][standard-stream] pipeline. + +
+ + + +
+ +### Examples + +```bash +$ printf 'beep boop\n' | append-file ./examples/fixtures/file.txt +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/fs/append-file/benchmark/benchmark.js b/lib/node_modules/@stdlib/fs/append-file/benchmark/benchmark.js new file mode 100644 index 000000000000..f663f60b73d4 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/append-file/benchmark/benchmark.js @@ -0,0 +1,80 @@ +/** + * @license Apache-2.0 + * + * Copyright (c) 2018 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 join = require("path").join; +var bench = require("@stdlib/bench"); +var readFile = require("@stdlib/fs/read-file").sync; +var pkg = require("./../package.json").name; +var appendFile = require("./../lib"); + +// FIXTURES // + +var FILEPATH = join(__dirname, "fixtures", "file.txt"); +var DATA = readFile(FILEPATH); + +// MAIN // + +bench(pkg, function benchmark(b) { + var i; + + i = 0; + b.tic(); + + return next(); + + function next() { + i += 1; + if (i <= b.iterations) { + return appendFile(FILEPATH, DATA, done); + } + b.toc(); + b.pass("benchmark finished"); + b.end(); + } + + function done(error) { + if (error) { + b.fail(error.message); + } + next(); + } +}); + +bench(pkg + ":sync", function benchmark(b) { + var out; + let i; + + b.tic(); + for (i = 0; i < b.iterations; i++) { + out = appendFile.sync(FILEPATH, DATA); + if (out instanceof Error) { + b.fail(out.message); + } + } + b.toc(); + if (out instanceof Error) { + b.fail("something went wrong"); + } else { + b.pass("benchmark finished"); + } + b.end(); +}); diff --git a/lib/node_modules/@stdlib/fs/append-file/bin/cli b/lib/node_modules/@stdlib/fs/append-file/bin/cli new file mode 100644 index 000000000000..ab4be1543b73 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/append-file/bin/cli @@ -0,0 +1,109 @@ +#!/usr/bin/env node + +/** + * @license Apache-2.0 + * + * Copyright (c) 2018 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 stdin = require("@stdlib/process/read-stdin"); +var cwd = require("@stdlib/process/cwd"); +var appendFile = require("./../lib"); + +// MAIN // + +/** + * Main execution sequence. + * + * @private + * @returns {void} + */ +function main() { + var flags; + var fpath; + var args; + var opts; + 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(); + + opts = {}; + if (flags.encoding) { + opts.encoding = flags.encoding; + } + if (flags.flag) { + opts.flag = flags.flag; + } + if (flags.mode) { + opts.mode = parseInt(flags.mode, 8); + } + fpath = resolve(cwd(), args[0]); + + // Gather data from `stdin`... + stdin(onRead); + + /** + * Callback invoked upon reading from `stdin`. + * + * @private + * @param {(Error|null)} error - error object + * @param {Buffer} data - data + * @returns {void} + */ + function onRead(error, data) { + if (error) { + return cli.error(error); + } + appendFile(fpath, data, opts, onAppend); + } + + /** + * Callback invoked upon writing a file. + * + * @private + * @param {Error} [err] - error object + * @returns {void} + */ + function onAppend(err) { + if (err) { + return cli.error(err); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/fs/append-file/docs/repl.txt b/lib/node_modules/@stdlib/fs/append-file/docs/repl.txt new file mode 100644 index 000000000000..f2244ff85032 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/append-file/docs/repl.txt @@ -0,0 +1,65 @@ + +{{alias}}( path, data[, options], clbk ) + Asynchronously appends data to a file. + + Parameters + ---------- + path: string|Buffer|integer + Filename or file descriptor. + + data: string|Buffer + Data to append. + + options: Object|string (optional) + Options. If a string, the value is the encoding. + + options.encoding: string|null (optional) + Encoding. The encoding option is ignored if the data argument is a + buffer. Default: 'utf8'. + + options.flag: string (optional) + Flag. Default: 'a'. + + options.mode: integer (optional) + Mode. Default: 0o666. + + clbk: Function + Callback to invoke upon appending data to the file. + + Examples + -------- + > function onAppend( err ) { + ... if ( err ) { + ... console.error( err.message ); + ... } + ... }; + > {{alias}}( './beep/boop.txt', 'beep boop', onAppend ); + + +{{alias}}.sync( path, data[, options] ) + Synchronously appends data to a file. + + Parameters + ---------- + path: string|Buffer|integer + Filename or file descriptor. + + data: string|Buffer + Data to append. + + options: Object|string (optional) + Options. If a string, the value is the encoding. + + options.encoding: string|null (optional) + Encoding. The encoding option is ignored if the data argument is a + buffer. Default: 'utf8'. + + options.flag: string (optional) + Flag. Default: 'a'. + + options.mode: integer (optional) + Mode. Default: 0o666. + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/fs/append-file/docs/types/index.d.ts b/lib/node_modules/@stdlib/fs/append-file/docs/types/index.d.ts new file mode 100644 index 000000000000..106b4c0e7d04 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/append-file/docs/types/index.d.ts @@ -0,0 +1,142 @@ +/* + * @license Apache-2.0 + * + * Copyright (c) 2021 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 { Buffer } from "buffer"; + +/** + * Interface defining function options. + */ +interface Options { + /** + * Encoding; ignored if the data argument is a buffer (default: null). + */ + encoding?: string | null; + + /** + * Flag (default: 'a'). + */ + flag?: string; + + /** + * Mode (default: 0o666) + */ + mode?: number; +} + +/** + * Callback invoked upon writing data to a file. + * + * @param err - error object + */ +type Callback = (err: Error | null) => void; + +/** + * Interface for appending a file. + */ +interface AppendFile { + /** + * Asynchronously appends data to a file. + * + * @param path - file path or file descriptor + * @param data - data to append + * @param options - options; if a string, the value is the encoding + * @param clbk - callback to invoke after appending data to a file + * + * @example + * function onAppend( err ) { + * if ( err ) { + * throw err; + * } + * } + * + * var opts = { 'flag': 'r' }; + * appendFile( './beep/boop.txt', 'beep boop\n', opts, onAppend ); + */ + ( + path: string | Buffer | number, + data: string | Buffer, + options: Options | string, + clbk: Callback + ): void; + + /** + * Asynchronously appends data to a file. + * + * @param path - file path or file descriptor + * @param data - data to append + * @param clbk - callback to invoke after appending data to a file + * + * @example + * function onAppend( err ) { + * if ( err ) { + * throw err; + * } + * } + * + * appendFile( './beep/boop.txt', 'beep boop\n', onAppend ); + */ + (path: string | Buffer | number, data: string | Buffer, clbk: Callback): void; + + /** + * Synchronously appends data to a file. + * + * @param path - file path or file descriptor + * @param data - data to append + * @param options - options; if a string, the value is the encoding + * + * @example + * try { + * appendFileSync('./beep/boop.txt', 'data to append\n'); + * console.log('The "data to append" was appended to file!'); + * } catch (err) { + * throw err; + * } + */ + sync( + path: string | Buffer | number, + data: string | Buffer, + options?: Options | string + ): void; +} + +/** + * Asynchronously appends data to a file. + * + * @param path - file path or file descriptor + * @param data - data to append + * @param options - options; if a string, the value is the encoding + * @param clbk - callback to invoke after appending data to a file + * + * @example + * function onAppend( err ) { + * if ( err ) { + * throw err; + * } + * } + * + * appendFile( './beep/boop.txt', 'beep boop\n', onAppend ); + */ +declare var appendFile: AppendFile; + +// EXPORTS // + +export = appendFile; diff --git a/lib/node_modules/@stdlib/fs/append-file/docs/types/test.ts b/lib/node_modules/@stdlib/fs/append-file/docs/types/test.ts new file mode 100644 index 000000000000..38f227907ca6 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/append-file/docs/types/test.ts @@ -0,0 +1,218 @@ +/* + * @license Apache-2.0 + * + * Copyright (c) 2021 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 appendFile = require("./index"); + +const onAppend = (err: Error | null): void => { + if (err) { + throw err; + } +}; + +// TESTS // + +// The function does not have a return value... +{ + appendFile("./beep/boop.txt", "beepboop", onAppend); // $ExpectType void +} + +// The compiler throws an error if the function is provided a first argument which is not a string, buffer, or file descriptor... +{ + appendFile(false, "beepboop", onAppend); // $ExpectError + appendFile(true, "beepboop", onAppend); // $ExpectError + appendFile(null, "beepboop", onAppend); // $ExpectError + appendFile(undefined, "beepboop", onAppend); // $ExpectError + appendFile([], "beepboop", onAppend); // $ExpectError + appendFile({}, "beepboop", onAppend); // $ExpectError + appendFile((x: number): number => x, "beepboop", onAppend); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a string or buffer... +{ + appendFile("./beep/boop.txt", false, onAppend); // $ExpectError + appendFile("./beep/boop.txt", true, onAppend); // $ExpectError + appendFile("./beep/boop.txt", null, onAppend); // $ExpectError + appendFile("./beep/boop.txt", undefined, onAppend); // $ExpectError + appendFile("./beep/boop.txt", [], onAppend); // $ExpectError + appendFile("./beep/boop.txt", {}, onAppend); // $ExpectError + appendFile("./beep/boop.txt", (x: number): number => x, onAppend); // $ExpectError +} + +// The compiler throws an error if the function is provided a callback argument which is not a function with the expected signature... +{ + appendFile("/path/to/beepboop", "beepboop", "abc"); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", 1); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", false); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", true); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", null); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", undefined); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", []); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", {}); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", (x: number): number => x); // $ExpectError +} + +// The compiler throws an error if the function is provided an options argument which is not an object or string... +{ + appendFile("/path/to/beepboop", "beepboop", false, onAppend); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", true, onAppend); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", null, onAppend); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", undefined, onAppend); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", 123, onAppend); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", [], onAppend); // $ExpectError + appendFile( + "/path/to/beepboop", + "beepboop", + (x: number): number => x, + onAppend + ); // $ExpectError +} + +// The compiler throws an error if the function is provided an `encoding` option which is not a string or null... +{ + appendFile("/path/to/beepboop", "beepboop", { encoding: 123 }, onAppend); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", { encoding: true }, onAppend); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", { encoding: false }, onAppend); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", { encoding: [] }, onAppend); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", { encoding: {} }, onAppend); // $ExpectError + appendFile( + "/path/to/beepboop", + "beepboop", + { encoding: (x: number): number => x }, + onAppend + ); // $ExpectError +} + +// The compiler throws an error if the function is provided a `flag` option which is not a string... +{ + appendFile("/path/to/beepboop", "beepboop", { flag: 123 }, onAppend); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", { flag: true }, onAppend); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", { flag: false }, onAppend); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", { flag: null }, onAppend); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", { flag: [] }, onAppend); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", { flag: {} }, onAppend); // $ExpectError + appendFile( + "/path/to/beepboop", + "beepboop", + { flag: (x: number): number => x }, + onAppend + ); // $ExpectError +} + +// The compiler throws an error if the function is provided a `mode` option which is not a number... +{ + appendFile("/path/to/beepboop", "beepboop", { mode: "abc" }, onAppend); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", { mode: true }, onAppend); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", { mode: false }, onAppend); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", { mode: null }, onAppend); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", { mode: [] }, onAppend); // $ExpectError + appendFile("/path/to/beepboop", "beepboop", { mode: {} }, onAppend); // $ExpectError + appendFile( + "/path/to/beepboop", + "beepboop", + { mode: (x: number): number => x }, + onAppend + ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + appendFile(); // $ExpectError + appendFile("C:\\foo\\bar\\baz\\beepboop"); // $ExpectError + appendFile("C:\\foo\\bar\\baz\\beepboop", "beepboop"); // $ExpectError +} + +// Attached to main export is a `sync` method which returns an error or null... +{ + appendFile.sync("/path/to/beepboop", "beepboop"); // $ExpectType Error | null +} + +// The compiler throws an error if the `sync` method is provided a first argument which is not a string, buffer, or file descriptor... +{ + appendFile.sync(false, "beepboop"); // $ExpectError + appendFile.sync(true, "beepboop"); // $ExpectError + appendFile.sync(null, "beepboop"); // $ExpectError + appendFile.sync(undefined, "beepboop"); // $ExpectError + appendFile.sync([], "beepboop"); // $ExpectError + appendFile.sync({}, "beepboop"); // $ExpectError + appendFile.sync((x: number): number => x, "beepboop"); // $ExpectError +} + +// The compiler throws an error if the `sync` method is provided a second argument which is not a string or buffer... +{ + appendFile.sync("/path/to/beepboop", false); // $ExpectError + appendFile.sync("/path/to/beepboop", true); // $ExpectError + appendFile.sync("/path/to/beepboop", null); // $ExpectError + appendFile.sync("/path/to/beepboop", undefined); // $ExpectError + appendFile.sync("/path/to/beepboop", []); // $ExpectError + appendFile.sync("/path/to/beepboop", {}); // $ExpectError + appendFile.sync("/path/to/beepboop", (x: number): number => x); // $ExpectError +} + +// The compiler throws an error if the `sync` method is provided an options argument which is not an object or string... +{ + appendFile.sync("/path/to/beepboop", "beepboop", null); // $ExpectError + appendFile.sync("/path/to/beepboop", "beepboop", true); // $ExpectError + appendFile.sync("/path/to/beepboop", "beepboop", false); // $ExpectError + appendFile.sync("/path/to/beepboop", "beepboop", 123); // $ExpectError + appendFile.sync("/path/to/beepboop", "beepboop", []); // $ExpectError + appendFile.sync("/path/to/beepboop", "beepboop", (x: number): number => x); // $ExpectError +} + +// The compiler throws an error if the `sync` method is provided an `encoding` option which is not a string or null... +{ + appendFile.sync("/path/to/beepboop", "beepboop", { encoding: 123 }); // $ExpectError + appendFile.sync("/path/to/beepboop", "beepboop", { encoding: true }); // $ExpectError + appendFile.sync("/path/to/beepboop", "beepboop", { encoding: false }); // $ExpectError + appendFile.sync("/path/to/beepboop", "beepboop", { encoding: [] }); // $ExpectError + appendFile.sync("/path/to/beepboop", "beepboop", { encoding: {} }); // $ExpectError + appendFile.sync("/path/to/beepboop", "beepboop", { + encoding: (x: number): number => x, + }); // $ExpectError +} + +// The compiler throws an error if the `sync` method is provided a `flag` option which is not a string... +{ + appendFile.sync("/path/to/beepboop", "beepboop", { flag: 123 }); // $ExpectError + appendFile.sync("/path/to/beepboop", "beepboop", { flag: true }); // $ExpectError + appendFile.sync("/path/to/beepboop", "beepboop", { flag: false }); // $ExpectError + appendFile.sync("/path/to/beepboop", "beepboop", { flag: null }); // $ExpectError + appendFile.sync("/path/to/beepboop", "beepboop", { flag: [] }); // $ExpectError + appendFile.sync("/path/to/beepboop", "beepboop", { flag: {} }); // $ExpectError + appendFile.sync("/path/to/beepboop", "beepboop", { + flag: (x: number): number => x, + }); // $ExpectError +} + +// The compiler throws an error if the `sync` method is provided a `mode` option which is not a number... +{ + appendFile.sync("/path/to/beepboop", "beepboop", { mode: "abc" }); // $ExpectError + appendFile.sync("/path/to/beepboop", "beepboop", { mode: true }); // $ExpectError + appendFile.sync("/path/to/beepboop", "beepboop", { mode: false }); // $ExpectError + appendFile.sync("/path/to/beepboop", "beepboop", { mode: null }); // $ExpectError + appendFile.sync("/path/to/beepboop", "beepboop", { mode: [] }); // $ExpectError + appendFile.sync("/path/to/beepboop", "beepboop", { mode: {} }); // $ExpectError + appendFile.sync("/path/to/beepboop", "beepboop", { + mode: (x: number): number => x, + }); // $ExpectError +} + +// The compiler throws an error if the `sync` method is provided an unsupported number of arguments... +{ + appendFile.sync(); // $ExpectError + appendFile.sync("/path/to/beepboop"); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/fs/append-file/docs/usage.txt b/lib/node_modules/@stdlib/fs/append-file/docs/usage.txt new file mode 100644 index 000000000000..8fadf00fcab2 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/append-file/docs/usage.txt @@ -0,0 +1,10 @@ + +Usage: append-file [options] + +Options: + + -h, --help Print this message. + -V, --version Print the package version. + --enc, --encoding encoding Encoding. Default: 'utf8'. + --flag flag Flag. Default: 'a'. + --mode mode Mode. Default: 0o666. \ No newline at end of file diff --git a/lib/node_modules/@stdlib/fs/append-file/etc/cli_opts.json b/lib/node_modules/@stdlib/fs/append-file/etc/cli_opts.json new file mode 100644 index 000000000000..2f250be139c3 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/append-file/etc/cli_opts.json @@ -0,0 +1,22 @@ +{ + "string": [ + "encoding", + "flag", + "mode" + ], + "boolean": [ + "help", + "version" + ], + "alias": { + "help": [ + "h" + ], + "version": [ + "V" + ], + "encoding": [ + "enc" + ] + } +} diff --git a/lib/node_modules/@stdlib/fs/append-file/examples/index.js b/lib/node_modules/@stdlib/fs/append-file/examples/index.js new file mode 100644 index 000000000000..281280de84a4 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/append-file/examples/index.js @@ -0,0 +1,42 @@ +/** + * @license Apache-2.0 + * + * Copyright (c) 2018 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 join = require("path").join; +var appendFile = require("./../lib"); + +var fpath = join(__dirname, "fixtures", "file.txt"); + +// Synchronously append data to a file: +try { + appendFile.sync(fpath, "beep boop\n", "utf8"); +} catch (err) { + console.log(err.message); + // => false +} + +// Asynchronously append data to a file: +appendFile(fpath, "appended something\n", onAppend); + +function onAppend(err) { + if (err) { + console.error("Error: %s", err.message); + } + console.log("Success!"); +} diff --git a/lib/node_modules/@stdlib/fs/append-file/lib/async.js b/lib/node_modules/@stdlib/fs/append-file/lib/async.js new file mode 100644 index 000000000000..0d32fe16e4ad --- /dev/null +++ b/lib/node_modules/@stdlib/fs/append-file/lib/async.js @@ -0,0 +1,56 @@ +/** + * @license Apache-2.0 + * + * Copyright (c) 2018 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 append = require("fs").appendFile; + +// MAIN // + +/** + * Asynchronously append data to a file, creating the file if it does not yet exist. + * + * @param {(string|Buffer|integer)} path - file path or file descriptor + * @param {(string|Buffer)} data - data to append + * @param {(Object|string)} [options] - options + * @param {Function} clbk - callback to invoke after appending data to the file + * + * @example + * function onAppend( err ) { + * if ( err ) { + * throw err; + * } + * } + * + * appendFile( './beep/boop.txt', 'appended something\n', onAppend ); + */ +function appendFile() { + var args; + var i; + args = []; + for (i = 0; i < arguments.length; i++) { + args.push(arguments[i]); + } + append.apply(null, args); +} + +// EXPORTS // + +module.exports = appendFile; diff --git a/lib/node_modules/@stdlib/fs/append-file/lib/index.js b/lib/node_modules/@stdlib/fs/append-file/lib/index.js new file mode 100644 index 000000000000..c51d3ff6fca7 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/append-file/lib/index.js @@ -0,0 +1,60 @@ +/** + * @license Apache-2.0 + * + * Copyright (c) 2018 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"; + +/** + * Appends data to a file. + * + * @module @stdlib/fs/append-file + * + * @example + * var appendFile = require( '@stdlib/fs/append-file' ); + * + * function onAppend( err ) { + * if ( err ) { + * throw err; + * } + * } + * + * appendFile( './beep/boop.txt', 'appended something\n', onAppend ); + * + * @example + * var appendFileSync = require( '@stdlib/fs/append-file' ).sync; + * + * try { + * appendFileSync('./beep/boop.txt', 'data to append\n'); + * console.log('The "data to append" was appended to file!'); + * } catch (err) { + * throw err; + * } + */ + +// MODULES // + +var setReadOnly = require("@stdlib/utils/define-nonenumerable-read-only-property"); +var async = require("./async.js"); +var sync = require("./sync.js"); + +// MAIN // + +setReadOnly(async, "sync", sync); + +// EXPORTS // + +module.exports = async; diff --git a/lib/node_modules/@stdlib/fs/append-file/lib/sync.js b/lib/node_modules/@stdlib/fs/append-file/lib/sync.js new file mode 100644 index 000000000000..140c6fa198fe --- /dev/null +++ b/lib/node_modules/@stdlib/fs/append-file/lib/sync.js @@ -0,0 +1,58 @@ +/** + * @license Apache-2.0 + * + * Copyright (c) 2018 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 appendFile = require("fs").appendFileSync; // eslint-disable-line node/no-sync + +// MAIN // + +/** + * Synchronously append data to a file, creating the file if it does not yet exist. + * + * @param {(string|Buffer|integer)} path - file path or file descriptor + * @param {(string|Buffer)} data - data to append + * @param {(Object|string)} [options] - options + * + * @example + * try { + * appendFileSync('./beep/boop.txt', 'data to append\n'); + * console.log('The "data to append" was appended to file!'); + * } catch (err) { + * throw err; + * } + */ + +function appendFileSync(path, data, options) { + try { + if (arguments.length > 2) { + appendFile(path, data, options); + } else { + appendFile(path, data); + } + } catch (err) { + throw err; + } + return null; +} + +// EXPORTS // + +module.exports = appendFileSync; diff --git a/lib/node_modules/@stdlib/fs/append-file/package.json b/lib/node_modules/@stdlib/fs/append-file/package.json new file mode 100644 index 000000000000..adda3eb66f93 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/append-file/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/fs/append-file", + "version": "0.0.0", + "description": "Appends data to a file.", + "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": { + "append-file": "./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", + "appendfile", + "appendfilesync", + "path", + "async", + "sync", + "file", + "append", + "appends", + "open", + "filesystem" + ] +} diff --git a/lib/node_modules/@stdlib/fs/append-file/test/test.async.js b/lib/node_modules/@stdlib/fs/append-file/test/test.async.js new file mode 100644 index 000000000000..0e9e132b1a92 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/append-file/test/test.async.js @@ -0,0 +1,219 @@ +/** + * @license Apache-2.0 + * + * Copyright (c) 2018 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 join = require("path").join; +var tape = require("tape"); +var readFile = require("@stdlib/fs/read-file").sync; +var IS_BROWSER = require("@stdlib/assert/is-browser"); +var string2buffer = require("@stdlib/buffer/from-string"); +var appendFileSync = require("../lib/sync.js"); +var appendFile = require("../lib/async.js"); + +// VARIABLES // + +// Don't run tests in the browser...for now... +var opts = { + skip: IS_BROWSER, // FIXME +}; +var fpath = join(__dirname, "fixtures", "file.txt"); +var DATA = readFile(fpath, "utf8"); + +// FUNCTIONS // + +/** + * Restores a fixture file. + * + * ## Notes + * + * - Every function which has the **potential** to affect the fixture file should invoke this function immediately before calling `t.end()`. + * + * @private + */ +function restore() { + appendFileSync(fpath, DATA); +} + +// TESTS // + +tape("main export is a function", function test(t) { + t.ok(true, __filename); + t.strictEqual(typeof appendFile, "function", "main export is a function"); + t.end(); +}); + +tape("the function appends data to a file (string)", opts, function test(t) { + var expected = "beep boop 1"; + appendFile(fpath, "beep boop 1", onAppend); + + function onAppend(error) { + var actual; + if (error) { + t.fail(error.message); + } + actual = readFile(fpath, "utf8"); + t.strictEqual(actual, expected, "file contains expected contents"); + + restore(); + t.end(); + } +}); + +tape("the function appends data to a file (buffer)", opts, function test(t) { + var expected = "beep boop 2"; + appendFile(fpath, string2buffer("beep boop 2"), onAppend); + + function onAppend(error) { + var actual; + if (error) { + t.fail(error.message); + } + actual = readFile(fpath, "utf8"); + t.strictEqual(actual, expected, "file contains expected contents"); + + restore(); + t.end(); + } +}); + +tape( + "the function appends data to a file using provided options (option string)", + opts, + function test(t) { + var expected = "beep boop 3"; + appendFile(fpath, "beep boop 3", "utf8", onAppend); + + function onAppend(error) { + var actual; + if (error) { + t.fail(error.message); + } + actual = readFile(fpath, "utf8"); + t.strictEqual(actual, expected, "file contains expected contents"); + + restore(); + t.end(); + } + } +); + +tape( + "the function appends data to a file using provided options (option object)", + opts, + function test(t) { + var expected; + var opts; + + expected = "beep boop 4"; + opts = { + encoding: "utf8", + }; + appendFile(fpath, "beep boop 4", opts, onAppend); + + function onAppend(error) { + var actual; + if (error) { + t.fail(error.message); + } + actual = readFile(fpath, "utf8"); + t.strictEqual(actual, expected, "file contains expected contents"); + + restore(); + t.end(); + } + } +); + +tape( + "if the function encounters an error, the function returns the error", + opts, + function test(t) { + var file = + "beepboopbapbop/dkfjldjfaklsjf/bdlfalfas/bkldflakfjas/travashHRD"; // non-existent directory path + appendFile(file, "beepboopbapbop", onAppend); + + function onAppend(error) { + var expected; + var actual; + + t.strictEqual(error instanceof Error, true, error.message); + + expected = DATA; + actual = readFile(fpath, "utf8"); + t.strictEqual(actual, expected, "file contains expected contents"); + + restore(); + t.end(); + } + } +); + +tape( + "if the function encounters an error, the function returns the error (option string)", + opts, + function test(t) { + var file = "beepboopbapbop/dkfjldjfaklsjf/bdlfalfas/bkldflakfjas"; // non-existent directory path + appendFile(file, "beepboopbapbop", "utf8", onAppend); + + function onAppend(error) { + var expected; + var actual; + + t.strictEqual(error instanceof Error, true, error.message); + + expected = DATA; + actual = readFile(fpath, "utf8"); + t.strictEqual(actual, expected, "file contains expected contents"); + + restore(); + t.end(); + } + } +); + +tape( + "if the function encounters an error, the function returns the error (option object)", + opts, + function test(t) { + var file; + var opts; + + file = "beepboopbapbop/dkfjldjfaklsjf/bdlfalftisas/bkldflHRDakfjas"; // non-existent directory path + opts = { + encoding: "utf8", + }; + appendFile(file, "beepboopbapbop", opts, onAppend); + + function onAppend(error) { + var expected; + var actual; + + t.strictEqual(error instanceof Error, true, error.message); + + expected = DATA; + actual = readFile(fpath, "utf8"); + t.strictEqual(actual, expected, "file contains expected contents"); + + restore(); + t.end(); + } + } +); diff --git a/lib/node_modules/@stdlib/fs/append-file/test/test.cli.js b/lib/node_modules/@stdlib/fs/append-file/test/test.cli.js new file mode 100644 index 000000000000..5d62caea716f --- /dev/null +++ b/lib/node_modules/@stdlib/fs/append-file/test/test.cli.js @@ -0,0 +1,270 @@ +/** + * @license Apache-2.0 + * + * Copyright (c) 2018 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 join = require("path").join; +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 replace = require("@stdlib/string/replace"); +var readFileSync = require("@stdlib/fs/read-file").sync; +var appendFileSync = require("../lib/sync.js"); + +// VARIABLES // + +var fpath = resolve(__dirname, "..", "bin", "cli"); +var opts = { + skip: IS_BROWSER || IS_WINDOWS, +}; +var FILE = join(__dirname, "fixtures", "file.txt"); +var DATA = readFileSync(FILE); + +// FIXTURES // + +var PKG_VERSION = require("./../package.json").version; + +// FUNCTIONS // + +/** + * Restores a fixture file. + * + * ## Notes + * + * - Every function which has the **potential** to affect the fixture file should invoke this function immediately before calling `t.end()`. + * + * @private + */ +function restore() { + appendFileSync(FILE, DATA); +} + +// 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 appends data received from `stdin` to a file", + opts, + function test(t) { + var expected; + var opts; + var cmd; + + cmd = ['printf "beep boop 1"', "|", EXEC_PATH, fpath, FILE]; + opts = {}; + + expected = "beep boop 1"; + exec(cmd.join(" "), opts, done); + + function done(error, stdout, stderr) { + var actual; + if (error) { + t.fail(error.message); + } else { + t.strictEqual(stdout.toString(), "", "does not print to `stdout`"); + t.strictEqual(stderr.toString(), "", "does not print to `stderr`"); + } + actual = readFileSync(FILE, "utf8"); + t.strictEqual(actual, expected, "file contains expected contents"); + + restore(); + t.end(); + } + } +); + +tape( + "if an error is encountered when reading from `stdin`, the command-line interface prints an error and sets a non-zero exit code", + opts, + function test(t) { + var script; + var opts; + var cmd; + + script = readFileSync( + resolve(__dirname, "fixtures", "stdin_error.js.txt"), + { + encoding: "utf8", + } + ); + + // Replace single quotes with double quotes: + script = replace(script, "'", '"'); + + cmd = [EXEC_PATH, "-e", "'" + script + "'"]; + + opts = { + cwd: __dirname, + }; + + exec(cmd.join(" "), opts, done); + + function done(error, stdout, stderr) { + if (error) { + t.pass(error.message); + t.strictEqual(error.code, 1, "expected exit code"); + } + t.strictEqual(stdout.toString(), "", "does not print to `stdout`"); + t.strictEqual(stderr.toString(), "Error: beep\n", "expected value"); + + restore(); + t.end(); + } + } +); + +tape( + "if an error is encountered when appending to file, the command-line interface prints an error and sets a non-zero exit code", + opts, + function test(t) { + var script; + var opts; + var cmd; + + script = readFileSync( + resolve(__dirname, "fixtures", "write_error.js.txt"), + { + encoding: "utf8", + } + ); + + // Replace single quotes with double quotes: + script = replace(script, "'", '"'); + + cmd = [EXEC_PATH, "-e", "'" + script + "'"]; + + opts = { + cwd: __dirname, + }; + + exec(cmd.join(" "), opts, done); + + function done(error, stdout, stderr) { + if (error) { + t.pass(error.message); + t.strictEqual(error.code, 1, "expected exit code"); + } + t.strictEqual(stdout.toString(), "", "does not print to `stdout`"); + t.strictEqual(stderr.toString(), "Error: beep\n", "expected value"); + + restore(); + t.end(); + } + } +); diff --git a/lib/node_modules/@stdlib/fs/append-file/test/test.js b/lib/node_modules/@stdlib/fs/append-file/test/test.js new file mode 100644 index 000000000000..eebf36dcdcee --- /dev/null +++ b/lib/node_modules/@stdlib/fs/append-file/test/test.js @@ -0,0 +1,40 @@ +/** + * @license Apache-2.0 + * + * Copyright (c) 2018 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 appendFile = require("../lib"); + +// TESTS // + +tape("main export is a function", function test(t) { + t.ok(true, __filename); + t.strictEqual(typeof writeFile, "function", "main export is a function"); + t.end(); +}); + +tape( + "attached to the main export is a method that synchronously appends data to a file", + function test(t) { + t.strictEqual(typeof writeFile.sync, "function", "has method"); + t.end(); + } +); diff --git a/lib/node_modules/@stdlib/fs/append-file/test/test.sync.js b/lib/node_modules/@stdlib/fs/append-file/test/test.sync.js new file mode 100644 index 000000000000..b876d199ce08 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/append-file/test/test.sync.js @@ -0,0 +1,221 @@ +/** + * @license Apache-2.0 + * + * Copyright (c) 2018 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 join = require("path").join; +var tape = require("tape"); +var readFile = require("@stdlib/fs/read-file").sync; +var IS_BROWSER = require("@stdlib/assert/is-browser"); +var string2buffer = require("@stdlib/buffer/from-string"); +var appendFile = require("../lib/sync.js"); + +// VARIABLES // + +// Don't run tests in the browser...for now... +var opts = { + skip: IS_BROWSER, // FIXME +}; +var fpath = join(__dirname, "fixtures", "file.txt"); +var DATA = readFile(fpath, "utf8"); + +// FUNCTIONS // + +/** + * Restores a fixture file. + * + * ## Notes + * + * - Every function which has the **potential** to affect the fixture file should invoke this function immediately before calling `t.end()`. + * + * @private + */ +function restore() { + appendFile(fpath, DATA); +} + +// TESTS // + +tape("main export is a function", function test(t) { + t.ok(true, __filename); + t.strictEqual(typeof appendFile, "function", "main export is a function"); + t.end(); +}); + +tape("the function appends data to a file (string)", opts, function test(t) { + var expected; + var actual; + + expected = "beep boop 1"; + + appendFile(fpath, "beep boop 1"); + actual = readFile(fpath, "utf8"); + + t.strictEqual(actual, expected, "file contains expected data"); + + restore(); + t.end(); +}); + +tape("the function appends data to a file (buffer)", opts, function test(t) { + var expected; + var actual; + + expected = "beep boop 2"; + + appendFile(fpath, string2buffer("beep boop 2")); + actual = readFile(fpath, "utf8"); + + t.strictEqual(actual, expected, "file contains expected data"); + + restore(); + t.end(); +}); + +tape( + "the function appends data to a file using provided options (string)", + opts, + function test(t) { + var expected; + var actual; + + expected = "beep boop 3"; + + appendFile(fpath, "beep boop 3", "utf8"); + actual = readFile(fpath, "utf8"); + + t.strictEqual(actual, expected, "file contains expected data"); + + restore(); + t.end(); + } +); + +tape( + "the function appends data to a file using provided options (object)", + opts, + function test(t) { + var expected; + var actual; + var opts; + + expected = "beep boop 4"; + + opts = { + encoding: "utf8", + }; + appendFile(fpath, "beep boop 4", opts); + actual = readFile(fpath, "utf8"); + + t.strictEqual(actual, expected, "file contains expected data"); + + restore(); + t.end(); + } +); + +tape( + "if the function encounters an error, the function throws the error", + opts, + function test(t) { + var expected; + var actual; + var file; + var err; + + file = "beepboopbapbop/dkfjldjfaklsjf/bdlfalfas/bkldflakfjas"; // non-existent directory path + + try { + appendFile(file, "beepboopbapbop"); + } catch (error) { + err = error; + } + + t.strictEqual(err instanceof Error, true, err.message); + + expected = DATA; + actual = readFile(fpath, "utf8"); + t.strictEqual(actual, expected, "file contains expected contents"); + + restore(); + t.end(); + } +); + +tape( + "if the function encounters an error, the function throws the error (option string)", + opts, + function test(t) { + var expected; + var actual; + var file; + var err; + + file = "beepboopbapbop/dkfjldjfaklsjf/bdlfalfas/bkldflakfjas"; // non-existent directory path + + try { + appendFile(file, "beepboopbapbop", "utf8"); + } catch (error) { + err = error; + } + + t.strictEqual(err instanceof Error, true, err.message); + + expected = DATA; + actual = readFile(fpath, "utf8"); + t.strictEqual(actual, expected, "file contains expected contents"); + + restore(); + t.end(); + } +); + +tape( + "if the function encounters an error, the function throws the error (option object)", + opts, + function test(t) { + var expected; + var actual; + var file; + var opts; + var err; + + file = "beepboopbapbop/dkfjldjfaklsjf/bdlfalfas/bkldflakfjas"; // non-existent directory path + + opts = { + encoding: "utf8", + }; + + try { + appendFile(file, "beepboopbapbop", opts); + } catch (error) { + err = error; + } + + t.strictEqual(err instanceof Error, true, err.message); + + expected = DATA; + actual = readFile(fpath, "utf8"); + t.strictEqual(actual, expected, "file contains expected contents"); + + restore(); + t.end(); + } +); From eb22d523e4806958291e7ad6a969fd18192e4a13 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Wed, 20 Mar 2024 18:31:19 +0000 Subject: [PATCH 02/23] chore: update copyright years --- lib/node_modules/@stdlib/fs/append-file/README.md | 2 +- lib/node_modules/@stdlib/fs/append-file/benchmark/benchmark.js | 2 +- lib/node_modules/@stdlib/fs/append-file/bin/cli | 2 +- lib/node_modules/@stdlib/fs/append-file/docs/types/index.d.ts | 2 +- lib/node_modules/@stdlib/fs/append-file/docs/types/test.ts | 2 +- lib/node_modules/@stdlib/fs/append-file/examples/index.js | 2 +- lib/node_modules/@stdlib/fs/append-file/lib/async.js | 2 +- lib/node_modules/@stdlib/fs/append-file/lib/index.js | 2 +- lib/node_modules/@stdlib/fs/append-file/lib/sync.js | 2 +- lib/node_modules/@stdlib/fs/append-file/test/test.async.js | 2 +- lib/node_modules/@stdlib/fs/append-file/test/test.cli.js | 2 +- lib/node_modules/@stdlib/fs/append-file/test/test.js | 2 +- lib/node_modules/@stdlib/fs/append-file/test/test.sync.js | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/fs/append-file/README.md b/lib/node_modules/@stdlib/fs/append-file/README.md index bb6cd9a478d4..74b96e96a663 100644 --- a/lib/node_modules/@stdlib/fs/append-file/README.md +++ b/lib/node_modules/@stdlib/fs/append-file/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2018 The Stdlib Authors. +Copyright (c) 2024 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. diff --git a/lib/node_modules/@stdlib/fs/append-file/benchmark/benchmark.js b/lib/node_modules/@stdlib/fs/append-file/benchmark/benchmark.js index f663f60b73d4..2aea56008eb9 100644 --- a/lib/node_modules/@stdlib/fs/append-file/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/fs/append-file/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * - * Copyright (c) 2018 The Stdlib Authors. + * Copyright (c) 2024 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. diff --git a/lib/node_modules/@stdlib/fs/append-file/bin/cli b/lib/node_modules/@stdlib/fs/append-file/bin/cli index ab4be1543b73..0eda67d29f64 100644 --- a/lib/node_modules/@stdlib/fs/append-file/bin/cli +++ b/lib/node_modules/@stdlib/fs/append-file/bin/cli @@ -3,7 +3,7 @@ /** * @license Apache-2.0 * - * Copyright (c) 2018 The Stdlib Authors. + * Copyright (c) 2024 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. diff --git a/lib/node_modules/@stdlib/fs/append-file/docs/types/index.d.ts b/lib/node_modules/@stdlib/fs/append-file/docs/types/index.d.ts index 106b4c0e7d04..146e4c82f210 100644 --- a/lib/node_modules/@stdlib/fs/append-file/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/fs/append-file/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * - * Copyright (c) 2021 The Stdlib Authors. + * Copyright (c) 2024 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. diff --git a/lib/node_modules/@stdlib/fs/append-file/docs/types/test.ts b/lib/node_modules/@stdlib/fs/append-file/docs/types/test.ts index 38f227907ca6..d371533c77a7 100644 --- a/lib/node_modules/@stdlib/fs/append-file/docs/types/test.ts +++ b/lib/node_modules/@stdlib/fs/append-file/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * - * Copyright (c) 2021 The Stdlib Authors. + * Copyright (c) 2024 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. diff --git a/lib/node_modules/@stdlib/fs/append-file/examples/index.js b/lib/node_modules/@stdlib/fs/append-file/examples/index.js index 281280de84a4..12986a28edcf 100644 --- a/lib/node_modules/@stdlib/fs/append-file/examples/index.js +++ b/lib/node_modules/@stdlib/fs/append-file/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * - * Copyright (c) 2018 The Stdlib Authors. + * Copyright (c) 2024 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. diff --git a/lib/node_modules/@stdlib/fs/append-file/lib/async.js b/lib/node_modules/@stdlib/fs/append-file/lib/async.js index 0d32fe16e4ad..e063278039d0 100644 --- a/lib/node_modules/@stdlib/fs/append-file/lib/async.js +++ b/lib/node_modules/@stdlib/fs/append-file/lib/async.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * - * Copyright (c) 2018 The Stdlib Authors. + * Copyright (c) 2024 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. diff --git a/lib/node_modules/@stdlib/fs/append-file/lib/index.js b/lib/node_modules/@stdlib/fs/append-file/lib/index.js index c51d3ff6fca7..1abf08473bc0 100644 --- a/lib/node_modules/@stdlib/fs/append-file/lib/index.js +++ b/lib/node_modules/@stdlib/fs/append-file/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * - * Copyright (c) 2018 The Stdlib Authors. + * Copyright (c) 2024 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. diff --git a/lib/node_modules/@stdlib/fs/append-file/lib/sync.js b/lib/node_modules/@stdlib/fs/append-file/lib/sync.js index 140c6fa198fe..f49c22b22295 100644 --- a/lib/node_modules/@stdlib/fs/append-file/lib/sync.js +++ b/lib/node_modules/@stdlib/fs/append-file/lib/sync.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * - * Copyright (c) 2018 The Stdlib Authors. + * Copyright (c) 2024 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. diff --git a/lib/node_modules/@stdlib/fs/append-file/test/test.async.js b/lib/node_modules/@stdlib/fs/append-file/test/test.async.js index 0e9e132b1a92..6a4350ff219c 100644 --- a/lib/node_modules/@stdlib/fs/append-file/test/test.async.js +++ b/lib/node_modules/@stdlib/fs/append-file/test/test.async.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * - * Copyright (c) 2018 The Stdlib Authors. + * Copyright (c) 2024 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. diff --git a/lib/node_modules/@stdlib/fs/append-file/test/test.cli.js b/lib/node_modules/@stdlib/fs/append-file/test/test.cli.js index 5d62caea716f..1ce344261e46 100644 --- a/lib/node_modules/@stdlib/fs/append-file/test/test.cli.js +++ b/lib/node_modules/@stdlib/fs/append-file/test/test.cli.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * - * Copyright (c) 2018 The Stdlib Authors. + * Copyright (c) 2024 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. diff --git a/lib/node_modules/@stdlib/fs/append-file/test/test.js b/lib/node_modules/@stdlib/fs/append-file/test/test.js index eebf36dcdcee..9432894ea270 100644 --- a/lib/node_modules/@stdlib/fs/append-file/test/test.js +++ b/lib/node_modules/@stdlib/fs/append-file/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * - * Copyright (c) 2018 The Stdlib Authors. + * Copyright (c) 2024 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. diff --git a/lib/node_modules/@stdlib/fs/append-file/test/test.sync.js b/lib/node_modules/@stdlib/fs/append-file/test/test.sync.js index b876d199ce08..2950ca45a171 100644 --- a/lib/node_modules/@stdlib/fs/append-file/test/test.sync.js +++ b/lib/node_modules/@stdlib/fs/append-file/test/test.sync.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * - * Copyright (c) 2018 The Stdlib Authors. + * Copyright (c) 2024 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. From 2adca002ec36568eb3ad8603383a3b80cc667846 Mon Sep 17 00:00:00 2001 From: Hridyanshu7 Date: Fri, 22 Mar 2024 00:05:56 +0530 Subject: [PATCH 03/23] Attempts to solve the following issues in the PR -> run_affected_benchmarks / Run affected benchmarks (pull_request) -> run_affected_examples / Run changed examples (pull_request) -> run_affected_tests / Run affected tests (pull_request) --- .../@stdlib/fs/append-file/benchmark/fixtures/file.txt | 1 + .../@stdlib/fs/append-file/examples/fixtures/file.txt | 0 .../@stdlib/fs/append-file/test/fixtures/file.txt | 0 lib/node_modules/@stdlib/fs/append-file/test/test.async.js | 4 ++-- lib/node_modules/@stdlib/fs/append-file/test/test.js | 4 ++-- lib/node_modules/@stdlib/fs/append-file/test/test.sync.js | 3 ++- 6 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 lib/node_modules/@stdlib/fs/append-file/benchmark/fixtures/file.txt create mode 100644 lib/node_modules/@stdlib/fs/append-file/examples/fixtures/file.txt create mode 100644 lib/node_modules/@stdlib/fs/append-file/test/fixtures/file.txt diff --git a/lib/node_modules/@stdlib/fs/append-file/benchmark/fixtures/file.txt b/lib/node_modules/@stdlib/fs/append-file/benchmark/fixtures/file.txt new file mode 100644 index 000000000000..8d78e99b0d15 --- /dev/null +++ b/lib/node_modules/@stdlib/fs/append-file/benchmark/fixtures/file.txt @@ -0,0 +1 @@ +boop beep \ No newline at end of file diff --git a/lib/node_modules/@stdlib/fs/append-file/examples/fixtures/file.txt b/lib/node_modules/@stdlib/fs/append-file/examples/fixtures/file.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/lib/node_modules/@stdlib/fs/append-file/test/fixtures/file.txt b/lib/node_modules/@stdlib/fs/append-file/test/fixtures/file.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/lib/node_modules/@stdlib/fs/append-file/test/test.async.js b/lib/node_modules/@stdlib/fs/append-file/test/test.async.js index 0e9e132b1a92..d39672701868 100644 --- a/lib/node_modules/@stdlib/fs/append-file/test/test.async.js +++ b/lib/node_modules/@stdlib/fs/append-file/test/test.async.js @@ -23,9 +23,9 @@ var join = require("path").join; var tape = require("tape"); var readFile = require("@stdlib/fs/read-file").sync; +var writeFileSync = require("@stdlib/fs/write-file").sync; var IS_BROWSER = require("@stdlib/assert/is-browser"); var string2buffer = require("@stdlib/buffer/from-string"); -var appendFileSync = require("../lib/sync.js"); var appendFile = require("../lib/async.js"); // VARIABLES // @@ -49,7 +49,7 @@ var DATA = readFile(fpath, "utf8"); * @private */ function restore() { - appendFileSync(fpath, DATA); + writeFileSync(fpath, DATA); } // TESTS // diff --git a/lib/node_modules/@stdlib/fs/append-file/test/test.js b/lib/node_modules/@stdlib/fs/append-file/test/test.js index eebf36dcdcee..9019e240f9be 100644 --- a/lib/node_modules/@stdlib/fs/append-file/test/test.js +++ b/lib/node_modules/@stdlib/fs/append-file/test/test.js @@ -27,14 +27,14 @@ var appendFile = require("../lib"); tape("main export is a function", function test(t) { t.ok(true, __filename); - t.strictEqual(typeof writeFile, "function", "main export is a function"); + t.strictEqual(typeof appendFile, "function", "main export is a function"); t.end(); }); tape( "attached to the main export is a method that synchronously appends data to a file", function test(t) { - t.strictEqual(typeof writeFile.sync, "function", "has method"); + t.strictEqual(typeof appendFile.sync, "function", "has method"); t.end(); } ); diff --git a/lib/node_modules/@stdlib/fs/append-file/test/test.sync.js b/lib/node_modules/@stdlib/fs/append-file/test/test.sync.js index b876d199ce08..38f0b2374834 100644 --- a/lib/node_modules/@stdlib/fs/append-file/test/test.sync.js +++ b/lib/node_modules/@stdlib/fs/append-file/test/test.sync.js @@ -23,6 +23,7 @@ var join = require("path").join; var tape = require("tape"); var readFile = require("@stdlib/fs/read-file").sync; +var writeFile = require("@stdlib/fs/write-file").sync; var IS_BROWSER = require("@stdlib/assert/is-browser"); var string2buffer = require("@stdlib/buffer/from-string"); var appendFile = require("../lib/sync.js"); @@ -48,7 +49,7 @@ var DATA = readFile(fpath, "utf8"); * @private */ function restore() { - appendFile(fpath, DATA); + writeFile(fpath, DATA); } // TESTS // From 72d1a5820366e577dee583f728e3339a34f9cc03 Mon Sep 17 00:00:00 2001 From: Hridyanshu7 Date: Fri, 22 Mar 2024 04:04:18 +0530 Subject: [PATCH 04/23] attempt to solve the linting issues cming in the previous PRa --- .../@stdlib/fs/append-file/README.md | 84 +-- .../fs/append-file/benchmark/benchmark.js | 137 ++--- .../@stdlib/fs/append-file/bin/cli | 192 +++---- .../fs/append-file/docs/types/index.d.ts | 236 +++++---- .../@stdlib/fs/append-file/docs/types/test.ts | 293 +++++----- .../@stdlib/fs/append-file/etc/cli_opts.json | 40 +- .../@stdlib/fs/append-file/examples/index.js | 60 +-- .../@stdlib/fs/append-file/lib/async.js | 87 +-- .../@stdlib/fs/append-file/lib/index.js | 97 ++-- .../@stdlib/fs/append-file/lib/sync.js | 93 ++-- .../@stdlib/fs/append-file/package.json | 1 - .../@stdlib/fs/append-file/test/test.async.js | 374 ++++++------- .../@stdlib/fs/append-file/test/test.cli.js | 501 ++++++++++-------- .../@stdlib/fs/append-file/test/test.js | 62 +-- .../@stdlib/fs/append-file/test/test.sync.js | 352 ++++++------ 15 files changed, 1341 insertions(+), 1268 deletions(-) diff --git a/lib/node_modules/@stdlib/fs/append-file/README.md b/lib/node_modules/@stdlib/fs/append-file/README.md index 74b96e96a663..1e6c4c95cbd3 100644 --- a/lib/node_modules/@stdlib/fs/append-file/README.md +++ b/lib/node_modules/@stdlib/fs/append-file/README.md @@ -27,7 +27,7 @@ limitations under the License. ## Usage ```javascript -var appendFile = require("@stdlib/fs/append-file"); +var appendFile = require( '@stdlib/fs/append-file' ); ``` #### appendFile( file, data\[, options], clbk ) @@ -35,33 +35,33 @@ var appendFile = require("@stdlib/fs/append-file"); Asynchronously appends `data` to a `file`. ```javascript -var join = require("path").join; +var join = require( 'path' ).join; -var fpath = join(__dirname, "examples", "fixtures", "file.txt"); +var fpath = join( __dirname, 'examples', 'fixtures', 'file.txt' ); -appendFile(fpath, "beep boop\n", onAppend); +appendFile( fpath, 'beep boop\n', onAppend ); -function onAppend(error) { - if (error) { - throw error; - } +function onAppend( error ) { + if ( error ) { + throw error; + } } ``` The `data` argument may be either a `string` or a [`Buffer`][@stdlib/buffer/ctor]. ```javascript -var join = require("path").join; -var string2buffer = require("@stdlib/buffer/from-string"); +var join = require( 'path' ).join; +var string2buffer = require( '@stdlib/buffer/from-string' ); -var fpath = join(__dirname, "examples", "fixtures", "file.txt"); +var fpath = join( __dirname, 'examples', 'fixtures', 'file.txt' ); -appendFile(fpath, string2buffer("beep boop\n"), onAppend); +appendFile( fpath, string2buffer('beep boop\n'), onAppend ); -function onAppend(error) { - if (error) { - throw error; - } +function onAppend( error ) { + if ( error ) { + throw error; + } } ``` @@ -72,13 +72,13 @@ The function accepts the same `options` and has the same defaults as [`fs.append Synchronously appends `data` to a `file`. ```javascript -var join = require("path").join; +var join = require( 'path' ).join; -var fpath = join(__dirname, "examples", "fixtures", "file.txt"); +var fpath = join( __dirname, 'examples', 'fixtures', 'file.txt' ); -var err = appendFile.sync(fpath, "beep boop\n"); -if (err instanceof Error) { - throw err; +var err = appendFile.sync( fpath, 'beep boop\n' ); +if ( err instanceof Error ) { + throw err; } ``` @@ -113,8 +113,8 @@ The function accepts the same `options` and has the same defaults as [`fs.append // Explicitly handle the error... try{ appendFile.sync( '/path/to/file.txt', 'beep boop\n' ); - } catch(err) { - throw err + } catch( error ) { + throw error } ``` @@ -129,28 +129,28 @@ The function accepts the same `options` and has the same defaults as [`fs.append ```javascript -var join = require("path").join; -var appendFile = require("@stdlib/fs/append-file"); +var join = require( 'path' ).join; +var appendFile = require( '@stdlib/fs/append-file' ); -var fpath = join(__dirname, "examples", "fixtures", "file.txt"); +var fpath = join( __dirname, 'examples', 'fixtures', 'file.txt' ); // Synchronously append data to a file: try { - appendFile.sync(fpath, "beep boop\n", "utf8"); - // throws no errors -} catch (err) { - console.log(err instanceof Error); - // => false + appendFile.sync( fpath, 'beep boop\n', 'utf8' ); + // throws no errors +} catch ( error ) { + console.log( error instanceof Error ); + // => false } // Asynchronously append data to a file: -appendFile(fpath, "beep boop\n", onAppend); +appendFile( fpath, 'beep boop\n', onAppend ); -function onAppend(error) { - if (error) { - console.error("Error: %s", error.message); - } - console.log("Success!"); +function onAppend( error ) { + if ( error ) { + console.error( 'Error: %s', error.message ); + } + console.log( 'Success!' ); } ``` @@ -188,9 +188,9 @@ Options: ### Notes -- Relative output file paths are resolved relative to the current working directory. -- Errors are written to `stderr`. -- File contents should be provided over `stdin` as part of a [standard stream][standard-stream] pipeline. +- Relative output file paths are resolved relative to the current working directory. +- Errors are written to `stderr`. +- File contents should be provided over `stdin` as part of a [standard stream][standard-stream] pipeline. @@ -220,8 +220,8 @@ $ printf 'beep boop\n' | append-file ./examples/fixtures/file.txt ## See Also -- [`@stdlib/fs/exists`][@stdlib/fs/exists]: test whether a path exists on the filesystem. -- [`@stdlib/fs/read-file`][@stdlib/fs/read-file]: read the entire contents of a file. +- [`@stdlib/fs/exists`][@stdlib/fs/exists]: test whether a path exists on the filesystem. +- [`@stdlib/fs/read-file`][@stdlib/fs/read-file]: read the entire contents of a file. diff --git a/lib/node_modules/@stdlib/fs/append-file/benchmark/benchmark.js b/lib/node_modules/@stdlib/fs/append-file/benchmark/benchmark.js index 2aea56008eb9..cf695ff9bd27 100644 --- a/lib/node_modules/@stdlib/fs/append-file/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/fs/append-file/benchmark/benchmark.js @@ -1,80 +1,83 @@ /** - * @license Apache-2.0 - * - * Copyright (c) 2024 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"; +* @license Apache-2.0 +* +* Copyright (c) 2024 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 join = require("path").join; -var bench = require("@stdlib/bench"); -var readFile = require("@stdlib/fs/read-file").sync; -var pkg = require("./../package.json").name; -var appendFile = require("./../lib"); +var join = require( 'path' ).join; +var bench = require( '@stdlib/bench' ); +var readFile = require( '@stdlib/fs/read-file' ).sync; +var pkg = require( '../package.json' ).name; +var appendFile = require( '../lib' ); + // FIXTURES // -var FILEPATH = join(__dirname, "fixtures", "file.txt"); -var DATA = readFile(FILEPATH); +var FILEPATH = join( __dirname, 'fixtures', 'file.txt' ); +var DATA = readFile( FILEPATH ); + // MAIN // -bench(pkg, function benchmark(b) { - var i; - - i = 0; - b.tic(); - - return next(); - - function next() { - i += 1; - if (i <= b.iterations) { - return appendFile(FILEPATH, DATA, done); - } - b.toc(); - b.pass("benchmark finished"); - b.end(); - } - - function done(error) { - if (error) { - b.fail(error.message); - } - next(); - } +bench( pkg, function benchmark( b ) { + var i; + + i = 0; + b.tic(); + + return next(); + + function next() { + i += 1; + if ( i <= b.iterations ) { + return appendFile( FILEPATH, DATA, done ); + } + b.toc(); + b.pass( 'benchmark finished' ); + b.end(); + } + + function done( error ) { + if ( error ) { + b.fail( error.message ); + } + next(); + } }); -bench(pkg + ":sync", function benchmark(b) { - var out; - let i; - - b.tic(); - for (i = 0; i < b.iterations; i++) { - out = appendFile.sync(FILEPATH, DATA); - if (out instanceof Error) { - b.fail(out.message); - } - } - b.toc(); - if (out instanceof Error) { - b.fail("something went wrong"); - } else { - b.pass("benchmark finished"); - } - b.end(); +bench( pkg + ':sync', function benchmark( b ) { + var out; + let i; + + b.tic(); + for (i = 0; i < b.iterations; i++) { + out = appendFile.sync( FILEPATH, DATA ); + if ( out instanceof Error ) { + b.fail( out.message ); + } + } + b.toc(); + if ( out instanceof Error ) { + b.fail( 'something went wrong' ); + } else { + b.pass( 'benchmark finished' ); + } + b.end(); }); diff --git a/lib/node_modules/@stdlib/fs/append-file/bin/cli b/lib/node_modules/@stdlib/fs/append-file/bin/cli index 0eda67d29f64..ba9bbd597932 100644 --- a/lib/node_modules/@stdlib/fs/append-file/bin/cli +++ b/lib/node_modules/@stdlib/fs/append-file/bin/cli @@ -1,109 +1,111 @@ #!/usr/bin/env node /** - * @license Apache-2.0 - * - * Copyright (c) 2024 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"; +* @license Apache-2.0 +* +* Copyright (c) 2024 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 stdin = require("@stdlib/process/read-stdin"); -var cwd = require("@stdlib/process/cwd"); -var appendFile = require("./../lib"); +var resolve = require( 'path' ).resolve; +var readFileSync = require( '@stdlib/fs/read-file' ).sync; +var CLI = require( '@stdlib/cli/ctor' ); +var stdin = require( '@stdlib/process/read-stdin' ); +var cwd = require( '@stdlib/process/cwd' ); +var appendFile = require( '../lib' ); + // MAIN // /** - * Main execution sequence. - * - * @private - * @returns {void} - */ +* Main execution sequence. +* +* @private +* @returns {void} +*/ function main() { - var flags; - var fpath; - var args; - var opts; - 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(); - - opts = {}; - if (flags.encoding) { - opts.encoding = flags.encoding; - } - if (flags.flag) { - opts.flag = flags.flag; - } - if (flags.mode) { - opts.mode = parseInt(flags.mode, 8); - } - fpath = resolve(cwd(), args[0]); - - // Gather data from `stdin`... - stdin(onRead); - - /** - * Callback invoked upon reading from `stdin`. - * - * @private - * @param {(Error|null)} error - error object - * @param {Buffer} data - data - * @returns {void} - */ - function onRead(error, data) { - if (error) { - return cli.error(error); - } - appendFile(fpath, data, opts, onAppend); - } - - /** - * Callback invoked upon writing a file. - * - * @private - * @param {Error} [err] - error object - * @returns {void} - */ - function onAppend(err) { - if (err) { - return cli.error(err); - } - } + var flags; + var fpath; + var args; + var opts; + 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(); + + opts = {}; + if ( flags.encoding ) { + opts.encoding = flags.encoding; + } + if ( flags.flag ) { + opts.flag = flags.flag; + } + if ( flags.mode ) { + opts.mode = parseInt(flags.mode, 8); + } + fpath = resolve( cwd(), args[0] ); + + // Gather data from `stdin`... + stdin( onRead ); + + /** + * Callback invoked upon reading from `stdin`. + * + * @private + * @param {( Error|null )} error - error object + * @param { Buffer } data - data + * @returns { void } + */ + function onRead( error, data ) { + if ( error ) { + return cli.error( error ); + } + appendFile( fpath, data, opts, onAppend ); + } + + /** + * Callback invoked upon writing a file. + * + * @private + * @param { Error } [ err ] - error object + * @returns { void } + */ + function onAppend( err ) { + if ( err ) { + return cli.error( err ); + } + } } main(); diff --git a/lib/node_modules/@stdlib/fs/append-file/docs/types/index.d.ts b/lib/node_modules/@stdlib/fs/append-file/docs/types/index.d.ts index 146e4c82f210..2f59d898ea35 100644 --- a/lib/node_modules/@stdlib/fs/append-file/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/fs/append-file/docs/types/index.d.ts @@ -1,140 +1,144 @@ /* - * @license Apache-2.0 - * - * Copyright (c) 2024 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. - */ +* @license Apache-2.0 +* +* Copyright (c) 2024 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 { Buffer } from "buffer"; +import { Buffer } from 'buffer'; /** - * Interface defining function options. - */ +* Interface defining function options. +*/ interface Options { - /** - * Encoding; ignored if the data argument is a buffer (default: null). - */ - encoding?: string | null; + /** + * Encoding; ignored if the data argument is a buffer (default: null). + */ + encoding?: string | null; - /** - * Flag (default: 'a'). - */ - flag?: string; + /** + * Flag (default: 'a'). + */ + flag?: string; - /** - * Mode (default: 0o666) - */ - mode?: number; + /** + * Mode (default: 0o666) + */ + mode?: number; } /** - * Callback invoked upon writing data to a file. - * - * @param err - error object - */ -type Callback = (err: Error | null) => void; +* Callback invoked upon writing data to a file. +* +* @param err - error object +*/ +type Callback = ( err: Error | null ) => void; /** - * Interface for appending a file. - */ +* Interface for appending a file. +*/ interface AppendFile { - /** - * Asynchronously appends data to a file. - * - * @param path - file path or file descriptor - * @param data - data to append - * @param options - options; if a string, the value is the encoding - * @param clbk - callback to invoke after appending data to a file - * - * @example - * function onAppend( err ) { - * if ( err ) { - * throw err; - * } - * } - * - * var opts = { 'flag': 'r' }; - * appendFile( './beep/boop.txt', 'beep boop\n', opts, onAppend ); - */ - ( - path: string | Buffer | number, - data: string | Buffer, - options: Options | string, - clbk: Callback - ): void; + /** + * Asynchronously appends data to a file. + * + * @param path - file path or file descriptor + * @param data - data to append + * @param options - options; if a string, the value is the encoding + * @param clbk - callback to invoke after appending data to a file + * + * @example + * function onAppend( err ) { + * if ( err ) { + * throw err; + * } + * } + * + * var opts = { 'flag': 'r' }; + * appendFile( './beep/boop.txt', 'beep boop\n', opts, onAppend ); + */ + ( + path: string | Buffer | number, + data: string | Buffer, + options: Options | string, + clbk: Callback + ): void; - /** - * Asynchronously appends data to a file. - * - * @param path - file path or file descriptor - * @param data - data to append - * @param clbk - callback to invoke after appending data to a file - * - * @example - * function onAppend( err ) { - * if ( err ) { - * throw err; - * } - * } - * - * appendFile( './beep/boop.txt', 'beep boop\n', onAppend ); - */ - (path: string | Buffer | number, data: string | Buffer, clbk: Callback): void; + /** + * Asynchronously appends data to a file. + * + * @param path - file path or file descriptor + * @param data - data to append + * @param clbk - callback to invoke after appending data to a file + * + * @example + * function onAppend( err ) { + * if ( err ) { + * throw err; + * } + * } + * + * appendFile( './beep/boop.txt', 'beep boop\n', onAppend ); + */ + ( + path: string | Buffer | number, + data: string | Buffer, + clbk: Callback + ): void; - /** - * Synchronously appends data to a file. - * - * @param path - file path or file descriptor - * @param data - data to append - * @param options - options; if a string, the value is the encoding - * - * @example - * try { - * appendFileSync('./beep/boop.txt', 'data to append\n'); - * console.log('The "data to append" was appended to file!'); - * } catch (err) { - * throw err; - * } - */ - sync( - path: string | Buffer | number, - data: string | Buffer, - options?: Options | string - ): void; + /** + * Synchronously appends data to a file. + * + * @param path - file path or file descriptor + * @param data - data to append + * @param options - options; if a string, the value is the encoding + * + * @example + * try { + * appendFileSync('./beep/boop.txt', 'data to append\n'); + * console.log('The "data to append" was appended to file!'); + * } catch (err) { + * throw err; + * } + */ + sync( + path: string | Buffer | number, + data: string | Buffer, + options?: Options | string + ): void; } /** - * Asynchronously appends data to a file. - * - * @param path - file path or file descriptor - * @param data - data to append - * @param options - options; if a string, the value is the encoding - * @param clbk - callback to invoke after appending data to a file - * - * @example - * function onAppend( err ) { - * if ( err ) { - * throw err; - * } - * } - * - * appendFile( './beep/boop.txt', 'beep boop\n', onAppend ); - */ +* Asynchronously appends data to a file. +* +* @param path - file path or file descriptor +* @param data - data to append +* @param options - options; if a string, the value is the encoding +* @param clbk - callback to invoke after appending data to a file +* +* @example +* function onAppend( err ) { +* if ( err ) { +* throw err; +* } +* } +* +* appendFile( './beep/boop.txt', 'beep boop\n', onAppend ); +*/ declare var appendFile: AppendFile; // EXPORTS // diff --git a/lib/node_modules/@stdlib/fs/append-file/docs/types/test.ts b/lib/node_modules/@stdlib/fs/append-file/docs/types/test.ts index d371533c77a7..bf24a68d961a 100644 --- a/lib/node_modules/@stdlib/fs/append-file/docs/types/test.ts +++ b/lib/node_modules/@stdlib/fs/append-file/docs/types/test.ts @@ -1,218 +1,219 @@ /* - * @license Apache-2.0 - * - * Copyright (c) 2024 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 appendFile = require("./index"); - -const onAppend = (err: Error | null): void => { - if (err) { - throw err; - } +* @license Apache-2.0 +* +* Copyright (c) 2024 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 appendFile = require( './index' ); + +const onAppend = ( err: Error | null ): void => { + if ( err ) { + throw err; + } }; + // TESTS // // The function does not have a return value... { - appendFile("./beep/boop.txt", "beepboop", onAppend); // $ExpectType void + appendFile( './beep/boop.txt', 'beepboop', onAppend ); // $ExpectType void } // The compiler throws an error if the function is provided a first argument which is not a string, buffer, or file descriptor... { - appendFile(false, "beepboop", onAppend); // $ExpectError - appendFile(true, "beepboop", onAppend); // $ExpectError - appendFile(null, "beepboop", onAppend); // $ExpectError - appendFile(undefined, "beepboop", onAppend); // $ExpectError - appendFile([], "beepboop", onAppend); // $ExpectError - appendFile({}, "beepboop", onAppend); // $ExpectError - appendFile((x: number): number => x, "beepboop", onAppend); // $ExpectError + appendFile( false, 'beepboop', onAppend ); // $ExpectError + appendFile( true, 'beepboop', onAppend ); // $ExpectError + appendFile( null, 'beepboop', onAppend ); // $ExpectError + appendFile( undefined, 'beepboop', onAppend ); // $ExpectError + appendFile( [], 'beepboop', onAppend ); // $ExpectError + appendFile( {}, 'beepboop', onAppend ); // $ExpectError + appendFile( ( x: number ): number => x, 'beepboop', onAppend ); // $ExpectError } // The compiler throws an error if the function is provided a second argument which is not a string or buffer... { - appendFile("./beep/boop.txt", false, onAppend); // $ExpectError - appendFile("./beep/boop.txt", true, onAppend); // $ExpectError - appendFile("./beep/boop.txt", null, onAppend); // $ExpectError - appendFile("./beep/boop.txt", undefined, onAppend); // $ExpectError - appendFile("./beep/boop.txt", [], onAppend); // $ExpectError - appendFile("./beep/boop.txt", {}, onAppend); // $ExpectError - appendFile("./beep/boop.txt", (x: number): number => x, onAppend); // $ExpectError + appendFile( './beep/boop.txt', false, onAppend ); // $ExpectError + appendFile( './beep/boop.txt', true, onAppend ); // $ExpectError + appendFile( './beep/boop.txt', null, onAppend ); // $ExpectError + appendFile( './beep/boop.txt', undefined, onAppend ); // $ExpectError + appendFile( './beep/boop.txt', [], onAppend ); // $ExpectError + appendFile( './beep/boop.txt', {}, onAppend ); // $ExpectError + appendFile( './beep/boop.txt', ( x: number ): number => x, onAppend ); // $ExpectError } // The compiler throws an error if the function is provided a callback argument which is not a function with the expected signature... { - appendFile("/path/to/beepboop", "beepboop", "abc"); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", 1); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", false); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", true); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", null); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", undefined); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", []); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", {}); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", (x: number): number => x); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', 'abc' ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', 1 ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', false ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', true ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', null ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', undefined ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', [] ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', {} ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided an options argument which is not an object or string... { - appendFile("/path/to/beepboop", "beepboop", false, onAppend); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", true, onAppend); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", null, onAppend); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", undefined, onAppend); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", 123, onAppend); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", [], onAppend); // $ExpectError - appendFile( - "/path/to/beepboop", - "beepboop", - (x: number): number => x, - onAppend - ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', false, onAppend ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', true, onAppend ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', null, onAppend ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', undefined, onAppend ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', 123, onAppend ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', [], onAppend ); // $ExpectError + appendFile( + '/path/to/beepboop', + 'beepboop', + ( x: number ): number => x, + onAppend + ); // $ExpectError } // The compiler throws an error if the function is provided an `encoding` option which is not a string or null... { - appendFile("/path/to/beepboop", "beepboop", { encoding: 123 }, onAppend); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", { encoding: true }, onAppend); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", { encoding: false }, onAppend); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", { encoding: [] }, onAppend); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", { encoding: {} }, onAppend); // $ExpectError - appendFile( - "/path/to/beepboop", - "beepboop", - { encoding: (x: number): number => x }, - onAppend - ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', { encoding: 123 }, onAppend ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', { encoding: true }, onAppend ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', { encoding: false }, onAppend ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', { encoding: [] }, onAppend ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', { encoding: {} }, onAppend ); // $ExpectError + appendFile( + '/path/to/beepboop', + 'beepboop', + { encoding: ( x: number ): number => x }, + onAppend + ); // $ExpectError } // The compiler throws an error if the function is provided a `flag` option which is not a string... { - appendFile("/path/to/beepboop", "beepboop", { flag: 123 }, onAppend); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", { flag: true }, onAppend); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", { flag: false }, onAppend); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", { flag: null }, onAppend); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", { flag: [] }, onAppend); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", { flag: {} }, onAppend); // $ExpectError - appendFile( - "/path/to/beepboop", - "beepboop", - { flag: (x: number): number => x }, - onAppend - ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', { flag: 123 }, onAppend ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', { flag: true }, onAppend ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', { flag: false }, onAppend ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', { flag: null }, onAppend ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', { flag: [] }, onAppend ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', { flag: {} }, onAppend ); // $ExpectError + appendFile( + '/path/to/beepboop', + 'beepboop', + { flag: ( x: number ): number => x }, + onAppend + ); // $ExpectError } // The compiler throws an error if the function is provided a `mode` option which is not a number... { - appendFile("/path/to/beepboop", "beepboop", { mode: "abc" }, onAppend); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", { mode: true }, onAppend); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", { mode: false }, onAppend); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", { mode: null }, onAppend); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", { mode: [] }, onAppend); // $ExpectError - appendFile("/path/to/beepboop", "beepboop", { mode: {} }, onAppend); // $ExpectError - appendFile( - "/path/to/beepboop", - "beepboop", - { mode: (x: number): number => x }, - onAppend - ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', { mode: 'abc' }, onAppend ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', { mode: true }, onAppend ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', { mode: false }, onAppend ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', { mode: null }, onAppend ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', { mode: [] }, onAppend ); // $ExpectError + appendFile( '/path/to/beepboop', 'beepboop', { mode: {} }, onAppend ); // $ExpectError + appendFile( + '/path/to/beepboop', + 'beepboop', + { mode: ( x: number ): number => x }, + onAppend + ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... { - appendFile(); // $ExpectError - appendFile("C:\\foo\\bar\\baz\\beepboop"); // $ExpectError - appendFile("C:\\foo\\bar\\baz\\beepboop", "beepboop"); // $ExpectError + appendFile(); // $ExpectError + appendFile( 'C:\\foo\\bar\\baz\\beepboop' ); // $ExpectError + appendFile( 'C:\\foo\\bar\\baz\\beepboop', 'beepboop' ); // $ExpectError } // Attached to main export is a `sync` method which returns an error or null... { - appendFile.sync("/path/to/beepboop", "beepboop"); // $ExpectType Error | null + appendFile.sync( '/path/to/beepboop', 'beepboop' ); // $ExpectType Error | null } // The compiler throws an error if the `sync` method is provided a first argument which is not a string, buffer, or file descriptor... { - appendFile.sync(false, "beepboop"); // $ExpectError - appendFile.sync(true, "beepboop"); // $ExpectError - appendFile.sync(null, "beepboop"); // $ExpectError - appendFile.sync(undefined, "beepboop"); // $ExpectError - appendFile.sync([], "beepboop"); // $ExpectError - appendFile.sync({}, "beepboop"); // $ExpectError - appendFile.sync((x: number): number => x, "beepboop"); // $ExpectError + appendFile.sync( false, 'beepboop' ); // $ExpectError + appendFile.sync( true, 'beepboop' ); // $ExpectError + appendFile.sync( null, 'beepboop' ); // $ExpectError + appendFile.sync( undefined, 'beepboop' ); // $ExpectError + appendFile.sync( [], 'beepboop' ); // $ExpectError + appendFile.sync( {}, 'beepboop' ); // $ExpectError + appendFile.sync( ( x: number ): number => x, 'beepboop' ); // $ExpectError } // The compiler throws an error if the `sync` method is provided a second argument which is not a string or buffer... { - appendFile.sync("/path/to/beepboop", false); // $ExpectError - appendFile.sync("/path/to/beepboop", true); // $ExpectError - appendFile.sync("/path/to/beepboop", null); // $ExpectError - appendFile.sync("/path/to/beepboop", undefined); // $ExpectError - appendFile.sync("/path/to/beepboop", []); // $ExpectError - appendFile.sync("/path/to/beepboop", {}); // $ExpectError - appendFile.sync("/path/to/beepboop", (x: number): number => x); // $ExpectError + appendFile.sync( '/path/to/beepboop', false ); // $ExpectError + appendFile.sync( '/path/to/beepboop', true ); // $ExpectError + appendFile.sync( '/path/to/beepboop', null ); // $ExpectError + appendFile.sync( '/path/to/beepboop', undefined ); // $ExpectError + appendFile.sync( '/path/to/beepboop', [] ); // $ExpectError + appendFile.sync( '/path/to/beepboop', {} ); // $ExpectError + appendFile.sync( '/path/to/beepboop', ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the `sync` method is provided an options argument which is not an object or string... { - appendFile.sync("/path/to/beepboop", "beepboop", null); // $ExpectError - appendFile.sync("/path/to/beepboop", "beepboop", true); // $ExpectError - appendFile.sync("/path/to/beepboop", "beepboop", false); // $ExpectError - appendFile.sync("/path/to/beepboop", "beepboop", 123); // $ExpectError - appendFile.sync("/path/to/beepboop", "beepboop", []); // $ExpectError - appendFile.sync("/path/to/beepboop", "beepboop", (x: number): number => x); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', null ); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', true ); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', false ); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', 123 ); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', [] ); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the `sync` method is provided an `encoding` option which is not a string or null... { - appendFile.sync("/path/to/beepboop", "beepboop", { encoding: 123 }); // $ExpectError - appendFile.sync("/path/to/beepboop", "beepboop", { encoding: true }); // $ExpectError - appendFile.sync("/path/to/beepboop", "beepboop", { encoding: false }); // $ExpectError - appendFile.sync("/path/to/beepboop", "beepboop", { encoding: [] }); // $ExpectError - appendFile.sync("/path/to/beepboop", "beepboop", { encoding: {} }); // $ExpectError - appendFile.sync("/path/to/beepboop", "beepboop", { - encoding: (x: number): number => x, - }); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', { encoding: 123 } ); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', { encoding: true } ); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', { encoding: false } ); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', { encoding: [] } ); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', { encoding: {} } ); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', { + encoding: ( x: number ): number => x, + } ); // $ExpectError } // The compiler throws an error if the `sync` method is provided a `flag` option which is not a string... { - appendFile.sync("/path/to/beepboop", "beepboop", { flag: 123 }); // $ExpectError - appendFile.sync("/path/to/beepboop", "beepboop", { flag: true }); // $ExpectError - appendFile.sync("/path/to/beepboop", "beepboop", { flag: false }); // $ExpectError - appendFile.sync("/path/to/beepboop", "beepboop", { flag: null }); // $ExpectError - appendFile.sync("/path/to/beepboop", "beepboop", { flag: [] }); // $ExpectError - appendFile.sync("/path/to/beepboop", "beepboop", { flag: {} }); // $ExpectError - appendFile.sync("/path/to/beepboop", "beepboop", { - flag: (x: number): number => x, - }); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', { flag: 123 } ); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', { flag: true } ); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', { flag: false } ); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', { flag: null } ); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', { flag: [] } ); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', { flag: {} } ); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', { + flag: (x: number): number => x, + } ); // $ExpectError } // The compiler throws an error if the `sync` method is provided a `mode` option which is not a number... { - appendFile.sync("/path/to/beepboop", "beepboop", { mode: "abc" }); // $ExpectError - appendFile.sync("/path/to/beepboop", "beepboop", { mode: true }); // $ExpectError - appendFile.sync("/path/to/beepboop", "beepboop", { mode: false }); // $ExpectError - appendFile.sync("/path/to/beepboop", "beepboop", { mode: null }); // $ExpectError - appendFile.sync("/path/to/beepboop", "beepboop", { mode: [] }); // $ExpectError - appendFile.sync("/path/to/beepboop", "beepboop", { mode: {} }); // $ExpectError - appendFile.sync("/path/to/beepboop", "beepboop", { - mode: (x: number): number => x, - }); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', { mode: 'abc' } ); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', { mode: true } ); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', { mode: false } ); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', { mode: null } ); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', { mode: [] } ); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', { mode: {} } ); // $ExpectError + appendFile.sync( '/path/to/beepboop', 'beepboop', { + mode: ( x: number ): number => x, + } ); // $ExpectError } // The compiler throws an error if the `sync` method is provided an unsupported number of arguments... { - appendFile.sync(); // $ExpectError - appendFile.sync("/path/to/beepboop"); // $ExpectError + appendFile.sync(); // $ExpectError + appendFile.sync( '/path/to/beepboop' ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/fs/append-file/etc/cli_opts.json b/lib/node_modules/@stdlib/fs/append-file/etc/cli_opts.json index 2f250be139c3..d290ba89bdfb 100644 --- a/lib/node_modules/@stdlib/fs/append-file/etc/cli_opts.json +++ b/lib/node_modules/@stdlib/fs/append-file/etc/cli_opts.json @@ -1,22 +1,22 @@ { - "string": [ - "encoding", - "flag", - "mode" - ], - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ], - "encoding": [ - "enc" - ] - } + "string": [ + "encoding", + "flag", + "mode" + ], + "boolean": [ + "help", + "version" + ], + "alias": { + "help": [ + "h" + ], + "version": [ + "V" + ], + "encoding": [ + "enc" + ] + } } diff --git a/lib/node_modules/@stdlib/fs/append-file/examples/index.js b/lib/node_modules/@stdlib/fs/append-file/examples/index.js index 12986a28edcf..5db8a337d0fe 100644 --- a/lib/node_modules/@stdlib/fs/append-file/examples/index.js +++ b/lib/node_modules/@stdlib/fs/append-file/examples/index.js @@ -1,42 +1,42 @@ /** - * @license Apache-2.0 - * - * Copyright (c) 2024 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. - */ +* @license Apache-2.0 +* +* Copyright (c) 2024 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"; +'use strict'; -var join = require("path").join; -var appendFile = require("./../lib"); +var join = require( 'path' ).join; +var appendFile = require( './../lib' ); -var fpath = join(__dirname, "fixtures", "file.txt"); +var fpath = join( __dirname, 'fixtures', 'file.txt' ); // Synchronously append data to a file: try { - appendFile.sync(fpath, "beep boop\n", "utf8"); -} catch (err) { - console.log(err.message); - // => false + appendFile.sync( fpath, 'beep boop\n', 'utf8' ); +} catch ( err ) { + console.log( err.message ); + // => false } // Asynchronously append data to a file: -appendFile(fpath, "appended something\n", onAppend); +appendFile( fpath, 'appended something\n', onAppend ); -function onAppend(err) { - if (err) { - console.error("Error: %s", err.message); - } - console.log("Success!"); +function onAppend( err ) { + if ( err ) { + console.error( 'Error: %s', err.message ); + } + console.log( 'Success!' ); } diff --git a/lib/node_modules/@stdlib/fs/append-file/lib/async.js b/lib/node_modules/@stdlib/fs/append-file/lib/async.js index e063278039d0..8993277b07a7 100644 --- a/lib/node_modules/@stdlib/fs/append-file/lib/async.js +++ b/lib/node_modules/@stdlib/fs/append-file/lib/async.js @@ -1,56 +1,59 @@ /** - * @license Apache-2.0 - * - * Copyright (c) 2024 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"; +* @license Apache-2.0 +* +* Copyright (c) 2024 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 append = require("fs").appendFile; +var append = require( 'fs' ).appendFile; + // MAIN // /** - * Asynchronously append data to a file, creating the file if it does not yet exist. - * - * @param {(string|Buffer|integer)} path - file path or file descriptor - * @param {(string|Buffer)} data - data to append - * @param {(Object|string)} [options] - options - * @param {Function} clbk - callback to invoke after appending data to the file - * - * @example - * function onAppend( err ) { - * if ( err ) { - * throw err; - * } - * } - * - * appendFile( './beep/boop.txt', 'appended something\n', onAppend ); - */ +* Asynchronously append data to a file, creating the file if it does not yet exist. +* +* @param {( string|Buffer|integer )} path - file path or file descriptor +* @param {( string|Buffer )} data - data to append +* @param {( Object|string )} [options] - options +* @param { Function } clbk - callback to invoke after appending data to the file +* +* @example +* function onAppend( err ) { +* if ( err ) { +* throw err; +* } +* } +* +* appendFile( './beep/boop.txt', 'appended something\n', onAppend ); +*/ function appendFile() { - var args; - var i; - args = []; - for (i = 0; i < arguments.length; i++) { - args.push(arguments[i]); - } - append.apply(null, args); + var args; + var i; + args = []; + for (i = 0; i < arguments.length; i++) { + args.push( arguments[i] ); + } + append.apply( null, args ); } + // EXPORTS // module.exports = appendFile; diff --git a/lib/node_modules/@stdlib/fs/append-file/lib/index.js b/lib/node_modules/@stdlib/fs/append-file/lib/index.js index 1abf08473bc0..1f19ab1b83ca 100644 --- a/lib/node_modules/@stdlib/fs/append-file/lib/index.js +++ b/lib/node_modules/@stdlib/fs/append-file/lib/index.js @@ -1,59 +1,62 @@ /** - * @license Apache-2.0 - * - * Copyright (c) 2024 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"; +* @license Apache-2.0 +* +* Copyright (c) 2024 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'; /** - * Appends data to a file. - * - * @module @stdlib/fs/append-file - * - * @example - * var appendFile = require( '@stdlib/fs/append-file' ); - * - * function onAppend( err ) { - * if ( err ) { - * throw err; - * } - * } - * - * appendFile( './beep/boop.txt', 'appended something\n', onAppend ); - * - * @example - * var appendFileSync = require( '@stdlib/fs/append-file' ).sync; - * - * try { - * appendFileSync('./beep/boop.txt', 'data to append\n'); - * console.log('The "data to append" was appended to file!'); - * } catch (err) { - * throw err; - * } - */ +* Appends data to a file. +* +* @module @stdlib/fs/append-file +* +* @example +* var appendFile = require( '@stdlib/fs/append-file' ); +* +* function onAppend( err ) { +* if ( err ) { +* throw err; +* } +* } +* +* appendFile( './beep/boop.txt', 'appended something\n', onAppend ); +* +* @example +* var appendFileSync = require( '@stdlib/fs/append-file' ).sync; +* +* try { +* appendFileSync('./beep/boop.txt', 'data to append\n'); +* console.log('The "data to append" was appended to file!'); +* } catch (err) { +* throw err; +* } +*/ + // MODULES // -var setReadOnly = require("@stdlib/utils/define-nonenumerable-read-only-property"); -var async = require("./async.js"); -var sync = require("./sync.js"); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var async = require( './async.js' ); +var sync = require( './sync.js' ); + // MAIN // -setReadOnly(async, "sync", sync); +setReadOnly( async, 'sync', sync ); + // EXPORTS // diff --git a/lib/node_modules/@stdlib/fs/append-file/lib/sync.js b/lib/node_modules/@stdlib/fs/append-file/lib/sync.js index f49c22b22295..4861e0b86d32 100644 --- a/lib/node_modules/@stdlib/fs/append-file/lib/sync.js +++ b/lib/node_modules/@stdlib/fs/append-file/lib/sync.js @@ -1,58 +1,61 @@ /** - * @license Apache-2.0 - * - * Copyright (c) 2024 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"; +* @license Apache-2.0 +* +* Copyright (c) 2024 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 appendFile = require("fs").appendFileSync; // eslint-disable-line node/no-sync +var appendFile = require( 'fs' ).appendFileSync; // eslint-disable-line node/no-sync + // MAIN // /** - * Synchronously append data to a file, creating the file if it does not yet exist. - * - * @param {(string|Buffer|integer)} path - file path or file descriptor - * @param {(string|Buffer)} data - data to append - * @param {(Object|string)} [options] - options - * - * @example - * try { - * appendFileSync('./beep/boop.txt', 'data to append\n'); - * console.log('The "data to append" was appended to file!'); - * } catch (err) { - * throw err; - * } - */ - -function appendFileSync(path, data, options) { - try { - if (arguments.length > 2) { - appendFile(path, data, options); - } else { - appendFile(path, data); - } - } catch (err) { - throw err; - } - return null; +* Synchronously append data to a file, creating the file if it does not yet exist. +* +* @param {( string|Buffer|integer )} path - file path or file descriptor +* @param {( string|Buffer )} data - data to append +* @param {( Object|string )} [ options ] - options +* +* @example +* try { +* appendFileSync('./beep/boop.txt', 'data to append\n'); +* console.log('The "data to append" was appended to file!'); +* } catch (err) { +* throw err; +* } +*/ + +function appendFileSync( path, data, options ) { + try { + if ( arguments.length > 2 ) { + appendFile( path, data, options ); + } else { + appendFile( path, data ); + } + } catch ( err ) { + throw err; + } + return null; } + // EXPORTS // module.exports = appendFileSync; diff --git a/lib/node_modules/@stdlib/fs/append-file/package.json b/lib/node_modules/@stdlib/fs/append-file/package.json index adda3eb66f93..4b5452c73efd 100644 --- a/lib/node_modules/@stdlib/fs/append-file/package.json +++ b/lib/node_modules/@stdlib/fs/append-file/package.json @@ -34,7 +34,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": {}, "devDependencies": {}, "engines": { "node": ">=0.10.0", diff --git a/lib/node_modules/@stdlib/fs/append-file/test/test.async.js b/lib/node_modules/@stdlib/fs/append-file/test/test.async.js index 4bec383f5acd..989c48599a11 100644 --- a/lib/node_modules/@stdlib/fs/append-file/test/test.async.js +++ b/lib/node_modules/@stdlib/fs/append-file/test/test.async.js @@ -1,219 +1,223 @@ /** - * @license Apache-2.0 - * - * Copyright (c) 2024 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"; +* @license Apache-2.0 +* +* Copyright (c) 2024 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 join = require("path").join; -var tape = require("tape"); -var readFile = require("@stdlib/fs/read-file").sync; -var writeFileSync = require("@stdlib/fs/write-file").sync; -var IS_BROWSER = require("@stdlib/assert/is-browser"); -var string2buffer = require("@stdlib/buffer/from-string"); -var appendFile = require("../lib/async.js"); +var join = require( 'path' ).join; +var tape = require( 'tape' ); +var readFile = require( '@stdlib/fs/read-file' ).sync; +var writeFileSync = require( '@stdlib/fs/write-file' ).sync; +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var string2buffer = require( '@stdlib/buffer/from-string' ); +var appendFile = require( '../lib/async.js' ); + // VARIABLES // // Don't run tests in the browser...for now... var opts = { - skip: IS_BROWSER, // FIXME + skip: IS_BROWSER, // FIXME }; -var fpath = join(__dirname, "fixtures", "file.txt"); -var DATA = readFile(fpath, "utf8"); +var fpath = join( __dirname, 'fixtures', 'file.txt' ); +var DATA = readFile( fpath, 'utf8' ); + // FUNCTIONS // /** - * Restores a fixture file. - * - * ## Notes - * - * - Every function which has the **potential** to affect the fixture file should invoke this function immediately before calling `t.end()`. - * - * @private - */ +* Restores a fixture file. +* +* ## Notes +* +* - Every function which has the **potential** to affect the fixture file should invoke this function immediately before calling `t.end()`. +* +* @private +*/ function restore() { - writeFileSync(fpath, DATA); + writeFileSync( fpath, DATA ); } + // TESTS // -tape("main export is a function", function test(t) { - t.ok(true, __filename); - t.strictEqual(typeof appendFile, "function", "main export is a function"); - t.end(); -}); - -tape("the function appends data to a file (string)", opts, function test(t) { - var expected = "beep boop 1"; - appendFile(fpath, "beep boop 1", onAppend); - - function onAppend(error) { - var actual; - if (error) { - t.fail(error.message); - } - actual = readFile(fpath, "utf8"); - t.strictEqual(actual, expected, "file contains expected contents"); - - restore(); - t.end(); - } -}); - -tape("the function appends data to a file (buffer)", opts, function test(t) { - var expected = "beep boop 2"; - appendFile(fpath, string2buffer("beep boop 2"), onAppend); - - function onAppend(error) { - var actual; - if (error) { - t.fail(error.message); - } - actual = readFile(fpath, "utf8"); - t.strictEqual(actual, expected, "file contains expected contents"); - - restore(); - t.end(); - } -}); +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof appendFile, 'function', 'main export is a function' ); + t.end(); +} ); + +tape( 'the function appends data to a file (string)', opts, function test( t ) { + var expected = 'beep boop 1'; + appendFile( fpath, 'beep boop 1', onAppend ); + + function onAppend( error ) { + var actual; + if ( error ) { + t.fail( error.message ); + } + actual = readFile( fpath, 'utf8' ); + t.strictEqual( actual, expected, 'file contains expected contents' ); + + restore(); + t.end(); + } +} ); + +tape( 'the function appends data to a file (buffer)', opts, function test( t ) { + var expected = 'beep boop 2'; + appendFile( fpath, string2buffer('beep boop 2'), onAppend ); + + function onAppend( error ) { + var actual; + if ( error ) { + t.fail( error.message ); + } + actual = readFile( fpath, 'utf8' ); + t.strictEqual( actual, expected, 'file contains expected contents' ); + + restore(); + t.end(); + } +} ); tape( - "the function appends data to a file using provided options (option string)", - opts, - function test(t) { - var expected = "beep boop 3"; - appendFile(fpath, "beep boop 3", "utf8", onAppend); - - function onAppend(error) { - var actual; - if (error) { - t.fail(error.message); - } - actual = readFile(fpath, "utf8"); - t.strictEqual(actual, expected, "file contains expected contents"); - - restore(); - t.end(); - } - } + 'the function appends data to a file using provided options (option string)', + opts, + function test( t ) { + var expected = 'beep boop 3'; + appendFile( fpath, 'beep boop 3', 'utf8', onAppend ); + + function onAppend( error ) { + var actual; + if ( error ) { + t.fail( error.message ); + } + actual = readFile( fpath, 'utf8' ); + t.strictEqual( actual, expected, 'file contains expected contents' ); + + restore(); + t.end(); + } + } ); tape( - "the function appends data to a file using provided options (option object)", - opts, - function test(t) { - var expected; - var opts; - - expected = "beep boop 4"; - opts = { - encoding: "utf8", - }; - appendFile(fpath, "beep boop 4", opts, onAppend); - - function onAppend(error) { - var actual; - if (error) { - t.fail(error.message); - } - actual = readFile(fpath, "utf8"); - t.strictEqual(actual, expected, "file contains expected contents"); - - restore(); - t.end(); - } - } + 'the function appends data to a file using provided options (option object)', + opts, + function test( t ) { + var expected; + var opts; + + expected = 'beep boop 4'; + opts = { + encoding: 'utf8', + }; + appendFile( fpath, 'beep boop 4', opts, onAppend ); + + function onAppend( error ) { + var actual; + if ( error ) { + t.fail( error.message ); + } + actual = readFile( fpath, 'utf8' ); + t.strictEqual( actual, expected, 'file contains expected contents' ); + + restore(); + t.end(); + } + } ); tape( - "if the function encounters an error, the function returns the error", - opts, - function test(t) { - var file = - "beepboopbapbop/dkfjldjfaklsjf/bdlfalfas/bkldflakfjas/travashHRD"; // non-existent directory path - appendFile(file, "beepboopbapbop", onAppend); - - function onAppend(error) { - var expected; - var actual; - - t.strictEqual(error instanceof Error, true, error.message); - - expected = DATA; - actual = readFile(fpath, "utf8"); - t.strictEqual(actual, expected, "file contains expected contents"); - - restore(); - t.end(); - } - } + 'if the function encounters an error, the function returns the error', + opts, + function test( t ) { + var file = + 'beepboopbapbop/dkfjldjfaklsjf/bdlfalfas/bkldflakfjas/travashHRD'; // non-existent directory path + appendFile( file, 'beepboopbapbop', onAppend ); + + function onAppend( error ) { + var expected; + var actual; + + t.strictEqual( error instanceof Error, true, error.message ); + + expected = DATA; + actual = readFile( fpath, 'utf8' ); + t.strictEqual( actual, expected, 'file contains expected contents' ); + + restore(); + t.end(); + } + } ); tape( - "if the function encounters an error, the function returns the error (option string)", - opts, - function test(t) { - var file = "beepboopbapbop/dkfjldjfaklsjf/bdlfalfas/bkldflakfjas"; // non-existent directory path - appendFile(file, "beepboopbapbop", "utf8", onAppend); - - function onAppend(error) { - var expected; - var actual; - - t.strictEqual(error instanceof Error, true, error.message); - - expected = DATA; - actual = readFile(fpath, "utf8"); - t.strictEqual(actual, expected, "file contains expected contents"); - - restore(); - t.end(); - } - } + 'if the function encounters an error, the function returns the error (option string)', + opts, + function test( t ) { + var file = 'beepboopbapbop/dkfjldjfaklsjf/bdlfalfas/bkldflakfjas'; // non-existent directory path + appendFile( file, 'beepboopbapbop', 'utf8', onAppend ); + + function onAppend( error ) { + var expected; + var actual; + + t.strictEqual( error instanceof Error, true, error.message ); + + expected = DATA; + actual = readFile( fpath, 'utf8' ); + t.strictEqual( actual, expected, 'file contains expected contents' ); + + restore(); + t.end(); + } + } ); tape( - "if the function encounters an error, the function returns the error (option object)", - opts, - function test(t) { - var file; - var opts; - - file = "beepboopbapbop/dkfjldjfaklsjf/bdlfalftisas/bkldflHRDakfjas"; // non-existent directory path - opts = { - encoding: "utf8", - }; - appendFile(file, "beepboopbapbop", opts, onAppend); - - function onAppend(error) { - var expected; - var actual; - - t.strictEqual(error instanceof Error, true, error.message); - - expected = DATA; - actual = readFile(fpath, "utf8"); - t.strictEqual(actual, expected, "file contains expected contents"); - - restore(); - t.end(); - } - } + 'if the function encounters an error, the function returns the error (option object)', + opts, + function test( t ) { + var file; + var opts; + + file = 'beepboopbapbop/dkfjldjfaklsjf/bdlfalftisas/bkldflHRDakfjas'; // non-existent directory path + opts = { + encoding: 'utf8', + }; + appendFile( file, 'beepboopbapbop', opts, onAppend ); + + function onAppend( error ) { + var expected; + var actual; + + t.strictEqual( error instanceof Error, true, error.message ); + + expected = DATA; + actual = readFile( fpath, 'utf8' ); + t.strictEqual( actual, expected, 'file contains expected contents' ); + + restore(); + t.end(); + } + } ); diff --git a/lib/node_modules/@stdlib/fs/append-file/test/test.cli.js b/lib/node_modules/@stdlib/fs/append-file/test/test.cli.js index 1ce344261e46..dc684d2142ca 100644 --- a/lib/node_modules/@stdlib/fs/append-file/test/test.cli.js +++ b/lib/node_modules/@stdlib/fs/append-file/test/test.cli.js @@ -1,270 +1,315 @@ /** - * @license Apache-2.0 - * - * Copyright (c) 2024 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"; +* @license Apache-2.0 +* +* Copyright (c) 2024 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 join = require("path").join; -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 replace = require("@stdlib/string/replace"); -var readFileSync = require("@stdlib/fs/read-file").sync; -var appendFileSync = require("../lib/sync.js"); +var resolve = require( 'path' ).resolve; +var join = require( 'path' ).join; +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 replace = require( '@stdlib/string/replace' ); +var readFileSync = require( '@stdlib/fs/read-file' ).sync; +var writeFileSync = require( '@stdlib/fs/write-file' ).sync; + // VARIABLES // -var fpath = resolve(__dirname, "..", "bin", "cli"); +var fpath = resolve( __dirname, '..', 'bin', 'cli' ); var opts = { - skip: IS_BROWSER || IS_WINDOWS, + skip: IS_BROWSER || IS_WINDOWS, }; -var FILE = join(__dirname, "fixtures", "file.txt"); -var DATA = readFileSync(FILE); +var FILE = join( __dirname, 'fixtures', 'file.txt' ); +var DATA = readFileSync( FILE ); + // FIXTURES // -var PKG_VERSION = require("./../package.json").version; +var PKG_VERSION = require( './../package.json' ).version; + // FUNCTIONS // /** - * Restores a fixture file. - * - * ## Notes - * - * - Every function which has the **potential** to affect the fixture file should invoke this function immediately before calling `t.end()`. - * - * @private - */ +* Restores a fixture file. +* +* ## Notes +* +* - Every function which has the **potential** to affect the fixture file should invoke this function immediately before calling `t.end()`. +* +* @private +*/ function restore() { - appendFileSync(FILE, DATA); + writeFileSync( FILE, DATA ); } + // TESTS // -tape("command-line interface", function test(t) { - t.ok(true, __filename); - t.end(); -}); +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(); - } - } + '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(); - } - } + '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(); - } - } + '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(); - } - } + '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 appends data received from `stdin` to a file", - opts, - function test(t) { - var expected; - var opts; - var cmd; - - cmd = ['printf "beep boop 1"', "|", EXEC_PATH, fpath, FILE]; - opts = {}; - - expected = "beep boop 1"; - exec(cmd.join(" "), opts, done); - - function done(error, stdout, stderr) { - var actual; - if (error) { - t.fail(error.message); - } else { - t.strictEqual(stdout.toString(), "", "does not print to `stdout`"); - t.strictEqual(stderr.toString(), "", "does not print to `stderr`"); - } - actual = readFileSync(FILE, "utf8"); - t.strictEqual(actual, expected, "file contains expected contents"); - - restore(); - t.end(); - } - } + 'the command-line interface appends data received from `stdin` to a file', + opts, + function test( t ) { + var expected; + var opts; + var cmd; + + cmd = [ 'printf "beep boop 1"', '|', EXEC_PATH, fpath, FILE ]; + opts = {}; + + expected = 'beep boop 1'; + exec( cmd.join( ' ' ), opts, done ); + + function done( error, stdout, stderr ) { + var actual; + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( + stdout.toString(), + '', + 'does not print to `stdout`' + ); + t.strictEqual( + stderr.toString(), + '', + 'does not print to `stderr`' + ); + } + actual = readFileSync( FILE, 'utf8' ); + t.strictEqual(actual, expected, 'file contains expected contents'); + + restore(); + t.end(); + } + } ); tape( - "if an error is encountered when reading from `stdin`, the command-line interface prints an error and sets a non-zero exit code", - opts, - function test(t) { - var script; - var opts; - var cmd; - - script = readFileSync( - resolve(__dirname, "fixtures", "stdin_error.js.txt"), - { - encoding: "utf8", - } - ); - - // Replace single quotes with double quotes: - script = replace(script, "'", '"'); - - cmd = [EXEC_PATH, "-e", "'" + script + "'"]; - - opts = { - cwd: __dirname, - }; - - exec(cmd.join(" "), opts, done); - - function done(error, stdout, stderr) { - if (error) { - t.pass(error.message); - t.strictEqual(error.code, 1, "expected exit code"); - } - t.strictEqual(stdout.toString(), "", "does not print to `stdout`"); - t.strictEqual(stderr.toString(), "Error: beep\n", "expected value"); - - restore(); - t.end(); - } - } + 'if an error is encountered when reading from `stdin`, the command-line interface prints an error and sets a non-zero exit code', + opts, + function test( t ) { + var script; + var opts; + var cmd; + + script = readFileSync( + resolve( __dirname, 'fixtures', 'stdin_error.js.txt' ), + { + encoding: 'utf8', + } + ); + + // Replace single quotes with double quotes: + script = replace( script, "'", '"' ); + + cmd = [ EXEC_PATH, '-e', "'" + script + "'" ]; + + opts = { + cwd: __dirname, + }; + + exec( cmd.join( ' ' ), opts, done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.pass( error.message ); + t.strictEqual( error.code, 1, 'expected exit code' ); + } + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), 'Error: beep\n', 'expected value' ); + + restore(); + t.end(); + } + } ); tape( - "if an error is encountered when appending to file, the command-line interface prints an error and sets a non-zero exit code", - opts, - function test(t) { - var script; - var opts; - var cmd; - - script = readFileSync( - resolve(__dirname, "fixtures", "write_error.js.txt"), - { - encoding: "utf8", - } - ); - - // Replace single quotes with double quotes: - script = replace(script, "'", '"'); - - cmd = [EXEC_PATH, "-e", "'" + script + "'"]; - - opts = { - cwd: __dirname, - }; - - exec(cmd.join(" "), opts, done); - - function done(error, stdout, stderr) { - if (error) { - t.pass(error.message); - t.strictEqual(error.code, 1, "expected exit code"); - } - t.strictEqual(stdout.toString(), "", "does not print to `stdout`"); - t.strictEqual(stderr.toString(), "Error: beep\n", "expected value"); - - restore(); - t.end(); - } - } + 'if an error is encountered when appending to file, the command-line interface prints an error and sets a non-zero exit code', + opts, + function test( t ) { + var script; + var opts; + var cmd; + + script = readFileSync( + resolve( __dirname, 'fixtures', 'write_error.js.txt' ), + { + encoding: 'utf8', + } + ); + + // Replace single quotes with double quotes: + script = replace( script, "'", '"' ); + + cmd = [ EXEC_PATH, '-e', "'" + script + "'" ]; + + opts = { + cwd: __dirname, + }; + + exec( cmd.join( ' ' ), opts, done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.pass( error.message ); + t.strictEqual( error.code, 1, 'expected exit code' ); + } + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), 'Error: beep\n', 'expected value' ); + + restore(); + t.end(); + } + } ); diff --git a/lib/node_modules/@stdlib/fs/append-file/test/test.js b/lib/node_modules/@stdlib/fs/append-file/test/test.js index e080d3dddd46..6958b5dd0093 100644 --- a/lib/node_modules/@stdlib/fs/append-file/test/test.js +++ b/lib/node_modules/@stdlib/fs/append-file/test/test.js @@ -1,40 +1,42 @@ /** - * @license Apache-2.0 - * - * Copyright (c) 2024 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"; +* @license Apache-2.0 +* +* Copyright (c) 2024 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 appendFile = require("../lib"); +var tape = require( 'tape' ); +var appendFile = require( '../lib' ); + // TESTS // -tape("main export is a function", function test(t) { - t.ok(true, __filename); - t.strictEqual(typeof appendFile, "function", "main export is a function"); - t.end(); -}); +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof appendFile, 'function', 'main export is a function' ); + t.end(); +} ); tape( - "attached to the main export is a method that synchronously appends data to a file", - function test(t) { - t.strictEqual(typeof appendFile.sync, "function", "has method"); - t.end(); - } + 'attached to the main export is a method that synchronously appends data to a file', + function test( t ) { + t.strictEqual( typeof appendFile.sync, 'function', 'has method' ); + t.end(); + } ); diff --git a/lib/node_modules/@stdlib/fs/append-file/test/test.sync.js b/lib/node_modules/@stdlib/fs/append-file/test/test.sync.js index 36962d283c0f..024edd92bd3e 100644 --- a/lib/node_modules/@stdlib/fs/append-file/test/test.sync.js +++ b/lib/node_modules/@stdlib/fs/append-file/test/test.sync.js @@ -1,222 +1,226 @@ /** - * @license Apache-2.0 - * - * Copyright (c) 2024 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"; +* @license Apache-2.0 +* +* Copyright (c) 2024 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 join = require("path").join; -var tape = require("tape"); -var readFile = require("@stdlib/fs/read-file").sync; -var writeFile = require("@stdlib/fs/write-file").sync; -var IS_BROWSER = require("@stdlib/assert/is-browser"); -var string2buffer = require("@stdlib/buffer/from-string"); -var appendFile = require("../lib/sync.js"); +var join = require( 'path' ).join; +var tape = require( 'tape' ); +var readFile = require( '@stdlib/fs/read-file' ).sync; +var writeFile = require( '@stdlib/fs/write-file' ).sync; +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var string2buffer = require( '@stdlib/buffer/from-string' ); +var appendFile = require( '../lib/sync.js' ); + // VARIABLES // // Don't run tests in the browser...for now... var opts = { - skip: IS_BROWSER, // FIXME + skip: IS_BROWSER, // FIXME }; -var fpath = join(__dirname, "fixtures", "file.txt"); -var DATA = readFile(fpath, "utf8"); +var fpath = join( __dirname, 'fixtures', 'file.txt' ); +var DATA = readFile( fpath, 'utf8' ); + // FUNCTIONS // /** - * Restores a fixture file. - * - * ## Notes - * - * - Every function which has the **potential** to affect the fixture file should invoke this function immediately before calling `t.end()`. - * - * @private - */ +* Restores a fixture file. +* +* ## Notes +* +* - Every function which has the **potential** to affect the fixture file should invoke this function immediately before calling `t.end()`. +* +* @private +*/ function restore() { - writeFile(fpath, DATA); + writeFile( fpath, DATA ); } + // TESTS // -tape("main export is a function", function test(t) { - t.ok(true, __filename); - t.strictEqual(typeof appendFile, "function", "main export is a function"); - t.end(); -}); +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof appendFile, 'function', 'main export is a function' ); + t.end(); +} ); -tape("the function appends data to a file (string)", opts, function test(t) { - var expected; - var actual; +tape( 'the function appends data to a file (string)', opts, function test( t ) { + var expected; + var actual; - expected = "beep boop 1"; + expected = 'beep boop 1'; - appendFile(fpath, "beep boop 1"); - actual = readFile(fpath, "utf8"); + appendFile( fpath, 'beep boop 1' ); + actual = readFile( fpath, 'utf8' ); - t.strictEqual(actual, expected, "file contains expected data"); + t.strictEqual( actual, expected, 'file contains expected data' ); - restore(); - t.end(); -}); + restore(); + t.end(); +} ); -tape("the function appends data to a file (buffer)", opts, function test(t) { - var expected; - var actual; +tape( 'the function appends data to a file (buffer)', opts, function test( t ) { + var expected; + var actual; - expected = "beep boop 2"; + expected = 'beep boop 2'; - appendFile(fpath, string2buffer("beep boop 2")); - actual = readFile(fpath, "utf8"); + appendFile( fpath, string2buffer( 'beep boop 2' ) ); + actual = readFile( fpath, 'utf8' ); - t.strictEqual(actual, expected, "file contains expected data"); + t.strictEqual( actual, expected, 'file contains expected data' ); - restore(); - t.end(); -}); + restore(); + t.end(); +} ); tape( - "the function appends data to a file using provided options (string)", - opts, - function test(t) { - var expected; - var actual; + 'the function appends data to a file using provided options (string)', + opts, + function test( t ) { + var expected; + var actual; - expected = "beep boop 3"; + expected = 'beep boop 3'; - appendFile(fpath, "beep boop 3", "utf8"); - actual = readFile(fpath, "utf8"); + appendFile( fpath, 'beep boop 3', 'utf8' ); + actual = readFile( fpath, 'utf8' ); - t.strictEqual(actual, expected, "file contains expected data"); + t.strictEqual( actual, expected, 'file contains expected data' ); - restore(); - t.end(); - } + restore(); + t.end(); + } ); tape( - "the function appends data to a file using provided options (object)", - opts, - function test(t) { - var expected; - var actual; - var opts; - - expected = "beep boop 4"; - - opts = { - encoding: "utf8", - }; - appendFile(fpath, "beep boop 4", opts); - actual = readFile(fpath, "utf8"); - - t.strictEqual(actual, expected, "file contains expected data"); - - restore(); - t.end(); - } + 'the function appends data to a file using provided options (object)', + opts, + function test( t ) { + var expected; + var actual; + var opts; + + expected = 'beep boop 4'; + + opts = { + encoding: 'utf8', + }; + appendFile( fpath, 'beep boop 4', opts ); + actual = readFile( fpath, 'utf8' ); + + t.strictEqual( actual, expected, 'file contains expected data' ); + + restore(); + t.end(); + } ); tape( - "if the function encounters an error, the function throws the error", - opts, - function test(t) { - var expected; - var actual; - var file; - var err; - - file = "beepboopbapbop/dkfjldjfaklsjf/bdlfalfas/bkldflakfjas"; // non-existent directory path - - try { - appendFile(file, "beepboopbapbop"); - } catch (error) { - err = error; - } - - t.strictEqual(err instanceof Error, true, err.message); - - expected = DATA; - actual = readFile(fpath, "utf8"); - t.strictEqual(actual, expected, "file contains expected contents"); - - restore(); - t.end(); - } + 'if the function encounters an error, the function throws the error', + opts, + function test( t ) { + var expected; + var actual; + var file; + var err; + + file = 'beepboopbapbop/dkfjldjfaklsjf/bdlfalfas/bkldflakfjas'; // non-existent directory path + + try { + appendFile( file, 'beepboopbapbop' ); + } catch ( error ) { + err = error; + } + + t.strictEqual( err instanceof Error, true, err.message ); + + expected = DATA; + actual = readFile( fpath, 'utf8' ); + t.strictEqual( actual, expected, 'file contains expected contents' ); + + restore(); + t.end(); + } ); tape( - "if the function encounters an error, the function throws the error (option string)", - opts, - function test(t) { - var expected; - var actual; - var file; - var err; - - file = "beepboopbapbop/dkfjldjfaklsjf/bdlfalfas/bkldflakfjas"; // non-existent directory path - - try { - appendFile(file, "beepboopbapbop", "utf8"); - } catch (error) { - err = error; - } - - t.strictEqual(err instanceof Error, true, err.message); - - expected = DATA; - actual = readFile(fpath, "utf8"); - t.strictEqual(actual, expected, "file contains expected contents"); - - restore(); - t.end(); - } + 'if the function encounters an error, the function throws the error (option string)', + opts, + function test( t ) { + var expected; + var actual; + var file; + var err; + + file = 'beepboopbapbop/dkfjldjfaklsjf/bdlfalfas/bkldflakfjas'; // non-existent directory path + + try { + appendFile( file, 'beepboopbapbop', 'utf8' ); + } catch ( error ) { + err = error; + } + + t.strictEqual( err instanceof Error, true, err.message ); + + expected = DATA; + actual = readFile( fpath, 'utf8' ); + t.strictEqual( actual, expected, 'file contains expected contents' ); + + restore(); + t.end(); + } ); tape( - "if the function encounters an error, the function throws the error (option object)", - opts, - function test(t) { - var expected; - var actual; - var file; - var opts; - var err; - - file = "beepboopbapbop/dkfjldjfaklsjf/bdlfalfas/bkldflakfjas"; // non-existent directory path - - opts = { - encoding: "utf8", - }; - - try { - appendFile(file, "beepboopbapbop", opts); - } catch (error) { - err = error; - } - - t.strictEqual(err instanceof Error, true, err.message); - - expected = DATA; - actual = readFile(fpath, "utf8"); - t.strictEqual(actual, expected, "file contains expected contents"); - - restore(); - t.end(); - } + 'if the function encounters an error, the function throws the error (option object)', + opts, + function test( t ) { + var expected; + var actual; + var file; + var opts; + var err; + + file = 'beepboopbapbop/dkfjldjfaklsjf/bdlfalfas/bkldflakfjas'; // non-existent directory path + + opts = { + encoding: 'utf8', + }; + + try { + appendFile( file, 'beepboopbapbop', opts ); + } catch ( error ) { + err = error; + } + + t.strictEqual( err instanceof Error, true, err.message ); + + expected = DATA; + actual = readFile( fpath, 'utf8' ); + t.strictEqual( actual, expected, 'file contains expected contents' ); + + restore(); + t.end(); + } ); From 5392ab4c02f7253d80da1688a242c3f341ce1a3d Mon Sep 17 00:00:00 2001 From: Hridyanshu7 Date: Fri, 22 Mar 2024 23:18:23 +0530 Subject: [PATCH 05/23] Made changes to adhere to the repo lint rules and solve othr errors highlighted during the CI check --- .../@stdlib/fs/append-file/README.md | 76 +++++++++---------- .../fs/append-file/benchmark/benchmark.js | 5 +- .../@stdlib/fs/append-file/bin/cli | 17 ++--- .../fs/append-file/docs/types/index.d.ts | 25 ++---- .../@stdlib/fs/append-file/lib/async.js | 11 ++- .../@stdlib/fs/append-file/lib/index.js | 2 +- .../@stdlib/fs/append-file/lib/sync.js | 7 +- .../@stdlib/fs/append-file/package.json | 1 + .../test/fixtures/stdin_error.js.txt | 34 +++++++++ .../test/fixtures/write_error.js.txt | 43 +++++++++++ .../@stdlib/fs/append-file/test/test.async.js | 3 +- .../@stdlib/fs/append-file/test/test.cli.js | 3 +- .../@stdlib/fs/append-file/test/test.js | 3 +- .../@stdlib/fs/append-file/test/test.sync.js | 3 +- 14 files changed, 145 insertions(+), 88 deletions(-) create mode 100644 lib/node_modules/@stdlib/fs/append-file/test/fixtures/stdin_error.js.txt create mode 100644 lib/node_modules/@stdlib/fs/append-file/test/fixtures/write_error.js.txt diff --git a/lib/node_modules/@stdlib/fs/append-file/README.md b/lib/node_modules/@stdlib/fs/append-file/README.md index 1e6c4c95cbd3..ac3af3f18062 100644 --- a/lib/node_modules/@stdlib/fs/append-file/README.md +++ b/lib/node_modules/@stdlib/fs/append-file/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2024 The Stdlib Authors. +Copyright (c) 2018 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. @@ -42,9 +42,9 @@ var fpath = join( __dirname, 'examples', 'fixtures', 'file.txt' ); appendFile( fpath, 'beep boop\n', onAppend ); function onAppend( error ) { - if ( error ) { - throw error; - } + if ( error ) { + throw error; + } } ``` @@ -56,12 +56,12 @@ var string2buffer = require( '@stdlib/buffer/from-string' ); var fpath = join( __dirname, 'examples', 'fixtures', 'file.txt' ); -appendFile( fpath, string2buffer('beep boop\n'), onAppend ); +appendFile( fpath, string2buffer( 'beep boop\n' ), onAppend ); function onAppend( error ) { - if ( error ) { - throw error; - } + if ( error ) { + throw error; + } } ``` @@ -78,7 +78,7 @@ var fpath = join( __dirname, 'examples', 'fixtures', 'file.txt' ); var err = appendFile.sync( fpath, 'beep boop\n' ); if ( err instanceof Error ) { - throw err; + throw err; } ``` @@ -92,31 +92,31 @@ The function accepts the same `options` and has the same defaults as [`fs.append ## Notes - + - ```javascript - var fs = require( 'fs' ); +```javascript +var fs = require( 'fs' ); - // Check for directory path existence to prevent an error being thrown... - if ( fs.existsSync( '/path/to' ) ) { - fs.appendFileSync( '/path/to/file.txt', 'beep boop\n' ); - } - ``` +// Check for directory path existence to prevent an error being thrown... +if ( fs.existsSync( '/path/to' ) ) { + fs.appendFileSync( '/path/to/file.txt', 'beep boop\n' ); +} +``` - can be replaced by an approach which addresses existence via `error` handling. +can be replaced by an approach which addresses existence via `error` handling. - + - ```javascript - var appendFile = require( '@stdlib/fs/append-file' ); +```javascript +var appendFile = require( '@stdlib/fs/append-file' ); - // Explicitly handle the error... - try{ - appendFile.sync( '/path/to/file.txt', 'beep boop\n' ); - } catch( error ) { - throw error - } - ``` +// Explicitly handle the error... +try{ + appendFile.sync( '/path/to/file.txt', 'beep boop\n' ); +} catch( error ) { + console.log( error.message ); +} +``` @@ -136,21 +136,21 @@ var fpath = join( __dirname, 'examples', 'fixtures', 'file.txt' ); // Synchronously append data to a file: try { - appendFile.sync( fpath, 'beep boop\n', 'utf8' ); - // throws no errors + appendFile.sync( fpath, 'beep boop\n', 'utf8' ); + // throws no errors } catch ( error ) { - console.log( error instanceof Error ); - // => false + console.log( error instanceof Error ); + // => false } // Asynchronously append data to a file: appendFile( fpath, 'beep boop\n', onAppend ); function onAppend( error ) { - if ( error ) { - console.error( 'Error: %s', error.message ); - } - console.log( 'Success!' ); + if ( error ) { + console.error( 'Error: %s', error.message ); + } + console.log( 'Success!' ); } ``` @@ -158,7 +158,7 @@ function onAppend( error ) { ---- +***
@@ -216,7 +216,7 @@ $ printf 'beep boop\n' | append-file ./examples/fixtures/file.txt