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

neopreen

v1.0.0

Published

A set of functions for formatting `neo4j-driver` results.

Downloads

1

Readme

Neopreen Build Status

A tiny library of formatters and combinators to simplify working with neo4j-driver's returned structure.

Example

const np = require('neopreen')

const preen = np.row({
  person: np.node({
    name: np.string
  }),

  food: np.node({
    name: np.string,
    litres: np.real
  }),

  relation: np.relation({
    amount: np.string
  })
})

const data = sess.run(
  ` CREATE (person:Person { name: "Tom" })
    CREATE (food:Item { name: 'Sherbet lemonade'
                      , litres: 0.5 })
    CREATE (person)
      -[relation:LIKES { amount: "A LOT" }]
      ->(food)
    RETURN person, relation, food `)
.then(preen)

The resulting contents of data's promise will look like this:

{
  person: {
    name: 'Tom',
    $id: 14001, // Whatever Neo4j assigns.
    $labels: [ 'Person' ]
  },

  food: {
    name: 'Sherbet lemonade',
    litres: 0.5,
    $id: 14002, // Whatever Neo4j assigns.
    $labels: [ 'Item' ]
  },

  relation: {
    amount: 'A LOT',
    $from: 14001,
    $id: 59009, // Whatever Neo4j assigns.
    $to: 14002,
    $type: 'LIKES'
  }
}

API

As we would all hope, this API treats data as immutable. It won't update the structure you pass in; it will, instead, return a copy with the changes applied.

Formatters

int

Take a Neo4j integer, and call x.toNumber() on it, returning the int value.

float

Cast the given value to a float. This is done with the unary x => +x.

string

Cast the given value to a string using x => '' + x.

bool

Cast the given value to a bool using x => !!x.

array(formatter)

Format an array, applying the given formatter to each element within. For example:

// Returns [1.0, 2.0, 3.0]
np.array(np.float)([1, '2', 3.0])

object(schema)

Format an object according to the given schema. Missing keys will be denoted by null:

const validator = np.object({
  name: np.string,
  cats: np.int,
  hat: np.string
})

// { name: 'Jeff', cats: 12, hat: null }
validator({
  name: 'Jeff',
  cats: require('neo4j-driver').v1.int(12)
})

Structure Handlers

node(formatter)

Format a Node type from the neo4j-driver library. The result is an object with the node's properties formatted according to the provided formatter, along with two extra properties:

  • $id, the Neo4j ID of the node (converted to int).
  • $labels, the labels applied to the node (as a string array).

relation(formatter)

Format a Relationship type from the neo4j-driver library. The result is an object with the relationship's properties formatted according to the provided formatter, along with two extra properties:

  • $from, the Neo4j ID of the source node (converted to int).
  • $to, the Neo4j ID of the target node (converted to int).
  • $id, the Neo4j ID of the relationship.
  • $type, the label for the relationship.

record(formatter)

Format a Record type from the neo4j-driver library. This is useful for users consuming the output via neo4j-driver's observable interface. Each record can be formatted according to the formatter as it arrives.

one(formatter)

If you're expecting one result (that is, a single returned row containing a single value), this function returns that structure. It is advised that this result is formatted with one of the original formatters (unless it's a Node or Relationship, in which case you can nest the node and relation formatters).

many(formatter)

For a result set of any number of rows with more than one field being returned per row. In the repository's main example, row is used as only one row is being returned. If that is not the case, chances are that many is what you want.

row(formatter)

Format the results of a query that returns multiple fields, but only one row (such as the example at the top of this README).

column(formatter)

Format the results of a query that returns multiple rows, but only one field.

Contributing

PRs are always welcome! There's a code of conduct, naturally, so be mindful!