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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@typedly/data

v2.0.0

Published

A TypeScript type definitions package for @typescript-package/data.

Readme

@typedly/data

npm version GitHub issues GitHub license

A TypeScript type definitions package for @typescript-package/data.

Table of contents

Installation

Peer dependencies

npm install @typedly/constructor --save-peer

The package

npm install @typedly/data --save-peer

Api

import {
  // Interface.
  DataConstructor,
  DataShape,
  ValueConstructor,
  ValueShape,
  // Type.
  DataConstructorInput,
  DataConstructorTuple,
} from '@typedly/data';

Interface

DataConstructor

The constructor interface for data types.

import { DataConstructor, DataShape } from '@typedly/data';

// Import DataShape and DataConstructor.
// Create a data class that implements `DataShape` of `Type`.
export class ProfileData<
  Value extends { age: number, name: string }
> implements DataShape<Value> {

  get value(): Value {
    return {
      age: this.#age,
      name: this.#name
    } as Value;
  }

  #age;
  #name;
  constructor(value: Value, ...args: any[]) {
    console.log(`Instantiated DataConstructor`, value, ...args);
    this.#age = value.age;
    this.#name = value.name;
  }

  set(value: Value): this { this.validate(value); return this; }
  clear(): this { return this; }
  destroy(): this { return this; }
  lock(): this { return this; };
  validate(value: Value): boolean {
    return true;
  }
}

// Create `ProfileClass` with customizable data.
export class ProfileClass<
  Value extends { age: number, name: string },
  DataType extends DataShape<Value>,
  Args extends any[]
> {

  public get age(): Value['age'] {
    return this.#data.value.age;
  }

  public get name(): Value['name'] {
    return this.#data.value.name;
  }

  public get data() {
    return this.#data;
  }

  #data: DataType;

  constructor(value: Value, dataCtor: DataConstructor<Value, DataType>);
  constructor(value: Value, dataCtor: [DataConstructor<Value, DataType>, ...Args]);
  constructor(value: Value, dataCtor: any) {
    // ...implementation
    console.log(`DataConstructor`, value, dataCtor[1]);
    this.#data = Array.isArray(dataCtor)
      ? new dataCtor[0](value, ...dataCtor.slice(1))
      : new dataCtor(value);
  }
}

// Initialize.
// const frankProfile: ProfileClass<object, ProfileData<object>, any[]>
const frankProfile = new ProfileClass({ age: 37, name: 'Frank' }, ProfileData);

frankProfile.age; // 37
frankProfile.name; // Frank

// Set the data.
frankProfile.data.set({ age: 37, name: 'Frank' });
frankProfile.data.clear();
frankProfile.data.lock();
frankProfile.data.value;

Source

DataShape

The shape of a Data type.

import { DataShape } from '@typedly/data';

class TestData implements DataShape<number> {
  get value(): number { return this.initialValue; }
  constructor(private initialValue: number) {}
  public clear(): this { return this; }
  public destroy(): this { return this; }
  public lock(): this { return this; }
  public set(value: number): this { return this; }
}

Source

ValueConstructor

import { ValueConstructor } from '@typedly/data';

Source

ValueShape

The shape of a Value type.

import { ValueShape } from '@typedly/data';

Source

Type

DataConstructorInput

The input type for data constructors, with arguments support.

import { DataConstructorInput } from '@typedly/data';

Source

DataConstructorTuple

The input type for data constructors, with arguments support.

import { DataConstructorTuple } from '@typedly/data';

Source

Full example usage

import { DataConstructor, DataShape, ValueConstructor, ValueShape } from '@typedly/data';

// Import ValueShape and ValueConstructor.
// Create a profile data value.
export class ProfileDataValue<
  Type extends { age: number, name: string },
  Args extends any[] = any[]
