Registry / serialization / my-node-fp

my-node-fp

JSON →
library0.10.3jsnpmunverified

my-node-fp is a utility library for Node.js, currently at version 0.10.3, offering a collection of simple functional programming utilities primarily focused on file system (fs) and path manipulation. It ships with TypeScript types, enhancing developer experience. The library provides both asynchronous and synchronous versions for many file system operations, such as checking file existence or directory status. Key differentiators include specialized path utilities like `replaceSepToPosix` and `win32DriveLetterUpdown`, which abstract away OS-specific path concerns. Given its pre-1.0 versioning, users should anticipate potential API changes in future releases, though it appears to be actively maintained based on its recent version number.

npm install my-node-fp
INSTALL
IMPORT
SIG · MY-NODE-FP
M
my-node-fp
serializationjavascriptv0.10.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

exists
import { exists } from 'my-node-fp/fs';
const { exists } = require('my-node-fp').fs;
Imports the asynchronous file existence check. Note that Node.js's native `fs.exists` is deprecated, and this library's `exists` mirrors that behavior.
isDirectorySync
import { isDirectorySync } from 'my-node-fp/fs';
import { isDirectorySync } from 'my-node-fp';
Imports the synchronous directory check. Ensure you import from the '/fs' subpath, not directly from the root package, as functions are organized by category.
basenames
import { basenames } from 'my-node-fp/path';
import { basenames } from 'my-node-fp/utils';
Imports the utility for extracting basenames from a path, allowing suffixes to be specified. Functions are grouped into subpaths like '/path' for better organization and tree-shaking.

Demonstrates basic asynchronous file system checks and path manipulation utilities, including creating and cleaning up temporary files and directories, and transforming path separators.

import { exists, isDirectory, isEmptyDir } from 'my-node-fp/fs'; import { basenames, replaceSepToPosix } from 'my-node-fp/path'; import * as fs from 'node:fs/promises'; import * as path from 'node:path'; async function runExample() { const tempDir = path.join(process.cwd(), 'temp_my_node_fp_test'); const tempFile = path.join(tempDir, 'test_file.txt'); // Ensure temp directory exists and is empty for consistent testing if (await exists(tempDir)) { await fs.rm(tempDir, { recursive: true, force: true }); } await fs.mkdir(tempDir, { recursive: true }); await fs.writeFile(tempFile, 'Hello, my-node-fp!'); console.log(`Checking if '${tempDir}' exists: ${await exists(tempDir)}`); console.log(`Checking if '${tempFile}' is a directory: ${await isDirectory(tempFile)}`); console.log(`Checking if '${tempDir}' is empty: ${await isEmptyDir(tempDir)}`); // Should be false now const filePath = '/usr/local/bin/node_modules/my-package/index.js'; const windowsPath = 'C:\\Users\\User\\Documents\\file.txt'; console.log(`Basenames of '${filePath}' (excluding '.js'): ${basenames(filePath, '.js')}`); console.log(`Posix path for '${windowsPath}': ${replaceSepToPosix(windowsPath)}`); // Cleanup after example await fs.rm(tempDir, { recursive: true, force: true }); console.log('Cleanup complete.'); } runExample().catch(console.error);
Debug
Known issues
deprecatedThe `exists` and `existsSync` functions directly mirror the deprecated `fs.exists` and `fs.existsSync` in Node.js. While they function, Node.js documentation recommends using `fs.stat` or `fs.access` for existence checks, as `fs.exists` can lead to race conditions (e.g., checking for existence then performing an operation, where the file might be deleted between checks).
fix
For robust existence checks, consider using `fs.access` (or `fs.promises.access`) with `fs.constants.F_OK` or `fs.stat` (or `fs.promises.stat`) within a `try...catch` block directly, especially in new code or security-sensitive contexts.
affects: >=0.1.0
breakingAs a pre-1.0 package (current version 0.10.3), the API surface of `my-node-fp` is not yet stable. Future minor versions may introduce breaking changes without strict adherence to semantic versioning for major increments, as the library is still in active development.
fix
Pin to exact versions (e.g., `"my-node-fp": "0.10.3"`) or use a lockfile (`package-lock.json`, `yarn.lock`) to prevent unexpected breaking changes during dependency updates. Always review release notes carefully when upgrading to newer pre-1.0 versions.
affects: <1.0.0
gotchaSome functions, particularly in the `fs` category, offer both asynchronous (e.g., `isDirectory`) and synchronous (e.g., `isDirectorySync`) variants. Using synchronous file system calls can block the Node.js event loop, severely impacting application performance and responsiveness in server environments or I/O-intensive tasks.
fix
Prefer the asynchronous versions of functions (e.g., `isDirectory` over `isDirectorySync`) for all I/O operations in performance-sensitive applications, especially in Node.js server contexts. Only use synchronous variants for startup scripts, CLI tools, or non-critical blocking operations where performance is not a primary concern.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: (0, _my_node_fp_fs__WEBPACK_IMPORTED_MODULE_0__.exists) is not a function
Attempting to import a module's function from the wrong subpath or using an incorrect destructuring pattern (e.g., importing from 'my-node-fp' instead of 'my-node-fp/fs'). This error is common in bundlers like Webpack.
fix
Ensure you are using named imports from the correct subpath for the specific utility category, e.g., `import { exists } from 'my-node-fp/fs';` for file system utilities or `import { basenames } from 'my-node-fp/path';` for path utilities.
Error: EPERM: operation not permitted, stat 'C:\path\to\file'
Insufficient operating system permissions for the Node.js process to perform the requested file system operation (e.g., reading a file, creating a directory), or a race condition when checking for file existence and then attempting an operation.
fix
Verify that your Node.js process has the necessary read/write/execute permissions for the target file or directory. If encountering this after an existence check, be aware of the race conditions inherent to `fs.exists` (and `my-node-fp`'s mirror thereof); prefer using `fs.promises.access` or handling errors from operations like `fs.promises.stat` or `fs.promises.mkdir` directly.
Upgrade
Version history
0.10.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
my-node-fp — npm install my-node-fp · libregistry