-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
85 lines (80 loc) · 2.21 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*!
* minibase-visit <https://github.com/node-minibase/minibase-visit>
*
* Copyright (c) Charlike Mike Reagent <@tunnckoCore> (http://i.am.charlike.online)
* Released under the MIT license.
*/
'use strict'
var collectionVisit = require('collection-visit')
var createPlugin = require('minibase-create-plugin')
/**
* > Adds `.visit` method to your application. That
* `opts` option is optional and does nothing. It is just convention
* each plugin to export function that returns a plugin.
*
* **Example**
*
* ```js
* var visit = require('minibase-visit')
*
* var MiniBase = require('minibase').MiniBase
* var app = new MiniBase()
* app.use(visit())
*
* // or as Base plugin
*
* var Base = require('base')
* var base = new Base()
* base.use(visit())
* ```
*
* @param {Object} `opts` optional, no options currently
* @return {Function} plugin that can be pass to [base][]/[minibase][]'s `.use` method
* @api public
*/
module.exports = function minibaseVisit (opts) {
return createPlugin('minibase-visit', function minibaseVisit (self) {
/**
* > Visit `method` over the properties in the [base][]/[minibase][]
* instance or map visit over the object-elements in an array.
* More info can see on [collection-visit][] to understand how
* this works.
*
* **Example**
*
* ```js
* var visit = require('minibase-visit')
* var app = require('minibase')
*
* app.use(visit())
*
* var context = {}
*
* app.foobar = function foobar (key, value) {
* context[key] = value
* }
*
* app.visit('foobar', {
* aa: 123,
* cc: {
* dd: 'bbb'
* }
* })
*
* console.log(context.aa) // => 123
* console.log(context.cc) // => { dd: 'bbb' }
* console.log(context.dd) // => 'bbb'
* ```
*
* @name .visit
* @param {String} `method` method to be called on each item in `value`, recursively
* @param {Array|Object} `value` object/array to be visited
* @return {Object} MiniBase/Base instance for chaining
* @api public
*/
self.define('visit', function visit (method, value) {
collectionVisit(self, method, value)
return self
})
})
}