npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gremlin-script

v1.1.0

Published

Generate Gremlin scripts with ease

Downloads

12

Readme

gremlin-script

Generate Gremlin scripts with ease.

Works in Node.js and the browser.

Installation

Node.js

$ npm install gremlin-script -S

Browsers

This module works as a CommonJS, AMD module or standalone module (exported globally as GremlinScript).

API

Instantiate a script object:

var GremlinScript = require('gremlin-script').GremlinScript;
var gremlin = new GremlinScript();

Get a reference to the graph:

var Graph = require('gremlin-script').Structure.Graph;
var g = new Graph('g'); // pass graph identifier/name to the constructor

gremlin.line(String|Helper[, ...parameters])

Adding a raw String line

var gremlin = new GremlinScript();

gremlin.line('g.v(1)');
gremlin.script.should.equal('g.v(1)\n');

Adding a raw String line with a bound parameter (printf style)

var gremlin = new GremlinScript();

gremlin.line('g.v(%s)', 1);
gremlin.script.should.equal('g.v(p0)\n');
gremlin.params.p0.should.equal(1);

Adding a raw String line with multiple parameters (printf style)

var gremlin = new GremlinScript();

gremlin.line('g.V(%s, %s)', 'name', 'Alice');
gremlin.script.should.equal('g.V(p0, p1)\n');
gremlin.params.p0.should.equal('name');
gremlin.params.p1.should.equal('Alice');

Adding a line with Graph and Element (Vertex/Edge) helpers

var gremlin = new GremlinScript();
var g = new Graph('g');

gremlin.line(g.v(1));
gremlin.script.should.equal('g.v(1)\n');

Bound parameters when using helpers

Using the bindParameter() function flags the argument passed to a function as a BoundParameter. When generating the string, Gremlin-Script will automatically replace such wrapped argument with an automatically generated variable name and push the argument to the gremlin.params Array.

var bind = require('gremlin-script').bindParameter;

var gremlin = new GremlinScript();
var g = new Graph('g');

var v1 = gremlin.var(g.addVertex(bind({ name: 'Alice' })), 'v1');
var v2 = gremlin.var(g.addVertex(bind({ name: 'Bob' })), 'v2');
gremlin.line(g.addEdge(v1, v2, 'knows', bind({ foo: 'bar' })));

gremlin.script.should.equal("v1=g.addVertex(p0)\nv2=g.addVertex(p1)\ng.addEdge(v1,v2,'knows',p2)\n");
gremlin.params.p0.name.should.equal('Alice');
gremlin.params.p1.name.should.equal('Bob');
gremlin.params.p2.foo.should.equal('bar');

Author

Jean-Baptiste Musso - @jbmusso.

This library was heavily inspired by the great work started by Frank Panetta on gRex. Thanks!

Contributors

https://github.com/gulthor/gremlin-script/graphs/contributors

License

MIT (c) 2014 Jean-Baptiste Musso