عکس pi0
Converts internasionalization to i18nJavaScript
موضوع‌ها
۰
فورک‌ها
۲
ستاره‌ها
۶
تاریخ ایجاد
۹ دی ۱۳۹۸
آخرین بروزرسانی
بیشتر از ۲ سال قبل

n10y (Numeronymify)

Converts internasionalization to i18n (where 18 stands for the number of letters between the first i and the last n in the word internationalization) and Wombat to W4t!

Usage

Install:

yarn add n10y
npm i n10y

Import:

import n10y from 'n10y'

const n10y = require('n10y')

Use:

console.log(n10y('wombat'))

Common Abbreviations

  • internasionalization (i18n)
  • localization (l10n)
  • globalization (g11n)
  • localizability (l12y)

Different implementations

Do you have another crazy idea? Open a PR! Everything working is accepted!

First (@pi0):

const n10y = s => s[0] + (s.length - 2) + s[s.length - 1]

Shift/Pop (@pi0):

const n10y = s => s.split('').shift() + (s.length - 2) + s.split('').pop()

Shift/Pop, taking advantage of mutation to get correct length (@jonaskuske):

const n10y = s => (s = s.split(''), s.shift() + (l => s.length + l)(s.pop()))

Replace (@pimlie)

const n10y = s => s.replace(/^(\S)(\S*)(\S)$/, (_, st, nd, rd) => st + (nd.length > 1 ? nd.length : nd) + rd)

Spread (@alireza-mh)

const n10y = s => {const {0: first, [s.length-1]: last} = s ; return first+(s.length-2)+last}
  • n10y - Numeronymify everything

License

MIT

Inspired by a tweet from @alvarotrigo. Also thanks to Harald Atteneder for package name suggestion.