Initial commit

This commit is contained in:
Graham Kelly 2023-04-11 16:38:39 -04:00
commit 83ccc6370c
72 changed files with 18984 additions and 0 deletions

1
build.sh Normal file
View file

@ -0,0 +1 @@
node ./lcakec.js > lcake.js

87
lcake.js Normal file
View file

@ -0,0 +1,87 @@
// Credit to http://m1el.github.io/smallest-lambda-eval/
function Eval(prog, env) {
if (typeof prog === 'string') {
// lookup a variable
return env[prog];
} else if (prog[0] === '$') {
// constructing a new lambda
return (arg) => Eval(prog[2], { ...env, [prog[1]]: arg });
} else {
// function application
return Eval(prog[0], env)(Eval(prog[1], env));
}
}
function FromChurch(f) {
var i = 0;
f(function (x) {
i++;
return x;
})(function (x) {
return x;
})(undefined);
}
function ToChurch(i) {
return function (a) {
return function (b) {
var c = b;
for (let j = 0; j < i; j++)c = a(c);
return c
}
}
}
function FromArray(x) {
return x([])((a) => (v) => [...a, v])
}
function ToArray(x) {
return function (n) {
return function (s) {
var o = n;
for (var i of x) {
o = s(o)(i);
}
return o
}
}
}
function FromString(x) {
return String.fromCodePoint(...FromArray(x).map(FromChurch))
}
function ToString(s){
return toArray([...s].map(x => x.codePointAt(0)).map(FromChurch))
}
var opcodes = {
0: 'io_ref_new',
1: 'io_ref_read',
2: 'io_ref_write',
}
function RunIO(prog) {
return prog(function(x){
return x;
})(function (ty) {
return function (pay) {
return function (cont) {
var then = function(x){
return RunIO(cont(x))
}
switch (opcodes[FromChurch(ty)]) {
case 'io_ref_new':
var x = Math.random().toString();
RunIO["io_ref/" + x] = pay;
return then(ToString(x));
case 'io_ref_read':
return then(RunIO["io_ref/" + FromString(pay)])
case 'io_ref_write':
return pay(function(a){
return function(b){
RunIO["io_ref/" + FromString(a)] = b;
return then(b);
}
})
}
}
}
})
}
RunIO(Eval([["$","val",["$","p",["$","i",["p","val"]]]],["$","+",["$","0","0"]]],{}))

286
lcakec.js Normal file
View file

