Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@gram-data/gram-stringify

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gram-data/gram-stringify - npm Package Compare versions

Comparing version 0.3.3 to 0.3.4

38

dist/gram-stringify.cjs.development.js

@@ -46,6 +46,10 @@ 'use strict';

} else {
return recordToString(v);
return objectToString(v);
}
};
var propertyToString = function propertyToString(property) {
return property.name + ":" + toStringValue(property.value);
};
var recordToString = function recordToString(record) {

@@ -58,7 +62,11 @@ var fields = record.map(function (property, i) {

var recordMapToString = function recordMapToString(record) {
var fields = Object.entries(record).map(function (_ref, i) {
var arrayToString = function arrayToString(xs) {
return "[" + xs.map(stringify).join(',') + "]";
};
var objectToString = function objectToString(o) {
var fields = Object.entries(o).map(function (_ref, i) {
var name = _ref[0],
value = _ref[1];
return "" + (i > 0 ? ',' : '') + name + ":" + toStringValue(value);
return "" + (i > 0 ? ',' : '') + name + ":" + stringify(value);
});

@@ -114,3 +122,11 @@ return "{" + fields.join('') + "}";

if (Array.isArray(ast)) {
return ast.map(stringify).join(' ');
if (ast.length > 0) {
var element = ast[0];
if (gramAst.isGramPath(element)) {
return ast.map(stringify).join(' ');
} else {
return arrayToString(ast);
}
} else return '[]';
} else if (ast.type !== undefined) {

@@ -123,5 +139,15 @@ switch (ast.type) {

return stringify(ast.children);
case 'property':
return propertyToString(ast);
default:
if (gramAst.isLiteral(ast)) {
return toStringLiteral(ast);
}
return objectToString(ast);
}
} else if (typeof ast === 'object') {
return recordMapToString(ast);
return objectToString(ast);
}

@@ -128,0 +154,0 @@

2

dist/gram-stringify.cjs.production.min.js

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@gram-data/gram-ast"),r=function(e){switch(e.type){case"integer":case"boolean":case"octal":case"hexadecimal":case"decimal":return e.value;case"string":return"`"+e.value+"`";case"tagged":return e.tag+"`"+e.value+"`";case"measurement":return""+e.value+e.unit;default:return function(e){throw new Error("Unexpected object: "+e)}(e)}},n=function(n){return e.isGramLiteralArray(n)?"["+n.map((function(e){return r(e)})).join(",")+"]":e.isLiteral(n)?r(n):t(n)},t=function(e){return"{"+e.map((function(e,r){return(r>0?",":"")+e.name+":"+n(e.value)})).join("")+"}"},i=function(e){var r=e.id||"",n=e.labels&&e.labels.length>0?":"+e.labels.join(":"):"",i=e.record&&0!==Object.keys(e.record).length?t(e.record):"";return""+r+n+(((r.length>0||n.length>0)&&i.length)>0?" ":"")+i},a=function(e){return"("+i(e)+")"},l=function(r){var n;return r?""+(e.isGramEmptyPath(r)?"":e.isGramNode(r)?a(r):e.isGramEdge(r)?function r(n){var t="left"===n.kind?"<-":"-",l="right"===n.kind?"->":"-",c=e.isGramNode(n.children[0])?a(n.children[0]):r(n.children[0]),o=e.isGramNode(n.children[1])?a(n.children[1]):r(n.children[1]),u=i(n);return""+c+t+(u.length>0?"["+u+"]":"")+l+o}(r):(n=r).id||n.labels||n.record?function(e){var r=e.children&&e.children.length>0?l(e.children[0]):"",n=e.children&&e.children.length>1?l(e.children[1]):"",t="left"===e.kind?"<--":"right"===e.kind?"--\x3e":"either"===e.kind?"--":r.length>0&&n.length>0?",":"";return"["+i(e)+(t.length>0?" ":"")+t+(r.length>0?" ":"")+r+(n.length>0?" ":"")+n+"]"}(r):function(e){var r=e.children&&e.children.length>0?l(e.children[0]):"",n=e.children&&e.children.length>1?l(e.children[1]):"";return r+","+(n.length>0?" ":"")+n}(r)):""},c=function e(r){if(Array.isArray(r))return r.map(e).join(" ");if(void 0!==r.type)switch(r.type){case"path":return l(r);case"seq":return e(r.children)}else if("object"==typeof r)return"{"+Object.entries(r).map((function(e,r){return(r>0?",":"")+e[0]+":"+n(e[1])})).join("")+"}";throw new Error("Can't stringify <"+r+">")},o=function(r){if(e.isGramPath(r))return c(r);if(e.isGramSeq(r))return c(r);throw new Error("Don't know how to stringify \""+r.type+'"')};exports.gramStringifyPlugin=function(){this.Compiler=o},exports.stringify=c,exports.toGram=c;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@gram-data/gram-ast"),r=function(e){switch(e.type){case"integer":case"boolean":case"octal":case"hexadecimal":case"decimal":return e.value;case"string":return"`"+e.value+"`";case"tagged":return e.tag+"`"+e.value+"`";case"measurement":return""+e.value+e.unit;default:return function(e){throw new Error("Unexpected object: "+e)}(e)}},n=function(n){return e.isGramLiteralArray(n)?"["+n.map((function(e){return r(e)})).join(",")+"]":e.isLiteral(n)?r(n):i(n)},t=function(e){return"["+e.map(u).join(",")+"]"},i=function(e){return"{"+Object.entries(e).map((function(e,r){return(r>0?",":"")+e[0]+":"+u(e[1])})).join("")+"}"},a=function(e){var r=e.id||"",t=e.labels&&e.labels.length>0?":"+e.labels.join(":"):"",i=e.record&&0!==Object.keys(e.record).length?"{"+e.record.map((function(e,r){return(r>0?",":"")+e.name+":"+n(e.value)})).join("")+"}":"";return""+r+t+(((r.length>0||t.length>0)&&i.length)>0?" ":"")+i},l=function(e){return"("+a(e)+")"},c=function(r){var n;return r?""+(e.isGramEmptyPath(r)?"":e.isGramNode(r)?l(r):e.isGramEdge(r)?function r(n){var t="left"===n.kind?"<-":"-",i="right"===n.kind?"->":"-",c=e.isGramNode(n.children[0])?l(n.children[0]):r(n.children[0]),u=e.isGramNode(n.children[1])?l(n.children[1]):r(n.children[1]),o=a(n);return""+c+t+(o.length>0?"["+o+"]":"")+i+u}(r):(n=r).id||n.labels||n.record?function(e){var r=e.children&&e.children.length>0?c(e.children[0]):"",n=e.children&&e.children.length>1?c(e.children[1]):"",t="left"===e.kind?"<--":"right"===e.kind?"--\x3e":"either"===e.kind?"--":r.length>0&&n.length>0?",":"";return"["+a(e)+(t.length>0?" ":"")+t+(r.length>0?" ":"")+r+(n.length>0?" ":"")+n+"]"}(r):function(e){var r=e.children&&e.children.length>0?c(e.children[0]):"",n=e.children&&e.children.length>1?c(e.children[1]):"";return r+","+(n.length>0?" ":"")+n}(r)):""},u=function a(l){var u;if(Array.isArray(l))return l.length>0?e.isGramPath(l[0])?l.map(a).join(" "):t(l):"[]";if(void 0!==l.type)switch(l.type){case"path":return c(l);case"seq":return a(l.children);case"property":return(u=l).name+":"+n(u.value);default:return e.isLiteral(l)?r(l):i(l)}else if("object"==typeof l)return i(l);throw new Error("Can't stringify <"+l+">")},o=function(r){if(e.isGramPath(r))return u(r);if(e.isGramSeq(r))return u(r);throw new Error("Don't know how to stringify \""+r.type+'"')};exports.gramStringifyPlugin=function(){this.Compiler=o},exports.stringify=u,exports.toGram=u;
//# sourceMappingURL=gram-stringify.cjs.production.min.js.map

@@ -1,3 +0,2 @@

import { GramPath, GramSeq, GramPropertyMap } from '@gram-data/gram-ast';
export declare const stringify: (ast: GramPath | GramSeq | GramPath[] | GramPropertyMap) => string;
export declare const stringify: (ast: any | any[]) => string;
export default stringify;

@@ -1,2 +0,2 @@

import { isGramEmptyPath, isGramNode, isGramEdge, isGramLiteralArray, isLiteral, isGramPath, isGramSeq } from '@gram-data/gram-ast';
import { isGramPath, isLiteral, isGramLiteralArray, isGramEmptyPath, isGramNode, isGramEdge, isGramSeq } from '@gram-data/gram-ast';

@@ -42,6 +42,10 @@ var isEmpty = function isEmpty(o) {

} else {
return recordToString(v);
return objectToString(v);
}
};
var propertyToString = function propertyToString(property) {
return property.name + ":" + toStringValue(property.value);
};
var recordToString = function recordToString(record) {

@@ -54,7 +58,11 @@ var fields = record.map(function (property, i) {

var recordMapToString = function recordMapToString(record) {
var fields = Object.entries(record).map(function (_ref, i) {
var arrayToString = function arrayToString(xs) {
return "[" + xs.map(stringify).join(',') + "]";
};
var objectToString = function objectToString(o) {
var fields = Object.entries(o).map(function (_ref, i) {
var name = _ref[0],
value = _ref[1];
return "" + (i > 0 ? ',' : '') + name + ":" + toStringValue(value);
return "" + (i > 0 ? ',' : '') + name + ":" + stringify(value);
});

@@ -110,3 +118,11 @@ return "{" + fields.join('') + "}";

if (Array.isArray(ast)) {
return ast.map(stringify).join(' ');
if (ast.length > 0) {
var element = ast[0];
if (isGramPath(element)) {
return ast.map(stringify).join(' ');
} else {
return arrayToString(ast);
}
} else return '[]';
} else if (ast.type !== undefined) {

@@ -119,5 +135,15 @@ switch (ast.type) {

return stringify(ast.children);
case 'property':
return propertyToString(ast);
default:
if (isLiteral(ast)) {
return toStringLiteral(ast);
}
return objectToString(ast);
}
} else if (typeof ast === 'object') {
return recordMapToString(ast);
return objectToString(ast);
}

@@ -124,0 +150,0 @@

@@ -127,6 +127,10 @@ (function (global, factory) {

} else {
return recordToString(v);
return objectToString(v);
}
};
var propertyToString = function propertyToString(property) {
return property.name + ":" + toStringValue(property.value);
};
var recordToString = function recordToString(record) {

@@ -139,7 +143,11 @@ var fields = record.map(function (property, i) {

var recordMapToString = function recordMapToString(record) {
var fields = Object.entries(record).map(function (_ref, i) {
var arrayToString = function arrayToString(xs) {
return "[" + xs.map(stringify).join(',') + "]";
};
var objectToString = function objectToString(o) {
var fields = Object.entries(o).map(function (_ref, i) {
var name = _ref[0],
value = _ref[1];
return "" + (i > 0 ? ',' : '') + name + ":" + toStringValue(value);
return "" + (i > 0 ? ',' : '') + name + ":" + stringify(value);
});

@@ -195,3 +203,11 @@ return "{" + fields.join('') + "}";

if (Array.isArray(ast)) {
return ast.map(stringify).join(' ');
if (ast.length > 0) {
var element = ast[0];
if (isGramPath(element)) {
return ast.map(stringify).join(' ');
} else {
return arrayToString(ast);
}
} else return '[]';
} else if (ast.type !== undefined) {

@@ -204,5 +220,15 @@ switch (ast.type) {

return stringify(ast.children);
case 'property':
return propertyToString(ast);
default:
if (isLiteral(ast)) {
return toStringLiteral(ast);
}
return objectToString(ast);
}
} else if (typeof ast === 'object') {
return recordMapToString(ast);
return objectToString(ast);
}

@@ -209,0 +235,0 @@

@@ -1,2 +0,2 @@

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(((e=e||self).gram=e.gram||{},e.gram.stringify={}))}(this,(function(e){"use strict";var n=function(e){return!!e.type&&"path"===e.type},r=function(e){return n(e)&&e.children&&0===e.children.length&&"ø"!==e.id},t=function(e){return!!e.type&&!!e.value&&"property"!==e.type},i=function(e){switch(e.type){case"integer":case"boolean":case"octal":case"hexadecimal":case"decimal":return e.value;case"string":return"`"+e.value+"`";case"tagged":return e.tag+"`"+e.value+"`";case"measurement":return""+e.value+e.unit;default:return function(e){throw new Error("Unexpected object: "+e)}(e)}},c=function(e){return function(e){return Array.isArray(e)&&t(e[0])}(e)?"["+e.map((function(e){return i(e)})).join(",")+"]":t(e)?i(e):l(e)},l=function(e){return"{"+e.map((function(e,n){return(n>0?",":"")+e.name+":"+c(e.value)})).join("")+"}"},u=function(e){var n=e.id||"",r=e.labels&&e.labels.length>0?":"+e.labels.join(":"):"",t=e.record&&0!==Object.keys(e.record).length?l(e.record):"";return""+n+r+(((n.length>0||r.length>0)&&t.length)>0?" ":"")+t},o=function(e){return"("+u(e)+")"},a=function(e){var t,i;return e?""+(n(i=e)&&"ø"===i.id?"":r(e)?o(e):function(e){return n(e)&&void 0!==e.kind&&"pair"!==e.kind&&void 0!==e.children&&e.children.every((function(e){return r(e)}))}(e)?function e(n){var t="left"===n.kind?"<-":"-",i="right"===n.kind?"->":"-",c=r(n.children[0])?o(n.children[0]):e(n.children[0]),l=r(n.children[1])?o(n.children[1]):e(n.children[1]),a=u(n);return""+c+t+(a.length>0?"["+a+"]":"")+i+l}(e):(t=e).id||t.labels||t.record?function(e){var n=e.children&&e.children.length>0?a(e.children[0]):"",r=e.children&&e.children.length>1?a(e.children[1]):"",t="left"===e.kind?"<--":"right"===e.kind?"--\x3e":"either"===e.kind?"--":n.length>0&&r.length>0?",":"";return"["+u(e)+(t.length>0?" ":"")+t+(n.length>0?" ":"")+n+(r.length>0?" ":"")+r+"]"}(e):function(e){var n=e.children&&e.children.length>0?a(e.children[0]):"",r=e.children&&e.children.length>1?a(e.children[1]):"";return n+","+(r.length>0?" ":"")+r}(e)):""},d=function e(n){if(Array.isArray(n))return n.map(e).join(" ");if(void 0!==n.type)switch(n.type){case"path":return a(n);case"seq":return e(n.children)}else if("object"==typeof n)return"{"+Object.entries(n).map((function(e,n){return(n>0?",":"")+e[0]+":"+c(e[1])})).join("")+"}";throw new Error("Can't stringify <"+n+">")},h=function(e){if(n(e))return d(e);if((r=e).type&&"seq"===r.type)return d(e);throw new Error("Don't know how to stringify \""+e.type+'"');var r};e.gramStringifyPlugin=function(){this.Compiler=h},e.stringify=d,e.toGram=d,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(((e=e||self).gram=e.gram||{},e.gram.stringify={}))}(this,(function(e){"use strict";var n=function(e){return!!e.type&&"path"===e.type},r=function(e){return n(e)&&e.children&&0===e.children.length&&"ø"!==e.id},t=function(e){return!!e.type&&!!e.value&&"property"!==e.type},i=function(e){switch(e.type){case"integer":case"boolean":case"octal":case"hexadecimal":case"decimal":return e.value;case"string":return"`"+e.value+"`";case"tagged":return e.tag+"`"+e.value+"`";case"measurement":return""+e.value+e.unit;default:return function(e){throw new Error("Unexpected object: "+e)}(e)}},c=function(e){return function(e){return Array.isArray(e)&&t(e[0])}(e)?"["+e.map((function(e){return i(e)})).join(",")+"]":t(e)?i(e):l(e)},u=function(e){return"["+e.map(h).join(",")+"]"},l=function(e){return"{"+Object.entries(e).map((function(e,n){return(n>0?",":"")+e[0]+":"+h(e[1])})).join("")+"}"},o=function(e){var n=e.id||"",r=e.labels&&e.labels.length>0?":"+e.labels.join(":"):"",t=e.record&&0!==Object.keys(e.record).length?"{"+e.record.map((function(e,n){return(n>0?",":"")+e.name+":"+c(e.value)})).join("")+"}":"";return""+n+r+(((n.length>0||r.length>0)&&t.length)>0?" ":"")+t},a=function(e){return"("+o(e)+")"},d=function(e){var t,i;return e?""+(n(i=e)&&"ø"===i.id?"":r(e)?a(e):function(e){return n(e)&&void 0!==e.kind&&"pair"!==e.kind&&void 0!==e.children&&e.children.every((function(e){return r(e)}))}(e)?function e(n){var t="left"===n.kind?"<-":"-",i="right"===n.kind?"->":"-",c=r(n.children[0])?a(n.children[0]):e(n.children[0]),u=r(n.children[1])?a(n.children[1]):e(n.children[1]),l=o(n);return""+c+t+(l.length>0?"["+l+"]":"")+i+u}(e):(t=e).id||t.labels||t.record?function(e){var n=e.children&&e.children.length>0?d(e.children[0]):"",r=e.children&&e.children.length>1?d(e.children[1]):"",t="left"===e.kind?"<--":"right"===e.kind?"--\x3e":"either"===e.kind?"--":n.length>0&&r.length>0?",":"";return"["+o(e)+(t.length>0?" ":"")+t+(n.length>0?" ":"")+n+(r.length>0?" ":"")+r+"]"}(e):function(e){var n=e.children&&e.children.length>0?d(e.children[0]):"",r=e.children&&e.children.length>1?d(e.children[1]):"";return n+","+(r.length>0?" ":"")+r}(e)):""},h=function e(r){var o;if(Array.isArray(r))return r.length>0?n(r[0])?r.map(e).join(" "):u(r):"[]";if(void 0!==r.type)switch(r.type){case"path":return d(r);case"seq":return e(r.children);case"property":return(o=r).name+":"+c(o.value);default:return t(r)?i(r):l(r)}else if("object"==typeof r)return l(r);throw new Error("Can't stringify <"+r+">")},f=function(e){if(n(e))return h(e);if((r=e).type&&"seq"===r.type)return h(e);throw new Error("Don't know how to stringify \""+e.type+'"');var r};e.gramStringifyPlugin=function(){this.Compiler=f},e.stringify=h,e.toGram=h,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=gram-stringify.umd.production.min.js.map
{
"name": "@gram-data/gram-stringify",
"description": "Pretty print gram data graphs",
"keywords": [

@@ -9,3 +10,3 @@ "graph",

],
"version": "0.3.3",
"version": "0.3.4",
"license": "MIT",

@@ -55,9 +56,9 @@ "repository": {

"devDependencies": {
"@gram-data/gram-builder": "^0.3.2",
"@gram-data/gram-ops": "^0.3.2",
"@types/jest": "^26.0.15",
"@gram-data/gram-builder": "^0.3.4",
"@gram-data/gram-ops": "^0.3.4",
"@types/jest": "^26.0.18",
"@types/unist": "^2.0.3",
"@typescript-eslint/parser": "^4.8.2",
"husky": "^4.3.0",
"npm-check-updates": "^10.2.2",
"@typescript-eslint/parser": "^4.9.1",
"husky": "^4.3.5",
"npm-check-updates": "^10.2.3",
"npm-run-all": "^4.1.5",

@@ -74,6 +75,6 @@ "rollup-plugin-node-builtins": "^2.1.2",

"dependencies": {
"@gram-data/gram-ast": "^0.3.2",
"@gram-data/gram-ast": "^0.3.4",
"unified": "^9.2.0"
},
"gitHead": "4968a0ac1569f0bab127c1c991ccf5314e306670",
"gitHead": "27de40df779bc903e8873563db12f7db477e4ad3",
"publishConfig": {

@@ -80,0 +81,0 @@ "access": "public"

@@ -11,7 +11,6 @@ import {

isGramEdge,
GramSeq,
isGramEmptyPath,
isGramLiteralArray,
GramPropertyMap,
GramLiteral,
isGramPath,
} from '@gram-data/gram-ast';

@@ -49,6 +48,8 @@

} else {
return recordToString(v);
return objectToString(v);
}
};
const propertyToString = (property: GramProperty) => (`${property.name}:${toStringValue(property.value)}`)
const recordToString = (record: GramRecord): string => {

@@ -62,6 +63,8 @@ const fields = record.map(

const recordMapToString = (record: GramPropertyMap): string => {
const fields = Object.entries(record).map(
const arrayToString = (xs:any[]): string => `[${xs.map(stringify).join(',')}]`;
const objectToString = (o: { [key:string]:any }): string => {
const fields = Object.entries(o).map(
([name, value], i: number) =>
`${i > 0 ? ',' : ''}${name}:${toStringValue(value)}`
`${i > 0 ? ',' : ''}${name}:${stringify(value)}`
);

@@ -161,7 +164,12 @@ return `{${fields.join('')}}`;

export const stringify = (
ast: GramPath | GramSeq | GramPath[] | GramPropertyMap
): string => {
export const stringify = ( ast: any | any[] ): string => {
if (Array.isArray(ast)) {
return ast.map(stringify).join(' ');
if (ast.length > 0) {
const element = ast[0];
if (isGramPath(element)) {
return ast.map(stringify).join(' ');
} else {
return arrayToString(ast);
}
} else return '[]';
} else if (ast.type !== undefined) {

@@ -173,5 +181,12 @@ switch (ast.type) {

return stringify(ast.children as GramPath[]);
case 'property':
return propertyToString(ast);
default:
if (isLiteral(ast)) {
return toStringLiteral(ast);
}
return objectToString(ast);
}
} else if (typeof ast === 'object') {
return recordMapToString(ast);
return objectToString(ast);
}

@@ -178,0 +193,0 @@

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