11const testValue = require ( 'test-value' )
22const where = testValue . where
33const arrayify = require ( 'array-back' )
4- const extract = require ( 'reduce-extract' )
54const omit = require ( 'lodash.omit' )
5+ const findReplace = require ( 'find-replace' )
66
77function 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
287293function 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
295301function 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
303309function 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
0 commit comments