Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

f

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

f - npm Package Compare versions

Comparing version 0.5.0 to 1.0.0

.npmignore

125

index.js

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

module.exports = require('./lib/f.js');
'use strict';
var http = require('http');
var https = require('https');
var fs = require('fs');
// Load environment variables for debugging if available
var path = require('path');
var fenv = {};
var envdir = path.join(__dirname, 'env', 'env.json');
if (fs.existsSync(envdir)) {
fenv = require(envdir);
}
function parseArgList(argList) {
var args;
var kwargs = {};
if (typeof argList[argList.length - 1] === 'object' && argList[argList.length - 1] !== 'null') {
kwargs = argList.pop();
}
args = argList.slice();
return new Buffer(
JSON.stringify({
args: args,
kwargs: kwargs
})
);
}
function parseContent(content) {
return new Buffer(content.toString());
}
function f(name, mode, config) {
mode = mode || 'json';
config = config || f.config;
return function external() {
var argList = [].slice.call(arguments);
var callback = function() {};
var payload;
var headers;
var req;
if (typeof argList[argList.length - 1] === 'function') {
callback = argList.pop();
}
if (mode === 'json') {
headers = {'Content-Type': 'application/json'};
payload = parseArgList(argList);
} else if (mode === 'command') {
headers = {'Content-Type': 'application/command'};
payload = parseContent(argList[0]);
} else if (mode === 'file') {
if (!argList[0] instanceof Buffer) {
return callback(new Error('Expecting Buffer for function mode: ' + mode));
}
headers = {'Content-Type': 'application/octet-stream'};
payload = argList[0];
} else {
return callback(new Error('Invalid function mode: ' + mode));
}
req = [http, https][(config.gateway.port === 443) | 0].request({
host: config.gateway.host,
method: 'POST',
headers: headers,
port: config.gateway.port,
path: config.gateway.path + name
}, function (res) {
var buffers = [];
res.on('data', function (chunk) { buffers.push(chunk); });
res.on('end', function () {
var response = Buffer.concat(buffers);
var contentType = res.headers['content-type'] || '';
if (contentType === 'application/json') {
response = response.toString();
try {
response = JSON.parse(response);
} catch(e) {
response = null;
}
} else if (contentType.match(/^text\/.*$/i)) {
response = response.toString();
}
if (((res.statusCode / 100) | 0) !== 2) {
return callback(new Error(response));
} else {
return callback(null, response);
}
});
});
req.on('error', callback);
req.write(payload);
req.end();
};
};
f.config = {
gateway: {
host: fenv.host || 'f.stdlib.com',
port: fenv.port || 443,
path: fenv.path || '/'
}
};
module.exports = f;

25

package.json
{
"author": {
"name": "Enrico Marino",
"email": "enrico.marino@email.com",
"url": "http://onirame.no.de"
},
"name": "f",
"description": "JavaScript functional library",
"version": "0.5.0",
"homepage": "https://github.com/onirame/f",
"repository": {
"type": "git",
"url": "git://github.com/onirame/f.git"
"version": "1.0.0",
"description": "Functional Microservice Request Library",
"main": "index.js",
"bin": {
"f": "cli/bin.js"
},
"main": "./index.js",
"engines": {
"node": "*"
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {},
"devDependencies": {}
"author": "Keith Horwood",
"license": "MIT"
}
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