New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

content-diff

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

content-diff - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

profile-test.json

147

lib/index.js

@@ -36,14 +36,36 @@ #!/usr/bin/env node

// Make babel happy
var Monitor = /*#__PURE__*/function () {
function Monitor(options) {
function Monitor() {
_classCallCheck(this, Monitor);
this.argv = (0, _yargs["default"])((0, _helpers.hideBin)(process.argv)).argv;
this.profilePath = this.argv.profilePath || "/tmp";
this.argv = (0, _yargs["default"])((0, _helpers.hideBin)(process.argv)).usage('Usage: cross-env --profile <profile> --url [URL TO TEST]').option('profile', {
describe: 'Name of the profile to test against',
"default": "default-profile",
alias: "p"
}).string("profile").option('url', {
describe: 'URL to test. eg: https://example.com',
alias: "u"
}).string("url").option('initUrls', {
describe: 'List of urls to create profile with'
}).array('initUrls').option('profilePath', {
describe: 'Location to store generated profiles in',
"default": process.cwd(),
alias: "path"
}).string("profilePath").option('learn', {
describe: 'Relearn profile even if it already exist',
alias: "l"
}).check(function (_ref) {
var profile = _ref.profile,
url = _ref.url,
initUrls = _ref.initUrls,
profilePath = _ref.profilePath;
if (this.argv.url) {
options.testUrl = this.argv.url;
}
if (!url && !initUrls) {
throw new Error("You must supply --profile and either --url or --initUrls");
}
this.run(options);
return true;
}).help().argv;
this.run();
}

@@ -54,3 +76,3 @@

value: function () {
var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime["default"].mark(function _callee(options) {
var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime["default"].mark(function _callee() {
var profile, testPage, matched;

@@ -62,3 +84,3 @@ return _regeneratorRuntime["default"].wrap(function _callee$(_context) {

_context.next = 2;
return this.getPageProfile(options.name);
return this.getPageProfile();

@@ -69,41 +91,46 @@ case 2:

if (!(!profile || this.argv.learn)) {
_context.next = 17;
_context.next = 20;
break;
}
if (!("initUrls" in options && options.initUrls.length > 0)) {
_context.next = 17;
if (!(this.argv.initUrls && this.argv.initUrls.length > 0)) {
_context.next = 18;
break;
}
console.log(_chalk["default"].cyan("Learning new profile for ".concat(options.name, " from ").concat(options.initUrls.length, " init urls...")));
console.log(_chalk["default"].cyan("Learning new profile for ".concat(this.argv.profile, " from ").concat(this.argv.initUrls.length, " init urls...")));
_context.t0 = this;
_context.t1 = options;
_context.next = 10;
return this.generatePageStructure(options);
_context.next = 9;
return this.generatePageStructure();
case 10:
_context.t2 = _context.sent;
_context.next = 13;
return _context.t0.saveProfile.call(_context.t0, _context.t1, _context.t2);
case 9:
_context.t1 = _context.sent;
_context.next = 12;
return _context.t0.saveProfile.call(_context.t0, _context.t1);
case 13:
_context.next = 15;
return this.getPageProfile(options.name);
case 12:
_context.next = 14;
return this.getPageProfile();
case 15:
case 14:
profile = _context.sent;
console.log(_chalk["default"].cyan("Profile created and saved to ".concat(_path["default"].join(this.profilePath, "profile-".concat(options.name, ".json")))));
console.log(_chalk["default"].cyan("Profile created and saved to ".concat(_path["default"].join(this.argv.profilePath, "profile-".concat(this.argv.profile, ".json")))));
_context.next = 20;
break;
case 17:
if (!("testUrl" in options)) {
_context.next = 24;
case 18:
console.log(_chalk["default"].red("Profile \"".concat(this.argv.profile, "\" does not exist! Pass --initUrls to generate it.")));
process.exit(1);
case 20:
if (!("url" in this.argv)) {
_context.next = 27;
break;
}
console.log(_chalk["default"].cyan("Testing ".concat(options.testUrl, " against profile...")));
_context.next = 21;
return this.getContentOfPage(options.testUrl);
console.log(_chalk["default"].cyan("Testing ".concat(this.argv.url, " against profile...")));
_context.next = 24;
return this.getContentOfPage(this.argv.url);
case 21:
case 24:
testPage = _context.sent;

@@ -119,3 +146,3 @@ matched = new _StructureParser["default"]([(0, _nodeHtmlParser.parse)(testPage.data)]).doPagesMatchProfile(profile);

case 24:
case 27:
case "end":

@@ -128,3 +155,3 @@ return _context.stop();

function run(_x) {
function run() {
return _run.apply(this, arguments);

@@ -138,3 +165,3 @@ }

value: function () {
var _saveProfile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime["default"].mark(function _callee2(options, structure) {
var _saveProfile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime["default"].mark(function _callee2(structure) {
var profile;

@@ -146,7 +173,6 @@ return _regeneratorRuntime["default"].wrap(function _callee2$(_context2) {

profile = {
meta: options,
structure: structure
};
_context2.next = 3;
return _promises["default"].writeFile(_path["default"].join(this.profilePath, "profile-".concat(options.name, ".json")), JSON.stringify(profile));
return _promises["default"].writeFile(_path["default"].join(this.argv.profilePath, "profile-".concat(this.argv.profile, ".json")), JSON.stringify(profile));

@@ -161,3 +187,3 @@ case 3:

function saveProfile(_x2, _x3) {
function saveProfile(_x) {
return _saveProfile.apply(this, arguments);

@@ -171,3 +197,3 @@ }

value: function () {
var _getPageProfile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime["default"].mark(function _callee3(name) {
var _getPageProfile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime["default"].mark(function _callee3() {
return _regeneratorRuntime["default"].wrap(function _callee3$(_context3) {

@@ -180,3 +206,3 @@ while (1) {

_context3.next = 4;
return _promises["default"].readFile(_path["default"].join("/tmp/", "profile-".concat(name, ".json")).toString("ascii"));
return _promises["default"].readFile(_path["default"].join(this.argv.profilePath, "profile-".concat(this.argv.profile, ".json")).toString("ascii"));

@@ -197,6 +223,6 @@ case 4:

}
}, _callee3, null, [[0, 8]]);
}, _callee3, this, [[0, 8]]);
}));
function getPageProfile(_x4) {
function getPageProfile() {
return _getPageProfile.apply(this, arguments);

@@ -210,3 +236,3 @@ }

value: function () {
var _generatePageStructure = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime["default"].mark(function _callee4(options) {
var _generatePageStructure = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime["default"].mark(function _callee4() {
var _this = this;

@@ -220,3 +246,3 @@

_context4.next = 2;
return Promise.all(options.initUrls.map(function (url) {
return Promise.all(this.argv.initUrls.map(function (url) {
return _this.getContentOfPage(url);

@@ -233,3 +259,3 @@ }));

throw new Error("Init urls for ".concat(options.name, " are not alike."));
throw new Error("Init urls for ".concat(this.argv.profile, " are not alike."));

@@ -250,3 +276,3 @@ case 5:

function generatePageStructure(_x5) {
function generatePageStructure() {
return _generatePageStructure.apply(this, arguments);

@@ -293,3 +319,3 @@ }

function getContentOfPage(_x6) {
function getContentOfPage(_x2) {
return _getContentOfPage.apply(this, arguments);

@@ -303,27 +329,4 @@ }

return Monitor;
}(); // new Monitor({
// name: "dunelm-search",
// initUrls: [
// "https://www.dunelm.com/search?q=dog",
// "https://www.dunelm.com/search?q=cat",
// "https://www.dunelm.com/search?q=bird",
// "https://www.dunelm.com/search?q=snake",
// "https://www.dunelm.com/search?q=curtain",
// "https://www.dunelm.com/search?q=sofa",
// "https://www.dunelm.com/search?q=frame",
// "https://www.dunelm.com/search?q=towel",
// "https://www.dunelm.com/search?q=curtains",
// "https://www.dunelm.com/search?q=rail",
// "https://www.dunelm.com/search?q=bedding",
// "https://www.dunelm.com/search?q=meme",
// "https://www.dunelm.com/search?q=ruffle",
// ],
// testUrl: "https://www.dunelm.com/search?q=lamp"
// });
}();
new Monitor({
name: "dunelm-product",
initUrls: ["https://www.dunelm.com/product/hartley-qcover-set-dbl-gry-1000170244", "https://www.dunelm.com/product/teddy-neck-hot-water-bottle-grey-1000170314", "https://www.dunelm.com/product/universal-linen-divan-base-grey-1000119449", "https://www.dunelm.com/product/ivyline-parlour-palm-plant-in-ceramic-pot-chamaedorea-elegans-1000182214", "https://www.dunelm.com/product/clara-cotton-velvet-cushion-1000115671", "https://www.dunelm.com/product/luxrurious-cotton-silver-towel-1000171593", "https://www.dunelm.com/product/disney-marvel-comics-duvet-cover-and-pillowcase-set-1000112971", "https://www.dunelm.com/product/indulgence-shaggy-rug-1000087020?defaultSkuId=30615844", "https://www.dunelm.com/product/delphi-1-drawer-bedside-table-1000162418", "https://www.dunelm.com/product/grey-and-white-hand-painted-chest-1000120112", "https://www.dunelm.com/product/hickory-bed-frame-white-1000163729", "https://www.dunelm.com/product/teddy-bear-grey-round-dog-bed-1000131130?defaultSkuId=30586887", "https://www.dunelm.com/product/bunty-blue-retractable-lead-1000156912?defaultSkuId=30675168"],
testUrl: "https://www.dunelm.com/product/day-and-night-roller-blind-2ft-grey-1000164524?blindSize=W+91cm+%2836%22%29+x+D+162cm+%2864%22%29&defaultSkuId=30687845"
});
new Monitor();
{
"name": "content-diff",
"version": "1.0.2",
"version": "1.0.3",
"description": "A tool for checking a page is a valid format by profiling a type of web page and then testing if a page matches that profile.",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc