DEV Community 👩‍💻👨‍💻

Dragoljub Bogićević
Dragoljub Bogićević

Posted on

Typescript - simple model/collection package

Recently, while I was learning about typescript generics I decided to write simple package for models and collections. Code sneak peek bellow:

import { Model } from 'pera-trta';
import { Collection } from 'pera-trta';

interface ICategoryProps {
    id: number;
    name: string;

class CategoryModel extends Model<ICategoryProps> {}

class CategoryCollection extends Collection<CategoryModel, ICategoryProps> {}

const cc = new CategoryCollection();
const c1 = new CategoryModel({ id: 1, name: 'pera' });

Package provides basic functionalities for models and collections by simple extending those classes.

Some of the functionalities that package provide are:

  • IntelliSense support
  • CLI support
  • get model property by key
  • update some properties of the model
  • update only one model property
  • store models in the collection
  • sort collection items
  • find particular item/items
  • map collection items ...

For more information about the package including the CLI support, and examples visit npm page.

Thank you for reading and if you have any suggestion please feel free to reach out.

Top comments (0)

🌙 Dark Mode?!

Turn it on in Settings