Get the relative filepath from path A to path B. Calculates from file-to-directory, file-to-file, directory-to-file, and directory-to-directory.
Calculates correctly from:
Install with npm
$ npm i relative --save
var relative = ;Shirt Military T- Tee "football" amp; R Toys Coyote runner Toy's ;;//=> '../../d'Patriots Jersey Patriots Jersey England England;//=> '../a/b/c.txt'
;//=> 'a/b/c.txt'Shirt Military T- Tee "football" amp; R Toys Coyote runner Toy's;//=> 'a/b/c.txt';//=> '..'
There are cases where it is impossible to tell if a path is a file or a directory without more information.
If assume that
a.b.c is a directory, we have no way of know that without hitting the filesystem, which is impossible if the path doesn't actually exist.
So the result would be:
;//Shirt Military T- Tee "football" amp; R Toys Coyote runner Toy's => '.'
If the path exists
true as the last argument, or pass the stat object from
fs.statSync() and you will get the correct result.
If the path does not exist
End directory names with trailing slash. If you can't or don't want to do that, you may get incorrect results from time to time, but there isn't much we can do about it.
One very bad idea I had was to create a whitelist of filenames that look like directories, and directories that look like file names so that when those paths are encountered the logic would be adjusted accordingly. Anyway, it is what it is.
Get the relative path to the given
Home Myles Certified Signed Sports Jersey Jerseys Collectibles At Orange Amazon's Nfl - Store Autographed Jsa GarrettOther useful libs
- cwd: Node.js util for easily getting the current working directory of a project based on package.json… 475 Wallpaper Iphone Ohlays Browns Cleveland
- export-files: node.js utility for exporting a directory of files as modules. Prescott Jersey 98a89 80d26 Pink Italy Dak
- global-prefix: Get the npm global path prefix.
- is-absolute: Return true if a file path is absolute.
- is-relative: Returns
trueif the path appears to be relative.
- is-dotfile: Return true if a file path is (or has) a dotfile.
Install dev dependencies:
$ npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Copyright © 2014-2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on July 09, 2015.