Skip to content

SL0TR/doc-converter

Repository files navigation

Document Conversion

This project is a document conversion tool that allows you to convert files between these formats:

  • TEXT (Plain Text)
  • JSON (JavaScript Object Notation)
  • XML (Extensible Markup Language)

To get started, first install the dependencies and then run the app. Follow the instructions below.

Installation

Firstly, make sure you have Node.js installed on your machine.

If you have pnpm installed, awesome and if not, you can either use npm or yarn instead.

To install the dependencies, run the following command:

$ pnpm install

Running the app

# development
$ pnpm run start

# watch mode
$ pnpm run start:dev

# production mode
$ pnpm run start:prod

The app will start on port 3000 by default. And you can access the app on http://localhost:3000.

Run Tests

# unit tests
$ pnpm run test

# e2e tests
$ pnpm run test:e2e

# test coverage
$ pnpm run test:cov

Usage

The app exposes a single endpoint for converting files between the supported formats.

If you have the Postman app installed, you can import the collection file from the directory in the root of the project.

API Specification

Endpoint: /document/convert

Method: POST

Request Content-Type: multipart/form-data

Request

The api expects a multipart/form-data request with the following fields:

Field Name Field Value Required
document Binary data of the file being uploaded Yes
targetFormat The target format/mimetype to convert the file to. Supported mime types are: text/plain, application/json and application/xml Yes
segmentSeparator The segment separator to use when converting the file to text. Yes (Only if document is text/plain)

Response

Success: The api responds with a 200 OK status code and the converted file as the response body. The response body is the transformed file in the target format.

For example, If the target format is application/xml, the response will be an XML file.

alt text Error: If the request is invalid, the api responds with a 400 Bad Request status code and an error message as the response body.

For example, if the document field is missing in the request, the api will respond with a 400 Bad Request status code and the following response body:

{
  "message": [
    "File must be of one of the types application/json, text/plain, application/xml",
    "Field \"document\" does not contain file"
  ],
  "error": "Bad Request",
  "statusCode": 400
}

Potential Improvements

  • Add support for more file formats
  • Dockerize the app
  • Add more tests
  • Update text to KV algorithm to be more memory efficient
  • Add more error handling and input validation

About

A conversion tool for plain text, json and xml

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published