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

ursa-major

v0.0.1

Published

Structs

Downloads

4

Readme

ursa-major

Define structs in Earl Grey with typing and validation.

Basic usage

Require the macro like this (require-macro, not require):

require-macros:
   ursa-major -> struct

A struct is defined like this. Fields marked maybe can either be of the specified type, or they can be null:

struct Person:
   ;; use the uuid command in the console to generate a unique id for your struct
   ;; Try to add /StructName to the end of the uuid for readability, like this:
   type-id: "46cb4b46-35b8-11e5-9645-e3f320d7342e/Person"
   String? name
   Number? age
   maybe Person? mother
   maybe Person? father

Structs are instantiated with a dictionary of the required properties:

p1 = Person(name = "Florence", age = 43)
p2 = Person(name = "Rashid", age = 57)
p3 = Person(name = "Emily", age = 23, mother = p1, father = p2)

Serialize/deserialize with kaiser. type-id must be defined for the struct in order for this to work.

require: kaiser

serialized = kaiser.serialize(p3)
deserialized = kaiser.deserialize(serialized)

Validation

A validate method can be defined by a struct in order to ensure it is in a consistent state. For example:

struct OrderedTriple:
   Number? a
   Number? b
   Number? c
   validate() =
      if @a > @b or @b > @c:
         throw E.not-ordered("The order a < b < c failed to be preserved.")

OrderedTriple(a = 1, b = 2, c = 3)    ;; OK!
OrderedTriple(a = 1, b = -2, c = 3)   ;; ERROR!

validate is called whenever properties are set:

o = OrderedTriple(a = 1, b = 2, c = 3)
o.b = -2  ;; ERROR!

The update method can set many fields at once:

o = OrderedTriple(a = 1, b = 2, c = 3)
o.update(a = 100, b = 200, c = 300)  ;; OK!