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

@amjs/data-types

v0.1.8

Published

Data types for your OOP javascript project

Downloads

26

Readme

@amjs/data-types 0.1.8

Statements Branches Functions Lines

Data types for your OOP javascript project

Installation

$ npm i @amjs/data-types

Usage

Can be use directly:

// some.js file
const AmjsDataTypes = require('@amjs/data-types');
const str = new AmjsDataTypes.AmjsDataTypesString();
str.value = 'My Awesome String';

console.log(str.value); // My Awesome String

Can be de-constructed:

const { AmjsDataTypesString } = require('@amjs/data-types');
const str = new AmjsDataTypesString();
str.value = 'My Awesome String';

console.log(str.value); // My Awesome String

Can be extended:

// MyString.js
const AmjsDataTypesString = require('@amjs/data-types/src/String');
module.exports = class MyString extends AmjsDataTypesString
{
    welcome(name = '')
    {
        this.value = `Welcome ${user}`;
    }
}

NOTICE: in those examples CommonJS architecture + ES6 syntax is being used, if its planned to use this ORM solution for web project, is suggested to use @babel to transpile files properly.

Working with Object data type

// Pre-register basic data types
require('@amjs/data-types/src/Date');
require('@amjs/data-types/src/Password');
require('@amjs/data-types/src/String');
// Requires parent Object class
const {AmjsDataTypesObject} = require('@amjs/data-types');

// Extend User from Object
class User extends AmjsDataTypesObject
{
    constructor(values)
    {
        super();

        // $privateProperties flags this object properties that should be handled internally
        this.$privateProperties = {
            password : true
        };

        // $propertyTypes maps the data type of each User property
        this.$propertyTypes = {
            password : 'Password',
            name     : 'String'
            birth    : 'Date'
        };

        // Use $propertyMap to map data values to User properties
        this.$propertyMap = {
            pwd         : 'password',
            userName    : 'name',
            dob         : 'birth'
        };

        // Flags $useMap to "true" to apply $propertyMap
        this.$useMap = true;

        // Declare properties
        this.password   = null;
        this.name       = null;
        this.birth      = null;

        this._setProperties(values);
    }
};

// Register User constructor (optional)
AmjsDataTypesObject.register('User', User);

const values = { pwd : '123456', userName : 'Mr. User', dob: '1989-02-03' };

// Direct creation
const user = new User();

// Factory creation
const user = AmjsDataTypesObject.create('User', values);

console.log(user.toJSON()); // { name : 'Mr. User', birth : '1989-02-03' }

Working with Collection data types


const { AmjsDataTypesCollection, AmjsDataTypesObject } = require('@amjs/data-types');

// Create (optional) & pre-register your item type class reference.
class MyObject extends AmjsDataTypesObject
{
    constructor(values)
    {
        super();

        /**
        * @override
        */
        this.$propertyTypes = {
            key : '*'
        };

        this.key = null;

        this._setProperties(values);
    }
}

AmjsDataTypesObject.register('MyObject', MyObject);

// Create a collection which "itemType" property is your new item type class
class MyCollection extends AmjsDataTypesCollection
{
    constructor(values)
    {
        super();
        this.$itemType = 'MyObject';
        this.value = values;
    }
}

const values = [{ key : 'value1' }, { key : 'value2' }, { key: 'value3' }];
const sut = new MyCollection(values);
console.log(sut.value); // [ MyObject { key: 'value1' }, MyObject { key: 'value2' }, MyObject { key: 'value3' } ]