debian-mirror-gitlab/app/assets/javascripts/locale/ensure_single_line.cjs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
542 B
JavaScript
Raw Normal View History

2018-11-20 20:47:30 +05:30
/* eslint-disable import/no-commonjs */
const SPLIT_REGEX = /\s*[\r\n]+\s*/;
/**
*
* strips newlines from strings and replaces them with a single space
*
* @example
*
* ensureSingleLine('foo \n bar') === 'foo bar'
*
* @param {String} str
* @returns {String}
*/
module.exports = function ensureSingleLine(str) {
// This guard makes the function significantly faster
if (str.includes('\n') || str.includes('\r')) {
return str
.split(SPLIT_REGEX)
2021-03-08 18:12:59 +05:30
.filter((s) => s !== '')
2018-11-20 20:47:30 +05:30
.join(' ');
}
return str;
};