source: imaps-frontend/node_modules/path-parse/index.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[d565449]1'use strict';
2
3var isWindows = process.platform === 'win32';
4
5// Regex to split a windows path into into [dir, root, basename, name, ext]
6var splitWindowsRe =
7 /^(((?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?[\\\/]?)(?:[^\\\/]*[\\\/])*)((\.{1,2}|[^\\\/]+?|)(\.[^.\/\\]*|))[\\\/]*$/;
8
9var win32 = {};
10
11function win32SplitPath(filename) {
12 return splitWindowsRe.exec(filename).slice(1);
13}
14
15win32.parse = function(pathString) {
16 if (typeof pathString !== 'string') {
17 throw new TypeError(
18 "Parameter 'pathString' must be a string, not " + typeof pathString
19 );
20 }
21 var allParts = win32SplitPath(pathString);
22 if (!allParts || allParts.length !== 5) {
23 throw new TypeError("Invalid path '" + pathString + "'");
24 }
25 return {
26 root: allParts[1],
27 dir: allParts[0] === allParts[1] ? allParts[0] : allParts[0].slice(0, -1),
28 base: allParts[2],
29 ext: allParts[4],
30 name: allParts[3]
31 };
32};
33
34
35
36// Split a filename into [dir, root, basename, name, ext], unix version
37// 'root' is just a slash, or nothing.
38var splitPathRe =
39 /^((\/?)(?:[^\/]*\/)*)((\.{1,2}|[^\/]+?|)(\.[^.\/]*|))[\/]*$/;
40var posix = {};
41
42
43function posixSplitPath(filename) {
44 return splitPathRe.exec(filename).slice(1);
45}
46
47
48posix.parse = function(pathString) {
49 if (typeof pathString !== 'string') {
50 throw new TypeError(
51 "Parameter 'pathString' must be a string, not " + typeof pathString
52 );
53 }
54 var allParts = posixSplitPath(pathString);
55 if (!allParts || allParts.length !== 5) {
56 throw new TypeError("Invalid path '" + pathString + "'");
57 }
58
59 return {
60 root: allParts[1],
61 dir: allParts[0].slice(0, -1),
62 base: allParts[2],
63 ext: allParts[4],
64 name: allParts[3],
65 };
66};
67
68
69if (isWindows)
70 module.exports = win32.parse;
71else /* posix */
72 module.exports = posix.parse;
73
74module.exports.posix = posix.parse;
75module.exports.win32 = win32.parse;
Note: See TracBrowser for help on using the repository browser.