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

riemap

v0.1.2

Published

> Operators for working with JSON objects of unknown structure.

Downloads

2

Readme

RieMap

Operators for working with JSON objects of unknown structure.

Content

Installation

You can get yourself a brand new copy of RieMap for FREE! (crazy, I know...) Just use the following command:

npm i riemap

Motivation

Long story short, I was working on a CMS system, which allowed users to edit db models, thus I didn't know data-types of fetched items ahead of time. As you may know, Reason doesn't allow for dynamic records. It made my use arrays of tuples, a.k.a. (key => value) pairs. Dealing with it was kinda tedious, so I decided to write a simple lib around it.

Example

Let's pretend a user wants to access a collection of kittens. Needless to say you had to prepare the structure in advance on the backend.

let fetchedKittens = Fetch.kittensSync() |> Json.parseDynamic
/*
  => [|
    ("Fluffykins#001", [|
      ("Age", "3"), <-- They all have to be of the same type;
      ("Breed", "Ragdoll")
    |]),
    ("Fluffykins#002", [|
      ("Age", "1"),
      ("Breed", "Ragdoll")
    |]),
    ("Toby#001", [|
      ("Age", "3"),
      ("Breed", "Birman")
    |])
  |]
*/

So now you've got this ugly mess of a structure, just because the user may want to change the fields anytime. Good for you!(unsarcastic cough) Alright, time to deal with it! Let's start with simply getting the Fluffykins#001.

let fluffykins001 = fetchedKittens @: "Fluffykins#001"
/*
  => Some([|
    ("Age", "3"),
    ("Breed", "Ragdoll")
  |])
*/

Oh... forgot to tell you that @: (or if you prefer the function form get()) returns an option('a), as what would happen if you tried accessing let's say, Bobby#001? As you can see, such kitten doesn't exist, so instead of throwing an error, you would just get None and let the user know. But if you're feeling adventures, you may just use @:! (or getUnsafe()). Let's stick with it just for simplicity's sake.

let fluffykins001 = fetchedKittens @:! "Fluffykins#001"

// Now let's say that we want to get it's breed.
let breed = fluffykins001 @:! "Breed" 
// => "Ragdoll"

Cool things, right? Ok, let's say it's just been Fluffykins's birthday (Happy birthday Fluffy :tada:), so now it's 4, not 3. Time to update that!

let newKittens = fetchedKittens 
  @# (
    "Fluffykins#001", 
    fluffykins001 @# ("Age", "4")
  )

/*
  => [|
    ("Fluffykins#001", [|
      ("Age", "4"), <-- Now it's 4 years old!
      ("Breed", "Ragdoll")
    |]),
    ("Fluffykins#002", [|
      ("Age", "1"),
      ("Breed", "Ragdoll")
    |]),
    ("Toby#001", [|
      ("Age", "3"),
      ("Breed", "Birman")
    |])
  |]
*/

Let me quickly walk you through. @# takes a key (Fluffykins#001) and a new value for the entry. The value is our fluffykins001 with the changed age. Ok, that was pretty awesome, but we hard-coded the age of 4. Let's rewrite the code such that it uses a dynamic age.

let newKittens = fetchedKittens
  @#> (
    "Fluffykins#001", 
    fluffykins => fluffykins 
      @# (
        "Age",
        (int_of_string(fluffykins @:! "Age") + 1)
          |> string_of_int
      )
  )

Here's how the @#> operator works. Instead of taking a new value, it takes a function ('a) => 'a.

Different forms

| Function | Operator | | ------------------------------------------ | -------- | | get(t('a), string) => option('a) | @: | | getOr(t('a), string, 'a) => 'a | @| | | getUnsafe(t('a), string) => 'a | @:! | | remove(t('a), string) => t('a) | @- | | concat(t('a), t('a)) => t('a) | @++ | | push(t('a), 'a) => t('a) | @+ | | replace(t('a), string, 'a) => t('a) | @# | | freplace(t('a), string, 'a => 'a) => t('a) | @#> | | map(t('a), string, 'a => 'b) => array('b) | @>>= | | getRe(t('a), Js.Re.t) => array('a) | $: | | aggregate(t('a), Js.Re.t) => t('a) | $:: |