Install untildify via npm
mainInstall the untildify package using npm to enable tilde path expansion in your project.
npm install untildifyrepository·main·Indexed 41 days ago
https://github.com/sindresorhus/untildifyA utility for converting tilde-prefixed paths (e.g., `~/dev`) into absolute paths based on the current user's home directory. Version 6.0.0 supports regular tilde expansion and username tilde expansion if the username matches the current user.
Install the untildify package using npm to enable tilde path expansion in your project.
npm install untildifyUse the untildify function to expand tilde (~) shortcuts into absolute file system paths.
~ is expanded to the current user's home directory.~username is expanded to that user's home directory only if the username matches the current user. If the username does not match, the path is returned unchanged.import untildify from 'untildify';
// Expands ~ to the current user's home directory
untildify('~/dev');
//=> '/Users/sindresorhus/dev'
// Expands ~username if the username matches the current user
untildify('~sindresorhus/dev');
//=> '/Users/sindresorhus/dev'The untildify function converts paths starting with a tilde (~) into absolute paths.
It supports two types of expansion:
~): Replaces the tilde with the current user's home directory (retrieved via os.homedir()).~username): If the username provided in the path matches the current user's username (retrieved via os.userInfo().username), it expands to that user's home directory. If the username does not match the current user, the path is returned unchanged.If the input is not a string, the function throws a TypeError.
import untildify from 'untildify';
// Regular tilde expansion
untildify('~/Documents') // returns '/Users/name/Documents'
// Username expansion (only if it matches current user)
untildify('~name/Documents') // returns '/Users/name/Documents'
// No expansion if username doesn't match
untildify('~otheruser/Documents') // returns '~otheruser/Documents'