
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
remove-trailing-separator
Advanced tools
The remove-trailing-separator npm package is a simple utility that helps in removing trailing separators from a given path string. This can be particularly useful in file path manipulations where consistency in path formatting is required.
Remove trailing path separator
This feature allows the removal of trailing slashes (or other relevant separators) from a file path. It ensures that the path is normalized without an ending separator, which is useful for concatenating paths or when directories are compared.
const removeTrailingSeparator = require('remove-trailing-separator');
console.log(removeTrailingSeparator('example/path/')); // Outputs: 'example/path'
normalize-path is similar to remove-trailing-separator but offers broader functionality including the normalization of path strings by removing unnecessary slashes and resolving '.' and '..' segments. Unlike remove-trailing-separator, which only removes the trailing separator, normalize-path adjusts the entire path structure.
The slash package converts Windows backslash paths to slash paths, which is somewhat related but not identical to remove-trailing-separator. While slash changes the type of separators, remove-trailing-separator specifically focuses on removing unnecessary trailing separators.
Removes all separators from the end of a string.
npm install remove-trailing-separator
const removeTrailingSeparator = require('remove-trailing-separator');
removeTrailingSeparator('/foo/bar/') // '/foo/bar'
removeTrailingSeparator('/foo/bar///') // '/foo/bar'
// leaves only/last separator
removeTrailingSeparator('/') // '/'
removeTrailingSeparator('///') // '/'
// returns empty string
removeTrailingSeparator('') // ''
\
is considered a separator only on WIN32 systems. All POSIX compliant systems
see backslash as a valid file name character, so it would break POSIX compliance
to remove it there.
In practice, this means that this code will return different things depending on what system it runs on:
removeTrailingSeparator('\\foo\\')
// UNIX => '\\foo\\'
// WIN32 => '\\foo'
FAQs
Removes separators from the end of the string.
We found that remove-trailing-separator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.