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

@plumier/reflect

Package Overview
Dependencies
Maintainers
1
Versions
252
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@plumier/reflect - npm Package Compare versions

Comparing version 1.0.0-rc.10 to 1.0.0-rc.11

26

lib/parser.d.ts
import { Class, ClassReflection, FunctionReflection } from "./types";
declare function getMethodParameters(fn: Class, method: string): (string | {
[key: string]: string[];
})[];
declare function getConstructorParameters(fn: Class): (string | {
[key: string]: string[];
})[];
declare function getFunctionParameters(fn: Function): (string | {
[key: string]: string[];
})[];
declare type RootNode = string | KeyValueNode | ObjectNode | ArrayNode;
declare type KeyValueNode = {
kind: "KeyValue";
key: string;
value: RootNode;
};
interface ObjectNode {
kind: "Object";
members: RootNode[];
}
interface ArrayNode {
kind: "Array";
members: RootNode[];
}
declare function getMethodParameters(fn: Class, method: string): RootNode[];
declare function getConstructorParameters(fn: Class): RootNode[];
declare function getFunctionParameters(fn: Function): RootNode[];
declare function getClassMembers(fun: Function): string[];

@@ -12,0 +20,0 @@ declare function parseFunction(fn: Function): FunctionReflection;

@@ -37,9 +37,10 @@ "use strict";

else {
const result = {};
result[node.key.name] = getName(node.value);
return result;
return { kind: "KeyValue", key: node.key.name, value: getName(node.value) };
}
}
//if (node.type === "ObjectPattern") {
return node.properties.map((x) => getName(x));
if (node.type === "ObjectPattern") {
return { kind: "Object", members: node.properties.map((x) => getName(x)) };
}
//if (node.type === "ArrayPattern") {
return { kind: "Array", members: node.elements.map((x) => getName(x)) };
//}

@@ -100,15 +101,22 @@ };

exports.getClassMembers = getClassMembers;
function printDestruct(params) {
const result = [];
for (const key in params) {
const par = params[key];
if (typeof par === "string")
result.push(par);
else {
const key = Object.keys(par)[0];
result.push(`${key}: ${printDestruct(par[key])}`);
}
}
return `{ ${result.join(", ")} }`;
function getName(param) {
const getNames = (p) => p.map(x => getName(x));
if (typeof param === "string")
return param;
if (param.kind === "KeyValue")
return `${param.key}: ${getName(param.value)}`;
if (param.kind === "Object")
return `{ ${getNames(param.members).join(", ")} }`;
return `[${getNames(param.members).join(", ")}]`;
}
function getField(params) {
const getFields = (p) => p.map(x => getField(x));
if (typeof params === "string")
return params;
if (params.kind === "KeyValue")
return { [params.key]: getField(params.value) };
if (params.kind === "Object")
return [...getFields(params.members)];
return [...getFields(params.members)];
}
// --------------------------------------------------------------------- //

@@ -118,12 +126,3 @@ // ------------------------------- PARSER ------------------------------ //

function parseParameter(name, index) {
let parName;
let fields = {};
if (typeof name === "object") {
parName = printDestruct(name);
fields = name;
}
else {
parName = name;
}
return { kind: "Parameter", name: parName, decorators: [], fields, index, type: undefined };
return { kind: "Parameter", name: getName(name), decorators: [], fields: getField(name), index, type: undefined };
}

@@ -130,0 +129,0 @@ function parseFunction(fn) {

@@ -24,2 +24,5 @@ import { CustomTypeDefinition } from "./helpers";

}
export declare type StringOrKeyValue = string | {
[key: string]: string[] | string;
} | StringOrKeyValue[];
export declare type Reflection = ParameterReflection | FunctionReflection | PropertyReflection | MethodReflection | ClassReflection | ObjectReflection | ConstructorReflection;

@@ -32,5 +35,3 @@ export interface ReflectionBase {

kind: "Parameter";
fields: string | {
[key: string]: string[];
};
fields: StringOrKeyValue;
decorators: any[];

@@ -37,0 +38,0 @@ type?: any;

{
"name": "@plumier/reflect",
"version": "1.0.0-rc.10",
"version": "1.0.0-rc.11",
"description": "Plumier reflection module",

@@ -21,3 +21,3 @@ "main": "lib/index.js",

"@types/acorn": "4.0.5",
"acorn": "8.1.0",
"acorn": "8.1.1",
"reflect-metadata": "^0.1.13"

@@ -27,8 +27,8 @@ },

"@types/jest": "^26.0.22",
"@types/node": "^14.14.37",
"@types/node": "^14.14.38",
"coveralls": "^3.1.0",
"jest": "^26.6.3",
"ts-jest": "^26.5.4",
"tslib": "^2.1.0",
"typescript": "^4.2.3"
"tslib": "^2.2.0",
"typescript": "^4.2.4"
},

@@ -44,3 +44,3 @@ "bugs": {

},
"gitHead": "701367e40dc31bf56da4620bcacbc9d2f4357384"
"gitHead": "c0486358f6e3ba0405847ed2f277735c58ad48f6"
}
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