Skip to content

Commit

Permalink
factor reduce-extract out of the project
Browse files Browse the repository at this point in the history
  • Loading branch information
75lb committed Aug 29, 2024
1 parent b25003f commit 1f502cf
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 117 deletions.
4 changes: 0 additions & 4 deletions .gitignore

This file was deleted.

16 changes: 11 additions & 5 deletions lib/transform.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const testValue = require('test-value')
const where = testValue.where
const arrayify = require('array-back')
const extract = require('reduce-extract')
const omit = require('lodash.omit')
const findReplace = require('find-replace')

function pick (object, keys) {
return keys.reduce((obj, key) => {
Expand All @@ -13,6 +13,12 @@ function pick (object, keys) {
}, {})
}

function extract (arr, fn) {
const result = arr.filter(fn)
findReplace(arr, fn)
return result
}

/**
* @module transform
*/
Expand Down Expand Up @@ -271,7 +277,7 @@ function buildTodoList (doclet) {
Combine @todo array with @done custom tags to make @todoList
*/
if (doclet.tags) {
const done = doclet.tags.reduce(extract({ title: 'done' }), [])
const done = extract(doclet.tags, t => t.title === 'done')
if (!doclet.tags.length) delete doclet.tags
todoList = todoList.concat(done.map(function (task) {
return { done: true, task: task.value }
Expand All @@ -286,23 +292,23 @@ function buildTodoList (doclet) {

function extractTypicalName (doclet) {
if (doclet.tags) {
const typicalName = doclet.tags.reduce(extract({ title: 'typicalname' }), [])
const typicalName = extract(doclet.tags, t => t.title === 'typicalname')
if (typicalName.length) doclet.typicalname = typicalName[0].value
}
return doclet
}

function extractCategory (doclet) {
if (doclet.tags) {
const category = doclet.tags.reduce(extract({ title: 'category' }), [])
const category = extract(doclet.tags, t => t.title === 'category')
if (category.length) doclet.category = category[0].value
}
return doclet
}

function extractChainable (doclet) {
if (doclet.tags) {
const chainable = doclet.tags.reduce(extract({ title: 'chainable' }), [])
const chainable = extract(doclet.tags, t => t.title === 'chainable')
if (chainable.length) doclet.chainable = true
}
return doclet
Expand Down
150 changes: 44 additions & 106 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
},
"dependencies": {
"array-back": "^6.2.2",
"find-replace": "^5.0.1",
"lodash.omit": "^4.5.0",
"reduce-extract": "^1.0.0",
"sort-array": "^4.1.5",
"sort-array": "^5.0.0",
"test-value": "^3.0.0"
},
"devDependencies": {
Expand Down

0 comments on commit 1f502cf

Please sign in to comment.