relative-path-to-relative-url

1.0.0 • Public • Published

relative-path-to-relative-url

Convert relative file system paths to relative URLs.

Examples

// Unix
relativePathToRelativeUrl('foo/bar')
relativePathToRelativeUrl('/foo/bar')
relativePathToRelativeUrl('./foo/bar')
// -> './foo/bar'
 
// Windows
relativePathToRelativeUrl('foo\\bar')
relativePathToRelativeUrl('\\foo\\bar')
relativePathToRelativeUrl('.\\foo\\bar')
// -> './foo/bar'

relativePathToRelativeUrl(path)

path is a string containing a relative file path.

Returns a string representing a relative URL.

The URL always starts with ./ to make it relative to the current directory.

Respects the path separator of the host environment, typically / or \.

For example ./foo.js or foo.js or /foo will all be returned as ./foo.js on macOS and Linux, while backslashes will not be converted. Conversely, on Windows .\foo.js will be returned as ./foo.js, while forward slashes will be left unchanged.

See Also

/relative-path-to-relative-url/

    Package Sidebar

    Install

    npm i relative-path-to-relative-url

    Weekly Downloads

    1

    Version

    1.0.0

    License

    ISC

    Last publish

    Collaborators

    • seb