New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@fraczak/k

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fraczak/k - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

codes.coffee

21

index.js
// Generated by CoffeeScript 2.7.0
(function() {
var compile, compile_file, fs, parse, run, runScriptOnData;
var compile, compile_file, finalize, fs, parse, run, runScriptOnData, t;

@@ -11,5 +11,22 @@ fs = require("fs");

t = require("./codes");
finalize = function(codes) {
var representatives;
representatives = t.minimize(codes).representatives;
codes = t.normalizeAll(codes, representatives);
return {codes, representatives};
};
compile = function(script) {
return (function({defs, exp}) {
run.defs = defs;
var codes, representatives;
// console.log defs
({codes, representatives} = finalize(defs.codes));
// console.log {codes, representatives}
run.defs = {
codes,
representatives,
rels: defs.rels
};
return function(data) {

@@ -16,0 +33,0 @@ return run(exp, data);

3

package.json
{
"name": "@fraczak/k",
"version": "1.1.0",
"version": "1.1.1",
"description": "k-language for JSON-like data transformation",

@@ -9,2 +9,3 @@ "main": "index.js",

"prepublishOnly": "coffee -c *.coffee; echo '#!/usr/bin/env node' | cat - k.js > k.sh",
"all": "npm run prepublishOnly; npm run prepare; npm run prepublishOnly",
"test": "coffee -c symbol-table.coffee; jison parser.jison; coffee test.coffee"

@@ -11,0 +12,0 @@ },

@@ -97,3 +97,3 @@ /* parser generated by jison 0.4.18 */

result = {defs: $$[$0-2], exp: $$[$0-1]};
result = {defs: {rels: s.rels, codes: s.codes}, exp: $$[$0-1]};
// console.log(JSON.stringify(result, "", 2));

@@ -104,9 +104,9 @@ return result;

case 5:
this.$ = {codes: {}, rels: {}};
break;
case 6:
$$[$0-4].rels[$$[$0-3]] = $$[$0-1]; this.$ = $$[$0-4];
s.add_rel($$[$0-3],$$[$0-1]);
break;
case 7:
$$[$0-5].codes[$$[$0-3]] = $$[$0-1]; this.$ = $$[$0-5];
s.add_code($$[$0-3],$$[$0-1]);
break;

@@ -119,3 +119,3 @@ case 8:

product: $$[$0-1].reduce((r, lc) => {
r[lc.label] = lc.code;
r[lc.label] = s.as_ref(lc.code);
return r }

@@ -125,3 +125,3 @@ , {})};

case 10:
this.$ = {code: "vector", vector: $$[$0-1]};
this.$ = {code: "vector", vector: s.as_ref($$[$0-1])};
break;

@@ -131,3 +131,3 @@ case 11:

union: $$[$0-1].reduce((r, lc) => {
r[lc.label] = lc.code;
r[lc.label] = s.as_ref(lc.code);
return r }

@@ -164,3 +164,3 @@ , {})};

case 24:
this.$ = {op: "union", union: $$[$0-1]};
this.$ = s.union($$[$0-1]);
break;

@@ -186,3 +186,3 @@ case 25:

case 33:
this.$ = {op: "code", code: $$[$0]};
this.$ = {op: "code", code: s.as_ref($$[$0])};
break;

@@ -189,0 +189,0 @@ case 34:

@@ -51,5 +51,5 @@ # k-language

[1, 2, 3] PLUS --> integer constant 6
[4, 4] TIMES toJSON --> string constant "16"
[3, 2] GT --> vector constant [3, 2]
[1, 2, 3] PLUS --> integer constant function 6
[4, 4] TIMES toJSON --> string constant function "16"
[3, 2] GT --> vector constant function [3, 2]
[3, 4] GT --> is not defined!

@@ -74,3 +74,3 @@

>;
{ x: (), "x!": factorial }
{ () x, factorial "x!" }

@@ -82,8 +82,12 @@ ## Value encodings (also called _types_ or _codes_)

* product, e.g., `{x: int, y: int, flag: bool}`
* disjoint union, e.g., `<x: string, y: bool>`
* product, e.g., `{int x, int y, bool flag}` (in JSON-like syntax `{x: int, y: int, flag: bool}`)
* disjoint union, e.g., `<{} true, {} false>` (in JSON-like syntax `<true: {}, false: {}>`)
* vector, e.g., `[ int ]` (all elements of the vector use the same encoding)
One can define recursive codes. E.g.,
One can define recursive codes. E.g.:
$ tree = <string leaf, {tree left, tree right} tree>;
or, the same in JSON-like notation:
$ tree = <leaf: string, tree: {left: tree, right: tree}>;

@@ -97,3 +101,3 @@

$tree = <leaf: string, tree: {left: tree, right: tree}>;
$tree = <string leaf, {tree left, tree right} tree>;
inc = [(),1] PLUS;

@@ -114,3 +118,3 @@ height = $ tree <

... errors ...
Usage: ./node_modules/.bin/k ( k-expr | -k k-file) [ json-file ]
Usage: ./node_modules/.bin/k ( k-expr | -k k-file) [ -1 ] [ json-file ]
E.g., cat '{"a": 10}' | ./node_modules/.bin/k '[(),()]'

@@ -117,0 +121,0 @@

@@ -16,4 +16,4 @@ // Generated by CoffeeScript 2.7.0

builtin = {
"_log_": function(arg) {
console.log(`_log_: ${JSON.stringify(arg)}`);
"_log!": function(arg) {
console.log(`_log!: ${JSON.stringify(arg)}`);
return arg;

@@ -115,10 +115,4 @@ },

verify = function(code, value) {
// console.log {code,value}
switch (code.code) {
case "ref":
return (function(c) {
if (c != null) {
return verify(c, value);
}
return codes[code.ref](value);
})(run.defs.codes[code.ref]);
case "vector":

@@ -144,2 +138,9 @@ return value.every(function(x) {

})(Object.keys(value));
default:
return (function(c) {
if (c != null) {
return verify(c, value);
}
return codes[code](value);
})(run.defs.codes[run.defs.representatives[code]]);
}

@@ -149,4 +150,5 @@ };

run = function(exp, value) {
var e, i, len, ref, result;
var e, i, len, ref, ref1, result;
if (value === void 0) {
// console.log {exp,value}
return void 0;

@@ -178,3 +180,3 @@ }

}
})(run.defs.rels[exp.ref]);
})((ref = run.defs.rels[exp.ref]) != null ? ref[0] : void 0);
case "dot":

@@ -200,5 +202,5 @@ return value[exp.dot];

case "union":
ref = exp.union;
for (i = 0, len = ref.length; i < len; i++) {
e = ref[i];
ref1 = exp.union;
for (i = 0, len = ref1.length; i < len; i++) {
e = ref1[i];
result = (function() {

@@ -205,0 +207,0 @@ try {

// Generated by CoffeeScript 2.7.0
(function() {
var comp, identity;
var add_code, add_rel, as_ref, codes, comp, identity, is_empty_rel, is_full_rel, is_identity_rel, rels, union;
rels = Object.create(null);
codes = Object.create(null);
codes["{}"] = {
code: "product",
product: {}
};
identity = {

@@ -9,9 +18,39 @@ op: "identity"

is_identity_rel = function(rel) {
return rel.op === "identity";
};
is_empty_rel = function(rel) {
return rel.op === "union" && rel.union.length === 0;
};
is_full_rel = function(rel) {
switch (rel.op) {
case "int":
case "str":
case "identity":
return true;
case "comp":
return rel.comp.every(is_full_rel);
case "product":
case "vector":
return Object.values(rel[rel.op]).every(is_full_rel);
default:
return false;
}
};
comp = function(e1, e2) {
if (e1.op === "identity") {
if (is_identity_rel(e1)) {
return e2;
}
if (e2.op === "identity") {
if (is_identity_rel(e2)) {
return e1;
}
if (is_empty_rel(e1)) {
return e1;
}
if (is_empty_rel(e2)) {
return e2;
}
if (e1.op === "comp" && e2.op === "comp") {

@@ -41,4 +80,51 @@ return {

module.exports = {identity, comp};
union = function(rels) {
var list;
list = [];
(function() {
var i, j, len, len1, new_rels, rel;
for (i = 0, len = rels.length; i < len; i++) {
rel = rels[i];
new_rels = rel.op === "union" ? rel.union : [rel];
for (j = 0, len1 = new_rels.length; j < len1; j++) {
rel = new_rels[j];
list.push(rel);
if (is_full_rel(rel)) {
return;
}
}
}
})();
if (list.length === 1) {
return list[0];
}
return {
op: "union",
union: list
};
};
as_ref = function(codeExp) {
var newName;
if (codeExp.code === "ref") {
return codeExp.ref;
}
newName = `:${Object.keys(codes).length}`;
codes[newName] = codeExp;
return newName;
};
add_rel = function(name, rel) {
if (rels[name] == null) {
rels[name] = [];
}
return rels[name].push(rel);
};
add_code = function(name, code) {
return codes[name] = code;
};
module.exports = {identity, comp, union, rels, codes, add_rel, add_code, as_ref};
}).call(this);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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