New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

npm-programmatic

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

npm-programmatic - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

test/list/list.test.js

34

index.js

@@ -43,3 +43,37 @@ const Promise = require('bluebird');

});
},
list:function(path){
var global = false;
if(!path) global = true;
var cmdString = "npm ls --depth=0 " + (global?"-g ":" ");
return new Promise(function(resolve, reject){
exec(cmdString, {cwd: path?path:"/"},(error, stdout, stderr) => {
if (error) {
reject(error);
} else {
var packages = [];
packages = stdout.split('\n');
packages = packages.filter(function(item){
if(item.match(/^├──.+/g) != null){
return true
}
if(item.match(/^└──.+/g) != null){
return true
}
return undefined;
});
packages = packages.map(function(item){
if(item.match(/^├──.+/g) != null){
return item.replace(/^├──\s/g, "");
}
if(item.match(/^└──.+/g) != null){
return item.replace(/^└──\s/g, "");
}
})
resolve(packages);
}
});
});
}
}

2

package.json
{
"name": "npm-programmatic",
"version": "0.0.1",
"version": "0.0.2",
"description": "Use NPM commands programmatically",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -60,4 +60,25 @@ # npm-programmatic

## List Installed Packages
```
npm.list(path).then(function)
```
| Name | Type | Value |
| ------------- |:-------------:| -----:|
| path | String | path at which to look |
### Example
```
var npm = require('npm-programmatic');
npm.list('/path/to/project')
.then(function(arrayOfPackages){
console.log(arrayOfPackages);
})
.catch(function(){
console.log("Unable to uninstall package");
});
```
## Tests
install mocha and dev dependencies. Then run
``` npm test ```
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