New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

algae

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

algae - npm Package Compare versions

Comparing version
0.1.1
to
0.1.2
+22
.babelrc
{
"plugins": [
[ "babel-root-import", [
{
"rootPathPrefix": "@",
"rootPathSuffix": "src"
},
{
"rootPathPrefix": "#",
"rootPathSuffix": "src/lib"
}
] ]
],
"env": {
"build": {
"presets": [ "es2015-rollup", "stage-2", "flow" ]
},
"development": {
"presets": [ "es2015", "stage-2", "flow" ]
}
}
}
{
"extends": "proper",
"plugins": [
"flowtype"
],
"env": {
"browser": true,
"node": true
},
"globals": {
Symbol: true
},
"rules": {
"arrow-parens": "off",
"flowtype/define-flow-type": 1,
"flowtype/use-flow-type": 1,
"no-constant-condition": "off"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

/* eslint no-unused-vars: off */
type num = number
type str = string
type obj = {}
type Unary<A, B> = (a: A) => B
type Binary<A, B, C> = (a: A, b: B) => C
type Dict<A> = { [k: str]: A }
type PrimitiveType = {
__primitive: true,
name: str
}
type ComplexType = Array<PrimitiveType | ComplexType>
type InhabitedType = PrimitiveType | ComplexType
type Kind = InhabitedType
type KindConstructor = (...a: Array<Kind>) => Kind
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.Algae=t.Algae||{})}(this,function(t){"use strict";function e(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:l,s=a(n,2),y=s[0],p=s[1],h=function(n){function a(){for(var n=arguments.length,o=Array(n),i=0;i<n;i++)o[i]=arguments[i];r(this,a);var c=u(this,(a.__proto__||Object.getPrototypeOf(a)).call(this,p));if(c.data={},o.length!==e.length)throw new TypeError(t+" expects "+e.length+" values, got "+o.length+": "+o.map(f).join(", "));return c.typeName=t,e.forEach(function(t,e){return c.data[t]=o[e]}),c}return i(a,n),o(a,[{key:"_getValues",value:function(){var t=this;return e.reduce(function(e,n){return[].concat(c(e),[t.data[n]])},[])}},{key:"extract",value:function(t){return t.apply(void 0,c(this._getValues()))}},{key:"toString",value:function(){var e=this._getValues(),n=e.length>0?" "+e.map(f).join(" "):"";return""+t+n}}],[{key:"of",value:function(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];return new(Function.prototype.bind.apply(a,[null].concat(e)))}},{key:"toString",value:function(){var n=e.length>0?" "+e.join(" "):"";return""+t+n}}]),a}(y);return h}function n(t,n,r){var o=Symbol(),i=function(e){if(e!==o)throw new Error(t+"() was called instead of one of its data constructors")};i.typeName=t,i.prototype.cases=function(t){var e=this.typeName;if(e in t)return this.extract(t[e]);if("_"in t)return this.extract(t._);throw new Error("Unable to match "+e+" against given patterns: "+Object.keys(t).join(", "))},i.toString=function(){return""+t},Object.keys(n).forEach(function(t){i[t]=e(t,n[t],[i,o]).of});var u=r||{},a=u.methods,c=void 0===a?{}:a,f=u.statics,l=void 0===f?{}:f;return Object.keys(c).forEach(function(t){return i.prototype[t]=c[t]}),Object.keys(l).forEach(function(t){return i[t]=l[t]}),i}var r=(function(){function t(t){this.value=t}function e(e){function n(t,e){return new Promise(function(n,o){var a={key:t,arg:e,resolve:n,reject:o,next:null};u?u=u.next=a:(i=u=a,r(t,e))})}function r(n,i){try{var u=e[n](i),a=u.value;a instanceof t?Promise.resolve(a.value).then(function(t){r("next",t)},function(t){r("throw",t)}):o(u.done?"return":"normal",u.value)}catch(t){o("throw",t)}}function o(t,e){switch(t){case"return":i.resolve({value:e,done:!0});break;case"throw":i.reject(e);break;default:i.resolve({value:e,done:!1})}i=i.next,i?r(i.key,i.arg):u=null}var i,u;this._invoke=n,"function"!=typeof e.return&&(this.return=void 0)}return"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)},{wrap:function(t){return function(){return new e(t.apply(this,arguments))}},await:function(e){return new t(e)}}}(),function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}),o=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),i=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},u=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},a=function(){function t(t,e){var n=[],r=!0,o=!1,i=void 0;try{for(var u,a=t[Symbol.iterator]();!(r=(u=a.next()).done)&&(n.push(u.value),!e||n.length!==e);r=!0);}catch(t){o=!0,i=t}finally{try{!r&&a.return&&a.return()}finally{if(o)throw i}}return n}return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),c=function(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)},f=function(t){return"string"==typeof t?'"'+t+'"':t},l=[function(){},Symbol()];t.dataType=n,t.tupleType=e,Object.defineProperty(t,"__esModule",{value:!0})});
import babel from 'rollup-plugin-babel';
import uglify from 'rollup-plugin-uglify';
export default {
entry: 'src/main.js',
moduleName: 'Algae',
format: 'umd',
plugins: [ babel(), uglify() ],
dest: 'index.js'
};
// @flow
import { dataType } from '@/type/data';
import { tupleType } from '@/type/tuple';
export { dataType, tupleType };
// @flow
import { tupleType } from '@/type/tuple';
type DataConstructors = {
[k: string]: Array<string>
}
type ProtoSpec = {
methods?: Dict<Function>,
statics?: Dict<*>
}
/**
* Creates a new data type
*/
export function dataType(name: string, spec: DataConstructors, protoSpec?: ProtoSpec): Class<*> {
const handshake = Symbol(),
DataType = function(arg) {
if (arg !== handshake) {
throw new Error(`${ name }() was called instead of one of its data constructors`);
}
};
DataType.typeName = name;
// cases() method
DataType.prototype.cases = function cases(patterns: Dict<Function>): * {
const tag = this.typeName;
if (tag in patterns) {
return this.extract(patterns[tag]);
}
else if ('_' in patterns) {
return this.extract(patterns._);
}
else {
throw new Error(`Unable to match ${ tag } against given patterns: ${ Object.keys(patterns).join(', ') }`);
}
};
// toString() method
DataType.toString = function toString(): string {
return `${ name }`;
};
// create data constructors
Object.keys(spec)
.forEach(ctor => {
DataType[ctor] = tupleType(ctor, spec[ctor], [ DataType, handshake ]).of;
});
const {
methods = {},
statics = {}
} = protoSpec || {};
// attach instance methods
Object.keys(methods)
.forEach(name => DataType.prototype[name] = methods[name]);
// attach static props
Object.keys(statics)
.forEach(name => DataType[name] = statics[name]);
return DataType;
}
// @flow
const wrapStr = (a) => typeof a === 'string' ? `"${ a }"` : a,
defaultExtend = [ function() {}, Symbol() ];
type ExtendSpec = [Class<*>, *]
/**
* Creates a new tuple type
*/
export function tupleType(name: str, fields: Array<string> = [], extendSpec: ExtendSpec = defaultExtend): Class<*> {
const [ Base, handshake ] = extendSpec;
const TupleType = class extends Base {
data: Dict<*> = {}
/**
* Constructs a new tuple instance
*/
constructor(...values: Array<*>) {
super(handshake);
if (values.length !== fields.length) {
throw new TypeError(`${ name } expects ${ fields.length } values, got ${ values.length }: ${ values.map(wrapStr).join(', ') }`);
}
this.typeName = name;
fields.forEach((field, i) => this.data[field] = values[i]);
}
/**
* Returns the tuple's values as an array
*/
_getValues(): Array<*> {
return fields.reduce((vals, field) => [ ...vals, this.data[field] ], []);
}
/**
* Passes the tuple's values into the given
* function and returns the result
*/
extract<A>(fn: (...a: Array<*>) => A): A {
return fn(...this._getValues());
}
/**
* Returns the tuple instance as a string
*/
toString(): string {
const values = this._getValues(),
valueStr = values.length > 0 ? ` ${ values.map(wrapStr).join(' ') }` : '';
return `${ name }${ valueStr }`;
}
/**
* Creates a tuple instance with the given values
*/
static of(...values): TupleType {
return new TupleType(...values);
}
/**
* Returns the tuple type as a string
*/
static toString(): string {
const fieldStr = fields.length > 0 ? ` ${ fields.join(' ') }` : '';
return `${ name }${ fieldStr }`;
}
};
return TupleType;
}
// @flow
import { dataType } from '@/type/data';
import test from 'tape';
test('dataType', t => {
t.plan(11);
const Maybe = dataType('Maybe', {
Just: [ 'a' ],
Nothing: []
}),
just42 = Maybe.Just(42),
none = Maybe.Nothing();
t.ok(just42 instanceof Maybe, 'instanceof');
t.ok(none instanceof Maybe, 'instanceof');
try {
Maybe();
t.fail('should have thrown an exception');
}
catch (err) {
t.equal(err.message, `Maybe() was called instead of one of its data constructors`, 'only data constructors can be called');
}
t.equal(just42.toString(), `Just 42`, 'toString');
t.equal(none.toString(), `Nothing`, 'toString');
t.deepEqual(just42, Maybe.Just(42));
t.deepEqual(none, Maybe.Nothing());
t.equal(just42.cases({
Just: () => 'just'
}), 'just', 'cases');
t.equal(none.cases({
Nothing: () => 'none'
}), 'none', 'cases');
t.equal(just42.cases({
_: () => 'default'
}), 'default', 'cases');
t.equal(none.cases({
_: () => 'default'
}), 'default', 'cases');
});
// @flow
import test from 'tape';
import { tupleType } from '@/type/tuple';
test('tupleType', t => {
t.plan(6);
const a = Math.random(),
b = Math.random(),
pair = tupleType('Pair', [ 'a', 'b' ]);
t.ok(pair.of('a', 'b') instanceof pair, 'instanceof');
t.equal(pair.of(a, b).data.a, a, 'data is set');
t.equal(pair.of(a, b).data.b, b, 'data is set');
t.equal(pair.of(a, b).toString(), `Pair ${ a } ${ b }`, 'toString()');
try {
pair.of('a');
t.fail('should have thrown an exception');
}
catch (err) {
t.equal(err.message, `Pair expects 2 values, got 1: "a"`, 'fails with too few args');
}
try {
pair.of('a', 'b', 'c');
t.fail('should have thrown an exception');
}
catch (err) {
t.equal(err.message, `Pair expects 2 values, got 3: "a", "b", "c"`, 'fails with too many args');
}
});
// @flow
// tests that the given class is a functor
export function testFunctor(t, Functor) {
const u = Functor.of(42),
id = a => a,
f = a => a + 1,
g = a => a * 2;
t.plan(2);
t.deepEqual(u.map(id), u, 'map() identity');
t.deepEqual(u.map(a => f(g(a))), u.map(g).map(f), 'map() composition');
}
// tests that the given class is an applicative
export function testApplicative(t, Applicative) {
const a = Applicative.of(2),
f = Applicative.of(a => a + 1),
g = Applicative.of(a => a * 2);
t.plan(4);
t.deepEqual(a.ap(g.ap(f.map(f => g => x => f(g(x))))), a.ap(g).ap(f), 'ap() composition');
t.deepEqual(a.ap(Applicative.of(x => x)), a, 'ap() identity');
t.deepEqual(Applicative.of(2).ap(Applicative.of(a => a + 1)), Applicative.of((a => a + 1)(2)), 'ap() homomorphism');
t.deepEqual(Applicative.of(3).ap(g), g.ap(Applicative.of(f => f(3))), 'interchange');
}
// tests that the given class is a monad
export function testMonad(t, Monad) {
const a = 23,
Ma = Monad.of(a),
f = a => Monad.of(a + 2),
g = a => Monad.of(a * 2);
t.plan(3);
t.deepEqual(Ma.andThen(f).andThen(g), Ma.andThen(a => f(a).andThen(g)), 'andThen() associativity');
t.deepEqual(Ma.andThen(f), f(a), 'andThen() left identity');
t.deepEqual(Ma.andThen(Monad.of), Ma, 'andThen() right identity');
}

Sorry, the diff of this file is too big to display

+2
-5
{
"name": "algae",
"version": "0.1.1",
"version": "0.1.2",
"description": "Algebraic Data Types for JavaScript",

@@ -15,6 +15,3 @@ "author": "Tim Kuminecz <tkuminecz@gmail.com>",

},
"files": [
"dist.js"
],
"main": "dist.js",
"main": "index.js",
"jsnext:main": "src/main.js",

@@ -21,0 +18,0 @@ "scripts": {

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.Algae=t.Algae||{})}(this,function(t){"use strict";function e(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:l,s=a(n,2),y=s[0],p=s[1],h=function(n){function a(){for(var n=arguments.length,o=Array(n),i=0;i<n;i++)o[i]=arguments[i];r(this,a);var c=u(this,(a.__proto__||Object.getPrototypeOf(a)).call(this,p));if(c.data={},o.length!==e.length)throw new TypeError(t+" expects "+e.length+" values, got "+o.length+": "+o.map(f).join(", "));return c.typeName=t,e.forEach(function(t,e){return c.data[t]=o[e]}),c}return i(a,n),o(a,[{key:"_getValues",value:function(){var t=this;return e.reduce(function(e,n){return[].concat(c(e),[t.data[n]])},[])}},{key:"extract",value:function(t){return t.apply(void 0,c(this._getValues()))}},{key:"toString",value:function(){var e=this._getValues(),n=e.length>0?" "+e.map(f).join(" "):"";return""+t+n}}],[{key:"of",value:function(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];return new(Function.prototype.bind.apply(a,[null].concat(e)))}},{key:"toString",value:function(){var n=e.length>0?" "+e.join(" "):"";return""+t+n}}]),a}(y);return h}function n(t,n,r){var o=Symbol(),i=function(e){if(e!==o)throw new Error(t+"() was called instead of one of its data constructors")};i.typeName=t,i.prototype.cases=function(t){var e=this.typeName;if(e in t)return this.extract(t[e]);if("_"in t)return this.extract(t._);throw new Error("Unable to match "+e+" against given patterns: "+Object.keys(t).join(", "))},i.toString=function(){return""+t},Object.keys(n).forEach(function(t){i[t]=e(t,n[t],[i,o]).of});var u=r||{},a=u.methods,c=void 0===a?{}:a,f=u.statics,l=void 0===f?{}:f;return Object.keys(c).forEach(function(t){return i.prototype[t]=c[t]}),Object.keys(l).forEach(function(t){return i[t]=l[t]}),i}var r=(function(){function t(t){this.value=t}function e(e){function n(t,e){return new Promise(function(n,o){var a={key:t,arg:e,resolve:n,reject:o,next:null};u?u=u.next=a:(i=u=a,r(t,e))})}function r(n,i){try{var u=e[n](i),a=u.value;a instanceof t?Promise.resolve(a.value).then(function(t){r("next",t)},function(t){r("throw",t)}):o(u.done?"return":"normal",u.value)}catch(t){o("throw",t)}}function o(t,e){switch(t){case"return":i.resolve({value:e,done:!0});break;case"throw":i.reject(e);break;default:i.resolve({value:e,done:!1})}i=i.next,i?r(i.key,i.arg):u=null}var i,u;this._invoke=n,"function"!=typeof e.return&&(this.return=void 0)}return"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)},{wrap:function(t){return function(){return new e(t.apply(this,arguments))}},await:function(e){return new t(e)}}}(),function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}),o=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),i=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},u=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},a=function(){function t(t,e){var n=[],r=!0,o=!1,i=void 0;try{for(var u,a=t[Symbol.iterator]();!(r=(u=a.next()).done)&&(n.push(u.value),!e||n.length!==e);r=!0);}catch(t){o=!0,i=t}finally{try{!r&&a.return&&a.return()}finally{if(o)throw i}}return n}return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),c=function(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)},f=function(t){return"string"==typeof t?'"'+t+'"':t},l=[function(){},Symbol()];t.dataType=n,t.tupleType=e,Object.defineProperty(t,"__esModule",{value:!0})});