Skip to content

Commit 8128a77

Browse files
committed
1.0.0
1 parent e297ecc commit 8128a77

File tree

5 files changed

+416
-255
lines changed

5 files changed

+416
-255
lines changed

README.md

+37-54
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# apiez
22

3-
Easily generate API documentation for javascript from runtime instead of source.
3+
Easily generate API documentation at runtime, rather than from the source code.
44

5-
Contract:
6-
7-
The document is a continuous comment at the top of the function body
5+
Results details to see [test](./test.js) and [test-class](./test-class.js)
86

97
## Install
108

@@ -15,65 +13,50 @@ $ npm install apiez
1513
## Useage
1614

1715
```js
18-
var apidoc = require('apiez');
16+
var apiez = require('apiez');
1917

20-
apidoc(require('buffer'))
18+
apiez(apiez)
2119
```
2220

2321
cli
2422

2523
```shell
26-
$ apiez buffer
24+
$ apiez apiez
2725
```
2826

29-
## Example
30-
31-
```js
32-
var apiez = require('apiez'),
33-
assert = require('assert');
34-
35-
function A() {
36-
/*A*/
37-
}
38-
39-
A.prototype.a = function(a /**/ ) {
40-
/*
41-
a
42-
43-
b
44-
*/
45-
46-
// After the blank line is not a document
47-
}
27+
output
4828

49-
A.prototype.b = function a(a /**/ ) {
50-
//
51-
// a
52-
//
53-
// b
54-
//
55-
56-
// After the blank line is not a document
57-
}
58-
59-
function test(x, s) {
60-
assert.equal(apiez(x, JSON.stringify), s)
61-
}
62-
63-
test(function a(/*ignore*/ a , /*c,*/ /*ignore*/ b /*,c
64-
c*/ , /*ignore*/ c /*c*/ ) {
65-
66-
}, '{"a":{"args":[["a","c,"],["b",",c","c"],["c","c"]]}}')
67-
68-
test(A, '{"A":{"methods":{' +
69-
'"a":{"args":["a"],"doc":["a",""," b"]},' +
70-
'"b":{"args":["a"],"doc":["a",""," b"]}' +
71-
'}}}')
72-
73-
test({ B: A }, '{"B":{"methods":{' +
74-
'"a":{"args":["a"],"doc":["a",""," b"]},' +
75-
'"b":{"args":["a"],"doc":["a",""," b"]}' +
76-
'}}}')
29+
```
30+
apiez
31+
params
32+
funcInside
33+
a function or object
34+
results
35+
default Object.create(null)
36+
object as
37+
38+
{
39+
name:{
40+
params:[["paramN","doc"...]...],
41+
notes:["doc"...]
42+
}
43+
}
44+
notes
45+
Generate API documentation object for funcInside.
46+
47+
Contract:
48+
49+
The summary is a continuous comment at the top of the function body
50+
Anonymous functions named ""
51+
52+
Feature:
53+
54+
Parameter Comment
55+
Prototype methods
56+
Extends class
57+
Constructor, if it is first method
58+
Remove head and tail empty lines
59+
Remove the same indent white-spaces
7760
```
7861

7962
# License

cli.js

+48-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env node
22

3-
var docez = require('./index'),
3+
var apiez = require('./index'),
44
args = process.argv.slice(2),
5+
api,
56
x,
67
f;
78

@@ -14,12 +15,56 @@ try {
1415
x = require(args[0])
1516
if (args.length > 1)
1617
f = require(args[1])
17-
18+
f = typeof f == 'function' && f || null
1819
} catch (e) {
1920
console.error(e.message)
2021
process.exit(1)
2122
}
2223

23-
console.log(docez(x, f || true))
24+
api = apiez(x)
25+
26+
if (f) {
27+
console.log(f(api))
28+
} else
29+
echo(api)
30+
31+
function echo(api) {
32+
Object.keys(api).forEach(function(name) {
33+
console.log(format('', name, api[name]).join('\n'))
34+
}, api)
35+
}
36+
37+
function format(prefix, name, x, lines) {
38+
lines = lines || []
39+
lines.push(prefix + name);
40+
if (x.extends) lines.push(
41+
prefix + ' extends ' + x.extends)
42+
if (x.params) {
43+
lines.push(prefix + ' params');
44+
x.params.forEach(function(a) {
45+
lines.push(prefix + ' ' + a[0])
46+
a.forEach(function(c, i) {
47+
if (!i) return
48+
lines.push(prefix + ' ' + c)
49+
})
50+
})
51+
}
52+
53+
if (x.notes) {
54+
lines.push(prefix + ' notes');
55+
x.notes.forEach(function(c) {
56+
lines.push(prefix + ' ' + c)
57+
})
58+
}
59+
60+
if (x.methods) {
61+
lines.push(prefix + ' methods');
62+
Object.keys(x.methods).forEach(function(name) {
63+
format(prefix + ' ', name, x.methods[name], lines)
64+
})
65+
} else
66+
lines.push('\n')
67+
return lines
68+
}
2469

2570
process.exit(0)

0 commit comments

Comments
 (0)