@ -0,0 +1,286 @@
let {reduceUsing} = require('shift-reducer')
const cyrb53 = (str, seed = 0) => {
let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
for(let i = 0, ch; i < str.length; i++) {
ch = str.charCodeAt(i);
h1 = Math.imul(h1 ^ ch, 2654435761);
h2 = Math.imul(h2 ^ ch, 1597334677);
}
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
};
let srcBase = `
// Credit to http://m1el.github.io/smallest-lambda-eval/
function Eval(prog, env) {
if (typeof prog === 'string') {
// lookup a variable
return env[prog];
} else if (prog[0] === '$') {
// constructing a new lambda
return (arg) => Eval(prog[2], { ...env, [prog[1]]: arg });
} else {
// function application
return Eval(prog[0], env)(Eval(prog[1], env));
}
}
function FromChurch(f) {
var i = 0;
f(function (x) {
i++;
return x;
})(function (x) {
return x;
})(undefined);
}
function ToChurch(i) {
return function (a) {
return function (b) {
var c = b;
for (let j = 0; j < i; j++)c = a(c);
return c
}
}
}
function FromArray(x) {
return x([])((a) => (v) => [...a, v])
}
function ToArray(x) {
return function (n) {
return function (s) {
var o = n;
for (var i of x) {
o = s(o)(i);
}
return o
}
}
}
function FromString(x) {
return String.fromCodePoint(...FromArray(x).map(FromChurch))
}
function ToString(s){
return toArray([...s].map(x => x.codePointAt(0)).map(FromChurch))
}
var opcodes = {
0: 'io_ref_new',
1: 'io_ref_read',
2: 'io_ref_write',
}
function RunIO(prog) {
return prog(function(x){
return x;
})(function (ty) {
return function (pay) {
return function (cont) {
var then = function(x){
return RunIO(cont(x))
}
switch (opcodes[FromChurch(ty)]) {
case 'io_ref_new':
var x = Math.random().toString();
RunIO["io_ref/" + x] = pay;
return then(ToString(x));
case 'io_ref_read':
return then(RunIO["io_ref/" + FromString(pay)])
case 'io_ref_write':
return pay(function(a){
return function(b){
RunIO["io_ref/" + FromString(a)] = b;
return then(b);
}
})
}
}
}
})
}`
function vari(x){
return x;
}
function abs(a,b){
return ['$',a,b]
}
function app(a,b){
return [a,b]
}
function appx(...a){
var b = a[0];
for(var i in a){
if(i != 0){
b = app(b,a[i])
}
}
return b
}
function subst(x,b,c){
if(typeof x == 'string'){
if(x === b)return c;
return x;
}else if (x[0] == '$'){
if(x[1] == b){
return x;
}
return abs(x[1],subst(x[2],b,c));
}
return app(subst(x[0],b,c),subst(x[1],b,c))
}
Function.prototype.fuse = function(){
var a = abs('$$0',this('$$0'))
var h = cyrb53(JSON.stringify(a))
return abs(`h${h}`,subst(a[2],'$$0',`h${h}`))
}
function createChurch(n){
var v = '0';
for(let i = 0; i < n; i++){
v = ['+',v];
}
return ['$','+',['$','0',v]]
}
function createList(n){
var v = 'null';
for(var i of n){
v = app('push')(v)(i);
}
return abs('null',abs('push',v))
}
function createString(s){
return createList([...s].map(x => x.codePointAt(0)).map(createChurch))
}
function createBool(b){
return abs('x',app('y',b ? 'x' : 'y'))
}
var yb = abs('f',abs('x',app('x',abs('z',app(app(app('f','f'),'x'),'z')))))
var y = app(yb,yb)
var IO = {
pure: abs('val',abs('p',abs('i',app('p','val')))),
bind: app(y,abs('bind',abs('m',abs('f',app(app('m','f'),abs('ty',abs('pay',abs('cont',abs('h',app(app(app('h','ty'),'pay'),abs('x',app(app('bind',app('cont','x')),'f')))))))))))),
name: 'io'
}
var createIO = abs('t',abs('p',abs('pu',abs('i',appx('i','t','p',IO.pure)))))
var newIORef = appx(createIO,createChurch(0))
var readIORef = appx(createIO,createChurch(1))
var writeIORef = abs('r',abs('v',appx(createIO,createChurch(2),abs('f',appx('f','r','v')))))
function warp(x,{pure,bind,name} = IO){
if(typeof x == 'string'){
return app(pure,name + '$' + x);
}else if (x[0] == '$'){
return app(pure,abs(name + '$' + x[1],warpIO(x[2])))
}else if(x[0] == 'splice_' + name){
return x[1];
}
return appx(bind,warp(x[0],{pure,bind,name}),abs('f',appx(bind,warp(x[1],{pure,bind,name}),abs('x',app('f','x')))))
}
var pred = abs('n',abs('f',abs('x',app(app(app('n',abs('g',abs('h',app('h',app('g','f'))))),abs('u','x')),abs('u','u')))))
var isZero = abs('n',app(app('n',abs('x',createBool(false)),createBool(true))))
var l_and = abs('p',abs('q',app(app('p','q'),'p')))
var minus = abs('a',abs('b',app(app('b',pred),'a')))
var leq = abs('m',abs('n',app(isZero,app(app(minus,'m'),'n'))))
var eq = abs('m',abs('n',app(app(l_and,app(app(leq,'m'),'n')),app(app(leq,'n'),'m'))))
var tru = abs('t',abs('f','t'))
var fals = abs('t',abs('f','f'))
var jsFun = abs('x',abs('fn',abs('truthy',abs('falsy',app('fn','x')))))
var jsTruthy = abs('t',abs('v',abs('fn',abs('truthy',abs('falsy',app(app('truthy','t'),'v'))))))
var jsFalsy = abs('t',app('fn',abs('truthy',abs('falsy',app('falsy','t')))))
var sempty = abs('e',abs('c','e'))
var scons = abs('h',abs('t',abs('e',abs('c',appx('c','h','t')))))
var stoc = appx(y,function(a){
return abs('l',abs('n',abs('c',appx('l','n',abs('a',abs('b',appx('c','a',appx(a,'b','n','c'))))))))
}.fuse)
var ctos = abs('a',appx('a',sempty,scons))
var strEq = appx(y,abs('strEq',abs('a',abs('b',appx('a',appx('b',tru,abs('_a',abs('_b',fals))),abs('c',abs('d',appx('b',fals,abs('e',abs('f',appx(eq,'c','e',appx('strEq','d','f'),fals)))))))))))
var churchSucc = abs('x',abs('o',abs('s',app('s',appx('x','o','s')))))
var TY_NULL = 0;
var jsNull = app(jsFalsy,createChurch(TY_NULL))
var getVarS = getGetVarSlot => abs('v',abs('p',abs('b',abs('l',appx(stoc,'l',abs('_',appx(free.pure,jsNull)),abs('f',abs('p',appx(getGetVarSlot('f'),'p'))),'v')))))
var free = {
name: 'free',
pure: abs('x',abs('p',abs('b',abs('l',app('p','x'))))),
bind: abs('m',abs('f',abs('p',abs('b',abs('l',appx('b',appx('m','p','b','l'),abs('v',appx('f','v','p','b','l'))))))))
}
var addVarS = push => abs('f',abs('v',abs('p',abs('b',abs('l',appx('f',
abs('v',abs('x',app('p','v'))), // pure
abs('m',abs('f',abs('x',appx('b',app('m','x'),abs('v',appx('f','v','x')))))), // bind
appx(scons,push(
abs('m',abs('x','m')), //lift
abs('r',abs('v',abs('x',appx(isZero,'v',app(free.pure,'x'),abs('_', appx('r',appx(pred,'v'))))))), //getVar
),'l'),
'v'
))))))
var liftIOS = getLift => abs('i',abs('p',abs('b',app('l',appx(stoc,'l','i',abs('d',abs('m',app(getLift('d'),'m'))))))))
var readerT = old => ({
base: old,
lift: abs('x',abs('v','x')),
pure: abs('x',abs('v',app(old.pure,'x'))),
bind: abs('m',abs('f',abs('v',appx(old.bind,app('m','v'),abs('w',appx('f','w','v')))))),
name: `readerT(${old.name})`
})
var contT = old => ({
base: old,
lift: abs('x',abs('cc',appx(old.bind,'x','cc'))),
pure: abs('x',abs('cc',app('cc','x'))),
bind: abs('m',abs('f',abs('cc',app('m',abs('x',appx('f','x','cc')))))),
name: `contT(${old.name})`
})
var js = contT(readerT(free))
var getVarB = getGetVarSlot => abs('j',app(js.lift,abs('vs',appx(getVarS(getGetVarSlot),appx('vs','j')))))
var liftIOB = getLift => abs('i',app(js.lift,abs('v',appx(liftIOS(getLift),'i'))))
var pushBase = (a,b) => abs('f',appx('f',a,b))
var addVarB = push => abs('m',abs('v',abs('f',appx(js.base.lift,addVarS(push),appx('f',abs('n',appx(strEq,'m','n',createChurch(0),app(churchSucc,app('f','n'))))),'v'))));
var addVar = addVarB(pushBase)
js.addVar = addVar
var getGetVarSlotBase = x => app(x,abs('a',abs('b','b')))
var getLiftBase = x => app(x,abs('a',abs('b','a')))
var getVar = getVarB(getGetVarSlotBase)
js.getVar = getVar
var liftIOJ = liftIOB(getLiftBase)
js.liftIO = liftIOJ
console.log(srcBase + `
RunIO(Eval(${JSON.stringify(app(IO.pure,createChurch(0)))},{}))
`)

