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.1 to 1.1.2

dist/json-truncate.js

52

index.js

@@ -1,42 +0,16 @@

'use strict';
'use strict'
var flatTypes = ["string", "number", "boolean"];
var isFlat = function(val) {
return flatTypes.indexOf(typeof(val)) !== -1;
let JSONTruncate
try {
JSONTruncate = require('./dist/json-truncate')
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') {
require('babel-register')
JSONTruncate = require('./src/json-truncate')
} else {
console.log(err)
process.exit(1)
}
}
var truncate = function(obj, maxDepth, curDepth) {
curDepth = curDepth || 0;
if (curDepth < maxDepth) {
var newDepth = curDepth + 1;
if (isFlat(obj)) {
return obj;
} else if (Array.isArray(obj)) {
var newObj = [];
obj.map(function(value) {
if (isFlat(value)) {
newObj.push(value);
} else {
newObj.push(truncate(value, maxDepth, newDepth));
}
});
return newObj;
} else {
var newObj = {};
for (var key in obj) {
if (isFlat(obj[key])) {
newObj[key] = obj[key];
} else {
newObj[key] = truncate(obj[key], maxDepth, newDepth)
}
}
return newObj;
}
}
}
module.exports = function(obj, maxDepth) {
return truncate(obj, maxDepth || 10);
};
module.exports = JSONTruncate
{
"name": "json-truncate",
"version": "1.1.1",
"version": "1.1.2",
"description": "A way to truncate a json object.",
"main": "index.js",
"scripts": {
"commit": "./node_modules/.bin/git-cz",
"check-coverage": "./node_modules/.bin/istanbul check-coverage --statements 100 --branches 100 --functions 100 --lines 100",
"test": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha && npm run check-coverage",
"semantic-release": "npm test && ./node_modules/.bin/semantic-release pre && npm publish && ./node_modules/.bin/semantic-release post"
"precommit": "npm run standard && npm run build && npm run cover && npm run coverage-check",
"commit": "git-cz",
"standard": "standard",
"cover": "nyc npm t && npm run coverage-report",
"coverage-check": "nyc check-coverage --branches 100 --statements 100 --functions 100 --lines 100",
"coverage-report": "nyc report --reporter=lcov",
"test": "_mocha --compilers js:babel-register",
"prebuild": "rimraf dist",
"build": "babel --copy-files --out-dir dist src",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"travis": "npm run precommit && npm run coveralls",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},

@@ -37,9 +45,22 @@ "repository": {

"devDependencies": {
"babel-cli": "^6.10.1",
"babel-eslint": "^6.1.0",
"babel-preset-es2015": "^6.9.0",
"babel-register": "^6.9.0",
"chai": "^3.5.0",
"commitizen": "^2.8.2",
"coveralls": "^2.11.9",
"cz-conventional-changelog": "^1.1.6",
"istanbul": "^0.4.4",
"mocha": "^2.5.3",
"semantic-release": "^4.3.5"
"mocha-lcov-reporter": "^1.2.0",
"nyc": "^6.6.1",
"rimraf": "^2.5.2",
"semantic-release": "^4.3.5",
"standard": "^7.1.2"
},
"files": [
"dist",
"src",
"README.md"
],
"config": {

@@ -49,3 +70,17 @@ "commitizen": {

}
},
"standard": {
"parser": "babel-eslint",
"ignore": "/dist/"
},
"babel": {
"presets": [
"es2015"
]
},
"nyc": {
"include": [
"src/**/*.js"
]
}
}

@@ -7,6 +7,10 @@ # json-truncate

[![travis](https://travis-ci.org/mrsteele/json-truncate.svg?branch=master)](https://travis-ci.org/mrsteele/json-truncate)
[![dependencies](https://david-dm.org/mrsteele/json-truncate.svg)](#)
[![npm](https://img.shields.io/npm/v/json-truncate.svg?maxAge=0&style=flat)](https://www.npmjs.com/package/json-truncate)
[![GitHub commits](https://img.shields.io/github/commits-since/mrsteele/json-truncate/v1.1.0.svg?maxAge=0&style=flat)](https://github.com/mrsteele/json-truncate/commits/master)
[![Travis](https://travis-ci.org/mrsteele/json-truncate.svg?branch=master)](https://travis-ci.org/mrsteele/json-truncate)
[![Coverage Status](https://coveralls.io/repos/github/mrsteele/json-truncate/badge.svg?branch=master)](https://coveralls.io/github/mrsteele/json-truncate?branch=master)
[![Dependency Status](https://david-dm.org/mrsteele/json-truncate.svg)](#)
[![devDependency Status](https://david-dm.org/mrsteele/json-truncate/dev-status.svg)](https://david-dm.org/mrsteele/json-truncate#info=devDependencies)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![GitHub Commits](https://img.shields.io/github/commits-since/mrsteele/json-truncate/v1.1.0.svg?maxAge=0&style=flat)](https://github.com/mrsteele/json-truncate/commits/master)
[![npm](https://img.shields.io/npm/l/json-truncate.svg?maxAge=0&style=flat)](https://raw.githubusercontent.com/mrsteele/json-truncate/master/LICENSE)

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

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