Gitter migration: Setup redirects (rollout pt. 3)
[gitter.git] / shared / room-name-shortener.js
blobf231c1467ddb82286f6fef9c5dbfdf299553fee3
1 'use strict';
3 module.exports = function roomNameShortener(name) {
4 if (!name) return '';
6 var resultantName = '';
7 name
8 .split('/')
9 .reverse()
10 .some(function(piece, index) {
11 var newResult = piece + (resultantName.length ? '/' : '') + resultantName;
13 if (newResult.length <= 16 || index === 0) {
14 resultantName = newResult;
15 } else {
16 // break, we went over with this piece
17 return true;
19 }, '');
21 return resultantName || name;