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

@superhero/elastic

v0.0.1

Published

object modeling tool for elasticsearch

Downloads

3

Readme

An object modeling tool for elasticsearch.

Example

const
elastic = require('@superhero/elastic'),
type    = elastic.type,
schema  =
{
  created   : type.date,
  updated   : type.date,
  title     : type.text,
  body      : type.text,
  viewed    : type.integer,
  comments  :
  {
    ip      : type.ip,
    email   : type.keyword,
    avatar  : type.binary,
    location: type.geo_point,
    title   : type.text,
    body    : type.text,
    rating  : type.float,
    approved: type.boolean
  }
},
host  = 'localhost',
port  = 9200,
db    = elastic.db(host, port[, user, password, ssl=false]);

// Will reindex the index to reflect the defined schema, if the schema defined
// is different from what's already mapped.
// To prevent reindexing; use the last argument. If set to false, will throw an
// error if the mapping does not match what's already defined. Only creates the
// index if the index doesn't already exist.
// The "index-name" is optional an optional argument, if no index name is
// defined then the type name will be used.
db.index(['index-name',] 'blog', schema [, update=true], (error, index) =>
{
  // basic interface of the index, the interface can be extended
  // index.search(terms, cb);
  // index.remove(id, cb);
  // index.add(item, cb);
  // index.save(id, item, cb);
  // index.rest(method, uri, params, body, cb);
  // index.filter(map);
  // index.validate(map);

  // find by ...
  index.findByTitle         = (title, cb) => this.find({title}, cb);
  index.findByCommentTitle  = (title, cb) => this.find({comments:{title}}, cb);
  index.findCommentsByTitle = (title, cb) => this.find({title}, (error, result) => cb(error, result && [].concat(...result.map(item => item.comments))));

  // input filter
  index.filter =
  {
    title   : (value, action, cb) => cb(value.trim()),
    created : (value, action, cb) => cb(action == 'add'   ? Date.now()  : undefined),
    updated : (value, action, cb) => cb(action == 'save'  ? Date.now()  : undefined),
    comments: (value, action, cb) => cb([].isArray(value) ? value       : (item === undefined ? undefined : [value])),
  });

  // input validator
  index.validate =
  {
    comments:
    {
      email : (value, cb) => cb(value.test(/\S+@\S+\.\S+/))
    }
  });
});