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

@darlean/canonical

v2.0.0-alpha.10

Published

Library for representing data type-safe in a languiage and platform indepent way.

Downloads

275

Readme

Canonical

Darlean Canonical is a library for representing structured data, in such a way that it can be consumed natively in multiple programming languages, and with preservation of both physical type (like string, number, boolean) and logical type (like first-name, last-name, age).

The library contains a generic data type (the ICanonical) which is a container for logically and physically typed primitive and structured values.

A canonical has the following properties:

  • It has a physical type. The physical type is the type used to physically store (or serialize) the data. Examples of physical types are strings, numbers, booleans, objects, arrays, Buffers and Dates.
  • It has a logical type. The logical type describes what kind of data is represented. Examples of logical types are first-name, last-name, postal-address and list-of-people.
  • It has a value of the corresponding physical type.

Although canonicals can be combined very well with value objects that make them even more type-safe (as found in package] @darlean/valueobjects), and can be serialized to verious formats (like the one from package @darlean/canonical-json), canonicals themselves have nothing to do this with. They are just an in-memory representation of a value with an associate physical and logical type.

Serialization

Canonicals can be serialized to various formats. Currently, the only known implementation is the one provided by @darlean/canonican-json. As the name implies, it converts canonical data to a valid JSON document with embedded type annotations.

Supported physical types

Canonicals support the following physical types. The native representation in TypeScript and JavaScript is shown in brackets.

  • String - To contain unicode text (string).
  • Int - To contain positive or negative integer numbers (number).
  • Float - To contain floating point numbers (number).
  • Boolean - To contain true/false booleans. (boolean)
  • Binary - To contain an array of bytes (Buffer)
  • Moment - To contain a specific moment in time (Date)
  • Sequence - To contain an ordered sequence of canonicals ([...])
  • Mapping - To contain a key-value mapping from string keys to canonical values. ({...})
  • None - To indicate that there is no value (only useful in sequences). (undefined)

Notes:

  • How these physical types are represented in a serialized format depends on the specific serialization definition. That is out of scope for the concept of canonicals as defined in this package.
  • How these physical types are represented in memory depends on the library for the specific programming language. It is in general most convenient to stay close to the native data types that are supported by a language.