@@ -20,7 +20,7 @@ function isFile(item) {
20
20
function pathToArray ( path ) {
21
21
var nix = / ^ \/ / . test ( path ) ;
22
22
if ( ! nix ) {
23
- if ( ! / ^ [ A - Z a - z ] : / . test ( path ) ) throw new Error ( "Invalid path " + path ) ;
23
+ if ( ! / ^ [ A - Z a - z ] : / . test ( path ) ) throw new Error ( "Invalid path ' " + path + "'" ) ;
24
24
path = path . replace ( / [ \\ \/ ] + / g, "\\" ) ; // multi slashs
25
25
path = path . split ( / [ \\ \/ ] / ) ;
26
26
path [ 0 ] = path [ 0 ] . toUpperCase ( ) ;
@@ -32,15 +32,15 @@ function pathToArray(path) {
32
32
return path ;
33
33
}
34
34
35
- function trueFn ( ) { return true }
36
- function falseFn ( ) { return false }
35
+ function trueFn ( ) { return true ; }
36
+ function falseFn ( ) { return false ; }
37
37
38
38
MemoryFileSystem . prototype . statSync = function ( _path ) {
39
39
var path = pathToArray ( _path ) ;
40
40
var current = this . data ;
41
41
for ( var i = 0 ; i < path . length - 1 ; i ++ ) {
42
42
if ( ! isDir ( current [ path [ i ] ] ) )
43
- throw new Error ( "Path doesn't exist " + _path ) ;
43
+ throw new Error ( "Path doesn't exist ' " + _path + "'" ) ;
44
44
current = current [ path [ i ] ] ;
45
45
}
46
46
if ( _path === "/" || isDir ( current [ path [ i ] ] ) ) {
@@ -64,22 +64,22 @@ MemoryFileSystem.prototype.statSync = function(_path) {
64
64
isSocket : falseFn
65
65
} ;
66
66
} else
67
- throw new Error ( "Path doesn't exist " + _path ) ;
67
+ throw new Error ( "Path doesn't exist ' " + _path + "'" ) ;
68
68
} ;
69
69
70
70
MemoryFileSystem . prototype . readFileSync = function ( _path , encoding ) {
71
71
var path = pathToArray ( _path ) ;
72
72
var current = this . data ;
73
73
for ( var i = 0 ; i < path . length - 1 ; i ++ ) {
74
74
if ( ! isDir ( current [ path [ i ] ] ) )
75
- throw new Error ( "Path doesn't exist " + _path ) ;
75
+ throw new Error ( "Path doesn't exist ' " + _path + "'" ) ;
76
76
current = current [ path [ i ] ] ;
77
77
}
78
78
if ( ! isFile ( current [ path [ i ] ] ) ) {
79
79
if ( isDir ( current [ path [ i ] ] ) )
80
- throw new Error ( "Cannot readFile on directory " + _path ) ;
80
+ throw new Error ( "Cannot readFile on directory ' " + _path + "'" ) ;
81
81
else
82
- throw new Error ( "File doesn't exist " + _path ) ;
82
+ throw new Error ( "Path doesn't exist ' " + _path + "'" ) ;
83
83
}
84
84
current = current [ path [ i ] ] ;
85
85
return encoding ? current . toString ( encoding ) : current ;
@@ -91,14 +91,14 @@ MemoryFileSystem.prototype.readdirSync = function(_path) {
91
91
var current = this . data ;
92
92
for ( var i = 0 ; i < path . length - 1 ; i ++ ) {
93
93
if ( ! isDir ( current [ path [ i ] ] ) )
94
- throw new Error ( "Path doesn't exist " + _path ) ;
94
+ throw new Error ( "Path doesn't exist ' " + _path + "'" ) ;
95
95
current = current [ path [ i ] ] ;
96
96
}
97
97
if ( ! isDir ( current [ path [ i ] ] ) ) {
98
98
if ( isFile ( current [ path [ i ] ] ) )
99
- throw new Error ( "Cannot readdir on file " + _path ) ;
99
+ throw new Error ( "Cannot readdir on file ' " + _path + "'" ) ;
100
100
else
101
- throw new Error ( "File doesn't exist " + _path ) ;
101
+ throw new Error ( "Path doesn't exist ' " + _path + "'" ) ;
102
102
}
103
103
return Object . keys ( current [ path [ i ] ] ) . filter ( Boolean ) ;
104
104
} ;
@@ -109,7 +109,7 @@ MemoryFileSystem.prototype.mkdirpSync = function(_path) {
109
109
var current = this . data ;
110
110
for ( var i = 0 ; i < path . length ; i ++ ) {
111
111
if ( isFile ( current [ path [ i ] ] ) )
112
- throw new Error ( "Path is a file " + _path ) ;
112
+ throw new Error ( "Path is a file ' " + _path + "'" ) ;
113
113
else if ( ! isDir ( current [ path [ i ] ] ) )
114
114
current [ path [ i ] ] = { "" :true } ;
115
115
current = current [ path [ i ] ] ;
@@ -123,28 +123,28 @@ MemoryFileSystem.prototype.mkdirSync = function(_path) {
123
123
var current = this . data ;
124
124
for ( var i = 0 ; i < path . length - 1 ; i ++ ) {
125
125
if ( ! isDir ( current [ path [ i ] ] ) )
126
- throw new Error ( "Path doesn't exist " + _path ) ;
126
+ throw new Error ( "Path doesn't exist ' " + _path + "'" ) ;
127
127
current = current [ path [ i ] ] ;
128
128
}
129
129
if ( isDir ( current [ path [ i ] ] ) )
130
- throw new new Error ( "Directory already exist " + _path ) ;
130
+ throw new new Error ( "Directory already exist ' " + _path + "'" ) ;
131
131
else if ( isFile ( current [ path [ i ] ] ) )
132
- throw new Error ( "Cannot mkdir on file " + _path ) ;
132
+ throw new Error ( "Cannot mkdir on file ' " + _path + "'" ) ;
133
133
current [ path [ i ] ] = { "" :true } ;
134
134
return ;
135
135
} ;
136
136
137
137
MemoryFileSystem . prototype . _remove = function ( _path , name , testFn ) {
138
138
var path = pathToArray ( _path ) ;
139
- if ( path . length === 0 ) throw new Error ( "Path cannot be removed " + _path ) ;
139
+ if ( path . length === 0 ) throw new Error ( "Path cannot be removed ' " + _path + "'" ) ;
140
140
var current = this . data ;
141
141
for ( var i = 0 ; i < path . length - 1 ; i ++ ) {
142
142
if ( ! isDir ( current [ path [ i ] ] ) )
143
- throw new Error ( "Path doesn't exist " + _path ) ;
143
+ throw new Error ( "Path doesn't exist ' " + _path + "'" ) ;
144
144
current = current [ path [ i ] ] ;
145
145
}
146
146
if ( ! testFn ( current [ path [ i ] ] ) )
147
- throw new Error ( name + " doesn't exist " + _path ) ;
147
+ throw new Error ( "'" + name + "' doesn't exist ' " + _path + "'" ) ;
148
148
delete current [ path [ i ] ] ;
149
149
return ;
150
150
} ;
@@ -160,15 +160,15 @@ MemoryFileSystem.prototype.unlinkSync = function(_path) {
160
160
MemoryFileSystem . prototype . writeFileSync = function ( _path , content , encoding ) {
161
161
if ( ! content && ! encoding ) throw new Error ( "No content" ) ;
162
162
var path = pathToArray ( _path ) ;
163
- if ( path . length === 0 ) throw new Error ( "Path is not a file " + _path ) ;
163
+ if ( path . length === 0 ) throw new Error ( "Path is not a file ' " + _path + "'" ) ;
164
164
var current = this . data ;
165
165
for ( var i = 0 ; i < path . length - 1 ; i ++ ) {
166
166
if ( ! isDir ( current [ path [ i ] ] ) )
167
- throw new Error ( "Path doesn't exist " + _path ) ;
167
+ throw new Error ( "Path doesn't exist ' " + _path + "'" ) ;
168
168
current = current [ path [ i ] ] ;
169
169
}
170
170
if ( isDir ( current [ path [ i ] ] ) )
171
- throw new Error ( "Cannot writeFile on directory " + _path ) ;
171
+ throw new Error ( "Cannot writeFile on directory ' " + _path + "'" ) ;
172
172
current [ path [ i ] ] = encoding || typeof content === "string" ? new Buffer ( content , encoding ) : content ;
173
173
return ;
174
174
} ;
0 commit comments