1.1.5 • Published 7 years ago

@bluemango/smart-pixel-core v1.1.5

Weekly downloads
5
License
ISC
Repository
-
Last release
7 years ago

Smart Pixel

This library is a helper for creating a script that scrapes values of a page.

var smartPixel = new SmartPixel({
  title: {
    type:'text',
    selector:'h1.the-title' // this is a jquery selector that will look for the first h1 with the class the-title
  }
})
return smartPixel.getResults() // {title:'hello world'}

##The config The config is an objects where where every key stands for a field that wil be returned in the results. the value of the config item can be a string, object or a function.

###whitelistedDomain Only allow the library to work when the value matches the current domain. Value should be a regular expression of type string.

using an object

There are several types that you can select to configure your Smart Pixel via objects. the types you can choose from are listed below.

text

Use text to extract text from a page.

var smartPixel = new SmartPixel({
  title: {
    type:'text', // default value
    selector: '.title span',
    test: '/[0-9]*/g' // this wil test if the result only contains digits
  }
})

url

var smartPixel = new SmartPixel({
  clickUrl: {
    type:'url', // will return the current pageurl
    prefix: 'htttp://yourredirect.com/url=' (optional) use when you want to prefix your url,
    query: {myparam:''} // (optional) returns the url with only myparam appended to the url
  }
})

image

var smartPixel = new SmartPixel({
  imageUrl: {
    type:'image', // will return the src of an image
    selector: 'image#myImage'
  }
})

regex

var smartPixel = new SmartPixel({
  title: {
    type:'regex',
    selector: '.title span',
    test: '/€([0-9]*)/g' // wil return the first regex group
  }
})

template

var smartPixel = new SmartPixel({
  title: {
    type:'template',
    template: 'hello {{name}}' // will return the value of name
  },
  name: {
    type: 'text',
    selector: '.profile .name'
  }
})

using a string

Just a short hand for a selector with the type text (see example below).

var smartPixel1 = new SmartPixel({
  title: h1.the-title
})

var smartPixel2 = new SmartPixel({
  title: {
    type:'text',
    selector:'h1.the-title' // this is a jquery selector that will look for the first h1 with the class the-title
  }
})

using an function

var smartPixel = new SmartPixel({
  number1: {type:'template', template:'1'}
  number2: {type:'template', template:'3'}
  sum: function(smartPixel){
    var n1 = Number(smartPixel.getField('number1'))
    var n2 = Number(smartPixel.getField('number2'))
    return n1 + n2 // = 4
  }
})

You can also make a function property required:

var smartPixel = new SmartPixel({
  number1: {type:'template', template:'1'}
  number2: {type:'template', template:'3'}
  sum: {
    type: 'function',
    func: function() {
        var n1 = Number(smartPixel.getField('number1'))
        var n2 = Number(smartPixel.getField('number2'))
        return n1 + n2 // = 4
    },
    required: false,
  }
})

Default fields

by default the Smart Pixel only returns the following fields 'id', 'available', 'title', 'imageUrl', 'clickUrl', 'category', 'basket', 'description', 'priceNormal', 'priceDiscount', 'logoUrl', 'stickerText', 'custom1', 'custom2', 'custom3', 'custom4'

Releasing a new version

###Make a new build The main file for the module is the minified version of the Smart Pixel in dist/smartPixel.min.js, so we need to make sure we do a new build we publish the module. Before building, make sure you change the version number in package.json. You can't publish a NPM package with a specific version twice.

npm run build

###Publish new version to NPM

npm publish

After publishing a new version of the Smart Pixel core script, please create a new tag in Git. Use the vX.X.X format for the tag name.

Note: You need to be logged in to NPM (npm login) using the bluemango account. This is the only account that has the right permissions to publish the Smart Pixel NPM package.

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago