🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

public.js

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

public.js

Display the public interfaces for given JavaScript files

latest
Source
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

Public.js

This library analyzes JavaScript code and returns all the public interfaces exposed at runtime.

##Install

npm install public.js

Browser-based version may be available in the future.

##Example

/* this is the code we want to analyze

function pattern1(param){

    function pattern1Private(){
        return "should not be testable";
    }

    return param;
}
var pattern1Variable = "testable";

*/
var inputStr = <string representation of code to analyze>;


var output = publicjs.getPublic(backboneStr,{
        dependencies: [underscoreStr],
        tree: true
      });
console.log(output);

Result:

[ 
  { name: 'pattern1', type: 'function', parameters: [{ name: 'param' }] },
  { name: 'pattern1Variable', type: 'string', value: 'testable' } 
]

##Applications

  • Automated unit test scaffolding: The tree returned by publicjs could be parsed and used to automatically create unit test cases based on the publically exposed functions. See example at Scaffold.js.

  • Code security: Add publicjs to your build process to ensure that only the functionality that should be exposed publically by your code is, and that private functions are not accessible.

  • Code documentation: The interface tree could be parsed to automatically generate documentation for public methods. See example at Scaffold.js.

FAQs

Package last updated on 08 Jun 2013

Did you know?

Socket

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.

Install

Related posts