-
Notifications
You must be signed in to change notification settings - Fork 270
/
Copy pathutil.js
39 lines (39 loc) · 1.11 KB
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function bufFromString(str) {
var length = Buffer.byteLength(str);
var buffer = Buffer.allocUnsafe
? Buffer.allocUnsafe(length)
: new Buffer(length);
buffer.write(str);
return buffer;
}
exports.bufFromString = bufFromString;
function emptyBuffer() {
var buffer = Buffer.allocUnsafe
? Buffer.allocUnsafe(0)
: new Buffer(0);
return buffer;
}
exports.emptyBuffer = emptyBuffer;
function filterArray(arr, filter) {
var rtn = [];
for (var i = 0; i < arr.length; i++) {
if (filter.indexOf(i) > -1) {
rtn.push(arr[i]);
}
}
return rtn;
}
exports.filterArray = filterArray;
exports.trimLeft = String.prototype.trimLeft ? function trimLeftNative(str) {
return str.trimLeft();
} : function trimLeftRegExp(str) {
return str.replace(/^\s+/, "");
};
exports.trimRight = String.prototype.trimRight ? function trimRightNative(str) {
return str.trimRight();
} : function trimRightRegExp(str) {
return str.replace(/\s+$/, "");
};
//# sourceMappingURL=util.js.map