Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
tinspector
Advanced tools
TypeScript type inspector library
tinspector is a type inspector library, it can parse all exported functions and classes inside a module into Abstract Syntax Tree.
Example you have a file with classes like below:
//filename: src/mock.ts
export function myFun(firstPar: string, secondPar: string) { }
export function myOtherFun() { }
export class MyClass {
myMethod(firstPar: string, secondPar: string) { }
myOtherMethod(){}
}
You can retrieve AST from above module using:
//filename: src/index.ts
import {reflect} from "./reflect"
const result = reflect("./mock")
The result will be like below:
{
type: 'Object',
name: 'module',
members: [{
type: 'Function',
name: 'myFun',
parameters:
[{ type: 'Parameter', name: 'firstPar' },
{ type: 'Parameter', name: 'secondPar' }]
},
{ type: 'Function', name: 'myOtherFun', parameters: [] },
{
type: 'Class',
name: 'MyClass',
methods:
[{
type: 'Function',
name: 'myMethod',
parameters:
[{ type: 'Parameter', name: 'firstPar' },
{ type: 'Parameter', name: 'secondPar' }]
},
{ type: 'Function', name: 'myOtherMethod', parameters: [] }]
}]
}
The parameter of the reflect
method is the path of the module that will be parsed, it is respect the JavaScript import naming such as absolute "./module"
, "/path/of/module"
, relative "../../module"
or global "module"
tinspector can handle TypeScript style decorator properly
import {decorateClass, decorateMethod, decorateParameter} from "./reflect"
@decorateClass({ url: "/animal" })
export class AnimalClass {
@decorateMethod({ url: "/get" })
myMethod(@decorateParameter({ required: true }) firstPar: string, @decorateParameter({ required: false }) secondPar: string) { }
myOtherMethod(@decorateParameter({ required: true }) par1: string, par2: string) { }
}
The reflection result is like below:
{
type: 'Class',
name: 'AnimalClass',
methods:
[{
type: 'Function',
name: 'myMethod',
parameters:
[{
type: 'Parameter',
name: 'firstPar',
decorators:
[{ required: true }]
},
{
type: 'Parameter',
name: 'secondPar',
decorators:
[{ required: false }]
}],
decorators:
[{ url: '/get' }]
},
{
type: 'Function',
name: 'myOtherMethod',
parameters:
[{
type: 'Parameter',
name: 'par1',
decorators:
[{ required: true }]
},
{ type: 'Parameter', name: 'par2', decorators: [] }],
decorators: []
}],
decorators:
[{ url: '/animal' }]
}
FAQs
TypeScript type inspector
The npm package tinspector receives a total of 435 weekly downloads. As such, tinspector popularity was classified as not popular.
We found that tinspector demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.