1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

めざせNode.jsライブラリマスター (4)html-tableify

Posted at

#【ライブラリ説明】
 jsonをhtmlテーブルへ変換する

#【プログラム】

html-tableify.js
const tableify = require('html-tableify');
 
console.log(tableify([{
  name: 'optionalArray',
  description: 'Description of optionalArray.',
  required: '',
  type: 'array',
  defaultValue: '[]'
}, {
  name: 'optionalBool',
  description: 'Description of optionalBool.',
  required: '',
  type: 'bool',
  defaultValue: 'false'
}], {
  headers: [{
    name: 'name',
    align: 'left',
    title: 'Your Name'
  }, {
    name: 'description',
    align: 'left'
  }, {
    name: 'type',
    align: 'left'
  }, {
    name: 'required',
    align: 'center'
  }, {
    name: 'defaultValue',
    align: 'center',
    title: 'Default Value'
  }]
}));
/*
<table>
  <thead>
    <tr>
      <th style="text-align: left">Your Name</th>
      <th style="text-align: left">Description</th>
      <th style="text-align: left">Type</th>
      <th style="text-align: center">Required</th>
      <th style="text-align: center">Default Value</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="text-align: left">optionalArray</td>
      <td style="text-align: left">Description of optionalArray.</td>
      <td style="text-align: left">array</td>
      <td style="text-align: center"></td>
      <td style="text-align: center">[]</td>
    </tr>
    <tr>
      <td style="text-align: left">optionalBool</td>
      <td style="text-align: left">Description of optionalBool.</td>
      <td style="text-align: left">bool</td>
      <td style="text-align: center"></td>
      <td style="text-align: center">false</td>
    </tr>
  </tbody>
</table>
*/
 
console.log(tableify([{
 name: 'optionalArray',
 description: 'Description of optionalArray.',
 required: '',
 type: 'array',
 defaultValue: '[]'
}, {
 name: 'optionalBool',
 description: 'Description of optionalBool.',
 required: '',
 type: 'bool',
 defaultValue: 'false'
}], {
 tidy: false
}));
// <table><thead><tr><th style="text-align: center">Name</th><th style="text-align: center">Description</th><th style="text-align: center">Required</th><th style="text-align: center">Type</th><th style="text-align: center">DefaultValue</th></tr></thead><tbody><tr><td style="text-align: center">optionalArray</td><td style="text-align: center">Description of optionalArray.</td><td style="text-align: center"></td><td style="text-align: center">array</td><td style="text-align: center">[]</td></tr><tr><td style="text-align: center">optionalBool</td><td style="text-align: center">Description of optionalBool.</td><td style="text-align: center"></td><td style="text-align: center">bool</td><td style="text-align: center">false</td></tr></tbody></table>

#【結果】
tabel.png

#【参考サイト】
 npm
 github

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?