Skip to content

Commit eaffbea

Browse files
author
James Halliday
committed
inline the shims for tinier bundles
1 parent 94f6fc6 commit eaffbea

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

index.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

22-
var util = require('util');
23-
var shims = require('_shims');
24-
2522
// resolves . and .. elements in a path array with directory names there
2623
// must be no slashes, empty elements, or device names (c:\) in the array
2724
// (so also no leading and trailing slashes - it does not distinguish
@@ -70,7 +67,7 @@ exports.resolve = function() {
7067
var path = (i >= 0) ? arguments[i] : process.cwd();
7168

7269
// Skip empty and invalid entries
73-
if (!util.isString(path)) {
70+
if (typeof path !== 'string') {
7471
throw new TypeError('Arguments to path.resolve must be strings');
7572
} else if (!path) {
7673
continue;
@@ -84,7 +81,7 @@ exports.resolve = function() {
8481
// handle relative paths to be safe (might happen when process.cwd() fails)
8582

8683
// Normalize the path
87-
resolvedPath = normalizeArray(shims.filter(resolvedPath.split('/'), function(p) {
84+
resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
8885
return !!p;
8986
}), !resolvedAbsolute).join('/');
9087

@@ -95,10 +92,10 @@ exports.resolve = function() {
9592
// posix version
9693
exports.normalize = function(path) {
9794
var isAbsolute = exports.isAbsolute(path),
98-
trailingSlash = shims.substr(path, -1) === '/';
95+
trailingSlash = substr(path, -1) === '/';
9996

10097
// Normalize the path
101-
path = normalizeArray(shims.filter(path.split('/'), function(p) {
98+
path = normalizeArray(filter(path.split('/'), function(p) {
10299
return !!p;
103100
}), !isAbsolute).join('/');
104101

@@ -120,8 +117,8 @@ exports.isAbsolute = function(path) {
120117
// posix version
121118
exports.join = function() {
122119
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') {
125122
throw new TypeError('Arguments to path.join must be strings');
126123
}
127124
return p;
@@ -207,3 +204,21 @@ exports.basename = function(path, ext) {
207204
exports.extname = function(path) {
208205
return splitPath(path)[3];
209206
};
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

Comments
 (0)