Gitter migration: Setup redirects (rollout pt. 3)
[gitter.git] / shared / room-name-trimmer.js
blob84d2e84212c77898a87f66703b2e97d04c069754
1 'use strict';
3 module.exports = function trim(name, maxLength) {
4 maxLength = maxLength || 25; // defaults to 25
6 if (!name || name.length < maxLength) return name; // avoid computing
8 var parts = name.split('/'); // break it down
10 for (var i = 1; i < parts.length; i++) {
11 var sub = parts.slice(i).join('/');
12 if (sub.length <= maxLength) return sub; // trying to compose a smaller part that makes sense
15 // if all else fails, return the first part only
16 return parts.pop();