Socket
Socket
Sign inDemoInstall

pagetojson

Package Overview
Dependencies
63
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.3 to 0.0.4

4

lib/AbstractToJson.js

@@ -28,5 +28,5 @@ 'use strict';

static async convertUrl(url, arg1, arg2) {
return new Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
reject('Not callable on abstract class');
});
})
}

@@ -33,0 +33,0 @@

@@ -6,4 +6,12 @@ 'use strict';

class pagetojson extends AbstractToJson {
constructor() {
/**
* Constructor for page to json
* @param aTag {Array} Array of tags to be converted
*/
constructor(aTags) {
super();
aTags.forEach(tag => {
this[`${tag}tojson`] = require(`${tag}tojson`);
});
this.aTags = aTags;
}

@@ -15,4 +23,8 @@

*/
static convert(html, options) {
throw new Error('Not yet implemented');
convert(html, options) {
const oResult = {};
this.aTags.forEach(tag => {
oResult[tag] = this[`${tag}tojson`].convert(html, options);
});
return oResult;
}

@@ -24,3 +36,3 @@

*/
static async convertUrl(url, options) {
async convertUrl(url, options) {
return new Promise((resolve, reject) => {

@@ -27,0 +39,0 @@ reject('Not yet implemented');

{
"name": "pagetojson",
"version": "0.0.3",
"version": "0.0.4",
"description": "Convert HTML page parts into JSON objects",

@@ -25,3 +25,5 @@ "main": "lib/index.js",

"dependencies": {
"request": "^2.87.0"
"request": "^2.87.0",
"tabletojson": "*",
"listtojson": "*"
},

@@ -28,0 +30,0 @@ "devDependencies": {

@@ -15,2 +15,4 @@ [![NPM](https://nodei.co/npm/pagetojson.png)](https://nodei.co/npm/pagetojson/)

So ... it basically converts just parts that are known yet into an Object Array of JSON objects.
This list will grow over the time, so feel free to attend here and add your own 'tagname'tojson which
will be added to the dependencies list.

@@ -29,3 +31,3 @@ ## Installation

const converted = pagetojson.convert('HTML-STRING', {
tags: ['table', 'ol', 'ul']
tags: ['table', 'list']
})

@@ -38,14 +40,9 @@

table: [
0: [...]
1: [...]
0: [...],
1: [...],
2: [...]
],
ol: [
0: [...]
1: [...]
2: [...]
],
ul: [
0: [...]
1: [...]
list: [
0: [...],
1: [...],
2: [...]

@@ -52,0 +49,0 @@ ]

@@ -1,2 +0,2 @@

const pagetojson = require('../lib/pagetojson');
const PageToJson = require('../lib/pagetojson');
const fs = require('fs');

@@ -17,10 +17,51 @@ const path = require('path');

it('calls convert and expects an exception', () => {
expect(pagetojson.convert).toThrow('Not yet implemented');
it('Instanciation pagetojson with an unknown tag e.g. "title" should throw an error', () => {
try {
const p2j = new PageToJson(['title']);
} catch (err) {
expect(err.message).toBe("Cannot find module 'titletojson' from 'pagetojson.js'");
}
});
it('instanciates pagetojson with a known tag: <table>', () => {
const p2j = new PageToJson(['table']);
expect(p2j).toBeDefined();
});
it('Convert a page containing tables', () => {
const p2j = new PageToJson(['table']);
expect(p2j).toBeDefined();
const converted = p2j.convert(html);
expect(converted).toBeDefined();
expect(_.has(converted, 'table')).toBeTruthy();
expect(_.isArray(converted.table)).toBeTruthy();
});
it('Convert a page containing tables and lists', () => {
const p2j = new PageToJson(['table', 'list']);
expect(p2j).toBeDefined();
const converted = p2j.convert(html);
expect(converted).toBeDefined();
expect(_.has(converted, 'table')).toBeTruthy();
expect(_.has(converted, 'list')).toBeTruthy();
expect(_.isArray(converted.table)).toBeTruthy();
});
it('Convert page containing specifically only table', () => {
const p2j = new PageToJson(['table']);
expect(p2j).toBeDefined();
const converted = p2j.convert(html);
expect(converted).toBeDefined();
expect(_.has(converted, 'table')).toBeTruthy();
expect(_.isArray(converted.table)).toBeTruthy();
});
it('calls convertUrl and expects an exception', () => {
expect.assertions(1);
return pagetojson.convertUrl().catch(e => expect(e).toMatch('Not yet implemented'));
const p2j = new PageToJson(['table']);
return p2j.convertUrl().catch(e => expect(e).toMatch('Not yet implemented'));
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc