From 11013e648dbc86be4cf01701767ab8426a8552e5 Mon Sep 17 00:00:00 2001 From: MinRK Date: Thu, 17 Oct 2013 14:30:15 -0700 Subject: [PATCH] add utils.splitext to js mimic Python os.path.splitext --- IPython/html/static/base/js/utils.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/IPython/html/static/base/js/utils.js b/IPython/html/static/base/js/utils.js index 70f0e3444..8d06cec40 100644 --- a/IPython/html/static/base/js/utils.js +++ b/IPython/html/static/base/js/utils.js @@ -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 };