UNPKG

website-scraper

Version:

Download website to a local directory (including all css, images, js, etc.)

107 lines (79 loc) 1.56 kB
import types from './config/resource-types.js'; class Resource { constructor (url, filename) { this.url = url; this.filename = filename; this.type = null; this.depth = 0; this.parent = null; this.children = []; this.saved = false; this.encoding = 'binary'; } createChild (url, filename) { const child = new Resource(url, filename); let currentDepth = this.getDepth(); child.parent = this; child.depth = ++currentDepth; this.children.push(child); return child; } updateChild (oldChild, newChild) { const index = this.children.indexOf(oldChild); if (index >= 0) { this.children[index] = newChild; } } getUrl () { return this.url; } setUrl (url) { this.url = url; } getFilename () { return this.filename; } setFilename (filename) { this.filename = filename; } getText () { return this.text; } setText (text) { this.text = text; } getDepth () { return this.depth; } setType (type) { this.type = type; } getType () { return this.type; } setEncoding (encoding) { this.encoding = encoding; } getEncoding () { return this.encoding; } isHtml () { return this.getType() === types.html; } isCss () { return this.getType() === types.css; } toString () { return `{ url: "${this.getUrl()}", filename: "${this.getFilename()}", depth: ${this.getDepth()}, type: "${this.getType()}" }`; } isSaved () { return this.saved; } setSaved () { this.saved = true; } setMetadata (metadata) { this.metadata = metadata; } } export default Resource;