Compare commits

...

11 Commits
v1.0.2 ... main

10 changed files with 55 additions and 23 deletions

View File

@ -3,7 +3,7 @@ LABEL maintainer="sombochea@cubetiqs.com"
VOLUME [ "/app/data" ]
ENV INPUT_FILE './data/people.xlsx'
ENV INPUT_FILE './data/source.xlsx'
ENV OUTPUT_PATH './data/outputs'
ENV MAPPER_FILE './data/mapper.json'
@ -11,6 +11,12 @@ WORKDIR /app
COPY . /app
RUN yarn
RUN npm install
CMD [ "node" , "index.js"]
RUN npm link
RUN ln -s $(which excel2json-xlsx) /usr/bin/x2j
ENTRYPOINT [ "/usr/bin/x2j"]
CMD [ "--help" ]

View File

@ -9,7 +9,7 @@ run:
docker run --rm -t ${DOCKER_IMAGE}
publish:
@echo "Pubishing docker image..."
@echo "Publishing docker image..."
docker push ${DOCKER_IMAGE}
.PHONY: build

View File

@ -1,11 +1,13 @@
# excel2json
# excel2json-xlsx
[![Node.js Package](https://github.com/CUBETIQ/excel2json/actions/workflows/npm-publish.yml/badge.svg)](https://github.com/CUBETIQ/excel2json/actions/workflows/npm-publish.yml)
[![Docker CI](https://github.com/CUBETIQ/excel2json/actions/workflows/docker-publish.yml/badge.svg)](https://github.com/CUBETIQ/excel2json/actions/workflows/docker-publish.yml)
![Docker Image Size (latest by date)](https://img.shields.io/docker/image-size/cubetiq/excel2json)
![Docker Pulls](https://img.shields.io/docker/pulls/cubetiq/excel2json)
- Read file excel to json
- Custom mapping with custom columns and configs
- Custom props
- Docker suppport
# Install
```shell
@ -21,7 +23,21 @@ yarn add global excel2json-xlsx
```
Usage
```shell
excel2json-xlsx -i people.xlsx -o exported.json
excel2json-xlsx -i source.xlsx -o exported.json
```
OR
```shell
npx excel2json-xlsx -i source.xlsx -o exported.json
```
# [Docker Hub](https://hub.docker.com/r/cubetiq/excel2json)
***Pulling image***
```shell
docker pull cubetiq/excel2json
```
***Run container***
```shell
docker run --rm -it -v /my/path/data:/app/data cubetiq/excel2json -i ./data/source.xlsx -p true
```
# Build

View File

@ -1,7 +1,7 @@
#!/usr/bin/env node
const yargs = require("yargs");
const excel2json = require("./../excel2json");
const excel2json = require("./../index");
const options = yargs
.usage("Usage: -i <input> -o <output> -m <mapper>")
@ -29,12 +29,18 @@ const options = yargs
type: "string",
demandOption: false,
})
.argv;
.option("p", {
alias: "print",
describe: "Print the exported json to console",
type: "boolean",
demandOption: false,
}).argv;
const inputFile = options.input;
const outputFile = options.output;
const mapperFile = options.mapper;
const sheetName = options.sheet;
const print = options.print;
const exported = excel2json({
inputFile: inputFile,
@ -42,3 +48,7 @@ const exported = excel2json({
outputFile: outputFile,
sheetName: sheetName,
});
if (print) {
console.log(exported);
}

4
excel2json.d.ts vendored
View File

@ -1,4 +1,4 @@
interface Excel2JsonProps {
export interface Excel2JsonProps {
mappings?: Array<any>;
saveToOutput?: boolean;
outputPath?: string;
@ -10,4 +10,4 @@ interface Excel2JsonProps {
encoding?: string;
}
declare function excel2json(props: Excel2JsonProps);
export declare function excel2json(props: Excel2JsonProps);

View File

@ -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);
};

View File

@ -1,10 +1,5 @@
// import excel2json module
const excel2json = require("./excel2json");
const { excel2json } = require("./excel2json");
// called function export excel2json
const exported = excel2json({
inputFile: "./data/people.xlsx"
});
// output data from exported
console.log("Output =>\n", exported);
// export the function
module.exports = excel2json;

View File

@ -1,6 +1,6 @@
{
"name": "excel2json-xlsx",
"version": "1.0.2",
"version": "1.0.6",
"keywords": [
"excel",
"json",
@ -11,7 +11,7 @@
"publishConfig": {
"access": "public"
},
"bin": "bin/cli.js",
"bin": "./bin/cli.js",
"description": "Excel to JSON, able to export JSON from Excel (xlsx)",
"repository": {
"url": "https://github.com/CUBETIQ/excel2json.git"

5
test.js Normal file
View File

@ -0,0 +1,5 @@
const excel2json = require("./index");
const result = excel2json({
inputFile: "./data/source.xlsx",
});
console.log(result);