1.0.0 • Published 9 years ago

relative-path-to-relative-url v1.0.0

Weekly downloads
1
License
ISC
Repository
gitlab
Last release
9 years ago

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