Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ time.

- **Flat**: A JSON document is in this category if the height of the document
multiplied by the non-root level with the largest byte-size when taking
textual, numeric and boolean values into account is less than 10.
textual, numeric and boolean values into account is less than 10. If two
levels have the byte size, the highest level is taken into account.

- **Nested**: A JSON document is in this category if it is considered
*structural* and its height is greater than or equal to 5, or if the height
of the document multiplied by the non-root level with the largest byte-size
when taking textual, numeric and boolean values into account is greater than
or equal to 10.
or equal to 10. If two levels have the byte size, the highest level is taken
into account.

Usage (JavaScript)
------------------
Expand Down
3 changes: 3 additions & 0 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ module.exports = (value) => {
// Nesting characteristics
const largestLevel = analysis.levels.slice(1).map((level, index) => {
return { index: index + 1, ...level }
}).sort((left, right) => {
return right.index - left.index
}).sort((left, right) => {
return right.size - left.size
})[0]

if (textualWeight === 0 && numericWeight === 0 && booleanWeight === 0 && analysis.height >= 5) {
qualifiers.push('nested')
} else if (analysis.height * largestLevel.index >= 10) {
Expand Down
30 changes: 30 additions & 0 deletions test/js/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,36 @@ tap.test('should categorize the survey test object', (test) => {
test.end()
})

tap.test('should categorize a tier 1 numeric non-redundant nested document', (test) => {
const document = {
version: 2.1,
workflows: {
test: {
jobs: [
{
m1: {
matrix: {
parameters: {
a: [1, 2, 3]
}
}
}
}
]
}
}
}

test.strictSame(taxonomy(document), [
'tier 1',
'numeric',
'non-redundant',
'nested'
])

test.end()
})

tap.test('should categorize an empty object', (test) => {
const document = {}

Expand Down