New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fmt-obj

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fmt-obj - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

.travis.yml

48

dist.js

@@ -13,17 +13,13 @@

var formatValue = function (colors, val) {
var formatValue = function (formatter, val) {
if (typeof val === 'number') {
return colors.number(val)
return formatter.number(val)
}
if (typeof val === 'function') {
return formatFunction('Function', val)
}
if (isLiteral(val)) {
return colors.literal(val)
return formatter.literal(String(val))
}
if (isPlainObj(val)) {
return tsml(["\n ", "\n ", "\n ", "\n "], colors.punctuation('('), colors.string('collapsed'), colors.punctuation(')'))
return tsml(["\n ", "\n ", "\n ", "\n "], formatter.punctuation('('), formatter.string('collapsed'), formatter.punctuation(')'))
}

@@ -33,2 +29,6 @@

if (stringified === '[object Function]') {
return formatFunction('Function', val)
}
if (stringified === '[object GeneratorFunction]') {

@@ -38,3 +38,3 @@ return formatFunction('GeneratorFunction', val)

return tsml(["\n ", "\n ", "\n ", "\n "], colors.punctuation('"'), colors.string(val), colors.punctuation('"'))
return tsml(["\n ", "\n ", "\n ", "\n "], formatter.punctuation('"'), formatter.string(val), formatter.punctuation('"'))
}

@@ -44,5 +44,5 @@

var formatWithDepth = function (obj, depth, colors, offset) {
var formatWithDepth = function (obj, depth, formatter, offset) {
var keys = Object.keys(obj)
var coloredKeys = keys.map(function (key) { return colors.property(key); })
var coloredKeys = keys.map(function (key) { return formatter.property(key); })
var colon = ': '

@@ -52,3 +52,3 @@

var val = obj[key]
return tsml(["\n ", "\n ", "\n ", "\n "], lpadAlign(coloredKeys[i], coloredKeys, offset), colors.punctuation(colon), ifElse(
return tsml(["\n ", "\n ", "\n ", "\n "], lpadAlign(coloredKeys[i], coloredKeys, offset), formatter.punctuation(colon), ifElse(
depth.curr < depth.max && isPlainObj(val),

@@ -58,6 +58,6 @@ function () { return format(

{ curr: depth.curr + 1, max: depth.max },
colors,
formatter,
offset + longest(keys).length + colon.length
); },
function () { return formatValue(colors, val); }
function () { return formatValue(formatter, val); }
))

@@ -69,19 +69,21 @@ })

var defaultFormatter = {
punctuation: chalk.yellow,
property: chalk.green,
literal: chalk.magenta,
number: chalk.cyan,
string: chalk.bold
}
var format = function (
obj,
depth,
colors,
formatter,
offset
) {
if ( depth === void 0 ) depth = Infinity;
if ( colors === void 0 ) colors = {
punctuation: chalk.yellow,
property: chalk.green,
literal: chalk.magenta,
number: chalk.cyan,
string: chalk.bold
};
if ( formatter === void 0 ) formatter = defaultFormatter;
if ( offset === void 0 ) offset = 2;
return formatWithDepth(obj, { curr: 0, max: depth }, colors, offset);
return formatWithDepth(obj, { curr: 0, max: depth }, formatter, offset);
}

@@ -88,0 +90,0 @@

@@ -16,13 +16,9 @@

const formatValue = (colors, val) => {
const formatValue = (formatter, val) => {
if (typeof val === 'number') {
return colors.number(val)
return formatter.number(val)
}
if (typeof val === 'function') {
return formatFunction('Function', val)
}
if (isLiteral(val)) {
return colors.literal(val)
return formatter.literal(String(val))
}

@@ -32,5 +28,5 @@

return tsml`
${colors.punctuation('(')}
${colors.string('collapsed')}
${colors.punctuation(')')}
${formatter.punctuation('(')}
${formatter.string('collapsed')}
${formatter.punctuation(')')}
`

@@ -41,2 +37,6 @@ }

if (stringified === '[object Function]') {
return formatFunction('Function', val)
}
if (stringified === '[object GeneratorFunction]') {

@@ -47,5 +47,5 @@ return formatFunction('GeneratorFunction', val)

return tsml`
${colors.punctuation('"')}
${colors.string(val)}
${colors.punctuation('"')}
${formatter.punctuation('"')}
${formatter.string(val)}
${formatter.punctuation('"')}
`

@@ -56,5 +56,5 @@ }

const formatWithDepth = (obj, depth, colors, offset) => {
const formatWithDepth = (obj, depth, formatter, offset) => {
const keys = Object.keys(obj)
const coloredKeys = keys.map((key) => colors.property(key))
const coloredKeys = keys.map((key) => formatter.property(key))
const colon = ': '

@@ -66,3 +66,3 @@

${lpadAlign(coloredKeys[i], coloredKeys, offset)}
${colors.punctuation(colon)}
${formatter.punctuation(colon)}
${ifElse(

@@ -73,6 +73,6 @@ depth.curr < depth.max && isPlainObj(val),

{ curr: depth.curr + 1, max: depth.max },
colors,
formatter,
offset + longest(keys).length + colon.length
),
() => formatValue(colors, val)
() => formatValue(formatter, val)
)}

@@ -85,15 +85,17 @@ `

const defaultFormatter = {
punctuation: chalk.yellow,
property: chalk.green,
literal: chalk.magenta,
number: chalk.cyan,
string: chalk.bold
}
const format = (
obj,
depth = Infinity,
colors = {
punctuation: chalk.yellow,
property: chalk.green,
literal: chalk.magenta,
number: chalk.cyan,
string: chalk.bold
},
formatter = defaultFormatter,
offset = 2
) => formatWithDepth(obj, { curr: 0, max: depth }, colors, offset)
) => formatWithDepth(obj, { curr: 0, max: depth }, formatter, offset)
module.exports = format
{
"name": "fmt-obj",
"version": "1.1.0",
"version": "1.1.1",
"description": "Prettifies any javascript object in your console",

@@ -8,3 +8,4 @@ "scripts": {

"lint": "standard",
"prepublish": "buble --yes dangerousTaggedTemplateString index.js > dist.js"
"prepublish": "buble --yes dangerousTaggedTemplateString index.js > dist.js",
"test": "ava"
},

@@ -32,2 +33,3 @@ "main": "dist.js",

"devDependencies": {
"ava": "^0.18.1",
"buble": "^0.15.2",

@@ -34,0 +36,0 @@ "standard": "^8.6.0"

# `fmt-obj` [![NPM version][version-image]][version-url] [![Dependency Status][david-image]][david-url] [![License][license-image]][license-url] [![Js Standard Style][standard-image]][standard-url]
# `fmt-obj` [![Build status][travis-image]][travis-url] [![NPM version][version-image]][version-url] [![Dependency Status][david-image]][david-url] [![License][license-image]][license-url] [![Js Standard Style][standard-image]][standard-url]

@@ -46,5 +46,5 @@ Prettifies any javascript object in your console. Make it look awesome! :lipstick:

### `fmtObj(obj, depth = Infinity, colors = defaultColorMap, offset = 2)`
### `fmtObj(obj, depth = Infinity, formatter = defaultFormatter, offset = 2)`
Prettifies `obj` given a `colors` map with optional `depth`.
Prettifies `obj` given a `formatter` map with optional `depth`.

@@ -55,3 +55,3 @@ #### `depth` (optional)

#### `colors` (optional)
#### `formatter` (optional)

@@ -113,2 +113,5 @@ `fmt-obj` uses [`chalk`](https://github.com/chalk/chalk) behind the scenes.

[travis-image]: https://img.shields.io/travis/queckezz/fmt-obj.svg?style=flat-square
[travis-url]: https://travis-ci.org/queckezz/fmt-obj
[version-image]: https://img.shields.io/npm/v/fmt-obj.svg?style=flat-square

@@ -115,0 +118,0 @@ [version-url]: https://npmjs.org/package/fmt-obj

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc