Socket
Socket
Sign inDemoInstall

fairmont

Package Overview
Dependencies
Maintainers
3
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fairmont - npm Package Compare versions

Comparing version 1.0.0-beta-07 to 1.0.0-beta-08

94

lib/multimethods.js
// Generated by CoffeeScript 1.9.2
(function() {
var Method, _, assert, define, describe, dispatch, method, ref,
var Method, assert, create, define, describe, dispatch, ref,
slice = [].slice,

@@ -8,6 +8,4 @@ extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },

_ = require("./core")._;
dispatch = function(method, ax) {
var ai, argument, best, f, i, len, p, ref, ref1, term, ti, tx;
var arg, best, bi, bx, f, i, len, p, ref, ref1, term, ti, tx;
best = {

@@ -17,22 +15,19 @@ p: 0,

};
bx = method.map != null ? method.map(ax) : ax;
ref = method.entries;
for (i = 0, len = ref.length; i < len; i++) {
ref1 = ref[i], tx = ref1[0], f = ref1[1];
if (tx.length === ax.length || (tx[tx.length - 1] === _)) {
if (tx.length === bx.length) {
p = 0;
ai = ti = 0;
while (ai < ax.length && ti < tx.length) {
bi = ti = 0;
while (bi < bx.length && ti < tx.length) {
term = tx[ti++];
argument = ax[ai++];
if (term === _ && ti === tx.length) {
p += 1 + ax.length - ai;
break;
}
if (term === argument) {
arg = bx[bi++];
if (term === arg) {
p += 4;
} else if (term === argument.constructor) {
} else if (term === arg.constructor) {
p += 3;
} else if (term.constructor === Function && (argument instanceof term)) {
} else if (term.constructor === Function && (arg instanceof term)) {
p += 2;
} else if (term.constructor === Function && (term(argument)) === true) {
} else if (term.constructor === Function && (term(arg)) === true) {
p += 5;

@@ -59,6 +54,24 @@ } else {

method = function(description) {
var m;
create = function() {
var arg, args, description, m, map;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
args = args.slice(0, 2);
map = description = void 0;
while ((arg = args.shift())) {
switch (arg.constructor) {
case String:
if (description == null) {
description = arg;
}
break;
case Function:
if (map == null) {
map = arg;
}
}
}
m = function() {
return dispatch(m, arguments);
var args;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return dispatch(m, args);
};

@@ -69,2 +82,3 @@ m.entries = [];

};
m.map = map;
m.description = description;

@@ -81,3 +95,3 @@ return m;

Method = {
create: method,
create: create,
define: define

@@ -87,5 +101,3 @@ };

module.exports = {
Method: Method,
method: method,
define: define
Method: Method
};

@@ -98,4 +110,4 @@

var fib;
fib = method("Fibonacci sequence");
define(fib, (function(n) {
fib = Method.create("Fibonacci sequence");
Method.define(fib, (function(n) {
return n <= 0;

@@ -105,5 +117,5 @@ }), function() {

});
define(fib, 1, 1);
define(fib, 2, 1);
define(fib, Number, function(n) {
Method.define(fib, 1, 1);
Method.define(fib, 2, 1);
Method.define(fib, Number, function(n) {
return (fib(n - 1)) + (fib(n - 2));

@@ -133,16 +145,16 @@ });

b = new B;
foo = method();
define(foo, A, function() {
foo = Method.create();
Method.define(foo, A, function() {
return "foo: A";
});
define(foo, B, function() {
Method.define(foo, B, function() {
return "foo: B";
});
define(foo, A, B, function() {
Method.define(foo, A, B, function() {
return "foo: A + B";
});
define(foo, B, A, function() {
Method.define(foo, B, A, function() {
return "foo: B + A";
});
define(foo, a, b, function() {
Method.define(foo, a, b, function() {
return "foo: a + b";

@@ -159,5 +171,11 @@ });

var bar;
bar = method();
define(bar, Number, String, function() {});
define(bar, Number, _, function() {
bar = Method.create(function() {
var first, rest;
first = arguments[0], rest = 2 <= arguments.length ? slice.call(arguments, 1) : [];
return [first, rest];
});
Method.define(bar, String, Array, function(x, a) {
return x;
});
Method.define(bar, Number, Array, function() {
var a, x;

@@ -167,3 +185,3 @@ x = arguments[0], a = 2 <= arguments.length ? slice.call(arguments, 1) : [];

});
return assert((bar(7, 1, 2, 3)) === 1);
return assert((bar(1, 2, 3)) === 2);
});

@@ -170,0 +188,0 @@ });

{
"name": "fairmont",
"version": "1.0.0-beta-07",
"version": "1.0.0-beta-08",
"description": "A collection of useful functions and utilities.",

@@ -5,0 +5,0 @@ "files": [

Sorry, the diff of this file is not supported yet

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