> implements ValueShape<Type> {
  get value(): Type {
    return {
      age: this.#age,
      name: this.#name
    } as Type;
  }

  #age: Type['age'];
  #name: Type['name'];

  constructor(value: Type, ...args: Args) {
    console.log(`Instantiated ValueConstructor`, value, ...args);
    this.#age = value.age;
    this.#name = value.name;
  }

  set(value: Type): this { return this; }
}

export class ProfileDataOfValue<
  Value extends { age: number, name: string },
  Args extends any[] = any[],
  ValueInstance extends ValueShape<Value> = ProfileDataValue<Value, Args>,
> implements DataShape<Value> {

  get value(): Value {
    return {
    } as Value;
  }

  get valueInstance(): ValueInstance {
    return this.#value;
  }

  #value;
  constructor(
    value: Value,
    valueCtor: ValueConstructor<Value, ValueInstance, Args> = ProfileDataValue<Value, Args> as any,
    ...args: Args
  ) {
    console.log(`Instantiated DataConstructor`, value, ...args);
    this.#value = new valueCtor(value, ...args);
  }

  set(value: Value): this { this.validate(value); return this; }
  clear(): this { return this; }
  destroy(): this { return this; }
  lock(): this { return this; };
  validate(value: Value): boolean {
    return true;
  }
}

// const profileDataOfValue: ProfileDataOfValue<{
//     age: number;
//     name: string;
// }, ProfileDataValue<{
//     age: number;
//     name: string;
// }, []>, []>
const profileDataOfValue = new ProfileDataOfValue({
  age: 37,
  name: 'Mark'
}, ProfileDataValue);

const dataSymbol = Symbol('data');

// Create `ProfileClass` with customizable data.
export class ProfileClass<
  Value extends { age: number, name: string },
  DataType extends DataShape<Value>,
  Args extends any[]
> {

  public get age(): Value['age'] {
    return this.#data.value.age;
  }

  public get name(): Value['name'] {
    return this.#data.value.name;
  }

  public get [dataSymbol]() {
    return this.#data;
  }

  #data: DataType;

  constructor(value: Value, dataCtor: DataConstructor<Value, DataType, Args>);
  constructor(value: Value, dataCtor: [DataConstructor<Value, DataType, Args>, ...Args]);
  constructor(value: Value, dataCtor: any) {
    // ...implementation
    console.log(`DataConstructor`, value, dataCtor[1]);
    this.#data = Array.isArray(dataCtor)
      ? new dataCtor[0](value, ...dataCtor.slice(1))
      : new dataCtor(value);
  }
}

const markProfile = new ProfileClass({ age: 37, name: 'Mark' }, ProfileDataOfValue);

markProfile.age // 37
markProfile.name // Mark
markProfile[dataSymbol].value // { age, name }
markProfile[dataSymbol].valueInstance.set({ age: 27, name: 'Frank' });

Contributing

Your contributions are valued! If you'd like to contribute, please feel free to submit a pull request. Help is always appreciated.

Support

If you find this package useful and would like to support its and general development, you can contribute through one of the following payment methods. Your support helps maintain the packages and continue adding new.

Support via:

or via Trust Wallet

Thanks for your support!

Code of Conduct

By participating in this project, you agree to follow Code of Conduct.

GIT

Commit

Versioning

Semantic Versioning 2.0.0

Given a version number MAJOR.MINOR.PATCH, increment the:

  • MAJOR version when you make incompatible API changes,
  • MINOR version when you add functionality in a backwards-compatible manner, and
  • PATCH version when you make backwards-compatible bug fixes.

Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.

FAQ How should I deal with revisions in the 0.y.z initial development phase?

The simplest thing to do is start your initial development release at 0.1.0 and then increment the minor version for each subsequent release.

How do I know when to release 1.0.0?

If your software is being used in production, it should probably already be 1.0.0. If you have a stable API on which users have come to depend, you should be 1.0.0. If you’re worrying a lot about backwards compatibility, you should probably already be 1.0.0.

License

MIT © typedly (license)

Related packages