Skip to content

Commit

Permalink
factor test-value out of the project
Browse files Browse the repository at this point in the history
  • Loading branch information
75lb committed Aug 30, 2024
1 parent e206a5d commit 2bd8657
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 65 deletions.
47 changes: 17 additions & 30 deletions lib/transform.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const testValue = require('test-value')
const where = testValue.where
const arrayify = require('array-back')
const omit = require('lodash.omit')
const findReplace = require('find-replace')
Expand Down Expand Up @@ -55,14 +53,20 @@ function transform (data) {
return doclet
})

const exported = json.filter(where({ isExported: true }))
const exported = json.filter(i => i.isExported === true)
const newIDs = exported.map(d => d.id)

newIDs.forEach(function (newID) {
update(json, { isExported: undefined, '!kind': 'module' }, function (doclet) {
return updateIDReferences(doclet, newID)
})
})
for (const newID of newIDs) {
for (let i = 0; i < json.length; i++) {
const doclet = json[i]
if (doclet.isExported === undefined && doclet.kind !== 'module') {
const values = updateIDReferences(doclet, newID)
for (const prop in values) {
if (values[prop] !== undefined) doclet[prop] = values[prop]
}
}
}
}

json = removeEnumChildren(json)
json = json.map(removeUnwanted)
Expand Down Expand Up @@ -175,17 +179,11 @@ hence the need for these four functions */
function getEs6Constructor (data, parent) {
return data.find(i => isES6Constructor(i) && i.memberof === parent.longname)
}
function isES6Class (doclet) {
return testValue(doclet, {
kind: 'class',
meta: { code: { type: 'ClassDeclaration' } }
})
function isES6Class (doclet = {}) {
return doclet.kind === 'class' && doclet.meta && doclet.meta.code && doclet.meta.code.type === 'ClassDeclaration'
}
function isES6Constructor (doclet) {
return testValue(doclet, {
kind: 'class',
meta: { code: { type: 'MethodDefinition' } }
})
return doclet.kind === 'class' && doclet.meta && doclet.meta.code && doclet.meta.code.type === 'MethodDefinition'
}

function replaceID (id, oldID, newID) {
Expand Down Expand Up @@ -356,17 +354,6 @@ function sortIdentifier (doclet) {
})
}

function update (array, query, newValues) {
for (let i = 0; i < array.length; i++) {
if (testValue(array[i], query)) {
const values = typeof newValues === 'function' ? newValues(array[i]) : newValues
for (const prop in values) {
if (values[prop] !== undefined) array[i][prop] = values[prop]
}
}
}
}

function renameThisProperty (doclet) {
doclet.thisvalue = doclet.this
delete doclet.this
Expand All @@ -386,7 +373,7 @@ function fixES6ConstructorMemberLongnames (data) {
if (isES6Class(i)) {
const es6constructor = getEs6Constructor(data, i)
if (es6constructor) {
const constructorChildren = data.filter(where({ memberof: es6constructor.longname }))
const constructorChildren = data.filter(c => c.memberof === es6constructor.longname)
constructorChildren.forEach(child => {
child.memberof = i.longname
})
Expand All @@ -407,7 +394,7 @@ function convertIsEnumFlagToKind (doclet) {
/* remove properties which have enum parents.. depends on convertIsEnumFlagToKind */
function removeEnumChildren (json) {
return json.filter(function (doclet) {
const parent = json.find(where({ id: doclet.memberof }))
const parent = json.find(i => i.id === doclet.memberof)
if (parent && parent.kind === 'enum') {
return false
} else {
Expand Down
34 changes: 1 addition & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"array-back": "^6.2.2",
"find-replace": "^5.0.1",
"lodash.omit": "^4.5.0",
"sort-array": "^5.0.0",
"test-value": "^3.0.0"
"sort-array": "^5.0.0"
},
"devDependencies": {
"test-runner": "^0.10.1"
Expand Down

0 comments on commit 2bd8657

Please sign in to comment.