Skip to content

Commit 1f502cf

Browse files
committed
factor reduce-extract out of the project
1 parent b25003f commit 1f502cf

File tree

4 files changed

+57
-117
lines changed

4 files changed

+57
-117
lines changed

.gitignore

-4
This file was deleted.

lib/transform.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const testValue = require('test-value')
22
const where = testValue.where
33
const arrayify = require('array-back')
4-
const extract = require('reduce-extract')
54
const omit = require('lodash.omit')
5+
const findReplace = require('find-replace')
66

77
function pick (object, keys) {
88
return keys.reduce((obj, key) => {
@@ -13,6 +13,12 @@ function pick (object, keys) {
1313
}, {})
1414
}
1515

16+
function extract (arr, fn) {
17+
const result = arr.filter(fn)
18+
findReplace(arr, fn)
19+
return result
20+
}
21+
1622
/**
1723
* @module transform
1824
*/
@@ -271,7 +277,7 @@ function buildTodoList (doclet) {
271277
Combine @todo array with @done custom tags to make @todoList
272278
*/
273279
if (doclet.tags) {
274-
const done = doclet.tags.reduce(extract({ title: 'done' }), [])
280+
const done = extract(doclet.tags, t => t.title === 'done')
275281
if (!doclet.tags.length) delete doclet.tags
276282
todoList = todoList.concat(done.map(function (task) {
277283
return { done: true, task: task.value }
@@ -286,23 +292,23 @@ function buildTodoList (doclet) {
286292

287293
function extractTypicalName (doclet) {
288294
if (doclet.tags) {
289-
const typicalName = doclet.tags.reduce(extract({ title: 'typicalname' }), [])
295+
const typicalName = extract(doclet.tags, t => t.title === 'typicalname')
290296
if (typicalName.length) doclet.typicalname = typicalName[0].value
291297
}
292298
return doclet
293299
}
294300

295301
function extractCategory (doclet) {
296302
if (doclet.tags) {
297-
const category = doclet.tags.reduce(extract({ title: 'category' }), [])
303+
const category = extract(doclet.tags, t => t.title === 'category')
298304
if (category.length) doclet.category = category[0].value
299305
}
300306
return doclet
301307
}
302308

303309
function extractChainable (doclet) {
304310
if (doclet.tags) {
305-
const chainable = doclet.tags.reduce(extract({ title: 'chainable' }), [])
311+
const chainable = extract(doclet.tags, t => t.title === 'chainable')
306312
if (chainable.length) doclet.chainable = true
307313
}
308314
return doclet

package-lock.json

+44-106
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
},
2424
"dependencies": {
2525
"array-back": "^6.2.2",
26+
"find-replace": "^5.0.1",
2627
"lodash.omit": "^4.5.0",
27-
"reduce-extract": "^1.0.0",
28-
"sort-array": "^4.1.5",
28+
"sort-array": "^5.0.0",
2929
"test-value": "^3.0.0"
3030
},
3131
"devDependencies": {

0 commit comments

Comments
 (0)