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

menio

v0.2.1

Published

production-quality template convention to scrap web sites based on cheerio

Downloads

4

Readme

menio

production-quality template convention to scrap web sites based on cheerio

Installation

$ npm install menio

A Menio template

module.exports = {
    // Selector
    context: {
        selector: 'table > tr',
        index: 4
    },
    // Properties
    props: {
        
        render: function ($scope) {
            var numeros = $scope.$find('tr');

            // return scope and next = true if this only selects for another template, only available in callback mode
            return {
                $scope: numeros,
                next: true
            };
        }
    }
};

Another Menio template

module.exports = {
    context: 'td',
    props: {
        tipo: function ($scope) {
            // either return or assign to this.model
            return $scope.eq(0).text();
        },
        fecha: function ($scope) {
            return $scope.eq(1).text();
        },
        primero: function ($scope) {
            return {
                numero: $scope.eq(2).text(),
                serie: $scope.eq(4).text(),
                folio: $scope.eq(5).text(),
                verificacion: $scope.eq(6).text(),
                letras: $scope.eq(3).text()
            };
        },
        segundo: function ($scope) {
            return {
                numero: $scope.eq(7).text()
            };
        },
        tercero: function ($scope) {
            return {
                numero: $scope.eq(8).text()
            };
        },
        dateFormatISO: function () {
            return 'es-pa';
        },
        id: function($scope) {
          return this.tipo($scope) + this.fecha($scope);
        }
    }
};

Menio Docs

new Menio(templateDirectory)

menio.parse(htmlOrDOM, templateName, callback)

menio.render(options { template, data }, callback)

Callback(err, scope, model)

Menio Template Docs

Property(scope, cheerio, underscore)

Property(scope, cheerio, underscore)

Response(either value or options)

Response Options($scope, next), only available in callback mode

Example

        // add template directory
        var menio = new Menio(__dirname + '/templates');
        
        // async callback
        // 1st argument - either a $ element or HTML
        // 2nd argument - name of the template
        // 3rd and optional - callback
        menio.parse(html, 'loteria', function (err, $scope) {
            // callback returns error, scope and model
            var data = _.map(_.rest($scope, 3), function (row) {
                // sync returns results right away
                return menio.render({ template: 'row', data: row });
            });



            var matchWith = {
                tipo: 'Dominical',
                fecha: '01-09-2013',
                primero: {
                    numero: '0677',
                    serie: '4',
                    folio: '13',
                    verificacion: '',
                    letras: 'DDBC'
                },
                segundo: {
                    numero: '7260'
                },
                tercero: {
                    numero: '8783'
                },
                dateFormatISO: 'es-pa',
                id : 'Dominical01-09-2013'
            };
            expect(data[0]).toEqual(matchWith);
        });

    });

Changelog

  • 0.2.0: Better API with $scope.$find, context selector index and added render (same as parse) which accepts an options argument

License

Copyright 2015 Rogelio Morrell C. MIT License