From 7c0fa53c642993a9045f84a2cc2df51ec614c940 Mon Sep 17 00:00:00 2001 From: Luke Geneva Date: Fri, 25 Oct 2024 17:12:18 -0500 Subject: [PATCH] 0.2.0 --- dispense.js | 4 ++-- dispense.test.js | 18 ++++++------------ index.d.ts | 3 +++ package.json | 3 ++- 4 files changed, 13 insertions(+), 15 deletions(-) create mode 100644 index.d.ts diff --git a/dispense.js b/dispense.js index 38fbc6c..7633c39 100644 --- a/dispense.js +++ b/dispense.js @@ -6,7 +6,7 @@ const IMPORT_REGEX = /\{\{\s*import (\w+\.html)\s*\}\}/g; const IMPORT_WITH_CONTENT_REGEX = /\{\{\s*import\s+((\w+|\-+|_+)*.html)\s*\}\}\s*((.|\s)*)\{\{\s*\/\1\s*\}\}/g; -function dispense(filepath, options, callback) { +function dispense(filepath, options) { let content = fs.readFileSync(filepath, 'utf-8'); const dir = path.dirname(filepath); @@ -33,7 +33,7 @@ function dispense(filepath, options, callback) { } const rendered = render(content, options); - return callback(null, rendered); + return rendered; } module.exports = { dispense }; diff --git a/dispense.test.js b/dispense.test.js index 964ce57..55ea2cf 100644 --- a/dispense.test.js +++ b/dispense.test.js @@ -1,25 +1,19 @@ const { dispense } = require('./dispense'); -let callback; - -beforeEach(() => { - callback = jest.fn(); -}); - test('that files can be imported', () => { - dispense('./test/views/import-test.html', {}, callback); const html = '
\n
\n'; - expect(callback).toHaveBeenCalledWith(null, html); + const output = dispense('./test/views/import-test.html', {}); + expect(output).toEqual(html); }); test('that imported views can container inner markup', () => { - dispense('./test/views/inner-markup.html', {}, callback); const html = '
inner
\n
\n'; - expect(callback).toHaveBeenCalledWith(null, html); + const output = dispense('./test/views/inner-markup.html', {}); + expect(output).toEqual(html); }); test('that imported views can contain imported views', () => { - dispense('./test/views/nested-import.html', {}, callback); const html = '
\n
test
\n
\n'; - expect(callback).toHaveBeenCalledWith(null, html); + const output = dispense('./test/views/nested-import.html', {}); + expect(output).toEqual(html); }); diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..3098469 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,3 @@ +declare function dispense(filepath: string, options: any): string; + +export { dispense }; diff --git a/package.json b/package.json index 6c56b5b..aa4fb1b 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,9 @@ { "name": "nutrimatic-html-dispenser", - "version": "0.1.0", + "version": "0.2.0", "description": "A simple HTML template engine.", "main": "index.js", + "types": "index.d.ts", "scripts": { "test": "jest", "test:watch": "jest --watch"