Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doctoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

var path = require('path')
, fs = require('fs')
, os = require('os')
, minimist = require('minimist')
, file = require('./lib/file')
, transform = require('./lib/transform')
, files;

function cleanPath(path) {
var homeExpanded = (path.indexOf('~') === 0) ? process.env.HOME + path.substr(1) : path;
var homeExpanded = (path.indexOf('~') === 0) ? path.join(os.homedir() + path.substr(1)) : path;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While using os.homedir() indeed improves cross-platform compatibility, I noticed that the introduction of path.join() deviates slightly from the existing style. I'm unsure if this stylistic change was intended for this PR.

Additionally, if path.join() is used, it should accept multiple arguments (e.g., path.join(os.homedir(), path.substr(1))) rather than a single concatenated string.

Let me know your thoughts on this!

Copy link
Contributor Author

@hyperupcall hyperupcall Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! Embarrassingly, when I first tested these changes I must have forgotten to quote:

$ ./doctoc.js ~/Documents/...
$ ./doctoc.js '~/Documents/...'

I re-ran and it works as expected. I also fixed up the code to allow for using path.join by renaming the parameter in the function. path.join is also more cross platform.


// Escape all spaces
return homeExpanded.replace(/\s/g, '\\ ');
Expand Down