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

@gram-data/gram-ops

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 0.2.12 to 0.2.13-alpha.1

28

dist/gram-ops.cjs.development.js

@@ -26,6 +26,28 @@ 'use strict';

};
/**
* Node set projected from within a path.
*
* @param p paths from which to project nodes
*/
var nodes = function nodes(p) {
return p.children.reduce(function (acc, child) {
return [].concat(acc, nodes(child));
}, gramAst.isGramNode(p) ? [p] : []);
if (gramAst.isGramNode(p)) return [p];
if (gramAst.isGramSeq(p)) return nodes(p.children);
if (Array.isArray(p)) {
var nodemap = p.map(nodes).flat().reduce(function (acc, child) {
if (child.id) {
if (acc.has(child.id)) {
acc.set(child.id, Object.assign(acc.get(child.id), child));
} else {
acc.set(child.id, child);
}
}
return acc;
}, new Map());
return Array.from(nodemap.values());
} else {
return nodes(p.children);
}
};

@@ -32,0 +54,0 @@ var edges = function edges(p) {

2

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

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@gram-data/gram-ast"),r=require("@gram-data/gram-builder"),n=function e(r){return void 0===r.children||0===r.children.length?r:e(r.children[0])},i=function e(r){return void 0===r.children||0===r.children.length?r:e(r.children[r.children.length-1])};exports.count=function e(r){return r.children.reduce((function(r,n){return r+e(n)}),1)},exports.edges=function e(t){return void 0===t||void 0===t.children||0===t.children.length?[]:2===t.children.length?[].concat(e(t.children[0]),void 0!==t.kind&&"pair"!==t.kind?[r.edge([i(t.children[0]),n(t.children[1])],t.kind,t.id,t.labels,t.record)]:[],e(t.children[1])):t.children.reduce((function(r,n){return[].concat(r,e(n))}),[])},exports.head=n,exports.identity=function(e){return e.id},exports.merge=function(e,r){return r},exports.nodes=function r(n){return n.children.reduce((function(e,n){return[].concat(e,r(n))}),e.isGramNode(n)?[n]:[])},exports.tail=i;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@gram-data/gram-ast"),r=require("@gram-data/gram-builder"),n=function e(r){return void 0===r.children||0===r.children.length?r:e(r.children[0])},i=function e(r){return void 0===r.children||0===r.children.length?r:e(r.children[r.children.length-1])};exports.count=function e(r){return r.children.reduce((function(r,n){return r+e(n)}),1)},exports.edges=function e(t){return void 0===t||void 0===t.children||0===t.children.length?[]:2===t.children.length?[].concat(e(t.children[0]),void 0!==t.kind&&"pair"!==t.kind?[r.edge([i(t.children[0]),n(t.children[1])],t.kind,t.id,t.labels,t.record)]:[],e(t.children[1])):t.children.reduce((function(r,n){return[].concat(r,e(n))}),[])},exports.head=n,exports.identity=function(e){return e.id},exports.merge=function(e,r){return r},exports.nodes=function r(n){if(e.isGramNode(n))return[n];if(e.isGramSeq(n))return r(n.children);if(Array.isArray(n)){var i=n.map(r).flat().reduce((function(e,r){return r.id&&(e.has(r.id)?e.set(r.id,Object.assign(e.get(r.id),r)):e.set(r.id,r)),e}),new Map);return Array.from(i.values())}return r(n.children)},exports.tail=i;
//# sourceMappingURL=gram-ops.cjs.production.min.js.map

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

import { GramNode, GramPath } from '@gram-data/gram-ast';
import { GramNode, GramPath, GramSeq } from '@gram-data/gram-ast';
export declare const count: (p: GramPath) => number;

@@ -7,3 +7,8 @@ export declare const head: (p: GramPath) => GramNode;

