@alu0100966589/oop-alu0100966589

Toy demo to learn JavaScript. Following the example in the chapter 6 of eloquentjavascript.net

Usage no npm install needed!

<script type="module">
  import alu0100966589OopAlu0100966589 from 'https://cdn.skypack.dev/@alu0100966589/oop-alu0100966589';
</script>

README

Eloquent JavaScript. Laying out a table

Build Status

npm version

About this project

This is the assignment "Laying out a table" from the online book eloquentjavascript. The goal is to get familiar with the Object Oriented paradigm in JavaScript by implementing classes to build a nice looking string representation of a table. And also get familiar with testing, test coverage and continuous integration in JavaScript. Using mocha with better-assert and should for testing, istambul for test coverage and Travis CI for continuous integration.

Update

Now you can specify the type of cell to use for a certain element in the json data. There are some cell types by default but you can add new ones and specify which one to use for which type of data.

New cell types must have the following interface: minWidth(), minHeight(), draw(width, height).

API

You can see the documentation generated from jsdoc in the "docs" folder.

This package exports an object with the following methods:

{
    createTable,
    cellTableToString,
    addHandler,
    cells: {
        TextCell,
        RTextCell,
        UnderlinedCell,
        StretchCell
    }
}
  • createTable: expects an array of objects as argument and returns an array of cells. Every object of the array has to have the same properties. However, the value of any property can be an object with a type property that represents what kind of cell will be used to represent it and a value property that represents the data that the handler of the type needs.

  • cellTableToString: expects an array of cells as argument and returns the string representation of the table

  • addHandler: expects a type and a function. When createTable encounters said type, it will create an object from the handler (used as a constructor function):

    • If the type is not an object, it has to be a primitive type and the value passed to the constructor is the value itself.

    • If the value encountered is an object, the handler in this case will be decided based on the type property, and the content of the value property will be passed as argument to the constructor function.

  • cells: object containing the default cells classes

Author

  • Carlos Domínguez García (alu0100966589@ull.edu.es)

ES6 (deprecated as of 27/02/2018)

In the branch called es6 you can see the same source files using ES6 syntax. And using the ES6 imports. You can start the application just like in this branch.

Challenge (Thursday 15/02/2018)

You can see the result of the challenge in the branch "challenge". In particular, the file changed for the challenge is in src/main.js on that branch. And the data used to test is the one that the teacher gave us, it is in src/Data/mountains2.json

Example

There is an example of usage at src/Example. You can run it with npm start

Install

You can clone the repo:

git clone https://github.com/ULL-ESIT-PL-1718/oop-alu0100966589.git

Or, you can install the module via npm:

npm i --save @alu0100966589/oop-alu0100966589

Tests

To run the tests, run:

npm test

Coverage

You can see the results of the code coverage in the coverage folder. To run yourself the coverage, run:

node_modules/.bin/gulp cover

Or, if you have gulp installed globally:

gulp cover

Docs

You can see the documentation generated by jsdoc in the docs folder. To run yourself the doc generation, run:

node_modules/.bin/gulp generate-doc

Or, if you have gulp installed globally:

gulp generate-doc