83
node_modules/.package-lock.json generated vendored Normal file
View file

@ -0,0 +1,83 @@
{
"name": "lambdaworld",
"version": "0.0.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"node_modules/multimap": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/multimap/-/multimap-1.1.0.tgz",
"integrity": "sha512-0ZIR9PasPxGXmRsEF8jsDzndzHDj7tIav+JUmvIFB/WHswliFnquxECT/De7GR4yg99ky/NlRKJT82G1y271bw=="
},
"node_modules/shift-ast": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/shift-ast/-/shift-ast-7.0.0.tgz",
"integrity": "sha512-O0INwsZa1XH/lMSf52udGnjNOxKBLxFiZHt0Ys3i6bqtwuGEA3eDR4+e0qJELIsCy8+BiTtlTgQzP76K1ehipQ=="
},
"node_modules/shift-parser": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/shift-parser/-/shift-parser-8.0.0.tgz",
"integrity": "sha512-IShW1wGhvA5e+SPNVQ+Dwi/Be6651F2jZc6wwYHbYW7PiswAYfvR/v3Q+CjjxsVCna5L6J5OtR6y+tkkCzvCfw==",
"dependencies": {
"multimap": "^1.0.2",
"shift-ast": "7.0.0",
"shift-reducer": "7.0.0",
"shift-regexp-acceptor": "3.0.0"
}
},
"node_modules/shift-reducer": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/shift-reducer/-/shift-reducer-7.0.0.tgz",
"integrity": "sha512-9igIDMHzp1+CkQZITGHM1sAd9jqMPV0vhqHuh8jlYumHSMIwsYcrDeo1tlpzNRUnfbEq1nLyh8Bf1YU8HGUE7g==",
"dependencies": {
"shift-ast": "7.0.0"
}
},
"node_modules/shift-regexp-acceptor": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/shift-regexp-acceptor/-/shift-regexp-acceptor-3.0.0.tgz",
"integrity": "sha512-98UKizBjHY6SjjLUr51YYw4rtR+vxjGFm8znqNsoahesAI8Y9+WVAyiBCxxkov1KSDhW0Wz8FwwUqHnlFnjdUg==",
"dependencies": {
"unicode-match-property-ecmascript": "1.0.4",
"unicode-match-property-value-ecmascript": "1.0.2",
"unicode-property-aliases-ecmascript": "1.0.4"
}
},
"node_modules/unicode-canonical-property-names-ecmascript": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz",
"integrity": "sha512-jDrNnXWHd4oHiTZnx/ZG7gtUTVp+gCcTTKr8L0HjlwphROEW3+Him+IpvC+xcJEFegapiMZyZe02CyuOnRmbnQ==",
"engines": {
"node": ">=4"
}
},
"node_modules/unicode-match-property-ecmascript": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/unicode-match-property-ecmascript/-/unicode-match-property-ecmascript-1.0.4.tgz",
"integrity": "sha512-L4Qoh15vTfntsn4P1zqnHulG0LdXgjSO035fEpdtp6YxXhMT51Q6vgM5lYdG/5X3MjS+k/Y9Xw4SFCY9IkR0rg==",
"dependencies": {
"unicode-canonical-property-names-ecmascript": "^1.0.4",
"unicode-property-aliases-ecmascript": "^1.0.4"
},
"engines": {
"node": ">=4"
}
},
"node_modules/unicode-match-property-value-ecmascript": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/unicode-match-property-value-ecmascript/-/unicode-match-property-value-ecmascript-1.0.2.tgz",
"integrity": "sha512-Rx7yODZC1L/T8XKo/2kNzVAQaRE88AaMvI1EF/Xnj3GW2wzN6fop9DDWuFAKUVFH7vozkz26DzP0qyWLKLIVPQ==",
"engines": {
"node": ">=4"
}
},
"node_modules/unicode-property-aliases-ecmascript": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-1.0.4.tgz",
"integrity": "sha512-2WSLa6OdYd2ng8oqiGIWnJqyFArvhn+5vgx5GTxMbUYjCYKUcuKS62YLFF0R/BDGlB1yzXjQOLtPAfHsgirEpg==",
"engines": {
"node": ">=4"
}
}
}
}

