You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

chrome-web-store-item-property

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chrome-web-store-item-property - npm Package Compare versions

Comparing version

to
1.2.0

9

changelog.md

@@ -0,1 +1,10 @@

# [1.2.0](https://github.com/pandawing/node-chrome-web-store-item-property/compare/v1.1.3...v1.2.0) (2019-11-08)
### Features
* **app:** requires node v8 ([2612e0d](https://github.com/pandawing/node-chrome-web-store-item-property/commit/2612e0d566194b782a2487c54bf58c3a84d08b84))
* Use htmlparser2 directly
## [1.1.3](https://github.com/pandawing/node-chrome-web-store-item-property/compare/v1.1.2...v1.1.3) (2019-11-03)

@@ -2,0 +11,0 @@

6

package.json
{
"name": "chrome-web-store-item-property",
"description": "Gather meta information from chrome web store",
"version": "1.1.3",
"version": "1.2.0",
"author": {

@@ -12,5 +12,5 @@ "name": "sanemat",

"array-includes": "^3.0.3",
"cheerio": "^0.22.0",
"create-error-class": "^3.0.0",
"es6-promise": "^4.2.8",
"htmlparser2": "^4.0.0",
"is-ok": "^1.0.1",

@@ -37,3 +37,3 @@ "node-status-codes": "^3.0.0",

"engines": {
"node": ">=0.12.0"
"node": ">=8.0.0"
},

@@ -40,0 +40,0 @@ "files": [

'use strict';
var InvalidFormatError = require('./error').InvalidFormatError;
var Promise = Promise || require('es6-promise').Promise;
var cheerio = require('cheerio');
var htmlparser2 = require('htmlparser2');
var DomHandler = htmlparser2.DomHandler;
var Parser = htmlparser2.Parser;
var DomUtils = htmlparser2.DomUtils;
var includes = require('array-includes');

@@ -15,26 +18,31 @@ var parseFloatWithComma = require('./parse-float-with-comma');

return new Promise(function (resolve, reject) {
var $ = cheerio.load(detailHtml);
var itemProps = {};
var elementItemProp;
$('meta[itemprop]').each(function (index, element) {
var options = {};
var handler = new DomHandler(null, options);
new Parser(handler, options).end(detailHtml);
DomUtils.getElementsByTagName('meta', handler.dom, true).forEach(function(el) {
var itempropValue = DomUtils.getAttributeValue(el, 'itemprop');
if (!itempropValue) {
return;
}
var contentValue = DomUtils.getAttributeValue(el, 'content');
// Split content like <meta itemprop="interactionCount" content="UserDownloads:418" />
if ($(element).attr('itemprop') === 'interactionCount' &&
$(element).attr('content').indexOf(':') !== -1) {
var keyValue = $(element).attr('content').split(':', 2);
elementItemProp = $(element).attr('itemprop');
itemProps[elementItemProp] = itemProps[elementItemProp] || {};
if (itempropValue === 'interactionCount' && contentValue &&
contentValue.indexOf(':') !== -1) {
var keyValue = contentValue.split(':', 2);
itemProps[itempropValue] = itemProps[itempropValue] || {};
if (includes(keysStringToFloat, keyValue[0])) {
itemProps[elementItemProp][keyValue[0]] = parseFloatWithComma(keyValue[1]);
itemProps[itempropValue][keyValue[0]] = parseFloatWithComma(keyValue[1]);
} else {
itemProps[elementItemProp][keyValue[0]] = keyValue[1];
itemProps[itempropValue][keyValue[0]] = keyValue[1];
}
} else {
elementItemProp = $(element).attr('itemprop');
if (includes(keysStringToFloat, elementItemProp)) {
itemProps[elementItemProp] = parseFloatWithComma($(element).attr('content'));
if (includes(keysStringToFloat, itempropValue)) {
itemProps[itempropValue] = parseFloatWithComma(contentValue);
} else {
itemProps[elementItemProp] = $(element).attr('content');
itemProps[itempropValue] = contentValue;
}
}
});
handler = null;
if (Object.keys(itemProps).length === 0) {

@@ -41,0 +49,0 @@ reject(new InvalidFormatError('There is no meta property'));

Sorry, the diff of this file is too big to display