const cloneItemContent = (li: Element): Element[] => { const children = Traverse.children(li); const content = hasLastChildList(li) ? children.slice(0, -1) : children; return Arr.map(content, Replication.deep); }
const parseList: Parser = (depth: number, itemSelection: Option<ItemSelection>, selectionState: Cell<boolean>, list: Element): Entry[] => { return Arr.bind(Traverse.children(list), (element) => { const parser = isList(element) ? parseList : parseItem; const newDepth = depth + 1; return parser(newDepth, itemSelection, selectionState, element); }); }
getImagesNum(res, name) { if (res) { let $ = cheerio.load(res); let len = $(".pagenavi") .find("a") .find("span").length; if (len == 0) { fs.rmdirSync(`${depositPath}${name}`);//删除无法下载的文件夹 return 0; } let pageIndex = $(".pagenavi") .find("a") .find("span")[len - 2].children[0].data; return pageIndex;//返回图片总数 } }
it('render svg elements with correct namespace', () => { const vm = new Vue({}) const h = vm.$createElement const vnode = h('svg', [h('a', [h('foo', [h('bar')])])]) expect(vnode.ns).toBe('svg') // should apply ns to children recursively expect(vnode.children[0].ns).toBe('svg') expect(vnode.children[0].children[0].ns).toBe('svg') expect(vnode.children[0].children[0].children[0].ns).toBe('svg') })
static _buildTree(str) { let currentNode = { children: [] }; const openNodes = [currentNode]; const l = str.length; // eslint-disable-next-line no-plusplus for (let i = 0; i < l; i++) { if (str[i] === '(') { currentNode = { str: '', children: [] }; openNodes[openNodes.length - 1].children.push(currentNode); openNodes.push(currentNode); } else if (str[i] === ')') { this._cleanNode(currentNode); openNodes.pop(); currentNode = openNodes[openNodes.length - 1]; } else { currentNode.str += str[i]; } } return currentNode.children[0]; }
request(options,function(err,res,body){ if(err)console.log(err); if(!err&&res.statusCode==200){ var html = iconv.decode(body, 'gb2312'); var $ = cheerio.load(html); var data = [ { time:'', title:'', url:'' } ]; $('.p2_con .p2_list .new_list .list_14 li').each(function(i,el){ if(i<5){ data[i] = {}; data[i].title = el.children[0].children[0].data; data[i].description ='发表时间:'+ el.children[2].children[0].data; data[i].url = el.children[0].attribs.href; } }); fs.writeFileSync('request_test.json', JSON.stringify(data), 'utf8'); } })
router.get('/comments/load', function *(next) { var data = this.request.query; var user = tokenCache[data.token]; var commentList = yield comments.find({}, {sort: {upvotes: -1}}); var res = {0: { children: [] }}; _.forEach(commentList, function(comment) { c = transformComment(comment); if (user) { c.vote = comment.voters[user] || 0; } parent = res[c.parent]; if (!parent) { res[c.parent] = { children: [c] }; } else { res[c.parent].children.push(c); } var old = res[c._id]; if (old) c.children = old.children; res[c._id] = c; }); this.body = res[0].children; });
it('programmatic access to $slots', () => { const vm = new Vue({ template: '<test><p slot="a">A</p><div>C</div><p slot="b">B</div></p></test>', components: { test: { render () { expect(this.$slots.a.length).toBe(1) expect(this.$slots.a[0].tag).toBe('p') expect(this.$slots.a[0].children.length).toBe(1) expect(this.$slots.a[0].children[0].text).toBe('A') expect(this.$slots.b.length).toBe(1) expect(this.$slots.b[0].tag).toBe('p') expect(this.$slots.b[0].children.length).toBe(1) expect(this.$slots.b[0].children[0].text).toBe('B') expect(this.$slots.default.length).toBe(1) expect(this.$slots.default[0].tag).toBe('div') expect(this.$slots.default[0].children.length).toBe(1) expect(this.$slots.default[0].children[0].text).toBe('C') return this.$slots.default[0] } } } }).$mount() expect(vm.$el.tagName).toBe('DIV') expect(vm.$el.textContent).toBe('C') })
superagent.get('http://health.people.com.cn/GB/26466/401878/404200/404225/index.html') .charset('gb2312') .end(function(err,result){ if(err) console.log(err); var $ = cheerio.load(result.text); var data = [ { time:'', title:'', url:'' } ]; $('.p2_con .p2_list .new_list .list_14 li').each(function(i,el){ if(i<5){ data[i] = {}; data[i].title = el.children[0].children[0].data; data[i].description ='发表时间:'+ el.children[2].children[0].data; data[i].url = el.children[0].attribs.href; } }); fs.writeFile('./text.json',JSON.stringify(data),function(err){ if(err){console.log("save fail")} console.log("save success"); }); })
function parseIdolsUtils(body) { const $ = cheerio.load(body); const $div = $('.ak-nocontentpadding')[1].children; for (let i = 0; i < $div.length; i++) { if ($div[i].type !== 'div') { $div.splice(i, 1); } } for (let i = 0; i < $div.length; i++) { for (let j = 0; j < $div[i].children.length; j++) { const $actual = $div[i].children[j]; if ($actual.type == 'tag' && $actual.name == 'div' && $actual.attribs.class == 'ak-panel-content') { if (i == 0) { item.description = $actual.children[0].data.replace(/\n/g, ''); } else if (i == 2) { item.spell = $actual.children[0].data.replace(/\n/g, ''); } } } } }
it('render svg elements with correct namespace', () => { const vm = new Vue({}) const h = vm.$createElement const vnode = h('svg', [h('a', [h('foo', [h('bar')])])]) expect(vnode.ns).toBe('svg') // should apply ns to children recursively expect(vnode.children[0].ns).toBe('svg') expect(vnode.children[0].children[0].ns).toBe('svg') expect(vnode.children[0].children[0].children[0].ns).toBe('svg') })
it('programmatic access to $slots', () => { const vm = new Vue({ template: '<test><p slot="a">A</p><div>C</div><p slot="b">B</div></p></test>', components: { test: { render () { expect(this.$slots.a.length).toBe(1) expect(this.$slots.a[0].tag).toBe('p') expect(this.$slots.a[0].children.length).toBe(1) expect(this.$slots.a[0].children[0].text).toBe('A') expect(this.$slots.b.length).toBe(1) expect(this.$slots.b[0].tag).toBe('p') expect(this.$slots.b[0].children.length).toBe(1) expect(this.$slots.b[0].children[0].text).toBe('B') expect(this.$slots.default.length).toBe(1) expect(this.$slots.default[0].tag).toBe('div') expect(this.$slots.default[0].children.length).toBe(1) expect(this.$slots.default[0].children[0].text).toBe('C') return this.$slots.default[0] } } } }).$mount() expect(vm.$el.tagName).toBe('DIV') expect(vm.$el.textContent).toBe('C') })