41
node_modules/multimap/.jshintrc generated vendored Normal file
View file

@ -0,0 +1,41 @@
{
"passfail" : false,
"maxerr" : 20,
"browser" : false,
"node" : true,
"debug" : false,
"devel" : true,
"es5" : false,
"strict" : false,
"globalstrict" : false,
"asi" : false,
"laxbreak" : false,
"bitwise" : false,
"boss" : true,
"curly" : false,
"eqeqeq" : false,
"eqnull" : false,
"evil" : true,
"expr" : true,
"forin" : false,
"immed" : true,
"latedef" : false,
"loopfunc" : true,
"noarg" : true,
"regexp" : true,
"regexdash" : false,
"scripturl" : true,
"shadow" : true,
"supernew" : false,
"undef" : false,
"newcap" : false,
"proto" : true,
"noempty" : true,
"nonew" : false,
"nomen" : false,
"onevar" : false,
"plusplus" : false,
"sub" : false,
"trailing" : false,
"white" : false
}

6
node_modules/multimap/.travis.yml generated vendored Normal file
View file

@ -0,0 +1,6 @@
language: node_js
node_js:
- "0.10"
- "0.11"
script: npm run test

136
node_modules/multimap/README.md generated vendored Normal file
View file

@ -0,0 +1,136 @@
# Multimap - Map which Allow Multiple Values for the same Key
[![NPM version](https://badge.fury.io/js/multimap.svg)](http://badge.fury.io/js/multimap)
[![Build Status](https://travis-ci.org/villadora/multi-map.png?branch=master)](https://travis-ci.org/villadora/multi-map)
## Install
```bash
npm install multimap --save
```
## Usage
If you'd like to use native version when it exists and fallback to polyfill if it doesn't, but without implementing `Map` on global scope, do:
```javascript
var Multimap = require('multimap');
var m = new Multimap();
```
If the global es6 `Map` exists or `Multimap.Map` is set, `Multimap` will use the `Map` as inner store, that means Object can be used as key.
```javascript
var Multimap = require('multimap');
// if harmony is on
/* nothing need to do */
// or if you are using es6-shim
Multimap.Map = ShimMap;
var m = new Multimap();
var key = {};
m.set(key, 'one');
```
Otherwise, an object will be used, all the keys will be transformed into string.
### In Modern Browser
Just download the `index.js` as `Multimap.js`.
```
<script src=Multimap.js"></script>
<script>
var map = new Multimap([['a', 1], ['b', 2], ['c', 3]]);
map = map.set('b', 20);
map.get('b'); // [2, 20]
</script>
```
Or use as an AMD loader:
```
require(['./Multimap.js'], function (Multimap) {
var map = new Multimap([['a', 1], ['b', 2], ['c', 3]]);
map = map.set('b', 20);
map.get('b'); // [2, 20]
});
```
* Browsers should support `Object.defineProperty` and `Array.prototype.forEach`.
## API
Following shows how to use `Multimap`:
```javascript
var Multimap = require('multimap');
var map = new Multimap([['a', 'one'], ['b', 1], ['a', 'two'], ['b', 2]]);
map.size; // 4
map.count; // 2
map.get('a'); // ['one', 'two']
map.get('b'); // [1, 2]
map.has('a'); // true
map.has('foo'); // false
map.has('a', 'one'); // true
map.has('b', 3); // false
map.set('a', 'three');
map.size; // 5
map.count; // 2
map.get('a'); // ['one', 'two', 'three']
map.set('b', 3, 4);
map.size; // 7
map.count; // 2
map.delete('a', 'three'); // true
map.delete('x'); // false
map.delete('a', 'four'); // false
map.delete('b'); // true
map.size; // 2
map.count; // 1
map.set('b', 1, 2);
map.size; // 4
map.count; // 2
map.forEach(function (value, key) {
// iterates { 'one', 'a' }, { 'two', 'a' }, { 1, b }, { 2, 'b' }
});
map.forEachEntry(function (entry, key) {
// iterates {['one', 'two'], 'a' }, {[1, 2], 'b' }
});
var keys = map.keys(); // iterator with ['a', 'b']
keys.next().value; // 'a'
var values = map.values(); // iterator ['one', 'two', 1, 2]
map.clear(); // undefined
map.size; // 0
map.count; // 0
```
## License
(The MIT License)
Copyright (c) 2013, Villa.Gao <jky239@gmail.com>;
All rights reserved.

226
node_modules/multimap/index.js generated vendored Normal file
View file

@ -0,0 +1,226 @@
"use strict";
/* global module, define */
function mapEach(map, operation){
var keys = map.keys();
var next;
while(!(next = keys.next()).done) {
operation(map.get(next.value), next.value, map);
}
}
var Multimap = (function() {
var mapCtor;
if (typeof Map !== 'undefined') {
mapCtor = Map;
if (!Map.prototype.keys) {
Map.prototype.keys = function() {
var keys = [];
this.forEach(function(item, key) {
keys.push(key);
});
return keys;
};
}
}
function Multimap(iterable) {
var self = this;
self._map = mapCtor;
if (Multimap.Map) {
self._map = Multimap.Map;
}
self._ = self._map ? new self._map() : {};
if (iterable) {
iterable.forEach(function(i) {
self.set(i[0], i[1]);
});
}
}
/**
* @param {Object} key
* @return {Array} An array of values, undefined if no such a key;
*/
Multimap.prototype.get = function(key) {
return this._map ? this._.get(key) : this._[key];
};
/**
* @param {Object} key
* @param {Object} val...
*/
Multimap.prototype.set = function(key, val) {
var args = Array.prototype.slice.call(arguments);
key = args.shift();
var entry = this.get(key);
if (!entry) {
entry = [];
if (this._map)
this._.set(key, entry);
else
this._[key] = entry;
}
Array.prototype.push.apply(entry, args);
return this;
};
/**
* @param {Object} key
* @param {Object=} val
* @return {boolean} true if any thing changed
*/
Multimap.prototype.delete = function(key, val) {
if (!this.has(key))
return false;
if (arguments.length == 1) {
this._map ? (this._.delete(key)) : (delete this._[key]);
return true;
} else {
var entry = this.get(key);
var idx = entry.indexOf(val);
if (idx != -1) {
entry.splice(idx, 1);
return true;
}
}
return false;
};
/**
* @param {Object} key
* @param {Object=} val
* @return {boolean} whether the map contains 'key' or 'key=>val' pair
*/
Multimap.prototype.has = function(key, val) {
var hasKey = this._map ? this._.has(key) : this._.hasOwnProperty(key);
if (arguments.length == 1 || !hasKey)
return hasKey;
var entry = this.get(key) || [];
return entry.indexOf(val) != -1;
};
/**
* @return {Array} all the keys in the map
*/
Multimap.prototype.keys = function() {
if (this._map)
return makeIterator(this._.keys());
return makeIterator(Object.keys(this._));
};
/**
* @return {Array} all the values in the map
*/
Multimap.prototype.values = function() {
var vals = [];
this.forEachEntry(function(entry) {
Array.prototype.push.apply(vals, entry);
});
return makeIterator(vals);
};
/**
*
*/
Multimap.prototype.forEachEntry = function(iter) {
mapEach(this, iter);
};
Multimap.prototype.forEach = function(iter) {
var self = this;
self.forEachEntry(function(entry, key) {
entry.forEach(function(item) {
iter(item, key, self);
});
});
};
Multimap.prototype.clear = function() {
if (this._map) {
this._.clear();
} else {
this._ = {};
}
};
Object.defineProperty(
Multimap.prototype,
"size", {
configurable: false,
enumerable: true,
get: function() {
var total = 0;
mapEach(this, function(value){
total += value.length;
});
return total;
}
});
Object.defineProperty(
Multimap.prototype,
"count", {
configurable: false,
enumerable: true,
get: function() {
return this._.size;
}
});
var safariNext;
try{
safariNext = new Function('iterator', 'makeIterator', 'var keysArray = []; for(var key of iterator){keysArray.push(key);} return makeIterator(keysArray).next;');
}catch(error){
// for of not implemented;
}
function makeIterator(iterator){
if(Array.isArray(iterator)){
var nextIndex = 0;
return {
next: function(){
return nextIndex < iterator.length ?
{value: iterator[nextIndex++], done: false} :
{done: true};
}
};
}
// Only an issue in safari
if(!iterator.next && safariNext){
iterator.next = safariNext(iterator, makeIterator);
}
return iterator;
}
return Multimap;
})();
if(typeof exports === 'object' && module && module.exports)
module.exports = Multimap;
else if(typeof define === 'function' && define.amd)
define(function() { return Multimap; });

34
node_modules/multimap/package.json generated vendored Normal file
View file

@ -0,0 +1,34 @@
{
"name": "multimap",
"version": "1.1.0",
"description": "multi-map which allow multiple values for the same key",
"main": "index.js",
"scripts": {
"lint": "./node_modules/.bin/jshint *.js test/*.js",
"test": "npm run lint; node test/index.js;node test/es6map.js"
},
"repository": {
"type": "git",
"url": "git://github.com/villadora/multi-map.git"
},
"bugs": {
"url": "https://github.com/villadora/multi-map/issues"
},
"keywords": [
"keys",
"map",
"multiple"
],
"dependencies": {},
"devDependencies": {
"chai": "~1.7.2",
"es6-shim": "^0.13.0",
"jshint": "~2.1.9"
},
"readmeFilename": "README.md",
"author": {
"name": "villa.gao",
"email": "jky239@gmail.com"
},
"license": "MIT"
}

86
node_modules/multimap/test/es6map.js generated vendored Normal file
View file

@ -0,0 +1,86 @@
"use strict";
var assert = require('chai').assert;
require('es6-shim');
var Multimap = require('..');
var map = new Multimap([
['a', 'one'],
['b', 1],
['a', 'two'],
['b', 2]
]);
assert.equal(map.size, 4);
assert.equal(map.get('a').length, 2);
assert.equal(map.get('a')[0], 'one'); // ['one', 'two']
assert.equal(map.get('a')[1], 'two'); // ['one', 'two']
assert.equal(map.get('b').length, 2);
assert.equal(map.get('b')[0], 1); // [1, 2]
assert.equal(map.get('b')[1], 2); // [1, 2]
assert(map.has('a'), "map contains key 'a'");
assert(!map.has('foo'), "map does not contain key 'foo'");
assert(map.has('a', 'one'), "map contains entry 'a'=>'one'");
assert(!map.has('b', 3), "map does not contain entry 'b'=>3");
map.set('a', 'three');
assert.equal(map.size, 5);
assert.equal(map.get('a').length, 3); // ['one', 'two', 'three']
map.set('b', 3, 4);
assert.equal(map.size, 7);
assert(map.delete('a', 'three'), "delete 'a'=>'three'");
assert.equal(map.size, 6);
assert(!map.delete('x'), "empty 'x' for delete");
assert(!map.delete('a', 'four'), "no such entry 'a'=>'four'");
assert(map.delete('b'), "delete all 'b'");
assert.equal(map.size, 2);
map.set('b', 1, 2);
assert.equal(map.size, 4); // 4
var cnt = 0;
map.forEach(function(value, key) {
// iterates { 'a', 'one' }, { 'a', 'two' }, { 'b', 1 }, { 'b', 2 }
cnt++;
assert(key == 'a' || key == 'b', "key must be either 'a' or 'b'");
});
assert.equal(cnt, 4);
cnt = 0;
map.forEachEntry(function(entry, key) {
// iterates { 'a', ['one', 'two'] }, { 'b', [1, 2] }
cnt++;
assert(key == 'a' || key == 'b', "key must be either 'a' or 'b'");
assert.equal(entry.length, 2);
});
assert.equal(cnt, 2);
var keys = map.keys(); // ['a', 'b']
assert.equal(keys.next().value, 'a');
assert.equal(keys.next().value, 'b');
assert(keys.next().done);
var values = map.values(); // ['one', 'two', 1, 2]
assert.equal(values.next().value, 'one');
assert.equal(values.next().value, 'two');
assert.equal(values.next().value, 1);
assert.equal(values.next().value, 2);
assert(values.next().done);
map.clear();
assert.equal(map.size, 0);

91
node_modules/multimap/test/index.js generated vendored Normal file
View file

@ -0,0 +1,91 @@
"use strict";
var assert = require('chai').assert;
var Multimap = require('..');
var map = new Multimap([
['a', 'one'],
['b', 1],
['a', 'two'],
['b', 2]
]);
assert.equal(map.size, 4);
assert.equal(map.count, 2);
assert.equal(map.get('a').length, 2);
assert.equal(map.get('a')[0], 'one'); // ['one', 'two']
assert.equal(map.get('a')[1], 'two'); // ['one', 'two']
assert.equal(map.get('b').length, 2);
assert.equal(map.get('b')[0], 1); // [1, 2]
assert.equal(map.get('b')[1], 2); // [1, 2]
assert(map.has('a'), "map contains key 'a'");
assert(!map.has('foo'), "map does not contain key 'foo'");
assert(map.has('a', 'one'), "map contains entry 'a'=>'one'");
assert(!map.has('b', 3), "map does not contain entry 'b'=>3");
map.set('a', 'three');
assert.equal(map.size, 5);
assert.equal(map.count, 2);
assert.equal(map.get('a').length, 3); // ['one', 'two', 'three']
map.set('b', 3, 4);
assert.equal(map.size, 7);
assert.equal(map.count, 2);
assert(map.delete('a', 'three'), "delete 'a'=>'three'");
assert.equal(map.size, 6);
assert.equal(map.count, 2);
assert(!map.delete('x'), "empty 'x' for delete");
assert(!map.delete('a', 'four'), "no such entry 'a'=>'four'");
assert(map.delete('b'), "delete all 'b'");
assert.equal(map.size, 2);
assert.equal(map.count, 1);
map.set('b', 1, 2);
assert.equal(map.size, 4); // 4
assert.equal(map.count, 2);
var cnt = 0;
map.forEach(function(value, key) {
// iterates { 'a', 'one' }, { 'a', 'two' }, { 'b', 1 }, { 'b', 2 }
cnt++;
assert(key == 'a' || key == 'b', "key must be either 'a' or 'b'");
});
assert.equal(cnt, 4);
cnt = 0;
map.forEachEntry(function(entry, key) {
// iterates { 'a', ['one', 'two'] }, { 'b', [1, 2] }
cnt++;
assert(key == 'a' || key == 'b', "key must be either 'a' or 'b'");
assert.equal(entry.length, 2);
});
assert.equal(cnt, 2);
var keys = map.keys(); // ['a', 'b']
assert.equal(keys.next().value, 'a');
assert.equal(keys.next().value, 'b');
assert(keys.next().done);
var values = map.values(); // ['one', 'two', 1, 2]
assert.equal(values.next().value, 'one');
assert.equal(values.next().value, 'two');
assert.equal(values.next().value, 1);
assert.equal(values.next().value, 2);
assert(values.next().done);
map.clear();
assert.equal(map.size, 0);
assert.equal(map.count, 0);

92
node_modules/multimap/test/test.html generated vendored Normal file
View file

@ -0,0 +1,92 @@
<html>
<head>
<title>MultiMap Tests</title>
<script src="../node_modules/chai/chai.js"></script>
<script src="../index.js"></script>
<script type="text/javascript">
var assert = chai.assert;
var map = new Multimap([
['a', 'one'],
['b', 1],
['a', 'two'],
['b', 2]
]);
assert.equal(map.size, 4);
assert.equal(map.get('a').length, 2);
assert.equal(map.get('a')[0], 'one'); // ['one', 'two']
assert.equal(map.get('a')[1], 'two'); // ['one', 'two']
assert.equal(map.get('b').length, 2);
assert.equal(map.get('b')[0], 1); // [1, 2]
assert.equal(map.get('b')[1], 2); // [1, 2]
assert(map.has('a'), "map contains key 'a'");
assert(!map.has('foo'), "map does not contain key 'foo'");
assert(map.has('a', 'one'), "map contains entry 'a'=>'one'");
assert(!map.has('b', 3), "map does not contain entry 'b'=>3");
map.set('a', 'three');
assert.equal(map.size, 5);
assert.equal(map.get('a').length, 3); // ['one', 'two', 'three']
map.set('b', 3, 4);
assert.equal(map.size, 7);
assert(map.delete('a', 'three'), "delete 'a'=>'three'");
assert.equal(map.size, 6);
assert(!map.delete('x'), "empty 'x' for delete");
assert(!map.delete('a', 'four'), "no such entry 'a'=>'four'");
assert(map.delete('b'), "delete all 'b'");
assert.equal(map.size, 2);
map.set('b', 1, 2);
assert.equal(map.size, 4); // 4
var cnt = 0;
map.forEach(function(value, key) {
// iterates { 'a', 'one' }, { 'a', 'two' }, { 'b', 1 }, { 'b', 2 }
cnt++;
assert(key == 'a' || key == 'b', "key must be either 'a' or 'b'");
});
assert.equal(cnt, 4);
cnt = 0;
map.forEachEntry(function(entry, key) {
// iterates { 'a', ['one', 'two'] }, { 'b', [1, 2] }
cnt++;
assert(key == 'a' || key == 'b', "key must be either 'a' or 'b'");
assert.equal(entry.length, 2);
});
assert.equal(cnt, 2);
var keys = map.keys(); // ['a', 'b']
assert.equal(keys.next().value, 'a');
assert.equal(keys.next().value, 'b');
assert(keys.next().done);
var values = map.values(); // ['one', 'two', 1, 2]
assert.equal(values.next().value, 'one');
assert.equal(values.next().value, 'two');
assert.equal(values.next().value, 1);
assert.equal(values.next().value, 2);
assert(values.next().done);
map.clear();
assert.equal(map.size, 0);
</script>
</head>
<body>
</body>
</html>

202
node_modules/shift-ast/LICENSE generated vendored Normal file
View file

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.

63
node_modules/shift-ast/README.md generated vendored Normal file
View file

@ -0,0 +1,63 @@
Shift AST Constructors
======================
## About
This project provides constructors for
[Shift format](https://github.com/shapesecurity/shift-spec) AST nodes.
The resulting objects are suitable for use with the rest of the [Shift suite](http://shift-ast.org/).
There is a version with typechecking available as `shift-ast/checked` for use during development.
## Status
[Stable](http://nodejs.org/api/documentation.html#documentation_stability_index).
## Installation
```sh
npm install shift-ast
```
## Usage
```js
var AST = require("shift-ast"); // or "shift-ast/checked"
var myAstFragment = new AST.LabeledStatement({
label: "label",
body: new AST.EmptyStatement
});
```
## Contributing
* Open a Github issue with a description of your desired change. If one exists already, leave a message stating that you are working on it with the date you expect it to be complete.
* Fork this repo, and clone the forked repo.
* Install dependencies with `npm install`.
* Build and test in your environment with `npm run build && npm test`.
* Create a feature branch. Make your changes. Add tests.
* Build and test in your environment with `npm run build && npm test`.
* Make a commit that includes the text "fixes #*XX*" where *XX* is the Github issue.
* Open a Pull Request on Github.
## License
Copyright 2014 Shape Security, Inc.
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.

17
node_modules/shift-ast/checked.js generated vendored Normal file
View file

@ -0,0 +1,17 @@
/**
* Copyright 2016 Shape Security, Inc.
*
* 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.
*/
module.exports = require('./gen/checked');

19
node_modules/shift-ast/gen/checked.d.ts generated vendored Normal file
View file

@ -0,0 +1,19 @@
// Generated by scripts/generate-dts.js.
/**
* Copyright 2019 Shape Security, Inc.
*