Socket
Socket
Sign inDemoInstall

amdextract

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

amdextract

Extracts AMD modules and their parts.


Version published
Weekly downloads
90
increased by83.67%
Maintainers
1
Weekly downloads
 
Created
Source

amdextract

Extracts AMD modules, their parts and an optimized output without unused dependencies.

example

source.js

define(["view/a", "view/b"], function (a, b) {
	var t = new a();
});

define(["view/a", "view/b", "view/c"], function (a, b, c) {
	b.fetch();
});

example.js

var fs = require('fs');
var amdextract = require('amdextract');

var content = fs.readFileSync('source.js');
var result = amdextract.parse(content);

console.log(result.results.length + ' modules detected.');

result.results.forEach(function (r) {
	console.log('Unused paths: ' + r.unusedPaths.join(', '));
});

console.log('\nOptimized output:');
console.log(result.optimizedContent);

coutput

2 modules detected.
Unused paths: view/b
Unused paths: view/a, view/c

Optimized output:

define(["view/a"], function (a) {
	var t = new a();
});

define(["view/b"], function (b) {
	var t = b;
});

methods

parse(content[, options])

content

Type: string
JavaScript source for parsing.

options

excepts

Type: Array
Default value: []

An array of strings or RegExps that represent dependency names that should not take into account.

exceptsPaths

Type: Array
Default value: []

An array of strings or RegExps that represent dependency paths that should not take into account.

removeUnusedDependencies

Type: Boolean
Default value: false

Removes unused dependencies from content and returns optimized content as optimizedContent property of result.

returns

Returns an object with the following properties:

results

Type: Array

An array of hash objects witch have this properties for each AMD module detected in content:

  • moduleId
  • paths
  • dependencies
  • unusedPaths
  • unusedDependencies
  • bodyWithComments
  • bodyWithoutComments
  • comments
optimizedContent

Type: String

Optimized content (original content without unused dependencies).
This property is available when option removeUnusedDependencies is true.

Release History

  • 2014-01-13   v0.1.0   Works on files with multiple modules. Can detect module id if provided. Can remove unused dependencies. Add the new exceptsPaths option. Options excepts and exceptsPaths can take RegExps.

Keywords

FAQs

Package last updated on 12 Jan 2014

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

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