Socket
Socket
Sign inDemoInstall

atocha

Package Overview
Dependencies
1
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.1 to 1.2.0

8

atocha.js

@@ -1,10 +0,8 @@

const magic = require('magic-promises');
const swear = require('swear');
const { promisify } = require('util');
const exec = promisify(require('child_process').exec);
export default (com, buffer = 10) => {
export default (command, buffer = 10) => {
const maxBuffer = buffer * 1024 * 1024;
return magic(exec(com, { maxBuffer }).then(out => {
if (!out) return '';
if (typeof out === 'string') return out.trim();
return swear(exec(command, { maxBuffer }).then(out => {
if (out.stderr) throw new Error(out.stderr);

@@ -11,0 +9,0 @@ return out.stdout.trim();

@@ -1,1 +0,1 @@

(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory():typeof define==="function"&&define.amd?define(factory):global.atocha=factory()})(this,function(){"use strict";const magic=require("magic-promises");const{promisify:promisify}=require("util");const exec=promisify(require("child_process").exec);var atocha=(com,buffer=10)=>{const maxBuffer=buffer*1024*1024;return magic(exec(com,{maxBuffer:maxBuffer}).then(out=>{if(!out)return"";if(typeof out==="string")return out.trim();if(out.stderr)throw new Error(out.stderr);return out.stdout.trim()}))};return atocha});
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory():typeof define==="function"&&define.amd?define(factory):(global=global||self,global.atocha=factory())})(this,function(){"use strict";const swear=require("swear");const{promisify:promisify}=require("util");const exec=promisify(require("child_process").exec);var atocha=(command,buffer=10)=>{const maxBuffer=buffer*1024*1024;return swear(exec(command,{maxBuffer:maxBuffer}).then(out=>{if(out.stderr)throw new Error(out.stderr);return out.stdout.trim()}))};return atocha});

@@ -10,2 +10,5 @@ import atocha from './atocha';

expect(await atocha('ls')).toContain('node_modules');
});
it('uses swear()', async () => {
expect(await atocha('ls').split('\n')).toContain('node_modules');

@@ -15,8 +18,8 @@ });

it('can handle fatal errors', async () => {
await expect(atocha('echho')).rejects.toMatchObject({});
await expect(atocha('echho')).rejects.toThrow(/echho: not found/);
});
it('can handle error messages', async () => {
await expect(atocha('>&2 echo "error"')).rejects.toMatchObject({});
await expect(atocha('>&2 echo "custom error"')).rejects.toThrow(/custom error/);
});
});
{
"name": "atocha",
"version": "1.1.1",
"version": "1.2.0",
"description": "Tiny exec() with Promises and trim()",
"main": "atocha.min.js",

@@ -8,3 +9,4 @@ "scripts": {

"gzip": "echo $(gzip -c fs.min.js | wc -c) bytes",
"test": "npm run build && jest --coverage"
"pretest": "npm run build",
"test": "jest --coverage"
},

@@ -14,3 +16,7 @@ "keywords": [

"console",
"terminal"
"terminal",
"promise",
"promises",
"async",
"await"
],

@@ -27,5 +33,4 @@ "author": "Francisco Presencia <public@francisco.io> (https://francisco.io/)",

"homepage": "https://github.com/franciscop/atocha#readme",
"description": "Tiny exec() with magic-promises and trim()",
"dependencies": {
"magic-promises": "^1.2.0"
"swear": "^1.0.0"
},

@@ -37,4 +42,5 @@ "devDependencies": {

"jest": "^23.5.0",
"rollup": "^1.1.2",
"uglify-es": "^3.3.9"
}
}

@@ -9,5 +9,10 @@ # Atocha [![npm install atocha](https://img.shields.io/badge/npm%20install-atocha-blue.svg)](https://www.npmjs.com/package/atocha)

(async () => {
console.log(await cmd('ls')); // Any basic command will work
console.log(await cmd('ls').split('\n')); // Not a typo; see `magic-primses`
console.log(await cmd('sort record.txt | uniq')); // Can pipe
// Any basic command will work
console.log(await cmd('ls'));
// Using a better Promise interface, see the lib `swear`
console.log(await cmd('ls').split('\n'));
// Can pipe commands as normal
console.log(await cmd('sort record.txt | uniq'));
})();

@@ -24,3 +29,3 @@ ```

- Better error handling. `stderr` will _reject_ the promise with an error instance. Can be caught as normal with `.catch()` or `try {} catch (error) {}`.
- Advanced [magic-promises interface](https://github.com/franciscop/magic-promises) so you can concatenate operations easily.
- Advanced [Promise interface](https://github.com/franciscop/swear) so you can concatenate operations easily.
- Full commands, commands with piping, etc. Note: Do **not** pass unsanitized input since there's no filtering going on. See [execa](https://github.com/sindresorhus/execa) for that.

@@ -27,0 +32,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc