1
1
const testValue = require ( 'test-value' )
2
2
const where = testValue . where
3
3
const arrayify = require ( 'array-back' )
4
- const extract = require ( 'reduce-extract' )
5
4
const omit = require ( 'lodash.omit' )
5
+ const findReplace = require ( 'find-replace' )
6
6
7
7
function pick ( object , keys ) {
8
8
return keys . reduce ( ( obj , key ) => {
@@ -13,6 +13,12 @@ function pick (object, keys) {
13
13
} , { } )
14
14
}
15
15
16
+ function extract ( arr , fn ) {
17
+ const result = arr . filter ( fn )
18
+ findReplace ( arr , fn )
19
+ return result
20
+ }
21
+
16
22
/**
17
23
* @module transform
18
24
*/
@@ -271,7 +277,7 @@ function buildTodoList (doclet) {
271
277
Combine @todo array with @done custom tags to make @todoList
272
278
*/
273
279
if ( doclet . tags ) {
274
- const done = doclet . tags . reduce ( extract ( { title : 'done' } ) , [ ] )
280
+ const done = extract ( doclet . tags , t => t . title === 'done' )
275
281
if ( ! doclet . tags . length ) delete doclet . tags
276
282
todoList = todoList . concat ( done . map ( function ( task ) {
277
283
return { done : true , task : task . value }
@@ -286,23 +292,23 @@ function buildTodoList (doclet) {
286
292
287
293
function extractTypicalName ( doclet ) {
288
294
if ( doclet . tags ) {
289
- const typicalName = doclet . tags . reduce ( extract ( { title : 'typicalname' } ) , [ ] )
295
+ const typicalName = extract ( doclet . tags , t => t . title === 'typicalname' )
290
296
if ( typicalName . length ) doclet . typicalname = typicalName [ 0 ] . value
291
297
}
292
298
return doclet
293
299
}
294
300
295
301
function extractCategory ( doclet ) {
296
302
if ( doclet . tags ) {
297
- const category = doclet . tags . reduce ( extract ( { title : 'category' } ) , [ ] )
303
+ const category = extract ( doclet . tags , t => t . title === 'category' )
298
304
if ( category . length ) doclet . category = category [ 0 ] . value
299
305
}
300
306
return doclet
301
307
}
302
308
303
309
function extractChainable ( doclet ) {
304
310
if ( doclet . tags ) {
305
- const chainable = doclet . tags . reduce ( extract ( { title : 'chainable' } ) , [ ] )
311
+ const chainable = extract ( doclet . tags , t => t . title === 'chainable' )
306
312
if ( chainable . length ) doclet . chainable = true
307
313
}
308
314
return doclet
0 commit comments