This repository was archived by the owner on Mar 7, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhelpers.js
107 lines (94 loc) · 3.12 KB
/
helpers.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
var _ = require('lodash'),
constants = require('./constants');
var pluralMap = constants.pluralMap,
singularMap = constants.singularMap,
itemtypes = constants.itemtypes;
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
// http://nodejs.org/api/
// https://github.com/yui/yuidoc/blob/2a1fdedbdf6d855536634e151869c6439e77ce37/lib/builder.js#L275
var nativeTypes = {
'Array': 1,
'Boolean': 1,
'Date': 1,
'decodeURI': 1,
'decodeURIComponent': 1,
'encodeURI': 1,
'encodeURIComponent': 1,
'eval': 1,
'Error': 1,
'EvalError': 1,
'Function': 1,
'Infinity': 1,
'isFinite': 1,
'isNaN': 1,
'Math': 1,
'NaN': 1,
'Number': 1,
'Object': 1,
'parseFloat': 1,
'parseInt': 1,
'RangeError': 1,
'ReferenceError': 1,
'RegExp': 1,
'String': 1,
'SyntaxError': 1,
'TypeError': 1,
'undefined': 1,
'URIError': 1,
'HTMLElement': 'https://developer.mozilla.org/en/Document_Object_Model_(DOM)/',
'HTMLCollection': 'https://developer.mozilla.org/en/Document_Object_Model_(DOM)/',
'DocumentFragment': 'https://developer.mozilla.org/en/Document_Object_Model_(DOM)/',
'HTMLDocument': 'https://developer.mozilla.org/en/Document_Object_Model_(DOM)/',
'EventEmitter': 'http://nodejs.org/api/events.html',
'Buffer': 'http://nodejs.org/api/buffer.html',
'fs.Stats': 'http://nodejs.org/api/fs.html#fs_class_fs_stats',
'fs.ReadStream': 'http://nodejs.org/api/fs.html#fs_class_fs_readstream',
'fs.WriteStream': 'http://nodejs.org/api/fs.html#fs_class_fs_readstream',
'stream.Readable': 'http://nodejs.org/api/stream.html#stream_class_stream_readable',
'stream.Writable': 'http://nodejs.org/api/stream.html#stream_class_stream_writable',
'stream.Duplex': 'http://nodejs.org/api/stream.html#stream_class_stream_duplex',
'stream.Transform': 'http://nodejs.org/api/stream.html#stream_class_stream_transform',
'Worker': 'http://nodejs.org/api/cluster.html#cluster_class_worker'
};
Object.keys(nativeTypes).forEach(function(i){
if (nativeTypes[i] === 1){
nativeTypes[i] = 'https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/' + i;
}
});
exports.yuidoc_type = function(types){
if (typeof types === 'string') types = types.split('|');
var yuidoc = this.site.yuidoc,
root = hexo.config.root,
result = [];
types.forEach(function(type){
var classObj = yuidoc.findClass(type),
link = '';
if (classObj){
link = root + classObj.path;
} else if (nativeTypes.hasOwnProperty(type)){
link = nativeTypes[type];
}
if (link){
result.push('<a href="' + link + '">' + type + '</a>');
} else {
result.push('<span>' + type + '</span>');
}
});
return result.join(' | ');
};
exports.yuidoc_params = function(params){
var arr = [];
if (params && params.length){
params.forEach(function(item){
if (item.optional){
arr.push('[' + item.name + (item.optdefault ? '=' + item.optdefault : '') + ']');
} else {
arr.push(item.name);
}
});
}
return '(' + arr.join(', ') + ')';
};
exports.get_current_yuidoc = function(){
return this.site.yuidoc.findByName(this.page.yuidoc_name);
};