Git Product home page Git Product logo

doc-converter's Introduction

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

doc-converter's People

Contributors

sl0tr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.