Skip to content

Commit

Permalink
feat(cli): Add max-repeat option to customise common functions & cate…
Browse files Browse the repository at this point in the history
…gories
  • Loading branch information
eemeli committed Aug 22, 2019
1 parent 3421285 commit e47a725
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
5 changes: 5 additions & 0 deletions packages/cli/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ const moduleCommandBuilder = yargs =>
desc: 'Include cardinal plurals',
type: 'boolean'
},
'max-repeat': {
default: 5,
desc: 'Maximum number of allowed repeats for plural functions & cagetories',
type: 'number'
},
ordinals: {
default: true,
desc: 'Include ordinal plurals',
Expand Down
5 changes: 2 additions & 3 deletions packages/cli/src/print-categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { identifier } from 'safe-identifier'
import getCompiler from './get-compiler'
import printUMD from './print-umd'

const MAX_CATEGORIES_REPEAT = 5
const NAMES = { zero: 'z', one: 'o', two: 't', few: 'f', many: 'm', other: 'x' }

function stringifyCategories({ cardinal, ordinal }) {
Expand All @@ -15,7 +14,7 @@ function stringifyCategories({ cardinal, ordinal }) {

export default function printCategoriesModule(args) {
const MakePlural = getCompiler(args)
const { locale, umd } = args
const { locale, maxRepeat, umd } = args
const locales =
locale.length === 0 ? Object.keys(MakePlural.rules.cardinal) : locale.sort()

Expand All @@ -37,7 +36,7 @@ export default function printCategoriesModule(args) {
let commonId = 'a'
const categories = []
for (const [cat, locales] of Object.entries(localesByCat)) {
if (locales.length > MAX_CATEGORIES_REPEAT && commonId <= 'z') {
if (locales.length > maxRepeat && commonId <= 'z') {
str += `${varType} ${commonId} = ${cat};\n`
for (const lc of locales) categories.push({ lc, cat: commonId })
do {
Expand Down
6 changes: 2 additions & 4 deletions packages/cli/src/print-plurals.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { identifier } from 'safe-identifier'
import getCompiler from './get-compiler'
import printUMD from './print-umd'

const MAX_PLURAL_REPEAT = 5

export default function printPluralsModule(args) {
const MakePlural = getCompiler(args)
const { locale, umd } = args
const { locale, maxRepeat, umd } = args
const locales =
locale.length === 0 ? Object.keys(MakePlural.rules.cardinal) : locale.sort()

Expand All @@ -25,7 +23,7 @@ export default function printPluralsModule(args) {
let commonId = 'a'
const plurals = []
for (const [fn, locales] of Object.entries(localesByFn)) {
if (locales.length > MAX_PLURAL_REPEAT) {
if (locales.length > maxRepeat && commonId <= 'z') {
str += fn.replace(/^function\b/, `function ${commonId}`) + '\n'
for (const lc of locales) plurals.push({ lc, id: commonId })
commonId = String.fromCharCode(commonId.charCodeAt(0) + 1)
Expand Down

0 comments on commit e47a725

Please sign in to comment.