const addWhitespace = (value, ...position) => {
if (value) {
const before = position.includes('before') ? ' ' : '';
const after = position.includes('after') ? ' ' : '';
return `${before}${value}${after}`;
}
};
// addWhitespace('Hello', 'before'); --> " Hello"
// addWhitespace('Hello', 'after'); --> "Hello "
// addWhitespace('Hello', 'before', 'after'); --> " Hello "
const addWhitespace = (value, options = {}) => `${options.before ? ' ' : ''}${value}${options.after ? ' ' : ''}`;
addWhitespace('Hello', { before: true, after: true }); // --> " Hello "