From 2b170c9bc03499ed66ee258d98cd0cff2b63d412 Mon Sep 17 00:00:00 2001 From: Sambo Chea Date: Tue, 30 Mar 2021 13:41:10 +0700 Subject: [PATCH] Fixed export module and add test and clean module and export declare function with props --- excel2json.d.ts | 4 ++-- excel2json.js | 4 ++-- index.js | 11 +++-------- package.json | 2 +- test.js | 5 +++++ 5 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 test.js diff --git a/excel2json.d.ts b/excel2json.d.ts index 78d5980..2fbe60a 100644 --- a/excel2json.d.ts +++ b/excel2json.d.ts @@ -1,4 +1,4 @@ -interface Excel2JsonProps { +export interface Excel2JsonProps { mappings?: Array; saveToOutput?: boolean; outputPath?: string; @@ -10,4 +10,4 @@ interface Excel2JsonProps { encoding?: string; } -declare function excel2json(props: Excel2JsonProps); +export declare function excel2json(props: Excel2JsonProps); diff --git a/excel2json.js b/excel2json.js index a852e9a..d3e601a 100644 --- a/excel2json.js +++ b/excel2json.js @@ -105,7 +105,7 @@ function _internalExport(props = {}) { console.log("Exported excel to json to output =>", outFile); } catch (err) { console.error(err); - } + } } return data; @@ -117,6 +117,6 @@ function _internalExport(props = {}) { * * @returns JSON Object of result */ -module.exports = excel2json = (props = {}) => { +module.exports.excel2json = excel2json = (props = {}) => { return _internalExport(props); }; diff --git a/index.js b/index.js index 1f9f5bd..9c34a45 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,5 @@ // import excel2json module -const excel2json = require("./excel2json"); +const { excel2json } = require("./excel2json"); -// called function export excel2json -const exported = excel2json({ - inputFile: "./data/source.xlsx" -}); - -// output data from exported -console.log("Output =>\n", exported); +// export the function +module.exports = excel2json; diff --git a/package.json b/package.json index 96e06fc..9a0af10 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "excel2json-xlsx", - "version": "1.0.4", + "version": "1.0.5", "keywords": [ "excel", "json", diff --git a/test.js b/test.js new file mode 100644 index 0000000..32fad57 --- /dev/null +++ b/test.js @@ -0,0 +1,5 @@ +const excel2json = require("./index"); +const result = excel2json({ + inputFile: "./data/source.xlsx", +}); +console.log(result);