export declare const identity: (p: GramPath) => string | undefined;
export declare const nodes: (p: GramPath) => GramPath[];
/**
* Node set projected from within a path.
*
* @param p paths from which to project nodes
*/
export declare const nodes: (p: GramPath | GramPath[] | GramSeq) => GramPath[];
export declare const edges: (p: GramPath) => GramPath[];

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

import { isGramNode } from '@gram-data/gram-ast';
import { isGramNode, isGramSeq } from '@gram-data/gram-ast';
import { edge } from '@gram-data/gram-builder';

@@ -22,6 +22,28 @@

};
/**
* Node set projected from within a path.
*
* @param p paths from which to project nodes
*/
var nodes = function nodes(p) {
return p.children.reduce(function (acc, child) {
return [].concat(acc, nodes(child));
}, isGramNode(p) ? [p] : []);
if (isGramNode(p)) return [p];
if (isGramSeq(p)) return nodes(p.children);
if (Array.isArray(p)) {
var nodemap = p.map(nodes).flat().reduce(function (acc, child) {
if (child.id) {
if (acc.has(child.id)) {
acc.set(child.id, Object.assign(acc.get(child.id), child));
} else {
acc.set(child.id, child);
}
}
return acc;
}, new Map());
return Array.from(nodemap.values());
} else {
return nodes(p.children);
}
};

