import fp from "https://cdn.skypack.dev/lodash@4.17.21/fp";
const nameMasking = name => {
const getLengthAndIdx = name => {
const length = Math.floor(name.length / 2);
return [
name,
length,
Math.floor(length / 2) + (name.length % 2 === 0 ? 0 : 1),
];
};
const masking = ([name, length ,idx]) => [
name.substr(0, idx),
fp.repeat(length, '*'),
name.substr(idx + length, name.length),
];
return fp.flow(
fp.split(' '),
fp.map(fp.flow(
getLengthAndIdx,
masking,
fp.compact,
fp.join(''),
)),
fp.join(' '),
)(name)
};
const names = [
'김구',
'안중근',
'John Smith',
'小鳥遊 小鳥'
];
fp.map(nameMasking)(names);