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

consistentity

v1.0.2

Published

Maintain your Datas/Entities at one point and manipulate it( encapsulated ) at one point

Downloads

25

Readme

ConsistEntity

npm devDependency Status

Maintain your Datas/Entities at one point and manipulate it( encapsulated ) at one point with a small(~1kb), well tested, Libraray.

Getting Started

This library is written in ECMAScript 6, therefore it requires Node.js >=0.10 and the npm( node-package-manager ) >=1.3 for transforming ES6 Code to ES5. Please make sure that you have installed Node.js and npm before you run e. g. "make build"( see below Install ). You also need make which is already available on Linux and MacOS.

Info:

If you use the installer npm comes with Node.js now

Downloads:

Install ConsistEntity with this command(s):

// this command transform ES6 Code to ES5 without any module dependency!
make build
// this command is equivalent to "make build"
make build module=ignore

// following modules are supported:
make build module=<name>
  @modules:
   - amd
   - amdStrict
   - common
   - commonStrict
   - ignore
   - system
   - umd
   - umdStrict
  @default:
   - module=ignore

If the build was successful you will find the library in:

dist/consistentity.js
Implementation and building for Browser
make build
<!DOCTYPE html>
<html>
    <head>
        <script src="path/to/lib/consistentity.js"></script>
    </head>
    <body>
        Content of the document......
    </body>
</html>
Implementation and building for AMD
make build module=amd
require(['consistentity'], function(Consistentity){
    ...
    ...
});
Implementation and building for commonjs
make build module=common
var Consistentity = require('consistentity');
...
...
Implementation and building for systemjs
make build module=system
import BaseComponent from 'consistentity';

// or

System.import('consistentity').then(function(Consistentity) {
    ...
    ...
});

Test your build in the Browser:

Note: before you run the test please open http://localhost:9876 in your Browser

make test

ConsistEntity is well tested in:

  • Chrome, Firefox, Safari, Opera, IE10, IE11

Why ConsitEntity? See below common situation!

Entities from somewhere( Database, etc. )

var entities = [
        {
            row : {
                location : 'Hamburg',
                foo : {
                    zipcode : '22117',
                    bar : {
                        brand : 'Mercedes'
                    }
                }
            }
        },
        {
            row : {
                location : 'Köln',
                foo : {
                    zipcode : '33443',
                    bar : {
                        brand : 'VW'
                    }
                }
            }
        },
        {
            row : {
                location : 'München',
                foo : {
                    zipcode : '88773',
                    bar : {
                        brand : 'BMW'
                    }
                }
            }
        },
        ...,
        ...,
        ...,
        ...,
        ...,
        ...,
];
Many templates that use the same entities

// advertising.handlebars
<div class="ad">
    {{#each entities}}
    <div class="ad-location">Location: {{row.location}}</div>
    <div class="ad-zip">Zipcode: {{row.foo.zipcode}}</div>
    <div class="ad-brand">Brand: {{row.foo.bar.brand}}</div>
    {{/each}}
</div>

// results.handlebars
<div class="results">
    {{#each entities}}
    <div class="item-wrapper">
        <div class="col-xs-4">
            <div class="res-location">Location: {{row.location}}</div>
        </div>
        <div class="col-xs-4">
            <div class="res-zip">Zipcode: {{row.foo.zipcode}}</div>
        </div>
        <div class="col-xs-4">
            <div class="res-brand">Brand: {{row.foo.bar.brand}}</div>
        </div>
    </div>
    {{/each}}
</div>

// product.handlebars
<div class="product">
    {{#each entities}}
    <div class="teaser">
        <img src="path/to/brandimages/{{row.foo.bar.brand}}.jpg" />
        <div class="product-brand">{{row.foo.bar.brand}}</div>
    </div>
    <div class="product-location">{{row.location}}</div>
    <div class="product-zip">{{row.foo.zipcode}}</div>
    {{/each}}
</div>

// and many other templates
...
...
...

But why is that( see below common situation ) not maintainable? Well, the answer is very simple! If your entities struct are changed then you have to correct it in all template files.

Thats why you have to use ConsistEntity:

var entities = [
        {
            row : {
                location : 'Hamburg',
                foo : {
                    zipcode : '22117',
                    bar : {
                        brand : 'Mercedes'
                    }
                }
            }
        },
        {
            row : {
                location : 'Köln',
                foo : {
                    zipcode : '33443',
                    bar : {
                        brand : 'VW'
                    }
                }
            }
        },
        {
            row : {
                location : 'München',
                foo : {
                    zipcode : '88773',
                    bar : {
                        brand : 'BMW'
                    }
                }
            }
        },
        ...,
        ...,
        ...,
        ...,
        ...,
        ...,
];

// control and/or manipulate your entity at one point
var accessor = {
        get location() { 
            return this.entity.row.location;
        },
        get zipcode() { 
            return this.entity.row.foo.zipcode;
        },
        get brand() { 
            var brand = this.entity.row.foo.bar.brand;
            return '*** '+ brand.toUpperCase() + ' ***';
        }
};

var entities = (new ConsistEntity(accessor, entities)).getDatas();

// advertising.handlebars
<div class="ad">
    {{#each entities}}
    <div class="ad-location">Location: {{row.location}}</div>
    <div class="ad-zip">Zipcode: {{row.zipcode}}</div>
    <div class="ad-brand">Brand: {{row.brand}}</div>
    {{/each}}
</div>

// results.handlebars
<div class="results">
    {{#each entities}}
    <div class="item-wrapper">
        <div class="col-xs-4">
            <div class="res-location">Location: {{row.location}}</div>
        </div>
        <div class="col-xs-4">
            <div class="res-zip">Zipcode: {{row.zipcode}}</div>
        </div>
        <div class="col-xs-4">
            <div class="res-brand">Brand: {{row.brand}}</div>
        </div>
    </div>
    {{/each}}
</div>

// product.handlebars
<div class="product">
    {{#each entities}}
    <div class="teaser">
        <img src="path/to/brandimages/{{row.brand}}.jpg" />
        <div class="product-brand">{{row.brand}}</div>
    </div>
    <div class="product-location">{{row.location}}</div>
    <div class="product-zip">{{row.zipcode}}</div>
    {{/each}}
</div>

// and many other templates
...
...
...

Todos

  • https://coveralls.io
  • constributors welcome

Maintainers

License

(C) Serkan Sipahi 2015, released under the MIT license