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

crispum

v0.2.0

Published

Declarative parsing pipeline with basic map reduction

Downloads

4

Readme

crispum

Cross-language declarative parsing pipeline.

Installation

Node: npm i crispum --save
Python: pip install crispum, or if you're clever pipenv install crispum

Usage

Crispum is designed to take in static JSON schema objects and return back a parser function which will apply all of the transformations listed in the schema object.

Here is an example of a simple obstruction example.

{
  "type": "simple",
  "keys": {
    "indeed": "awesome"
  }
}

This schema would transform the following object...

{
  "awesome": "it works!"
}

into

{
  "indeed": "it works!"
}

The schema may also be an array of instructions, and can apply instructions to to the whole object or to each element of an array.

[{
  "type": "pluck",
  "key": "indeed"
}, {
  "type": "array"
}, {
  "type": "conditional",
  "key": "foo",
  "default": {
    "type": "filter"
  },
  "options": {
    "bar": {
      "type": "pluck",
      "key": "nested"
    },
    "baz": {
      "type": "pluck",
      "key": "special"
    }
  }
}, {
  "type": "dearray"
}, {
  "type": "simple",
  "keys": {
    "result": "0",
    "extra": "1"
  }
}]

This results in a complex multistep schema, which when appled to data like this...

{
  "extra": "oh hey",
  "indeed": [{
    "foo": "bar",
    "nested": "value"
  }, {
    "foo": "boozle",
    "nested": "lost in space"
  }, {
    "foo": "baz",
    "nested": "value",
    "special": "so bazzy"
  }]
}

results in...

{
  "result": "value",
  "extra": "so bazzy"
}

API

crispum(schema) -> function (data)

Create a new crispum parser with the options passed. The returned parse method takes one parameter, which is input data, and returns the transformed data.

schema

Required
Type: object or array

The schema may either be a single instruction or an array of them. Each instruction must have a type, and may optionally contain an array field.

When array is true, the current data will be reinterpreted as an array and each instruction will execute on the entries instead of the list itself.

Available types are...

array

The array instruction tells the crispum pipeline to run all subsequent instructions as if they had array: true set. It also can take in an optional parameters, keys

keys is a list of keys to copy from the data into each element of the array before continuing on the pipeline

conditional

The conditional instruction looks at the value of a specified key and then executes a different instruction based on the value found.

  • key: They keyname to check the conditional against
  • default: The default instruction if the value found is not in the options list
  • options: An associative array of instruction options

dearray

Stops an array pipeline and goes back to interpreting the data as a whole instead of each element.

filter

This instruction deletes the current data and does ont take any parameters. This is useful in combination with array and conditional

simple

Simple onyl takes 1 other parameter, which is keys. Keys should be a valid obstruction schema. The result is the same as the output obstruction would generate, except extra keys not mentioned in the schema are not removed.

pluck

The pluck instruction takes a given key and rebases the dataset onto it. It takes in two parameters

  • key: The keyname to grab and rebase the current dataset onto
  • keys: An array of extra keys to copy from the parent object into the plucked value

License

MIT