Comparing version 0.2.0 to 1.0.0
29
api.js
@@ -1,8 +0,27 @@ | ||
// The erlang.js API | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
var term_to_binary = require('./term_to_binary'); | ||
var encode = require('./encode.js') | ||
var decode = require('./decode.js') | ||
var iolist = require('./iolist.js') | ||
module.exports = { "term_to_binary": term_to_binary.term_to_binary | ||
, "optlist_to_binary": term_to_binary.optlist_to_binary | ||
} | ||
module.exports = | ||
{ term_to_binary : encode | ||
, optlist_to_term : encode.optlist_to_term | ||
, optlist_to_binary: encode.optlist_to_binary | ||
, binary_to_term : decode | ||
, iolist_to_binary : iolist.to_buffer | ||
, iolist_to_buffer : iolist.to_buffer | ||
, iolist_size : iolist.size | ||
} |
69
lib.js
@@ -0,5 +1,20 @@ | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
exports.VERSION_MAGIC = 131; // 131 83 | ||
exports.MAX_INTEGER = (1 << 27) - 1; | ||
exports.MIN_INTEGER = -(1 << 27); | ||
exports.typeOf = typeOf | ||
exports.flatten = flatten | ||
exports.numbers = {} // To be filled in later. | ||
exports.tags = { 'SMALL_INTEGER' : 'a' // 97 61 | ||
@@ -29,7 +44,10 @@ , 'INTEGER' : 'b' // 98 62 | ||
// Actually these need to be integers to be useful. | ||
Object.keys(exports.tags).forEach(function(key) { | ||
exports.tags[key] = exports.tags[key].charCodeAt(0); | ||
}) | ||
// Actually these need to be integers to be useful. And set up a reverse-lookup object. | ||
for (var tag in exports.tags) { | ||
var num = exports.tags[tag].charCodeAt(0) | ||
exports.tags[tag] = num | ||
exports.numbers[num] = tag | ||
} | ||
// Note: using Object.prototype.toString instead of instanceof because it's not working. | ||
function to_s(val) { | ||
@@ -39,26 +57,25 @@ return Object.prototype.toString.apply(val); | ||
typeOf = exports.typeOf = function(value) { | ||
var s = typeof value; | ||
function typeOf(value) { | ||
if (Buffer.isBuffer(value)) | ||
return 'buffer' | ||
// Note: using Object.prototype.toString instead of instanceof because it's not working. | ||
if (s === 'object') { | ||
if (value) { | ||
if(to_s(value) === '[object Array]') | ||
s = 'array'; | ||
else if(to_s(value) === '[object Buffer]') | ||
s = 'buffer'; | ||
else if(typeof Buffer === 'function' && value instanceof Buffer) | ||
s = 'buffer'; | ||
} else { | ||
s = 'null'; | ||
} | ||
} else if(s === 'function' && to_s(value) === '[object RegExp]') { | ||
return 'regexp'; | ||
} | ||
return s; | ||
if (Array.isArray(value)) | ||
return 'array' | ||
var s = typeof value | ||
if (s === 'object' && !value) | ||
return 'null' | ||
if(s === 'function' && to_s(value) === '[object RegExp]') | ||
return 'regexp' | ||
return s | ||
} | ||
flatten = exports.flatten = function (ar) { | ||
function flatten(ar) { | ||
return ar.reduce(function(state, elem) { | ||
return state.concat(typeOf(elem) === 'array' ? flatten(elem) : [elem]); | ||
return typeOf(elem) === 'array' | ||
? state.concat(flatten(elem)) | ||
: state.concat([elem]) | ||
}, []) | ||
@@ -71,3 +88,3 @@ } | ||
, n >> 8 & 0xff | ||
, n >> 0 & 0xff ]; | ||
, n >> 0 & 0xff ] | ||
} | ||
@@ -77,3 +94,3 @@ | ||
return [ n >> 16 & 0xff | ||
, n >> 0 & 0xff ]; | ||
, n >> 0 & 0xff ] | ||
} |
{ "name": "erlang" | ||
, "version": "0.2.0" | ||
, "author": { "name": "Iris Couch" | ||
, "email": "jhs@iriscouch.com" } | ||
, "version": "1.0.0" | ||
, "author": { "name": "Jason Smith", "email": "jason.h.smith@gmail.com" } | ||
, "description": "Erlang interoperability with Javascript" | ||
@@ -10,3 +9,13 @@ , "homepage": "http://github.com/iriscouch/erlang.js" | ||
, "engines": [ "node" ] | ||
, "main": "api" | ||
, "main": "./api.js" | ||
, "scripts": { "test" : "tap test/" | ||
} | ||
, "dependencies": { "debug": "~1.0.4" | ||
} | ||
, "devDependencies": { "tap": "~0.4.8" | ||
, "async": "~0.2.10" | ||
, "traceback": "~0.3.1" | ||
} | ||
} |
@@ -9,9 +9,2 @@ var sys = require('util') | ||
/* XXX This used to be used however now objects are used to create special types. Keeping for posterity. | ||
// Return the "meat" of a regex, or null if it is not a regex. | ||
function regex_of(val) { | ||
return lib.typeOf(val) === 'regexp' ? val.toString().slice(1, -1) : null; | ||
} | ||
*/ | ||
// Use object creation because I don't like object literal syntax to place functions in a namespace. | ||
@@ -28,2 +21,6 @@ var Encoder = function() { | ||
self.null = function() { | ||
return [lib.tags.NIL] | ||
} | ||
self.number = function(x) { | ||
@@ -85,2 +82,5 @@ return is_int(x) ? self.int(x) : self.float(x); | ||
if((tag === 'pid' || tag === 'p') && valType === 'object') | ||
return self.pid(val); | ||
throw new Error("Unknown tag " + tag.toString() + " for value: " + sys.inspect(val)); | ||
@@ -109,2 +109,12 @@ } | ||
self.pid = function(x) { | ||
return [ | ||
lib.tags.PID, | ||
self.encode(x.node), | ||
lib.uint32(x.id), | ||
lib.uint32(x.serial), | ||
x.creation | ||
]; | ||
} | ||
self.buffer = function(x) { | ||
@@ -111,0 +121,0 @@ var result = [lib.tags.BINARY]; |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
51195
16
865
0
1
103
1
3
6
3
+ Addeddebug@~1.0.4
+ Addeddebug@1.0.5(transitive)
+ Addedms@2.0.0(transitive)