Skip to content

Commit

Permalink
Handle m coda in normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
lynn committed Jul 15, 2024
1 parent 42ddfdb commit a569a33
Show file tree
Hide file tree
Showing 4 changed files with 2,360 additions and 103 deletions.
18 changes: 18 additions & 0 deletions frontend/shared/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { test, describe, expect } from 'vitest';
import { normalize } from './index';

describe('normalize', () => {
test('it normalizes Toaq text', () => {
expect(normalize('Vyadi hoi2 pai2 ȷibo1')).toMatchInlineSnapshot(
`"Ꝡadı hóı páı jıbo"`,
);
expect(normalize('domu')).toMatchInlineSnapshot(`"domu"`);
expect(normalize("o'aomo")).toMatchInlineSnapshot(`"o'aomo"`);
expect(normalize('daqmiq')).toMatchInlineSnapshot(`"daqmıq"`);
expect(normalize('koammoa')).toMatchInlineSnapshot(`"koammoa"`);
expect(normalize("'amla")).toMatchInlineSnapshot(`"amla"`);
expect(normalize('chuom’ai')).toMatchInlineSnapshot(`"chuom'aı"`);
expect(normalize('ram-jea ji2')).toMatchInlineSnapshot(`"rạmjea jí"`);
expect(normalize('rao4 2024')).toMatchInlineSnapshot(`"râo 2024"`);
});
});
9 changes: 8 additions & 1 deletion frontend/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ export function convert_hue(h: number, theme?: string): Color {
};
}

/**
* Normalize Toaq text, e.g. turn `Vyadi hoi2 pai2` into `Ꝡadı hóı páı`.
*
* Beware! When Toadua starts up, this function gets called on everything in the
* database (see modules/housekeep.ts). Changing its behavior might cause
* widespread destruction.
*/
export function normalize(s: string, trim?: boolean): string {
if (trim === undefined) trim = true;
let suffix = trim ? '' : s.match(/\s*$/)[0];
Expand All @@ -45,7 +52,7 @@ export function normalize(s: string, trim?: boolean): string {
.map(w =>
w
.replace(
/(['ʼx-]*)([^aeiouq\u0300-\u036f'ʼ0-9x]*)([aeiou])([\u0323]?)([\u0300-\u036f]?)([\u0323]?)([aeiou]*(?![\u0300-\u036f])q?)([0-8]*)(?=(-.)?)/gi,
/(['ʼx-]*)([^aeiouq\u0300-\u036f'ʼ0-9x]*)([aeiou])([\u0323]?)([\u0300-\u036f]?)([\u0323]?)([aeiou]*(?![\u0300-\u036f])(?:q|m(?![aeiou]))?)([0-8]*)(?=(-.)?)/gi,
(
_,
_apo,
Expand Down
Loading

0 comments on commit a569a33

Please sign in to comment.