Skip to content

Commit c30c171

Browse files
authored
Merge pull request mrsteele#25 from mrsteele/bug/isFlatUndefined
fix: Resolves an issue when undefined values exist in the structure.
2 parents 5d7acb3 + c15d7ea commit c30c171

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"description": "A way to truncate a json object.",
55
"main": "index.js",
66
"scripts": {
7-
"precommit": "npm run standard && npm run build && npm run cover && npm run coverage-check",
7+
"precommit": "npm run standard && npm run cover && npm run coverage-check",
88
"commit": "git-cz",
99
"standard": "standard",
1010
"cover": "nyc npm t && npm run coverage-report",
1111
"coverage-check": "nyc check-coverage --branches 100 --statements 100 --functions 100 --lines 100",
1212
"coverage-report": "nyc report --reporter=lcov",
13-
"test": "_mocha --compilers js:babel-register",
13+
"test": "npm run build && _mocha --compilers js:babel-register",
1414
"prebuild": "rimraf dist",
1515
"build": "babel --copy-files --out-dir dist src",
1616
"coveralls": "nyc report --reporter=text-lcov | coveralls",

src/json-truncate.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
const flatTypes = [String, Number, Boolean]
44

5-
const isFlat = val => {
6-
return flatTypes.indexOf(val.constructor) !== -1
7-
}
8-
95
const isDefined = val => {
106
return val !== null && val !== undefined
117
}
128

9+
const isFlat = val => {
10+
return !isDefined(val) || flatTypes.indexOf(val.constructor) !== -1
11+
}
12+
1313
const truncate = (obj, maxDepth, curDepth) => {
1414
curDepth = curDepth || 0
1515
maxDepth = (isDefined(maxDepth)) ? maxDepth : 10

test/mocha.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const createDeep = levels => {
2020
obj.str = 'You are on level ' + level
2121
obj.arr = [true, 1, 'hi']
2222
obj.sub = {}
23+
obj.null = null
24+
obj.undefined = undefined
2325
return obj
2426
}
2527

0 commit comments

Comments
 (0)