Skip to content

Commit

Permalink
Merge pull request #27 from hegdeashwin/develop
Browse files Browse the repository at this point in the history
updates path e.g.
  • Loading branch information
Ashwin Hegde committed Mar 30, 2015
2 parents 9b84123 + acb3661 commit 8217c1f
Showing 1 changed file with 67 additions and 21 deletions.
88 changes: 67 additions & 21 deletions Kit/Session-3/Path/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,27 @@ var path = require('path');
* When multiple slashes are found, they're replaced by a single one;
*/

console.log('Given path: D:////Projects///NodeJS///////TrainingKit');
console.log('Apply normalize: ' + path.normalize('D:////Projects///NodeJS///////TrainingKit'));
console.log('Given path: D:////Projects///Nodejs///////TrainingKit');
console.log('Apply normalize: ' + path.normalize('D:////Projects///Nodejs///////TrainingKit'));


console.log('Given path: D:\\\Projects\NodeJS\\\\\\\\\\TrainingKit');
console.log('Apply normalize: ' + path.normalize('D:\\\Projects\NodeJS\\\\\\\\\\TrainingKit'));
console.log('Given path: D:\\\Projects\Nodejs\\\\\\\\\\TrainingKit');
console.log('Apply normalize: ' + path.normalize('D:\\\Projects\Nodejs\\\\\\\\\\TrainingKit'));


console.log('Given path: D:\\Projects\\NodeJS\\..\\Backbone');
console.log('Apply normalize: ' + path.normalize('D:\\Projects\\NodeJS\\..\\Backbone'));
console.log('Given path: D:\\Projects\\Nodejs\\..\\Backbone');
console.log('Apply normalize: ' + path.normalize('D:\\Projects\\Nodejs\\..\\Backbone'));


console.log('Given path: D:/Projects/NodeJS/../../Articles/Backbone');
console.log('Apply normalize: ' + path.normalize('D:/Projects/NodeJS/../../Articles/Backbone'));
console.log('Given path: D:/Projects/Nodejs/../../Articles/Backbone');
console.log('Apply normalize: ' + path.normalize('D:/Projects/Nodejs/../../Articles/Backbone'));


/***
* Return directory name of a path.
* Return directory name of a path.
* Note: Nodejs is considered as file.
*/
console.log(path.dirname('D:/Projects/NodeJS'));
console.log(path.dirname('D:/Projects/Nodejs'));


/***
Expand All @@ -57,40 +58,85 @@ console.log(path.extname('index'));
/***
* Return the last portion of a path.
*/
console.log(path.basename('D:/Projects/NodeJS/index.html'));
console.log(path.basename('D:/Projects/Nodejs/index.html'));

console.log(path.basename('D:/Projects/NodeJS/index.html', '.html'));
console.log(path.basename('D:/Projects/Nodejs/index.html', '.html'));

/***
* Return the relative path from `from` to `to`
*/
console.log(path.relative('D:/Projects/NodeJS', 'D:/Projects/Backbone'));
console.log(path.relative('D:/Projects/Nodejs', 'D:/Projects/Backbone'));

console.log(path.relative('D:/Training/Nodejs', 'D:/Projects/Backbone'));

/***
* Return the absolute path.
* Note: need latest node.js version.
*/
// console.log(path.isAbsolute('D:/Projects/Nodejs')); // true
// console.log(path.isAbsolute('D:/Projects/Nodejs/os.html')); // false
// console.log(path.isAbsolute('.')); // false

console.log(path.relative('D:/Training/NodeJS', 'D:/Projects/Backbone'));

/***
* Resolves `to` to an absolute path.
* It is as a sequence of cd commands in a shell.
*/
console.log(path.resolve('D:/Projects/NodeJS', './Architecture'));
console.log(path.resolve('D:/Projects/Nodejs', './Architecture'));

console.log(path.resolve('D:/Projects/Nodejs', 'D:/Projects/Backbone'));

console.log(path.resolve('D:/Projects/NodeJS', 'D:/Projects/Backbone'));
console.log(path.resolve('D:/Projects/Nodejs', '../Backbone'));

console.log(path.resolve('D:/Projects/NodeJS', '../Backbone'));
console.log(path.resolve('D:/', '/Projects', 'Nodejs', 'examples'));
console.log(path.resolve('D:/', '/Projects', '/Nodejs', 'examples'));
console.log(path.resolve('D:/', '/Projects', '/Nodejs', '/examples'));
console.log(path.resolve('D:/', 'Projects', 'Nodejs', 'examples'));

/***
* Join the path.
* Join all arguments and normalize the resulting path.
*/
console.log(path.join('D:/', 'Projects', 'NodeJS'));
console.log(path.join('D:/', 'Projects', 'Nodejs'));

console.log(path.join('D:/', 'Projects', 'Nodejs', '..', 'Backbone'));

console.log(path.join('D:/', 'Projects', 'NodeJS', '..', 'Backbone'));
// Throws exception.
// TypeError: Arguments to path.join must be strings.
// console.log(path.join('D:/', {}, 'Projects'));

/***
* The [PLATFORM] specific file separator `\` or `/`.
*/
console.log('D:/Projects/NodeJS'.split(path.sep));
console.log('Projects\\Nodejs\\examples'.split(path.sep));

/***
* The [PLATFORM] specific path delimiter `:` or `;`.
*/
console.log(process.env.PATH);
console.log(process.env.PATH.split(path.delimiter));

/***
* Returns an object from a path string.
* Note: need latest node.js version.
* OUTPUT: {
root : "C:\",
dir : "C:\path\dir",
base : "index.html",
ext : ".html",
name : "index"
}
*/
// console.log(path.parse('D:\\projects\\Nodejs\\examples\os.html'));

/***
* Returns an path string from an object. the opposite of path.parse
* Note: need latest node.js version.
* OUTPUT: 'D:/projects/Nodejs/examples/os.html'
*/
// path.format({
// root: "D:/",
// dir: "/projects/Nodejs/examples",
// base: "os.html",
// ext: ".html",
// name: "os"
// });

0 comments on commit 8217c1f

Please sign in to comment.