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

cekoya

v0.2.0

Published

Cekoya is a class template for modeling object with custom attributes it is oriented as a Model

Downloads

4

Readme

Cekoya

Build Status

Purposes

I wroked hard on building another library called modelizejs. These two share the same targets except that Cekoya should plugginable. I worked on projet when I wanted to use modelizejs but didn't want some feature that I thought were overwhelming for my use case. With Cekoya, I do a second attempt of building something everyone would enjoy. A Model library that is DRY.

Note The whole package was building under ES6 JavaScript standards. I recommend using them when working on new JavaScript. This said, the package comes with firenpm which has a basic webpack config to build the package if you want to deploy it at home.

Installation

npm install --save cekoya
// or
yarn add cekoya

Usage

Usage by proxy

Something I wanted to achieve long time ago with modelizejs was overriding default getter on class. I discovered Proxies.

const user = Cekoya.create({
    firstName: 'John',
    lastName: 'Doe',
    age: 20,
});

console.log(user.firstName)         // Outputs "John";
console.log(user.get('firstName'))  // Outputs "John";

If you instanciate a new Cekoya object, Proxies won't be applied to the object. Calling user.firstName will then return undefined. And that's bad.

Extension

This package should be used by extension. You create models that extends this one. You could create getters and setters just as any model.

Getters

Let's say I want to display my firstName attribute in upper case because I like the yelling style of the upper case.

class User extends Cekoya {
    getFirstNameAttribute() {
        return this.getAttribute('firstName').toUpperCase();
    }
}

const user = User.create({
    firstName: 'John',
    lastName: 'Doe',
    age: 20,    
});

console.log(user.firstName)         // Outputs "JOHN";
console.log(user.get('firstName'))  // Outputs "JOHN";
console.log(user.getAttribute('firstName'))  // Outputs "John";

Setters

Let's say I want to set my age to at least 18 and pretend I'm an adult (Which I am, in real life).

const MINIMUM_AGE = 18;
class User extends Cekoya {
    setAgeAttribute(value) {
        return (value >= MINIMUM_AGE) ? value : MINIMUM_AGE;
    }
}

const user = User.create({
    firstName: 'John',
    lastName: 'Doe',
    age: 10,    
});

console.log(user.age)         // Outputs "18";

Plugins

To add a plugins to the package, simply override the static method plugins on your class to return an array of Plugin classes.

Note Plugin classes must have a static method attach which will receive the instance in parameters

class GetAttributesPlugin {
    static attach(model) {
        model.constructor.prototype.getAttributes = () => model._attributes;
    }
}

Main purpose of this is adding plugins like :

  • Resource package for calling REST api
  • Relationnal casting between models
  • Casting of properties to other things
  • ...

This is a new projet so this is a only a starts but I think it go far away.