Socket
Socket
Sign inDemoInstall

json-truncate

Package Overview
Dependencies
0
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.4 to 1.2.0

11

dist/json-truncate.js

@@ -7,3 +7,3 @@ 'use strict';

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

@@ -20,5 +20,7 @@ var flatTypes = [String, Number, Boolean];

var truncate = function truncate(obj, maxDepth, curDepth) {
var truncate = function truncate(obj, maxDepth, options, curDepth) {
curDepth = curDepth || 0;
maxDepth = isDefined(maxDepth) ? maxDepth : 10;
options = (typeof options === 'undefined' ? 'undefined' : _typeof(options)) === 'object' ? options : {};
options.replace = typeof options.replace === 'string' ? options.replace : undefined;

@@ -40,3 +42,3 @@ if (curDepth < maxDepth) {

} else {
newArr.push(truncate(value, maxDepth, newDepth));
newArr.push(truncate(value, maxDepth, options, newDepth));
}

@@ -58,3 +60,3 @@ });

} else {
newObj[key] = truncate(obj[key], maxDepth, newDepth);
newObj[key] = truncate(obj[key], maxDepth, options, newDepth);
}

@@ -70,4 +72,5 @@ }

}
return options.replace;
};
exports.default = truncate;
{
"name": "json-truncate",
"version": "1.1.4",
"version": "1.2.0",
"description": "A way to truncate a json object.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -29,2 +29,6 @@ # json-truncate

console.log(JSON.truncate(SomeDeepObject, 10));
//OR specify a replacement string for truncated values
console.log(JSON.truncate(SomeDeepObject, 10, {replace: '[Truncated]'}));
```

@@ -40,6 +44,13 @@

* `maxDepth` - (optional) The depth at which to stop building the valid json. Defaults to `10`.
* `options` - (optional) An option object to customize the behavior of the utility. Defaults to `{}`.
**Current Option Properties**
|Option|Description|
|:--|:--|
|**replace**|A string value that is used to replace all truncated values. If this value is not a string then all truncated values will be replaced with `undefined`|
## Licence
MIT

@@ -13,5 +13,7 @@ 'use strict'

const truncate = (obj, maxDepth, curDepth) => {
const truncate = (obj, maxDepth, options, curDepth) => {
curDepth = curDepth || 0
maxDepth = (isDefined(maxDepth)) ? maxDepth : 10
options = (typeof options === 'object') ? options : {}
options.replace = (typeof options.replace === 'string') ? options.replace : undefined

@@ -29,3 +31,3 @@ if (curDepth < maxDepth) {

} else {
newArr.push(truncate(value, maxDepth, newDepth))
newArr.push(truncate(value, maxDepth, options, newDepth))
}

@@ -40,3 +42,3 @@ })

} else {
newObj[key] = truncate(obj[key], maxDepth, newDepth)
newObj[key] = truncate(obj[key], maxDepth, options, newDepth)
}

@@ -47,4 +49,5 @@ }

}
return options.replace
}
export default truncate
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc