/**
 * @since Last modified: 2023-11-14 16:48:50
 * @function trim
 * @description Clear string space, change and return.Supporting the space in multiple positions, which is more powerful than the native "trim" method.
 * @param {string} str - Any string.
 * @param {string} [placement] - Clear the position of the space, you can fill in the value: 'start' | 'end' | 'both' | 'global', can be empty or not filled in.
 * @returns {string}  - Returns the string after clearing the space without changing the original string.
 * @see {@link https://codepen.io/axui/pen/vYbmqYj|demo @ codepen}
 * @example
 * ax.trim('   My name     is Lily  ');
 * <!--return 'My name is Lily'-->
 */
'use strict';
import requireTypes from "./requireTypes";
const trim = (str, placement) => {
    requireTypes(str, 'string');
    return placement === 'start' ? str.trimStart() :
        placement === 'end' ? str.trimEnd() :
            placement === 'both' ? str.trim() :
                placement === 'global' ? str.replace(/[\s\r\n]+/g, '') : str.trim().replace(/[\s\r\n]+/g, ' ');
};
export default trim;
