1.0.0 • Published 4 years ago

next-page-kit v1.0.0

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

next-page-kit

Helper for handle next-next page

Build Status Coverage Status npm version npm downloads npm license

Install

$ npm i -S next-page-kit

API

const NextPageKit = require('next-page-kit')

n = new NextPageKit(options)

optionstyperemark
options.charsettype: String, allowedutf8 or gbkthe page charset
options.getCurrentfunction ($: cheerio) => anyreturns current paeg data
options.hasNextfunction ($: cheerio) => Booleantest has next page
options.getNextfunction ($: cheerio) => Stringget next page url
const n = new NextPageKit({
  getCurrent($) {
    return $('img')
      .map(function() {
        return $(this).attr('src')
      })
      .toArray()
  },
  hasNext($) {},
  getNext($) {},
})

// Promise<string[]>
// all img src
n.run()

n.run(url, options)

  • url: the entry
  • options:
    • limit: page limit

more see types/index.d.ts

/// <reference types="cheerio" />

export type Charset = 'utf8' | 'gbk'

export default class NextPageKit<T> {
  constructor(options: {
    charset?: Charset
    getCurrent($: CheerioStatic): T[] | T
    hasNext($: CheerioStatic): boolean
    getNext($: CheerioStatic): string
  })

  getCurrent($: CheerioStatic): T[] | T
  hasNext($: CheerioStatic): boolean
  getNext($: CheerioStatic): string

  run(url: string, options?: {limit?: number}): Promise<T[]>
}

Changelog

CHANGELOG.md

License

the MIT License http://magicdawn.mit-license.org