Skip to content

Commit 3ce712e

Browse files
author
deiu
committed
Added helper functions to simplify extension check
1 parent a2b7cc2 commit 3ce712e

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

lib/utils.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ function pathBasename(fullpath) {
5050
return bname;
5151
}
5252

53+
function hasSuffix(path, suffixes) {
54+
for (var i in suffixes) {
55+
if (path.indexOf(suffixes[i], path.length - suffixes[i].length) !== -1) {
56+
return true;
57+
}
58+
}
59+
return false;
60+
}
61+
5362
function getResourceLink(filename, uri, base, suffix, otherSuffix) {
5463
var link = filenameToBaseUri(filename, uri, base);
5564
if (S(link).endsWith(suffix)) {
@@ -80,13 +89,23 @@ function shortTime() {
8089
'{Hours}:{Minutes}:{Seconds}.{Milliseconds}');
8190
}
8291

92+
function pushIfNotExist (arr, item) {
93+
if (arr.indexOf(item) == -1) {
94+
arr.push(item);
95+
return true;
96+
}
97+
return false;
98+
}
99+
83100
exports.uriToFilename = uriToFilename;
84101
exports.uriToRelativeFilename = uriToRelativeFilename;
85102
exports.filenameToBaseUri = filenameToBaseUri;
86103
exports.uriAbs = uriAbs;
87104
exports.pathBasename = pathBasename;
88105
exports.uriBase = uriBase;
106+
exports.hasSuffix = hasSuffix;
89107
exports.getResourceLink = getResourceLink;
90108
exports.formatDateTime = formatDateTime;
91109
exports.timestamp = timestamp;
92-
exports.shortTime = shortTime;
110+
exports.shortTime = shortTime;
111+
exports.pushIfNotExist = pushIfNotExist;

0 commit comments

Comments
 (0)