formalsec / explode-js

Public mirror for Explode.js
MIT License
2 stars 0 forks source link

Lazy values example candidates #19

Open filipeom opened 3 weeks ago

filipeom commented 3 weeks ago
var _, child_process, utils;

_ = require('lodash');

child_process = require('child_process');

utils = require('./utils');

/**
 * @summary Unmount a device
 * @public
 * @function
 *
 * @description
 * It does nothing for Windows.
 *
 * @param {String} device - device path
 * @param {Function} callback - callback (error, stdout, stderr)
 *
 * @example
 * umount.umount '/dev/disk2', (error, stdout, stderr) ->
 *      throw error if error?
 */

exports.umount = function(device, callback) {
  var unmountCommand;
  if (device == null) {
    throw new Error('Missing device');
  }
  if (!_.isString(device)) {
    throw new Error("Invalid device: " + device);
  }
  if (callback == null) {
    throw new Error('Missing callback');
  }
  if (!_.isFunction(callback)) {
    throw new Error("Invalid callback: " + callback);
  }
  if (utils.isWin32()) {
    return callback(null, null, null);
  }
  if (utils.isMacOSX()) {
    unmountCommand = '/usr/sbin/diskutil unmountDisk force';
  } else {
    unmountCommand = 'umount';
  }
  device = "\"" + device + "\"";
  if (utils.isLinux()) {
    device += '?* 2>/dev/null || /bin/true';
  }
  return child_process.exec(unmountCommand + " " + device, callback);
};
filipeom commented 3 weeks ago
'use strict';

const { blue, bold, green, red } = require('chalk');
const path = require('path');
const semver = require('semver');
const { exec } = require('child_process');
const { promisify } = require('util');

const execAsync = promisify(exec);

async function getLatestVersions(name) {
  const { stdout } = await execAsync(`npm view ${name} versions --json`);
  try {
    return JSON.parse(stdout);
  } catch (err) {
    throw new Error(`Failed to parse output from NPM view - ${err.toString()}`);
  }
}