diff --git a/index.js b/index.js index f2d163a..a4bd55c 100644 --- a/index.js +++ b/index.js @@ -20,6 +20,10 @@ async function subsetFont( text, { targetFormat = fontverter.detectFormat(originalFont), preserveNameIds } = {} ) { + if (typeof text !== 'string') { + throw new Error('The subset text must be given as a string'); + } + const [exports, heapu8] = await loadAndInitializeHarfbuzz(); originalFont = await fontverter.convert(originalFont, 'truetype'); diff --git a/test/index.js b/test/index.js index 3274a9f..f9ef8c4 100644 --- a/test/index.js +++ b/test/index.js @@ -25,6 +25,16 @@ describe('subset-font', function () { ); }); + describe('when not supplying the subset text as a string', function () { + it('should fail with an error', async function () { + await expect( + () => subsetFont(this.sfntFont, ['f', 'o', 'o']), + 'to error with', + 'The subset text must be given as a string' + ); + }); + }); + describe('with no targetFormat given', function () { it('should return the subset as truetype', async function () { const result = await subsetFont(this.sfntFont, 'abcd');