19
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
22
- var util = require ( 'util' ) ;
23
- var shims = require ( '_shims' ) ;
24
-
25
22
// resolves . and .. elements in a path array with directory names there
26
23
// must be no slashes, empty elements, or device names (c:\) in the array
27
24
// (so also no leading and trailing slashes - it does not distinguish
@@ -70,7 +67,7 @@ exports.resolve = function() {
70
67
var path = ( i >= 0 ) ? arguments [ i ] : process . cwd ( ) ;
71
68
72
69
// Skip empty and invalid entries
73
- if ( ! util . isString ( path ) ) {
70
+ if ( typeof path !== 'string' ) {
74
71
throw new TypeError ( 'Arguments to path.resolve must be strings' ) ;
75
72
} else if ( ! path ) {
76
73
continue ;
@@ -84,7 +81,7 @@ exports.resolve = function() {
84
81
// handle relative paths to be safe (might happen when process.cwd() fails)
85
82
86
83
// Normalize the path
87
- resolvedPath = normalizeArray ( shims . filter ( resolvedPath . split ( '/' ) , function ( p ) {
84
+ resolvedPath = normalizeArray ( filter ( resolvedPath . split ( '/' ) , function ( p ) {
88
85
return ! ! p ;
89
86
} ) , ! resolvedAbsolute ) . join ( '/' ) ;
90
87
@@ -95,10 +92,10 @@ exports.resolve = function() {
95
92
// posix version
96
93
exports . normalize = function ( path ) {
97
94
var isAbsolute = exports . isAbsolute ( path ) ,
98
- trailingSlash = shims . substr ( path , - 1 ) === '/' ;
95
+ trailingSlash = substr ( path , - 1 ) === '/' ;
99
96
100
97
// Normalize the path
101
- path = normalizeArray ( shims . filter ( path . split ( '/' ) , function ( p ) {
98
+ path = normalizeArray ( filter ( path . split ( '/' ) , function ( p ) {
102
99
return ! ! p ;
103
100
} ) , ! isAbsolute ) . join ( '/' ) ;
104
101
@@ -120,8 +117,8 @@ exports.isAbsolute = function(path) {
120
117
// posix version
121
118
exports . join = function ( ) {
122
119
var paths = Array . prototype . slice . call ( arguments , 0 ) ;
123
- return exports . normalize ( shims . filter ( paths , function ( p , index ) {
124
- if ( ! util . isString ( p ) ) {
120
+ return exports . normalize ( filter ( paths , function ( p , index ) {
121
+ if ( typeof p !== 'string' ) {
125
122
throw new TypeError ( 'Arguments to path.join must be strings' ) ;
126
123
}
127
124
return p ;
@@ -207,3 +204,21 @@ exports.basename = function(path, ext) {
207
204
exports . extname = function ( path ) {
208
205
return splitPath ( path ) [ 3 ] ;
209
206
} ;
207
+
208
+ function filter ( xs , f ) {
209
+ if ( xs . filter ) return xs . filter ( f ) ;
210
+ var res = [ ] ;
211
+ for ( var i = 0 ; i < xs . length ; i ++ ) {
212
+ if ( f ( xs [ i ] , i , xs ) ) res . push ( xs [ i ] ) ;
213
+ }
214
+ return res ;
215
+ }
216
+
217
+ // String.prototype.substr - negative index don't work in IE8
218
+ var substr = 'ab' . substr ( - 1 ) === 'b'
219
+ ? function ( str , start , len ) { return str . substr ( start , len ) }
220
+ : function ( str , start , len ) {
221
+ if ( start < 0 ) start = str . length + start ;
222
+ return str . substr ( start , len ) ;
223
+ }
224
+ ;
0 commit comments