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

cmd-deps

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cmd-deps - npm Package Compare versions

Comparing version 2.1.2 to 2.1.3

lib/utils.js

23

index.js

@@ -0,14 +1,19 @@

/**
* @module index
* @license MIT
* @version 2017/11/10
*/
'use strict';
// Import lib
var util = require('./lib/util');
var parser = require('./lib/parser');
const utils = require('./lib/utils');
const parser = require('./lib/parser');
/**
* Cmd deps
*
* @param src
* @param replace
* @param flags
* @returns {String|Array}
* @function cmd
* @param {string} src
* @param {Function} replace
* @param {Array} flags
* @returns {string|Array}
*/

@@ -31,3 +36,3 @@ module.exports = function(src, replace, flags) {

// Is has require
if (!util.string(src) || !/\brequire\b/.test(src)) {
if (!utils.string(src) || !/\brequire\b/.test(src)) {
return replace ? src : [];

@@ -34,0 +39,0 @@ }

@@ -0,6 +1,12 @@

/**
* @module parser
* @license MIT
* @version 2017/11/10
*/
'use strict';
// Import lib
var util = require('./util');
var acorn = require('acorn');
const utils = require('./utils');
const acorn = require('acorn');

@@ -13,9 +19,9 @@ // The parse function

sourceType: options.sourceType,
ranges: util.defined(options.ranges, false),
locations: util.defined(options.locations, null),
ecmaVersion: util.defined(options.ecmaVersion, 6),
allowHashBang: util.defined(options.allowHashBang, true),
allowReserved: util.defined(options.allowReserved, true),
allowReturnOutsideFunction: util.defined(options.allowReturnOutsideFunction, true),
allowImportExportEverywhere: util.defined(options.allowImportExportEverywhere, true)
ranges: utils.defined(options.ranges, false),
locations: utils.defined(options.locations, null),
ecmaVersion: utils.defined(options.ecmaVersion, 6),
allowHashBang: utils.defined(options.allowHashBang, true),
allowReserved: utils.defined(options.allowReserved, true),
allowReturnOutsideFunction: utils.defined(options.allowReturnOutsideFunction, true),
allowImportExportEverywhere: utils.defined(options.allowImportExportEverywhere, true)
});

@@ -26,9 +32,6 @@ }

function traverse(object, visitor) {
var key;
var child;
if (visitor.call(null, object) !== false) {
for (key in object) {
for (let key in object) {
if (object.hasOwnProperty(key)) {
child = object[key];
let child = object[key];

@@ -45,3 +48,3 @@ if (child !== null && typeof child === 'object') {

function walk(src, options, callback) {
var syntax;
let syntax;

@@ -82,6 +85,6 @@ // Parse ast

module.exports = function(src, replace, options) {
var deps = [];
var offset = 0;
let offset = 0;
const deps = [];
if (replace && util.object(replace)) {
if (replace && utils.object(replace)) {
options = replace;

@@ -93,12 +96,12 @@ replace = undefined;

if (!util.string(src)) return deps;
if (!util.string(options.word)) options.word = 'require';
if (!utils.string(src)) return deps;
if (!utils.string(options.word)) options.word = 'require';
if (!(new RegExp('\\b' + options.word + '\\b')).test(src)) return deps;
if (!Array.isArray(options.flags)) options.flags = [];
if (replace && !util.fn(replace)) replace = util.noop;
if (replace && !utils.fn(replace)) replace = utils.noop;
// The handle function
var handle = function(node, flag) {
var update;
var value = node.value;
const handle = (node, flag) => {
let update;
const value = node.value;

@@ -115,3 +118,3 @@ // Push deps in to array

if (util.string(update)) {
if (utils.string(update)) {
src = src.substring(0, node.start + offset + 1) + update + src.substring(node.end + offset - 1);

@@ -124,7 +127,7 @@ offset += update.length - value.length;

// Walk code
walk(src, options.parse, function(node) {
walk(src, options.parse, (node) => {
if (isRequire(node, options.word, options.flags)) {
var args = node.arguments;
var property = node.callee.property;
var flag = property ? property.name : null;
let args = node.arguments;
const property = node.callee.property;
const flag = property ? property.name : null;

@@ -138,3 +141,3 @@ // When arguments length > 0

} else if (args.type === 'ArrayExpression') {
args.elements.forEach(function(args) {
args.elements.forEach((args) => {
if (args.type === 'Literal') {

@@ -141,0 +144,0 @@ handle(args, flag);

{
"name": "cmd-deps",
"version": "2.1.2",
"version": "2.1.3",
"description": "Transform cmd and get cmd dependences",

@@ -18,2 +18,5 @@ "author": {

},
"engines": {
"node": ">=0.8.0"
},
"license": "MIT",

@@ -30,6 +33,6 @@ "main": "index",

"dependencies": {
"acorn": "^5.1.2"
"acorn": "^5.2.1"
},
"devDependencies": {
"expect.js": "^0.3.1"
"chai": "^4.1.2"
},

@@ -36,0 +39,0 @@ "readmeFilename": "README.md",

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