pagetojson
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -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
Floating dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 2 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
67707
675
0
3
2
57
2
+ Addedlisttojson@*
+ Addedtabletojson@*
+ Addedboolbase@1.0.0(transitive)
+ Addedcheerio@1.0.0-rc.12(transitive)
+ Addedcheerio-select@2.1.0(transitive)
+ Addedcss-select@5.1.0(transitive)
+ Addedcss-what@6.1.0(transitive)
+ Addeddom-serializer@2.0.0(transitive)
+ Addeddomelementtype@2.3.0(transitive)
+ Addeddomhandler@5.0.3(transitive)
+ Addeddomutils@3.1.0(transitive)
+ Addedentities@4.5.0(transitive)
+ Addedhtmlparser2@8.0.2(transitive)
+ Addedlisttojson@0.0.6(transitive)
+ Addednth-check@2.1.1(transitive)
+ Addedparse5@7.1.2(transitive)
+ Addedparse5-htmlparser2-tree-adapter@7.0.0(transitive)
+ Addedtabletojson@4.1.3(transitive)