-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5e2095f
Showing
5 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
workflow "Build and Publish" { | ||
on = "push" | ||
resolves = ["Publish"] | ||
} | ||
|
||
action "Build" { | ||
uses = "actions/npm@master" | ||
args = "install" | ||
} | ||
|
||
action "Test" { | ||
needs = ["Build"] | ||
uses = "ianwalter/puppeteer@master" | ||
runs = "npm" | ||
args = "test" | ||
} | ||
|
||
action "Publish Filter" { | ||
needs = ["Test"] | ||
uses = "actions/bin/filter@master" | ||
args = "branch master" | ||
} | ||
|
||
action "Publish" { | ||
needs = "Publish Filter" | ||
uses = "mikeal/merge-release@master" | ||
secrets = ["GITHUB_TOKEN", "NPM_AUTH_TOKEN"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
package-lock.json | ||
.nyc_output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const chalk = require('chalk') | ||
const CID = require('cids') | ||
|
||
const _pre = obj => { | ||
if (Array.isArray(obj)) return '[' | ||
return '{' | ||
} | ||
const _post = obj => { | ||
if (Array.isArray(obj)) return ']' | ||
return '}' | ||
} | ||
|
||
module.exports = (obj, indent = 0, threshold = 80) => { | ||
let pre = Array.from({ length: indent }).map(() => ' ').join('') | ||
let lines = [] | ||
for (let key in obj) { | ||
let value = obj[key] | ||
let line | ||
if (Array.isArray(obj)) { | ||
line = '' | ||
} else { | ||
line = chalk.green(key) + ': ' | ||
} | ||
if (CID.isCID(value)) lines.push(line + 'CID(' + chalk.red(value.toString()) + ')') | ||
else if (Buffer.isBuffer(value)) lines.push(line + 'Bytes(' + `{${chalk.green('size')}: ${chalk.red(value.length)}})`) | ||
else if (typeof value === 'object' && value !== null) { | ||
lines.push(line + module.exports(value, indent + 2, threshold - line.length)) | ||
} else { | ||
lines.push(line + chalk.red(JSON.stringify(value))) | ||
} | ||
} | ||
if (lines.join(', ').length < threshold) return _pre(obj) + ' ' + lines.join(', ') + ' ' + _post(obj) | ||
let ipre = '\n' + pre + ' ' | ||
return _pre(obj) + ipre + lines.join(ipre) + '\n' + pre + _post(obj) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "@ipld/printify", | ||
"version": "0.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "Mikeal Rogers <[email protected]> (https://www.mikealrogers.com/)", | ||
"license": "(Apache-2.0 AND MIT)", | ||
"dependencies": { | ||
"chalk": "^2.4.2", | ||
"cids": "^0.7.1" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^6.1.4", | ||
"standard": "^12.0.1", | ||
"tsame": "^2.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const CID = require('cids') | ||
const assert = require('assert') | ||
const tsame = require('tsame') | ||
const printify = require('../') | ||
|
||
const same = (...args) => assert.ok(tsame(...args)) | ||
const test = it | ||
|
||
test('all', done => { | ||
let str = printify({ | ||
one: 1, | ||
two: 'two', | ||
three: { | ||
sub: 1, | ||
cid: new CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'), | ||
binary: Buffer.from('asdf'), | ||
array: [ | ||
'one', | ||
'two', | ||
3 | ||
] | ||
} | ||
}) | ||
same(str, "{\n \u001b[32mone\u001b[39m: \u001b[31m1\u001b[39m\n \u001b[32mtwo\u001b[39m: \u001b[31m\"two\"\u001b[39m\n \u001b[32mthree\u001b[39m: {\n \u001b[32msub\u001b[39m: \u001b[31m1\u001b[39m\n \u001b[32mcid\u001b[39m: CID(\u001b[31mQmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u\u001b[39m)\n \u001b[32mbinary\u001b[39m: Bytes({\u001b[32msize\u001b[39m: \u001b[31m4\u001b[39m})\n \u001b[32marray\u001b[39m: [ \u001b[31m\"one\"\u001b[39m, \u001b[31m\"two\"\u001b[39m, \u001b[31m3\u001b[39m ]\n }\n}") | ||
done() | ||
}) |