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

metaschema

Package Overview
Dependencies
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metaschema - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

test/example.js

8

lib/generator.js

@@ -18,2 +18,3 @@ 'use strict';

buf.push('`' + signature.method + '(' + keys.join(', ') + ')`');
buf.push(signature.description);
for (parameter of signature.parameters) {

@@ -26,4 +27,9 @@ buf.push(

}
buf.push('');
for (comment of signature.comments) {
buf.push(comment.name + ': ' + comment.rest);
if (comment.name === 'Example') {
buf.push('`' + comment.name + ': ' + comment.comment + '`\n');
} else {
buf.push(comment.name + ': ' + comment.comment + '\n');
}
}

@@ -30,0 +36,0 @@ buf.push('');

54

lib/introspection.js

@@ -5,11 +5,18 @@ 'use strict';

const SCALAR_TYPES = ['string', 'number', 'boolean', 'undefined'];
const OBJECT_TYPES = ['function', 'array', 'object', 'null', 'symbol'];
const META_TYPES = ['char', 'hash', 'record', 'set', 'map'];
const ALL_TYPES = common.merge(SCALAR_TYPES, OBJECT_TYPES, META_TYPES);
const FUNC_TERMS = [') {', ') => {', ') => ('];
const FUNC_LINES = ['Example:', 'Returns:'];
const NAMED_LINES = ['Example:', 'Returns:', 'Hint:', 'Result:'];
const indexing = s => term => s.indexOf(term);
const last = arr => arr[arr.length - 1];
const parseLines = (
// Parse signature lines
s, // string, signature lines
signature // record, { title, parameters, comments }
signature // record, { title, description, parameters, comments }
// Returns: array of string

@@ -20,17 +27,27 @@ ) => {

signature.title = (lines.shift() || '').replace('//', '').trim();
lines = lines.map(s => s.trim()
.replace(/^\/\/ /, '')
.replace(/^(.*) \/\//, '$1:')
.replace(',:', ':')
lines = lines.map(
d => d.trim().replace(/^(.*) \/\//, '$1:').replace(',:', ':')
);
let name, rest, type, comment;
for (const line of lines) {
const index = FUNC_LINES.find(s => line.startsWith(s));
[name, rest] = common.section(line, ':');
rest = rest.trim();
if (index) {
signature.comments.push({ name, rest });
for (let line of lines) {
if (line.startsWith('//')) {
line = line.replace(/^\/\/ /, '').trim();
if (NAMED_LINES.find(s => line.startsWith(s))) {
const [name, comment] = common.section(line, ': ');
signature.comments.push({ name, comment });
} else if (signature.parameters.length === 0) {
if (signature.description.length > 0) {
signature.description += '\n';
}
signature.description += line;
} else {
const par = last(signature.parameters);
par.comment += '\n' + line;
}
} else {
[type, comment] = common.section(rest, ',');
comment = comment.trim();
const [name, text] = common.section(line, ': ');
let [type, comment] = common.section(text, ', ');
if (!ALL_TYPES.find(s => type.startsWith(s))) {
comment = type;
type = '';
}
signature.parameters.push({ name, type, comment });

@@ -44,5 +61,8 @@ }

fn // function, method
// Returns: { title, parameters }
// Returns: { title, description, parameters, comments }
) => {
const signature = { title: '', parameters: [], comments: [] };
const signature = {
title: '', description: '',
parameters: [], comments: []
};
let s = fn.toString();

@@ -49,0 +69,0 @@ let pos = FUNC_TERMS.map(indexing(s))

{
"name": "metaschema",
"version": "0.0.4",
"version": "0.0.5",
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>",

@@ -26,3 +26,3 @@ "description": "Metadata Schema and Interface Definition Language (IDL)",

"scripts": {
"test": "npm run lint && ./bin/cli.js ./metaschema.js",
"test": "npm run lint && ./bin/cli.js ./test/example.js",
"lint": "eslint ."

@@ -29,0 +29,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