Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

webcheck-cheerio-multi-mapper

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webcheck-cheerio-multi-mapper

A webcheck plugin to map multiple times on one resource

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

webcheck-cheerio-multi-mapper

Webcheck plugin map data with cheerio multiple times on same resource

How to install

npm install --save webcheck-cheerio-multi-mapping

How to use

/*jslint node:true*/

'use strict';

var MappingPlugin = require('webcheck-cheerio-multi-mapper');

var Webcheck = require('webcheck');

var PluginGroup = require('webcheck-plugin-group');
var CheerioPlugin = require('webcheck-cheerio');
var webcheck = new Webcheck();
var plugin = new MappingPlugin({
    mappings: {
        a: '.a',
        nested: {
            b: 'div.b',
            c: '.c'
        }
    },
    each: 'body .eachClass'
});

var group = new PluginGroup({
    plugins: [new CheerioPlugin(), plugin]
});

webcheck.addPlugin(group);
group.enable();


Options

  • mappings: Object of mappings.
  • each: Query that matches each mapping root.
  • filterContentType: Follow only in matching content-type.
  • filterStatusCode: Follow only in matching HTTP status code (defaults to 2xx status codes).
  • filterUrl: Follow only in matching url.
  • onError: Function that get executed on errors.
  • onData: Function that get executed when data was fetched.

Note for filters

Filters are regular expressions, but the plugin uses only the .test(str) method to proof. You are able to write your own and much complexer functions by writing the logic in the test method of an object like this:

opts = {
   filterSomething: {
       test: function (val) {
           return false || true;
       }
   }
}

Overwrite values with crawl parameters


wbcheck.crawl({
    url: 'http://...',
    parameters: {
        forceValue: {
            a: 'This is now the value for a',
            nested: {
                b: 'This is now the value for b'
            }
        }
    }
}, function (err) {
    // go on here...
})

Working with onData

onData gives you the the result of the mapped data (named as data) and the result of the crawl (named as result).

Keywords

webcheck

FAQs

Package last updated on 19 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts