Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

reference

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reference - npm Package Compare versions

Comparing version 0.0.0 to 0.1.0

2

package.json
{
"name": "reference",
"version": "0.0.0",
"version": "0.1.0",
"description": "Generate documentation from JSON.",

@@ -5,0 +5,0 @@ "main": "reference.js",

# reference.js
Generate a simple API reference from JSON. Made specifically for
<a href="http://peerjs.com">PeerJS</a>, so it probably won't suit your needs.
<a href="http://peerjs.com/docs">PeerJS</a>, so it probably won't suit your needs.

@@ -18,2 +18,3 @@ ## Expected style

"type": "constructor",
"tags": ["my", "tags"], // newly-added; doesn't show up in the pic below.
"description": "This class does some stuff.",

@@ -20,0 +21,0 @@ "snippet": "var klass = new TopLevelClass(arg1, [callback]);",

// TODO: eventually allow configurable yaml/json, html/md.
function reference(file) {
function reference(file, options) {
options = options || {};
try {

@@ -9,6 +11,6 @@ var components = JSON.parse(file);

return process(components, '');
return process(components, '', options.anchor);
}
function process(arr, path) {
function process(arr, path, anchor) {
var html = '';

@@ -18,6 +20,6 @@

for (var i = 0, ii = arr.length; i < ii; i += 1) {
html += processObj(arr[i], path);
html += processObj(arr[i], path, anchor);
}
} else {
html += processObj(arr, path);
html += processObj(arr, path, anchor);
}

@@ -28,3 +30,3 @@

function processObj(obj, path) {
function processObj(obj, path, anchor) {
if (obj.name === undefined) {

@@ -34,7 +36,16 @@ throw new Error('Your objects must each have a `name` property: e.g. {"name":"MyObject", ...}');

var html = '';
var tags = '';
if (obj.tags && obj.tags.constructor === Array) {
for (var i = 0, ii = obj.tags.length; i < ii; i += 1) {
var tag = sanitize(obj.tags[i].toString());
tags += tag + ' ';
}
}
if (!path) {
// This is a top-level deal.
html += '<div class="toplevel" id="';
html += '<div class="toplevel ' + tags + '" id="';
} else {
html += '<div class="child" id="';
html += '<div class="child ' + tags + '" id="';
}

@@ -51,8 +62,20 @@

}
// Add anchor to name.
if (anchor) {
name = '<a href="#' + path + '">' + name + '</a>';
}
html += '<span class="name">' + name;
if (obj.type) {
html += '<span class="type ' + obj.type + '">' + obj.type + '</span>';
html += '<span class="tag type ' + obj.type + '">' + obj.type + '</span>';
}
if (obj.tags && obj.tags.constructor === Array) {
for (var i = 0, ii = obj.tags.length; i < ii; i += 1) {
var tagClass = sanitize(obj.tags[i].toString());
html += '<span class="tag ' + tagClass + '">' + obj.tags[i] + '</span>';
}
}
if (obj.snippet) {

@@ -69,3 +92,3 @@ html += '<span class="snippet">' + obj.snippet + '</span>';

if (obj.children) {
html += '<div class="children">' + process(obj.children, path + '-') + '</div>';
html += '<div class="children">' + process(obj.children, path + '-', anchor) + '</div>';
}

@@ -72,0 +95,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc