mirror of
https://github.com/JonasunderscoreJones/aka-worker.git
synced 2025-10-23 09:59:19 +02:00
Initial commit (by create-cloudflare CLI)
This commit is contained in:
parent
8cb86120f1
commit
fff961078a
1777 changed files with 1011798 additions and 0 deletions
3
cool-dawn-3d3b/node_modules/as-table/.babelrc
generated
vendored
Normal file
3
cool-dawn-3d3b/node_modules/as-table/.babelrc
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"plugins": ["transform-es2015-destructuring", "transform-es2015-spread"]
|
||||
}
|
6
cool-dawn-3d3b/node_modules/as-table/.eslintrc
generated
vendored
Normal file
6
cool-dawn-3d3b/node_modules/as-table/.eslintrc
generated
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 6,
|
||||
"sourceType": "script"
|
||||
}
|
||||
}
|
24
cool-dawn-3d3b/node_modules/as-table/.travis.yml
generated
vendored
Normal file
24
cool-dawn-3d3b/node_modules/as-table/.travis.yml
generated
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
language: node_js
|
||||
node_js:
|
||||
- '8'
|
||||
script:
|
||||
- set -e
|
||||
- npm run test
|
||||
- npm run coveralls
|
||||
after_success:
|
||||
- git config --global user.email "travis@travis-ci.org"
|
||||
- git config --global user.name "Travis CI"
|
||||
- npm config set git-tag-version=false
|
||||
- NPM_VERSION=$(npm version patch)
|
||||
- git commit -a -m "${NPM_VERSION:1}" -m "[ci skip]"
|
||||
- git remote remove origin
|
||||
- git remote add origin https://${GITHUB_TOKEN}@github.com/xpl/as-table.git
|
||||
- git push origin HEAD:master
|
||||
deploy:
|
||||
provider: npm
|
||||
email: rocket.mind@gmail.com
|
||||
api_key:
|
||||
secure: AVxwMF+0BKyQqTvA/9Va+G+1kgsVUKQ08LgzVhqfUv2yGgh5jWY0P5/IFLQocTuC+uef066KqTlvnWR3SWqB+am5EsqiZeFPzOHmtCgxrML2aZK8crjPoY4W/3ZfPy9H00nU9YPNVguXJY7K7MwEFXZ/SVOM1aQvr+omeqMpbnP6Cl4nQ6Hzbc/uAdUHIQG1qzoEbsnkT1EuQ39v1IQLBEoiBDkUj45bmEdETZXd9Nr42BOviFMYjba0vAn8gsuUgMj+bYXeb0XXedmRwBGjtgcNx76RwwmOXPtiC2IQs6FiDmCzZtCcoYuvrWSOFYhfEgptDeeZ080x38uhBxusYq3p0iRF+XyjWlr3w1A5JaHL8FkUfmdBxKAzKhiPTS5yDqteWL8znqGKSPjR+FJNQo5pbS5+C8I67xkcDHvigMWy30lnnjvCV7tPW4FdJ85kx+F1qNmHU0vYqVfDNet4KZofgWoS0cHMYskzl1BwWC+vofwI9/sKatDtFR25ffFg8f17nW+6vTX/n9uSqIFURUI8DhfFlxqG2giDd73KCB0uZ4Fqd0dqnmcp5qg2hQt0sIftDBOmOaX7xKbVdLbGBTAQ82KZmbQCnj0In10gJQf5O/mKD7rr2dMLHi6fvbBE/cEsWy4u/o50UQ7bDzGfXT3tJ+tktxmx1HfSf6eXilA=
|
||||
env:
|
||||
global:
|
||||
secure: KbUFKSmSkbuRb0mQ1kcKL5dA8TdI2SlnZAzyXwRXF/RpK5LDGI31gmPODl7DOKHPzEUTQaIeA/8dI0p8DKM9eTfHyM+pl0kZE+e6wSTdawVlI9FoxLgyBi8hz3UWnA39/YN65uFNvFX+kSYPPeOeV5zJNUaC8CT7Y3HYKR3tGrBaKrQbCnOlXIBsmyFryUHqdapBDmrqrU69Ab1uQca/djS2ztsjYvaP61aEIAKAsUZQRtDk8mP8sUQ5o15CwcpaWp/K1efeb3AuxHjcYOHH0Ci0SZmWpO9ky+wLCPeDqEeV4ZDN4Wfp9yx5dNkV0+ifevSRR5FNS9LHREPML8jz53KzOQQOXK5Fup/SsHPHU0XT6vB2TlG0YwatMSVGY4QIRCMftMkokjFwWsP8oPbuTuVCWhHQouMxRQDPQ/z3Dn/+blASG1lw16S92ksRLc8CCGA8gUZ6CrKh82gFAfyzwAUgLhoFIPEEu2e49W/VdAzeQ1VfAb/TbjwdgX9OR8F8TR48jM3Xpk8BdPANso7t9Rk9vvIw0JxR0Ir+7ufHV1dqCPsGa5KdZjaKrHHs6P/JI+Xl+w4o/6wmn3FhORSKqGuxDJqoQ8cw49Hh5OM0uf9tKfiyUyuFdsApom4vwrOTL+ZRbbD037JH/fzp24C33oaGwOCdyY0Eb/n0LI5ufRg=
|
3
cool-dawn-3d3b/node_modules/as-table/CHANGELOG.md
generated
vendored
Normal file
3
cool-dawn-3d3b/node_modules/as-table/CHANGELOG.md
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Recent Updates
|
||||
|
||||
- Now layouts ANSI-colored strings correctly, thanks to the [`printable-characters`](https://github.com/xpl/printable-characters) module.
|
21
cool-dawn-3d3b/node_modules/as-table/LICENSE
generated
vendored
Normal file
21
cool-dawn-3d3b/node_modules/as-table/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2016 Vitaly Gordon (https://github.com/xpl)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
113
cool-dawn-3d3b/node_modules/as-table/README.md
generated
vendored
Normal file
113
cool-dawn-3d3b/node_modules/as-table/README.md
generated
vendored
Normal file
|
@ -0,0 +1,113 @@
|
|||
# as-table
|
||||
|
||||
[](https://travis-ci.org/xpl/as-table) [](https://coveralls.io/github/xpl/as-table) [](https://npmjs.com/package/as-table) [](https://david-dm.org/xpl/as-table) [](https://scrutinizer-ci.com/g/xpl/as-table/?branch=master)
|
||||
|
||||
A simple function that print objects and arrays as ASCII tables. Supports ANSI styling and weird 💩 Unicode emoji symbols (they won't break the layout), thanks to [`printable-characters`](https://github.com/xpl/printable-characters).
|
||||
|
||||
```bash
|
||||
npm install as-table
|
||||
```
|
||||
|
||||
## Printing objects
|
||||
|
||||
```javascript
|
||||
asTable = require ('as-table')
|
||||
|
||||
asTable ([ { foo: true, string: 'abcde', num: 42 },
|
||||
{ foo: false, string: 'qwertyuiop', num: 43 },
|
||||
{ string: null, num: 44 } ])
|
||||
```
|
||||
```
|
||||
foo string num
|
||||
----------------------
|
||||
true abcde 42
|
||||
false qwertyuiop 43
|
||||
null 44
|
||||
```
|
||||
|
||||
## Printing arrays
|
||||
|
||||
```javascript
|
||||
asTable ([['qwe', '123456789', 'zxcvbnm'],
|
||||
['qwerty', '12', 'zxcvb'],
|
||||
['qwertyiop', '1234567', 'z']])
|
||||
```
|
||||
```
|
||||
qwe 123456789 zxcvbnm
|
||||
qwerty 12 zxcvb
|
||||
qwertyiop 1234567 z
|
||||
```
|
||||
|
||||
## Limiting total width by proportionally trimming cells + setting columns delimiter
|
||||
|
||||
```javascript
|
||||
asTable.configure ({ maxTotalWidth: 22, delimiter: ' | ' }) (data)
|
||||
```
|
||||
```
|
||||
qwe | 1234… | zxc…
|
||||
qwer… | 12 | zxc…
|
||||
qwer… | 1234… | z
|
||||
```
|
||||
|
||||
## Right align
|
||||
|
||||
```javascript
|
||||
asTable.configure ({ right: true }) (data)
|
||||
```
|
||||
```
|
||||
foo bar baz
|
||||
-----------------------------
|
||||
qwe 123456789 zxcvbnm
|
||||
qwerty 12 zxcvb
|
||||
qwertyiop 1234567 z
|
||||
```
|
||||
|
||||
## Providing a custom object printer
|
||||
|
||||
```javascript
|
||||
asTable.configure ({ print: x => (typeof x === 'boolean') ? (x ? 'yes' : 'no') : String (x) }) (data)
|
||||
```
|
||||
```
|
||||
foo string num
|
||||
--------------------
|
||||
yes abcde 42
|
||||
no qwertyuiop 43
|
||||
null 44
|
||||
```
|
||||
|
||||
The callback also receives a field name (in case of objects) or a column index (in case of arrays):
|
||||
|
||||
```javascript
|
||||
asTable = require ('as-table').configure ({
|
||||
print (x, k) {
|
||||
if (k === 'timestamp') return new Date (x).toGMTString()
|
||||
return String (x)
|
||||
}
|
||||
})
|
||||
|
||||
asTable ([ { name: 'A', timestamp: 1561202591572 },
|
||||
{ name: 'B', timestamp: 1558524240034 } ])
|
||||
```
|
||||
|
||||
## Obtaining a pre-configured function
|
||||
|
||||
```javascript
|
||||
asTable = require ('as-table').configure ({ maxTotalWidth: 25, delimiter: ' | ' })
|
||||
|
||||
asTable (data)
|
||||
```
|
||||
|
||||
## Customizing the title rendering and the header separator
|
||||
|
||||
With string coloring by [`ansicolor`](https://github.com/xpl/ansicolor) (just for the demo purposes, any library will fit):
|
||||
|
||||
```javascript
|
||||
asTable = require ('as-table').configure ({ title: x => x.bright, delimiter: ' | '.dim.cyan, dash: '-'.bright.cyan })
|
||||
|
||||
console.log (
|
||||
asTable ([ { foo: true, string: 'abcde', num: 42 },
|
||||
{ foo: false, string: 'qwertyuiop'.bgMagenta.green.bright, num: 43 } ])
|
||||
```
|
||||
|
||||
<img width="179" alt="screen shot 2017-07-21 at 23 46 14" src="https://user-images.githubusercontent.com/1707/28481945-dcb0f8d6-6e6e-11e7-896e-dfad40662daf.png">
|
||||
|
32
cool-dawn-3d3b/node_modules/as-table/as-table.d.ts
generated
vendored
Normal file
32
cool-dawn-3d3b/node_modules/as-table/as-table.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
|
||||
declare function asTable(rows: any[][]): string
|
||||
declare function asTable(objects: {[column: string]: any}[]): string
|
||||
declare namespace asTable {
|
||||
interface Config<T> {
|
||||
maxTotalWidth: number
|
||||
minColumnWidths?: number[]
|
||||
delimiter?: string
|
||||
dash: string
|
||||
right: boolean
|
||||
print(value: T, key?: string | number): string
|
||||
title(value: string): string
|
||||
}
|
||||
type OmitPrint<T> = Pick<T, Exclude<keyof T, 'print'>> & {print: undefined}
|
||||
type ValidValueType<O, T> = {
|
||||
[P in keyof O]: T;
|
||||
}
|
||||
interface Formatter<T> extends Readonly<Config<T>> {
|
||||
(rows: T[][]): string
|
||||
<O extends ValidValueType<O, T>>(objects: O[]): string
|
||||
configure(cfg: Partial<OmitPrint<Config<any>>>): Formatter<T>
|
||||
configure<T>(cfg: Partial<Config<T>>): Formatter<T>
|
||||
}
|
||||
function configure<T = any>(cfg: Partial<Config<T>>): Formatter<T>
|
||||
const maxTotalWidth: number
|
||||
const print: StringConstructor
|
||||
const title: StringConstructor
|
||||
const dash: '-'
|
||||
const right: false
|
||||
}
|
||||
|
||||
export = asTable
|
89
cool-dawn-3d3b/node_modules/as-table/as-table.js
generated
vendored
Normal file
89
cool-dawn-3d3b/node_modules/as-table/as-table.js
generated
vendored
Normal file
|
@ -0,0 +1,89 @@
|
|||
"use strict";
|
||||
|
||||
const O = Object
|
||||
, { first, strlen } = require ('printable-characters') // handles ANSI codes and invisible characters
|
||||
, limit = (s, n) => (first (s, n - 1) + '…')
|
||||
|
||||
const asColumns = (rows, cfg_) => {
|
||||
|
||||
const
|
||||
|
||||
zip = (arrs, f) => arrs.reduce ((a, b) => b.map ((b, i) => [...a[i] || [], b]), []).map (args => f (...args)),
|
||||
|
||||
/* Convert cell data to string (converting multiline text to singleline) */
|
||||
|
||||
cells = rows.map (r => r.map (c => c.replace (/\n/g, '\\n'))),
|
||||
|
||||
/* Compute column widths (per row) and max widths (per column) */
|
||||
|
||||
cellWidths = cells.map (r => r.map (strlen)),
|
||||
maxWidths = zip (cellWidths, Math.max),
|
||||
|
||||
/* Default config */
|
||||
|
||||
cfg = O.assign ({
|
||||
delimiter: ' ',
|
||||
minColumnWidths: maxWidths.map (x => 0),
|
||||
maxTotalWidth: 0 }, cfg_),
|
||||
|
||||
delimiterLength = strlen (cfg.delimiter),
|
||||
|
||||
/* Project desired column widths, taking maxTotalWidth and minColumnWidths in account. */
|
||||
|
||||
totalWidth = maxWidths.reduce ((a, b) => a + b, 0),
|
||||
relativeWidths = maxWidths.map (w => w / totalWidth),
|
||||
maxTotalWidth = cfg.maxTotalWidth - (delimiterLength * (maxWidths.length - 1)),
|
||||
excessWidth = Math.max (0, totalWidth - maxTotalWidth),
|
||||
computedWidths = zip ([cfg.minColumnWidths, maxWidths, relativeWidths],
|
||||
(min, max, relative) => Math.max (min, Math.floor (max - excessWidth * relative))),
|
||||
|
||||
/* This is how many symbols we should pad or cut (per column). */
|
||||
|
||||
restCellWidths = cellWidths.map (widths => zip ([computedWidths, widths], (a, b) => a - b))
|
||||
|
||||
/* Perform final composition. */
|
||||
|
||||
return zip ([cells, restCellWidths], (a, b) =>
|
||||
zip ([a, b], (str, w) => (w >= 0)
|
||||
? (cfg.right ? (' '.repeat (w) + str) : (str + ' '.repeat (w)))
|
||||
: (limit (str, strlen (str) + w))).join (cfg.delimiter))
|
||||
}
|
||||
|
||||
const asTable = cfg => O.assign (arr => {
|
||||
|
||||
/* Print arrays */
|
||||
|
||||
if (arr[0] && Array.isArray (arr[0])) {
|
||||
return asColumns (arr.map (r => r.map (
|
||||
(c, i) => (c === undefined) ? '' : cfg.print (c, i)
|
||||
)
|
||||
),
|
||||
cfg).join ('\n')
|
||||
}
|
||||
|
||||
/* Print objects */
|
||||
|
||||
const colNames = [...new Set ([].concat (...arr.map (O.keys)))],
|
||||
columns = [colNames.map (cfg.title),
|
||||
...arr.map (o => colNames.map (
|
||||
key => (o[key] === undefined) ? '' : cfg.print (o[key], key)
|
||||
)
|
||||
)
|
||||
],
|
||||
lines = asColumns (columns, cfg)
|
||||
|
||||
return (cfg.dash ? [lines[0], cfg.dash.repeat (strlen (lines[0])), ...lines.slice (1)] : lines).join ('\n')
|
||||
|
||||
}, cfg, {
|
||||
|
||||
configure: newConfig => asTable (O.assign ({}, cfg, newConfig)),
|
||||
})
|
||||
|
||||
module.exports = asTable ({
|
||||
|
||||
maxTotalWidth: Number.MAX_SAFE_INTEGER,
|
||||
print: String,
|
||||
title: String,
|
||||
dash: '-',
|
||||
right: false
|
||||
})
|
86
cool-dawn-3d3b/node_modules/as-table/build/as-table.js
generated
vendored
Normal file
86
cool-dawn-3d3b/node_modules/as-table/build/as-table.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
67
cool-dawn-3d3b/node_modules/as-table/package.json
generated
vendored
Normal file
67
cool-dawn-3d3b/node_modules/as-table/package.json
generated
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
{
|
||||
"name": "as-table",
|
||||
"version": "1.0.55",
|
||||
"description": "A simple function that print objects / arrays as ASCII tables. Handles ANSI styling and weird 💩 Unicode emoji symbols – they won't break the layout.",
|
||||
"main": "build/as-table.js",
|
||||
"typings": "./as-table.d.ts",
|
||||
"scripts": {
|
||||
"lint": "eslint as-table.js",
|
||||
"lint-test": "eslint test.js",
|
||||
"babel": "babel as-table.js --source-maps inline --out-file ./build/as-table.js",
|
||||
"build": "npm run lint && npm run lint-test && npm run babel",
|
||||
"coveralls": "nyc report --reporter=text-lcov | coveralls",
|
||||
"test": "npm run build && env AS_TABLE_TEST_FILE='./build/as-table' nyc --reporter=html --reporter=text mocha --reporter spec",
|
||||
"autotest": "env AS_TABLE_TEST_FILE='./as-table' mocha --reporter spec --watch"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/xpl/as-table.git"
|
||||
},
|
||||
"keywords": [
|
||||
"ASCII",
|
||||
"table",
|
||||
"sheet",
|
||||
"grid",
|
||||
"print",
|
||||
"log",
|
||||
"print table",
|
||||
"object as table",
|
||||
"array as table",
|
||||
"text table",
|
||||
"array table",
|
||||
"object table",
|
||||
"array format",
|
||||
"columns",
|
||||
"as table",
|
||||
"tablefy",
|
||||
"columns",
|
||||
"stringify",
|
||||
"print object",
|
||||
"grid",
|
||||
"tty",
|
||||
"terminal",
|
||||
"console",
|
||||
"text",
|
||||
"layout"
|
||||
],
|
||||
"author": "Vitaly Gordon <rocket.mind@gmail.com>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/xpl/as-table/issues"
|
||||
},
|
||||
"homepage": "https://github.com/xpl/as-table",
|
||||
"devDependencies": {
|
||||
"ansicolor": "^1.1.81",
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
|
||||
"babel-plugin-transform-es2015-spread": "^6.22.0",
|
||||
"coveralls": "^3.0.3",
|
||||
"eslint": "^4.19.1",
|
||||
"istanbul": "^0.4.5",
|
||||
"mocha": "^6.0.2",
|
||||
"nyc": "^13.3.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"printable-characters": "^1.0.42"
|
||||
}
|
||||
}
|
223
cool-dawn-3d3b/node_modules/as-table/test.js
generated
vendored
Normal file
223
cool-dawn-3d3b/node_modules/as-table/test.js
generated
vendored
Normal file
|
@ -0,0 +1,223 @@
|
|||
"use strict";
|
||||
|
||||
const assert = require ('assert'),
|
||||
asTable = require (process.env.AS_TABLE_TEST_FILE),
|
||||
ansi = require ('ansicolor').nice
|
||||
|
||||
describe ('as-table', () => {
|
||||
|
||||
it ('array printing works', () => {
|
||||
|
||||
var testData = [['qwe', '123456789', 'zxcvbnm'],
|
||||
['qwerty', '12', 'zxcvb'],
|
||||
['💩wertyiop', '1234567', 'z']]
|
||||
|
||||
assert.equal (asTable (testData),
|
||||
|
||||
'qwe 123456789 zxcvbnm\n' +
|
||||
'qwerty 12 zxcvb \n' +
|
||||
'💩wertyiop 1234567 z ')
|
||||
|
||||
assert.equal (asTable.configure ({ maxTotalWidth: 22, delimiter: ' | ' }) (testData),
|
||||
|
||||
'qwe | 1234… | zxc…\n' +
|
||||
'qwer… | 12 | zxc…\n' +
|
||||
'💩wer… | 1234… | z ')
|
||||
|
||||
console.log (asTable.configure ({ maxTotalWidth: 22, delimiter: ' | ' }) (testData))
|
||||
})
|
||||
|
||||
it ('object printing works', () => {
|
||||
|
||||
var testData =
|
||||
[ { foo: true, string: 'abcde', num: 42 },
|
||||
{ foo: false, string: 'qwertyuiop', num: 43 },
|
||||
{ string: null, num: 44 } ]
|
||||
|
||||
assert.equal (asTable (testData),
|
||||
|
||||
'foo string num\n' +
|
||||
'----------------------\n' +
|
||||
'true abcde 42 \n' +
|
||||
'false qwertyuiop 43 \n' +
|
||||
' null 44 ')
|
||||
})
|
||||
|
||||
|
||||
it ('object printing works (with ANSI styling)', () => {
|
||||
|
||||
var testData =
|
||||
[ { foo: true, string: 'abcde'.cyan.bgYellow, num: 42 },
|
||||
{ foo: false, string: 'qwertyuiop', num: 43 },
|
||||
{ string: null, num: 44 } ]
|
||||
|
||||
assert.equal (asTable (testData),
|
||||
|
||||
'foo string num\n' +
|
||||
'----------------------\n' +
|
||||
'true \u001b[43m\u001b[36mabcde\u001b[39m\u001b[49m 42 \n' +
|
||||
'false qwertyuiop 43 \n' +
|
||||
' null 44 ')
|
||||
})
|
||||
|
||||
it ('maxTotalWidth correctly handles object field names', () => {
|
||||
|
||||
assert.equal (
|
||||
|
||||
asTable.configure ({ maxTotalWidth: 15 }) ([{
|
||||
|
||||
'0123456789': '0123456789',
|
||||
'abcdefxyzw': 'abcdefxyzw' }]),
|
||||
|
||||
'01234… abcde…\n' +
|
||||
'--------------\n' +
|
||||
'01234… abcde…'
|
||||
)
|
||||
})
|
||||
|
||||
it ('maxTotalWidth correctly handles object field names (with ANSI styling)', () => {
|
||||
|
||||
assert.equal (
|
||||
|
||||
asTable.configure ({ maxTotalWidth: 15 }) ([{
|
||||
|
||||
'0123456789': '0123456789',
|
||||
'abcdefxyzw': 'abcdefxyzw'.cyan.bgYellow.italic.inverse.bright }]),
|
||||
|
||||
'01234… abcde…\n' +
|
||||
'--------------\n' +
|
||||
'01234… ' + 'abcde'.cyan.bgYellow.italic.inverse.bright + '…'
|
||||
)
|
||||
})
|
||||
|
||||
it ('everything renders as singleline', () => {
|
||||
|
||||
assert.equal (asTable ([['fooo\n\nbar']]), 'fooo\\n\\nbar')
|
||||
})
|
||||
|
||||
it ('configuring works', () => {
|
||||
|
||||
const asTable25 = asTable.configure ({ maxTotalWidth: 25 }),
|
||||
asTable25Delim = asTable25.configure ({ delimiter: ' | ' })
|
||||
|
||||
assert.notEqual (asTable25, asTable25Delim)
|
||||
assert.equal (asTable25.maxTotalWidth, 25)
|
||||
assert.equal (asTable25Delim.delimiter, ' | ')
|
||||
})
|
||||
|
||||
it ('degenerate case works', () => {
|
||||
|
||||
assert.equal (asTable ([]), '\n')
|
||||
assert.equal (asTable ([{}]), '\n\n')
|
||||
})
|
||||
|
||||
it ('null/undefined prints correctly', () => {
|
||||
|
||||
assert.equal (asTable.configure ({ delimiter: '|' }) ([[null, undefined, 1, 2, 3]]), 'null||1|2|3')
|
||||
})
|
||||
|
||||
it ('custom printer works', () => {
|
||||
|
||||
var testData =
|
||||
[ { foo: true, string: 'abcde', num: 42 },
|
||||
{ foo: false, string: 'qwertyuiop', num: 43 },
|
||||
{ string: null, num: 44 } ]
|
||||
|
||||
const formatsBooleansAsYesNo = asTable.configure ({ print: obj => (typeof obj === 'boolean') ? (obj ? 'yes' : 'no') : String (obj) })
|
||||
|
||||
assert.equal (formatsBooleansAsYesNo (testData),
|
||||
|
||||
'foo string num\n' +
|
||||
'--------------------\n' +
|
||||
'yes abcde 42 \n' +
|
||||
'no qwertyuiop 43 \n' +
|
||||
' null 44 ')
|
||||
})
|
||||
|
||||
it ('custom printer works with object titles', () => {
|
||||
|
||||
var testData =
|
||||
[ { foo: true, string: 'abcde', num: 42, timestamp: 1561202591572 },
|
||||
{ foo: false, string: 'qwertyuiop', num: 43, timestamp: 1558524240034 },
|
||||
{ string: null, num: 44, timestamp: 1555932240034 } ]
|
||||
|
||||
const formats = asTable.configure ({
|
||||
print: (obj, title) => {
|
||||
if (title === 'foo') {
|
||||
return obj ? 'yes' : 'no';
|
||||
}
|
||||
if (title === 'timestamp') {
|
||||
return new Date(obj).toGMTString();
|
||||
}
|
||||
return String(obj);
|
||||
}
|
||||
})
|
||||
|
||||
assert.equal (formats (testData),
|
||||
|
||||
'foo string num timestamp \n' +
|
||||
'---------------------------------------------------\n' +
|
||||
'yes abcde 42 Sat, 22 Jun 2019 11:23:11 GMT\n' +
|
||||
'no qwertyuiop 43 Wed, 22 May 2019 11:24:00 GMT\n' +
|
||||
' null 44 Mon, 22 Apr 2019 11:24:00 GMT')
|
||||
})
|
||||
|
||||
it ('custom printer works with array keys', () => {
|
||||
|
||||
var testData =
|
||||
[ [ true, 'abcde', 42, 1561202591572 ],
|
||||
[ false, 'qwertyuiop', 43, 1558524240034 ] ]
|
||||
|
||||
const formats = asTable.configure ({
|
||||
print: (obj, index) => {
|
||||
if (index === 0) {
|
||||
return obj ? 'yes' : 'no';
|
||||
}
|
||||
if (index === 3) {
|
||||
return new Date(obj).toGMTString();
|
||||
}
|
||||
return String(obj);
|
||||
}
|
||||
})
|
||||
|
||||
assert.equal (formats (testData),
|
||||
|
||||
'yes abcde 42 Sat, 22 Jun 2019 11:23:11 GMT\n' +
|
||||
'no qwertyuiop 43 Wed, 22 May 2019 11:24:00 GMT')
|
||||
})
|
||||
|
||||
|
||||
it ('right align works', () => {
|
||||
|
||||
var testData =
|
||||
[ { foo: 1234.567, bar: 12 },
|
||||
{ foo: '4.567'.bgMagenta.green, bar: 1234.456890 } ]
|
||||
|
||||
assert.equal (asTable.configure ({ right: true }) (testData),
|
||||
' foo bar\n' +
|
||||
'--------------------\n' +
|
||||
'1234.567 12\n' +
|
||||
' ' + '4.567'.bgMagenta.green + ' 1234.45689')
|
||||
})
|
||||
|
||||
it ('ANSI coloring works', () => {
|
||||
|
||||
const testData =
|
||||
[ { foo: true, string: 'abcde', num: 42 },
|
||||
{ foo: false, string: '💩wertyuiop'.bgMagenta.green.bright, num: 43 } ]
|
||||
|
||||
const d = ' | '.dim.cyan
|
||||
const _ = '-'.bright.cyan
|
||||
|
||||
const result = asTable.configure ({ title: x => x.bright, delimiter: d, dash: _ }) (testData)
|
||||
|
||||
console.log (result)
|
||||
|
||||
assert.equal (result,
|
||||
|
||||
['foo'.bright + ' ', 'string'.bright + ' ', 'num'.bright].join (d) + '\n' +
|
||||
_.repeat (24) + '\n' +
|
||||
['true ', 'abcde ', '42 '].join (d) + '\n' +
|
||||
['false', '💩wertyuiop'.bgMagenta.green.bright, '43 '].join (d))
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue