add utils.splitext to js

mimic Python os.path.splitext
This commit is contained in:
MinRK 2013-10-17 14:30:15 -07:00
parent 5ca1ad666d
commit 11013e648d

View File

@ -384,6 +384,18 @@ IPython.utils = (function (IPython) {
};
var splitext = function (filename) {
// mimic Python os.path.splitext
// Returns ['base', '.ext']
var idx = filename.lastIndexOf('.');
if (idx > 0) {
return [filename.slice(0, idx), filename.slice(idx)];
} else {
return [filename, ''];
}
}
// http://stackoverflow.com/questions/2400935/browser-detection-in-javascript
var browser = (function() {
var N= navigator.appName, ua= navigator.userAgent, tem;
@ -403,6 +415,7 @@ IPython.utils = (function (IPython) {
autoLinkUrls : autoLinkUrls,
points_to_pixels : points_to_pixels,
url_path_join : url_path_join,
splitext : splitext,
browser : browser
};