Skip to content

Commit

Permalink
chore: Fix typo in internal function name
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Oct 19, 2024
1 parent 22b5294 commit 21894d2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
16 changes: 8 additions & 8 deletions packages/i18n/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect } from 'vitest';
import { ChromeMessage } from '../build';
import { applyChromeMessagePlaceholders, getSubstitionCount } from '../utils';
import { applyChromeMessagePlaceholders, getSubstitutionCount } from '../utils';

describe('Utils', () => {
describe('applyChromeMessagePlaceholders', () => {
Expand Down Expand Up @@ -38,26 +38,26 @@ describe('Utils', () => {
});
});

describe('getSubstitionCount', () => {
describe('getSubstitutionCount', () => {
it('should return the last substution present in the message', () => {
expect(getSubstitionCount('I like $1, but I like $2 better')).toBe(2);
expect(getSubstitutionCount('I like $1, but I like $2 better')).toBe(2);
});

it('should return 0 when no substitutions are present', () => {
expect(getSubstitionCount('test')).toBe(0);
expect(getSubstitutionCount('test')).toBe(0);
});

it('should ignore escaped dollar signs', () => {
expect(getSubstitionCount('buy $1 now for $$2 dollars')).toBe(1);
expect(getSubstitutionCount('buy $1 now for $$2 dollars')).toBe(1);
});

it('should return the highest substitution when skipping numbers', () => {
expect(getSubstitionCount('I like $1, but I like $8 better')).toBe(8);
expect(getSubstitutionCount('I like $1, but I like $8 better')).toBe(8);
});

it('should only allow up to 9 substitutions', () => {
expect(getSubstitionCount('Hello $9')).toBe(9);
expect(getSubstitionCount('Hello $10')).toBe(1);
expect(getSubstitutionCount('Hello $9')).toBe(9);
expect(getSubstitutionCount('Hello $10')).toBe(1);
});
});
});
8 changes: 4 additions & 4 deletions packages/i18n/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { mkdir, readFile, writeFile } from 'node:fs/promises';
import { parseYAML, parseJSON5, parseTOML } from 'confbox';
import { dirname, extname } from 'node:path';
import { applyChromeMessagePlaceholders, getSubstitionCount } from './utils';
import { applyChromeMessagePlaceholders, getSubstitutionCount } from './utils';

//
// TYPES
Expand Down Expand Up @@ -155,7 +155,7 @@ function _parseMessagesObject(
case 'number':
case 'symbol': {
const message = String(object);
const substitutions = getSubstitionCount(message);
const substitutions = getSubstitutionCount(message);
return [
{
type: 'simple',
Expand All @@ -177,7 +177,7 @@ function _parseMessagesObject(
);
if (isPluralMessage(object)) {
const message = Object.values(object).join('|');
const substitutions = getSubstitionCount(message);
const substitutions = getSubstitutionCount(message);
return [
{
type: 'plural',
Expand All @@ -189,7 +189,7 @@ function _parseMessagesObject(
}
if (depth === 1 && isChromeMessage(object)) {
const message = applyChromeMessagePlaceholders(object);
const substitutions = getSubstitionCount(message);
const substitutions = getSubstitutionCount(message);
return [
{
type: 'chrome',
Expand Down
2 changes: 1 addition & 1 deletion packages/i18n/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function applyChromeMessagePlaceholders(message: ChromeMessage): string {
);
}

export function getSubstitionCount(message: string): number {
export function getSubstitutionCount(message: string): number {
return (
1 +
Array.from({ length: MAX_SUBSTITUTIONS }).findLastIndex((_, i) =>
Expand Down

0 comments on commit 21894d2

Please sign in to comment.