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

mistraljs

v0.1.5

Published

a core of first library which use MVRVM Programming concept

Downloads

3

Readme

mistraljs

Mistraljs is an modified and improvement of the Mustache templating language created by Chris Wanstrath. Mistraljs is library use MVR-VM (Model View Route - ViewModel) Concept to help you create prototype.

#MVR-VM Concept

A programming concept that combine MVVM with Routing System, that makes MVRVM really help to make a prototype. But for now, Mistraljs only in MVR development state.

Installation

To support open source community mistraljs use 2 important dependecies, jquery and underscorejs.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="../release/mistral.js"></script>

NPM

npm install mistraljs

Mistraljs use jquery and underscore to make it better. And this is base example using Mistraljs :

<!DOCTYPE html>
<html lang="">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>

</head>

<body>
    <div class="nav"></div>
    <div id="content"></div>
    <div class="nav"></div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
    <script src="../release/mistral.js"></script>
    <script>
        var nav = {
            pathToTemplate: 'templates/nav.html',
            renderIn: '.nav',
            name: 'nav'
        };
        Session.set("newsfeed", [{
            "content": "Moe"
        }, {
            "content": "Larry"
        }, {
            "content": "Curly"
        }]);
        Mistral.configure({
            templates: [nav]
        });
        Mistral.route('/', 'base', [{
            pathToTemplate: 'templates/hello.html',
            renderIn: '#content',
            name: 'hello'
        }]);
        Mistral.route('/about', 'about', [{
            pathToTemplate: 'templates/about.html',
            renderIn: '#content',
            name: 'about'
        }]);
        Mistral.route('/newsfeed', 'newsfeed', [{
            pathToTemplate: 'templates/newsfeed.html',
            renderIn: '#content',
            name: 'newsfeed',
            data: {
                name: "Yoza Wiratama",
                newsfeed: Session.get("newsfeed")
            },
            onBefore : function(){
                console.log('before');
            }
        }]);
        Mistral.routeOtherWise('/');

    </script>
</body>

</html>

Route

In router.js or router script we can init route code with this standard :

var nav = {
    pathToTemplate: 'templates/nav.html',
    renderIn: '.nav',
    name: 'nav'
};
Session.set("newsfeed", [{
    "content": "Moe"
}, {
    "content": "Larry"
}, {
    "content": "Curly"
}]);
Mistral.configure({
    templates: [nav]
});
Mistral.route('/', 'base', [{
    pathToTemplate: 'templates/hello.html',
    renderIn: '#content',
    name: 'hello'
}]);
Mistral.route('/about', 'about', [{
    pathToTemplate: 'templates/about.html',
    renderIn: '#content',
    name: 'about'
}]);
Mistral.route('/newsfeed', 'newsfeed', [{
    pathToTemplate: 'templates/newsfeed.html',
    renderIn: '#content',
    name: 'newsfeed',
    data: {
        name: "Yoza Wiratama",
        newsfeed: Session.get("newsfeed")
    },
    onBefore : function(){
        console.log('before');
    }
}]);
Mistral.routeOtherWise('/');

Example :

Mistral.route('/', 'home', [{
    pathToTemplate: 'home.html',
    renderIn: 'content',
    name: 'home'
}]);

Because templates using array of object (View Model), so we can render more templates in one route.

route(path, routeName, templates)

go(path)

getRoute(path)

getCurrentRoute()

getRouteByName(name)

routeOtherWise(route)

refresh(templateName)

Configure

If you want to use a default ViewModel in default template or layout for all routes you can configure it. :

var navbar = {
    pathToTemplate: 'navbar.html',
    renderIn: 'navbar',
    name: 'navbar'
}
Mistral.configure({
    templates: [nav]
});

templates using array of ViewModel, so we can add more templates in a layout, for example navbar and sidebar.

Session

Session is a provider to store data or value on client globally. Store and also can refresh view or template automatically.

set(name, value)

Session.set('activeId', 'TTdayoza76876adGQRA');

setReactive(name, value, templateName)

setReactive method will provide us to refresh all templates or a template by name. Leave empty or undefined it will refresh all.

Session.setReactive('activeId', 'TTdayoza76876adGQRA'); // refresh all templates
Session.setReactive('activeId', 'TTdayoza76876adGQRA', 'nav'); // refresh template with name nav

get(name)

var activeId = Session.get('activeId');

equals(name, value)

if(Session.equals('activeId', 'TTdayoza76876adGQRA')) return true;
else return false;

Collection

Collection is a connection between view and data, also like a table in database. For now collection only provides store data to localstorage easily. Simple init :

var feeds = new Mistral.Collection('feed');

Localstorage

var feeds = new Mistral.Collection('feed');

insert(data)

Insert data to collection.

feeds.insert({content : 'cool'}); 
var newId = feeds.insert({content : 'cool'}); // "tto2Mt0iTVhi8hK4E4RoxzIAuqH"

update(query, set)

feeds.update({id : 'tto2Mt0iTVhi8hK4E4RoxzIAuqH'}, {content : 'super cool'});

find(query)

find will return array.

feeds.find({id : 'tto2Mt0iTVhi8hK4E4RoxzIAuqH'});

findOne(query)

findOne will return first object.

feeds.findOne({id : 'tto2Mt0iTVhi8hK4E4RoxzIAuqH'});

remove

feeds.remove({id : 'tto2Mt0iTVhi8hK4E4RoxzIAuqH'});

Random (alpha)

Generate random string to make unique id or secret.

Random.id(length)

Random.id generated with datetime data, so it will really unique.

var id = Random.id(25);
console.log(id); // q0jxtLGNM2c771EuKt1uzzPmn

License

The MIT License (MIT) Copyright (c) 2015 by Yoza Wiratama

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.