UNPKG

eksi-sozluk

Version:
95 lines (84 loc) 1.39 kB
const { URLS } = require('../constants') /** * Tag. */ class Tag { /** * Tag ID. * * @type {(number|null)} */ id = null /** * Tag name. * * @type {TagName} */ name /** * Tag description. * * @type {string} */ description /** * Tag URL. * * @type {string} */ link /** * Is tag followed? * * @type {(boolean|null)} */ followed = null /** * Create tag. * * @param {string} [cookies=null] Cookie string. */ constructor (cookies = null) { this._cookies = cookies } /** * Parse properties with given document. * * @param {object} $ Cheerio document. * @param {object} elm Cheerio element. * @ignore */ serialize ($, elm) { this.name = $(elm) .find('h3 a') .text() .substring( 1, $(elm) .find('h3 a') .text().length ) this.description = $(elm) .find('p') .text() this.link = URLS.BASE + $(elm) .find('h3 a') .attr('href') const isAuth = this._cookies // bind auth properties if (isAuth) { this.id = parseInt( $(elm) .find('button') .data('follow-url') .split('/')[2] ) this.followed = $(elm) .find('button') .data('followed') } } } module.exports = Tag