Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,6 @@
"test": "test"
},
"dependencies": {
"kind-of": "^6.0.2",
"object-assign": "^4.1.0",
"string-width": "^2.1.1"
},
Expand Down
5 changes: 2 additions & 3 deletions src/cell.js
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
const kindOf = require('kind-of');
const utils = require('./utils');

class Cell {
Expand All@@ -22,13 +21,13 @@ class Cell {
}

setOptions(options) {
if (['boolean', 'number', 'string'].indexOf(kindOf(options)) !== -1) {
if (['boolean', 'number', 'string'].indexOf(typeof options) !== -1) {
options = { content: '' + options };
}
options = options || {};
this.options = options;
let content = options.content;
if (['boolean', 'number', 'string'].indexOf(kindOf(content)) !== -1) {
if (['boolean', 'number', 'string'].indexOf(typeof content) !== -1) {
this.content = String(content);
} else if (!content) {
this.content = '';
Expand Down
13 changes: 6 additions & 7 deletions src/layout-manager.js
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
const kindOf = require('kind-of');
const objectAssign = require('object-assign');
const Cell = require('./cell');
const { ColSpanCell, RowSpanCell } = Cell;
Expand DownExpand Up@@ -142,10 +141,10 @@ const { ColSpanCell, RowSpanCell } = Cell;

function generateCells(rows) {
return rows.map(function(row) {
if (kindOf(row) !== 'array') {
if (!Array.isArray(row)) {
let key = Object.keys(row)[0];
row = row[key];
if (kindOf(row) === 'array') {
if (Array.isArray(row)) {
row = row.slice();
row.unshift(key);
} else {
Expand DownExpand Up@@ -193,7 +192,7 @@ function makeComputeWidths(colSpan, desiredWidth, x, forcedMin) {
});

vals.forEach(function(val, index) {
if (kindOf(val) === 'number') {
if (typeof val === 'number') {
result[index] = val;
}
});
Expand All@@ -204,17 +203,17 @@ function makeComputeWidths(colSpan, desiredWidth, x, forcedMin) {
let span = cell[colSpan];
let col = cell[x];
let existingWidth = result[col];
let editableCols = kindOf(vals[col]) === 'number' ? 0 : 1;
let editableCols = typeof vals[col] === 'number' ? 0 : 1;
for (let i = 1; i < span; i++) {
existingWidth += 1 + result[col + i];
if (kindOf(vals[col + i]) !== 'number') {
if (typeof vals[col + i] !== 'number') {
editableCols++;
}
}
if (cell[desiredWidth] > existingWidth) {
let i = 0;
while (editableCols > 0 && cell[desiredWidth] > existingWidth) {
if (kindOf(vals[col + i]) !== 'number') {
if (typeof vals[col + i] !== 'number') {
let dif = Math.round((cell[desiredWidth] - existingWidth) / editableCols);
existingWidth += dif;
result[col + i] += dif;
Expand Down
3 changes: 1 addition & 2 deletions test/table-layout-test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,6 @@ describe('tableLayout', function() {
const Cell = require('../src/cell');
const layoutManager = require('../src/layout-manager');
const { makeTableLayout, addRowSpanCells, fillInTable, computeWidths, computeHeights } = layoutManager;
const kindOf = require('kind-of');

it('simple 2x2 layout', function() {
let actual = makeTableLayout([['hello', 'goodbye'], ['hola', 'adios']]);
Expand DownExpand Up@@ -345,7 +344,7 @@ describe('tableLayout', function() {
}

function checkExpectation(actualCell, expectedCell, x, y, actualTable) {
if (kindOf(expectedCell) === 'string') {
if (typeof expectedCell === 'string') {
expectedCell = { content: expectedCell };
}
if (expectedCell.hasOwnProperty('content')) {
Expand Down