Skip to content

Instantly share code, notes, and snippets.

@jfroffice
Created December 5, 2012 07:50
Show Gist options
  • Save jfroffice/4213579 to your computer and use it in GitHub Desktop.
Save jfroffice/4213579 to your computer and use it in GitHub Desktop.
Pretty Print File Name - Skrinking the filename in the middle in order to keep extension
function prettyprint(data, max) {
var max = max || 50,
min = 4,
separator = '...',
before = max * 0.618,
nL = data.length,
after = max - before - separator.length;
if (after < min) {
after = min;
}
if (nL > max) {
return data.slice(0, before) + separator + data.slice(nL-1-after, nL);
} else {
return data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment