/**
 * @license Copyright (c) 2017-2025, CKSource Holding sp. z o.o. All rights reserved.
 * For licensing, see LICENSE.md.
 */

'use strict';

/**
 * Replaces characters in a string. Mainly used to prepare a long-name to be used as a filename.
 *
 * @param {String} text
 * @returns {String}
 */
module.exports = text => {
	const str = text || '';

	return str.replace( /\([\s\S]*\)$/, '' )
		.replace( /^[.-]/, '' )
		.replace( /[|/\\:<>#.]/g, '_' )
		.replace( /~/g, '-' );
};
