UNPKG

cb10-sdk

Version:

Cybozu Office 10 SDK for Node.js

97 lines 3.96 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _a, _MessageHtmlParser_extractCommentInfo; Object.defineProperty(exports, "__esModule", { value: true }); const cheerio = __importStar(require("cheerio")); class MessageHtmlParser { static parseComments(html) { const $ = cheerio.load(html); const comments = []; $('#Follows > div').each((_, el) => { const comment = __classPrivateFieldGet(_a, _a, "m", _MessageHtmlParser_extractCommentInfo).call(_a, $, el); if (comment) { comments.push(comment); } }); return comments; } static parseReceivers(html) { const $ = cheerio.load(html); const receivers = []; $('select[name="UID"] > option').each((_, el) => { const $element = $(el); const uID = Number($element.val()); if (uID !== 0) { receivers.push({ uID, userName: $element.text(), }); } }); return receivers; } } _a = MessageHtmlParser, _MessageHtmlParser_extractCommentInfo = function _MessageHtmlParser_extractCommentInfo($, element) { const $element = $(element); const followIdMatch = $element.attr('id')?.match(/(?<=follow-root-)[0-9]+/i); if (!followIdMatch) { return null; } const $attachedLink = $element.find('.vr_viewContentsAttach td:first-child a'); const attached = $attachedLink.attr('href'); let attachedFile = undefined; let attachedQuery = undefined; if (attached) { const [_, file, query] = attached.split(/[/?]/); attachedFile = file || ''; const attachedQueryStr = query ? query.replace(/&amp;/gi, '&') : ''; if (attachedQueryStr) { attachedQuery = Object.fromEntries(new URLSearchParams(attachedQueryStr)); } } return { followId: Number(followIdMatch[0]), userName: $element.find('.vr_followUserName').text(), attachedFile, attachedQuery, }; }; exports.default = MessageHtmlParser; //# sourceMappingURL=parser.js.map