httpsnippet
Advanced tools
Comparing version 1.0.0-beta.1 to 1.0.0-beta.2
{ | ||
"version": "1.0.0-beta.1", | ||
"version": "1.0.0-beta.2", | ||
"name": "httpsnippet", | ||
@@ -4,0 +4,0 @@ "description": "HTTP Request snippet generator for *most* languages", |
@@ -111,3 +111,3 @@ # HTTP Snippet [![version][npm-version]][npm-url] [![License][npm-license]][license-url] | ||
// generate cURL output | ||
console.log(snippet.curl({ | ||
console.log(snippet.convert('curl', { | ||
indent: '\t'; | ||
@@ -117,3 +117,6 @@ })); | ||
// generate nodeJS output | ||
console.log(snippet.nodejs()); | ||
console.log(snippet.convert('node')); | ||
// generate PHP output | ||
console.log(snippet.convert('php', 'curl')); | ||
``` | ||
@@ -141,7 +144,8 @@ | ||
return { | ||
key: 'node', // target key | ||
family: 'node', // target family | ||
key: 'native', // target key | ||
ext: '.js', // preferred extension | ||
title: '', // target label | ||
description: '' // target description | ||
} | ||
}; | ||
}; | ||
@@ -148,0 +152,0 @@ ``` |
@@ -63,7 +63,53 @@ 'use strict'; | ||
// add each target as a prototype | ||
for (var lang in targets) { | ||
HTTPSnippet.prototype[lang] = targets[lang]; | ||
} | ||
HTTPSnippet.prototype.convert = function (family, target, opts) { | ||
if (!opts && target) { | ||
opts = target; | ||
} | ||
var func = this._matchTarget(family, target); | ||
if (func) { | ||
return func.call(this, opts); | ||
} | ||
return false; | ||
}; | ||
HTTPSnippet.prototype._matchTarget = function (familyName, target) { | ||
// does it exist? | ||
if (targets[familyName] === undefined) { | ||
return false; | ||
} | ||
// isolate the family | ||
var family = targets[familyName]; | ||
// childless targets | ||
if (typeof family === 'function') { | ||
return family; | ||
} | ||
// find the first possibel target | ||
var firstTarget = Object.keys(family).pop(); | ||
// shorthand | ||
if (!target || typeof target === 'object') { | ||
target = firstTarget; | ||
} | ||
// asking for a particular target | ||
if (typeof target === 'string') { | ||
// attempt to call the first one we find | ||
if (typeof family[target] !== 'function') { | ||
target = firstTarget; | ||
} | ||
// last chance | ||
if (typeof family[target] === 'function') { | ||
return family[target]; | ||
} | ||
} | ||
return false; | ||
}; | ||
// exports | ||
@@ -77,4 +123,10 @@ | ||
module.exports.info = function (lang) { | ||
return targets[lang].info(); | ||
module.exports.info = function (family, target) { | ||
var result = HTTPSnippet.prototype._matchTarget.call(null, family, target); | ||
if (result) { | ||
return result.info(); | ||
} | ||
return false; | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32298
16
441
232