@@ -28,0 +50,0 @@ var edges = function edges(p) {

@@ -8,2 +8,22 @@ (function (global, factory) {

/**
* # Gram AST Types
*
*
* References:
*
* - [unist](https://github.com/syntax-tree/unist) - Universal Synax Tree
* - [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree)
* @packageDocumentation
*/
/**
* Type guard for GramSeq.
*
* @param o any object
*/
var isGramSeq = function isGramSeq(o) {
return !!o.type && o.type === 'seq';
};
/**
* Type guard for a Path.

@@ -97,6 +117,28 @@ *

};
/**
* Node set projected from within a path.
*
* @param p paths from which to project nodes
*/
var nodes = function nodes(p) {
return p.children.reduce(function (acc, child) {
return [].concat(acc, nodes(child));
}, isGramNode(p) ? [p] : []);
if (isGramNode(p)) return [p];
if (isGramSeq(p)) return nodes(p.children);
if (Array.isArray(p)) {
var nodemap = p.map(nodes).flat().reduce(function (acc, child) {
if (child.id) {
if (acc.has(child.id)) {
acc.set(child.id, Object.assign(acc.get(child.id), child));
} else {
acc.set(child.id, child);
}
}
return acc;
}, new Map());
return Array.from(nodemap.values());
} else {
return nodes(p.children);
}
};

@@ -103,0 +145,0 @@ var edges = function edges(p) {

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

!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(((n=n||self).gram=n.gram||{},n.gram.ops={}))}(this,(function(n){"use strict";function e(){return(e=Object.assign||function(n){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(n[t]=r[t])}return n}).apply(this,arguments)}var r=function n(e){return void 0===e.children||0===e.children.length?e:n(e.children[0])},t=function n(e){return void 0===e.children||0===e.children.length?e:n(e.children[e.children.length-1])};n.count=function n(e){return e.children.reduce((function(e,r){return e+n(r)}),1)},n.edges=function n(i){return void 0===i||void 0===i.children||0===i.children.length?[]:2===i.children.length?[].concat(n(i.children[0]),void 0!==i.kind&&"pair"!==i.kind?[(c=[t(i.children[0]),r(i.children[1])],d=i.kind,o=i.id,l=i.labels,u=i.record,e({type:"path",id:o},l&&{labels:l},u&&{record:u},{kind:d,children:c}))]:[],n(i.children[1])):i.children.reduce((function(e,r){return[].concat(e,n(r))}),[]);var c,d,o,l,u},n.head=r,n.identity=function(n){return n.id},n.merge=function(n,e){return e},n.nodes=function n(e){return e.children.reduce((function(e,r){return[].concat(e,n(r))}),function(n){return!!n.type&&"path"===n.type}(r=e)&&r.children&&0===r.children.length&&"ø"!==r.id?[e]:[]);var r},n.tail=t,Object.defineProperty(n,"__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.ops={}))}(this,(function(e){"use strict";function n(){return(n=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e}).apply(this,arguments)}var r=function e(n){return void 0===n.children||0===n.children.length?n:e(n.children[0])},t=function e(n){return void 0===n.children||0===n.children.length?n:e(n.children[n.children.length-1])};e.count=function e(n){return n.children.reduce((function(n,r){return n+e(r)}),1)},e.edges=function e(i){return void 0===i||void 0===i.children||0===i.children.length?[]:2===i.children.length?[].concat(e(i.children[0]),void 0!==i.kind&&"pair"!==i.kind?[(d=[t(i.children[0]),r(i.children[1])],c=i.kind,o=i.id,u=i.labels,l=i.record,n({type:"path",id:o},u&&{labels:u},l&&{record:l},{kind:c,children:d}))]:[],e(i.children[1])):i.children.reduce((function(n,r){return[].concat(n,e(r))}),[]);var d,c,o,u,l},e.head=r,e.identity=function(e){return e.id},e.merge=function(e,n){return n},e.nodes=function e(n){if(function(e){return!!e.type&&"path"===e.type}(r=n)&&r.children&&0===r.children.length&&"ø"!==r.id)return[n];var r;if(function(e){return!!e.type&&"seq"===e.type}(n))return e(n.children);if(Array.isArray(n)){var t=n.map(e).flat().reduce((function(e,n){return n.id&&(e.has(n.id)?e.set(n.id,Object.assign(e.get(n.id),n)):e.set(n.id,n)),e}),new Map);return Array.from(t.values())}return e(n.children)},e.tail=t,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=gram-ops.umd.production.min.js.map

@@ -8,3 +8,3 @@ {

],
"version": "0.2.12",
"version": "0.2.13-alpha.1",
"license": "MIT",

@@ -67,4 +67,4 @@ "repository": {

"dependencies": {
"@gram-data/gram-ast": "^0.2.12",
"@gram-data/gram-builder": "^0.2.12",
"@gram-data/gram-ast": "^0.2.13-alpha.1",
"@gram-data/gram-builder": "^0.2.13-alpha.1",
"fp-ts": "^2.8.6"

@@ -75,3 +75,3 @@ },

},
"gitHead": "7f663c601c2fcd63f180bcd817d107e9cd5f29ee"
"gitHead": "b4a2abe648ff61d7c23add3c762e2953446a4976"
}

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

import { GramNode, GramPath, isGramNode } from '@gram-data/gram-ast';
import { GramNode, GramPath, GramSeq, isGramNode, isGramSeq } from '@gram-data/gram-ast';
import { edge } from '@gram-data/gram-builder';

@@ -32,7 +32,28 @@

export const nodes = (p: GramPath): GramPath[] => {
return (p.children as GramPath[]).reduce(
(acc: GramPath[], child: GramPath) => [...acc, ...nodes(child)],
isGramNode(p) ? [p] : ([] as GramPath[])
);
/**
* Node set projected from within a path.
*
* @param p paths from which to project nodes
*/
export const nodes = (p: GramPath | GramPath[] | GramSeq): GramPath[] => {
if (isGramNode(p)) return [p];
if (isGramSeq(p)) return nodes(p.children);
if (Array.isArray(p)) {
const nodemap = p.map(nodes).flat().reduce(
(acc: Map<string, GramPath>, child: GramPath) => {
if (child.id) {
if (acc.has(child.id)) {
acc.set(child.id, Object.assign(acc.get(child.id), child))
} else {
acc.set(child.id, child);
}
}
return acc;
},
new Map<string, GramPath>()
);
return Array.from(nodemap.values());
} else {
return nodes(p.children);
}
};

@@ -39,0 +60,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