diff --git a/i7h.js b/i7h.js new file mode 100644 index 0000000..f908e99 --- /dev/null +++ b/i7h.js @@ -0,0 +1,15 @@ +export const i18n = (str) => { + if (typeof str !== "string") { + throw new Error("Not string"); + } + + return str.replace(/\w+/g, ellipsis); +}; + +const ellipsis = (word) => { + if (word.length < 3) { + return word; + } + + return `${word.slice(0, 1)}${word.length - 2}${word.slice(-1)}`; +};