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

typesift

v1.0.2

Published

NoviSci compact complex data type definitions and value validation

Downloads

1

Readme

typesift Package

This package is UNFINISHED and still under development

Defines a compact specification of nested object data structures. Allows a single data structure to describe a complex type which can be used to create default initial values of the structure and validation of data structures claiming to conform to a particular structure.

The idea is to use the definition to build a set of functions which take input data whish may or may not conform to the declared structure. It's simple -- dirty data in, clean data out. Or, dirty data in, and a list of validation errors out. This is intended to reduce the amount of wordy and repeptitive valid value checking or structure initialization and keep the defintion of the data structure complete and in one place.

Structure of typesift definitions

At it's most basic level, a variable can be described by a tuple containing a type and a default value for that type. Simple examples are ['string', [validators], 'fred'], which describes a string variable whose default value is "fred".

The package supportes the definition of complex sub-types embedded within the typesift definition, such as an object, array element, or enumerated type. Sub-types are distinguished from concrete properties by prepending an underscore to the name. If the name of a particular definition starts with an underscore (_), the definition is ignored as a top-level property and is only references when speficied as a value of a complex type.

Example

{
  property: ['string', 'a property'],
  subobject: ['object', '_subtype'],
  _subtype: {
    prop1: ['integer', 0],
    prop2: ['string', 'fred']
  }
}

The case above would produce the following structure as an initial value:

{
  property: 'a property',
  subobject: {
    prop1: 0,
    prop2: 'fred'
  }
}

The particular use of an embedded subtype is inferred by it's use in the defintion structure. When used as a value, such as ['object', '_subtype'] appearing in the second slot of the tuple, the package treats the _subtype structure as a value to assign to the property of type object. Thus, the _subtype object is traversed in the same way as the top-level structure, defining a set of properties and their initializers which are treated as a typesift definition.

When an embedded subtype is used as a type specifier (appearing in the first slot of the tuple), such as ['enum', ['_subtype', 'val']], the subtype definition is treated as a type with all possible values enumerated within. In the case above, the structure describes an enumerated data type whose valid values are defined as the properties of the subtype. The above declaration would describe an enumerated type whose values are defined in _subtype and whose default value is val (which must appear in the subtype).

Base types

| Type name | Description | | --- | --- | | boolean | A true/false value | | integer | An integer number | | float | A floating point number | | string | A character string |

Complex sub-types

| Type name | Description | | --- | --- | | subtype| An enumerated type whose values are defined in an embedded sub-type | | array | An ordered vector of values. Valid values of the array are defined by an embedded sub-type | | object | A nested object whose value is determined by recursively traversing the provided embedded sub-type |