Comparing version 1.2.1 to 1.3.0
39
index.js
@@ -45,16 +45,35 @@ function getAbi (target, runtime) { | ||
function getTarget (abi, runtime) { | ||
if (abi && abi !== String(Number(abi))) return abi | ||
if (!runtime) runtime = 'node' | ||
if (runtime === 'node' && !abi) return process.versions.node | ||
var match = allTargets | ||
.filter(function (t) { | ||
return t.abi === abi && t.runtime === runtime | ||
}) | ||
.map(function (t) { | ||
return t.target | ||
}) | ||
if (match) return match[0] | ||
throw new Error('Could not detect target for abi ' + abi + ' and runtime ' + runtime) | ||
} | ||
var allTargets = [ | ||
{runtime: 'node', target: '0.10.48', lts: false}, | ||
{runtime: 'node', target: '0.12.17', lts: false}, | ||
{runtime: 'node', target: '4.6.1', lts: new Date() < new Date(2017, 04, 01)}, | ||
{runtime: 'node', target: '5.12.0', lts: false}, | ||
{runtime: 'node', target: '6.9.4', lts: new Date() < new Date(2018, 04, 18)}, | ||
{runtime: 'node', target: '7.4.0', lts: false}, | ||
{runtime: 'electron', target: '1.0.2', lts: false}, | ||
{runtime: 'electron', target: '1.2.8', lts: false}, | ||
{runtime: 'electron', target: '1.3.13', lts: false}, | ||
{runtime: 'electron', target: '1.4.15', lts: false} | ||
{runtime: 'node', target: '0.10.48', abi: '11', lts: false}, | ||
{runtime: 'node', target: '0.12.17', abi: '14', lts: false}, | ||
{runtime: 'node', target: '4.6.1', abi: '46', lts: new Date() < new Date(2017, 04, 01)}, | ||
{runtime: 'node', target: '5.12.0', abi: '47', lts: false}, | ||
{runtime: 'node', target: '6.9.4', abi: '48', lts: new Date() < new Date(2018, 04, 18)}, | ||
{runtime: 'node', target: '7.4.0', abi: '51', lts: false}, | ||
{runtime: 'electron', target: '1.0.2', abi: '47', lts: false}, | ||
{runtime: 'electron', target: '1.2.8', abi: '48', lts: false}, | ||
{runtime: 'electron', target: '1.3.13', abi: '49', lts: false}, | ||
{runtime: 'electron', target: '1.4.15', abi: '50', lts: false} | ||
] | ||
exports.getAbi = getAbi | ||
exports.getTarget = getTarget | ||
exports.allTargets = allTargets |
{ | ||
"name": "node-abi", | ||
"version": "1.2.1", | ||
"description": "Get the Node ABI for a given target and runtime", | ||
"version": "1.3.0", | ||
"description": "Get the Node ABI for a given target and runtime, and vice versa.", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
@@ -6,3 +6,3 @@ # Node.js ABI | ||
Get the Node ABI for a given target and runtime. | ||
Get the Node ABI for a given target and runtime, and vice versa. | ||
@@ -22,15 +22,19 @@ ## Installation | ||
// '50' | ||
nodeAbi.getTarget('51', 'node') | ||
// '7.2.0' | ||
nodeAbi.getTarget('50', 'electron') | ||
// '1.4.15' | ||
nodeAbi.allTargets | ||
// [ | ||
// { runtime: 'node', target: '0.10.48', lts: false }, | ||
// { runtime: 'node', target: '0.12.17', lts: false }, | ||
// { runtime: 'node', target: '4.6.1', lts: true }, | ||
// { runtime: 'node', target: '5.12.0', lts: false }, | ||
// { runtime: 'node', target: '6.9.4', lts: true }, | ||
// { runtime: 'node', target: '7.4.0', lts: false }, | ||
// { runtime: 'electron', target: '1.0.2', lts: false }, | ||
// { runtime: 'electron', target: '1.2.8', lts: false }, | ||
// { runtime: 'electron', target: '1.3.13', lts: false }, | ||
// { runtime: 'electron', target: '1.4.15', lts: false } | ||
// { runtime: 'node', target: '0.10.48', abi: '11', lts: false }, | ||
// { runtime: 'node', target: '0.12.17', abi: '14', lts: false }, | ||
// { runtime: 'node', target: '4.6.1', abi: '46', lts: true }, | ||
// { runtime: 'node', target: '5.12.0', abi: '47', lts: false }, | ||
// { runtime: 'node', target: '6.9.4', abi: '48', lts: true }, | ||
// { runtime: 'node', target: '7.4.0', abi: '51', lts: false }, | ||
// { runtime: 'electron', target: '1.0.2', abi: '47', lts: false }, | ||
// { runtime: 'electron', target: '1.2.8', abi: '48', lts: false }, | ||
// { runtime: 'electron', target: '1.3.13', abi: '49', lts: false }, | ||
// { runtime: 'electron', target: '1.4.15', abi: '50', lts: false } | ||
// ] | ||
@@ -37,0 +41,0 @@ ``` |
var test = require('tape') | ||
var getAbi = require('../index').getAbi | ||
var getTarget = require('../index').getTarget | ||
test('getTarget calculates correct Node target', function (t) { | ||
t.equal(getTarget(undefined), process.versions.node) | ||
t.equal(getTarget(null), process.versions.node) | ||
t.equal(getTarget('11'), '0.10.48') | ||
t.equal(getTarget('14'), '0.12.17') | ||
t.equal(getTarget('46'), '4.6.1') | ||
t.equal(getTarget('47'), '5.12.0') | ||
t.equal(getTarget('48'), '6.9.4') | ||
t.equal(getTarget('51'), '7.4.0') | ||
t.end() | ||
}) | ||
test('getTarget calculates correct Electron target', function (t) { | ||
t.equal(getTarget('47', 'electron'), '1.0.2') | ||
t.equal(getTarget('48', 'electron'), '1.2.8') | ||
t.equal(getTarget('49', 'electron'), '1.3.13') | ||
t.equal(getTarget('50', 'electron'), '1.4.15') | ||
t.end() | ||
}) | ||
test('getAbi calculates correct Node ABI', function (t) { | ||
@@ -5,0 +26,0 @@ t.equal(getAbi(undefined), process.versions.modules) |
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
9880
152
46