Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
path-unified
Advanced tools
Node's path builtin module exposed as dual ESM/CJS and browser-compatible out of the box.
This library is Node's built-in path
module, exposed for usage inside browsers as well as Node, without any build-tooling required whatsoever.
Bit hard to find an NPM name that isn't currently in use for this, so I went with "-unified" because this should cover both Linux & Windows, browser & Node environments.
Mostly due to the alternatives on NPM (path-browserify
, path
, node-path
, path-esm
, etc.) being:
Same as the Node built-in module:
import { resolve } from 'path-unified';
resolve('foo/bar'); // `/absolute/path/to/foo/bar` or with \'s on windows
Also possible to default import or grab win32
/posix
, to force windows/non-windows env:
import path, { posix } from 'path-unified';
path.resolve('foo/bar'); // `/absolute/path/to/foo/bar` or with \'s on windows
posix.path.resolve('foo/bar'); // `/absolute/path/to/foo/bar`, always posix style
I just copied https://github.com/nodejs/node/blob/v21.5.0/lib/path.js and made some changes to make it workable in ESM / browser context:
import path from 'path-unified';
and import { win32, posix } from 'path-unified';
are quite bad for tree-shaking, you're better off importing the path utilities separately import { resolve } from 'path-unified';
process.cwd()
for browser (should return '/'
)Disclaimer: the tests are just a few smoke tests that I run in both browser & node context, in both linux & windows. Apart from those few tests, I cannot really guarantee that my copy + patch of this built-in module doesn't contain regressions. More tests are a welcome contribution, and do let me know if something breaks.
I'd like to improve the treeshaking capabilities of the posix
/win32
imports e.g.:
import { resolve } from 'path-unified/win32';
which would be easier to treeshake than the current way:
import { posix } from 'path-unified';
const { resolve } = posix;
PR's welcome for that, I left it out for now due to personal time constraints
FAQs
Node's path builtin module exposed as dual ESM/CJS and browser-compatible out of the box.
The npm package path-unified receives a total of 30,724 weekly downloads. As such, path-unified popularity was classified as popular.
We found that path-unified demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.