npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

toapi

v0.0.2

Published

Make Every website provides APIs.

Downloads

3

Readme

ToAPI

Make Every website provides APIs.

Introduction

Topapi is a supper slight server framework, which provide one way to ask for every website to provide apis.

We don't need to climb the website day by day. Because they should provide the API we need!

All we need is a Temme snippet.

Architecture

Toapi provide multi cache for every page u visit. So, don't worry about u make a huge trivial ddos like to the website.

Demo

asciicast

Get Started

Install

git clone [email protected]:yesvods/toapi.git
cd toapi && npm install

Start Example

  • Node Require: 8.6+ to support async function
npm start
# then visit localhost:3000/job/3616345

That's all, can't be simple much more. Read more about example.

NPM

Install the NPM module:

npm install toapi

Usage

Let's say we need to visit the job detail API of lagou.

Such as https://www.lagou.com/jobs/3616345.html

We just write a temme selector like:

...
.job_company@company {
  .fl{find($name|fp, '拉勾认证企业')}
  .c_feature li:nth-child(1){find($domain|fp, '领域')}
  .c_feature li:nth-child(2){find($stage|fp, '发展阶段')}
  .c_feature li:nth-child(3){find($size|fp, '规模')}
  .c_feature li:nth-child(4) a[href=$link];
}
...

If u don't know what temme is. Maybe u can ref this: https://github.com/shinima/temme

And then register it!

const ToAPI = require('toapi')

ToAPI.register({
  routeName: '/job/:id',
  matchUrl: 'https://www.lagou.com/jobs/:id.html',
  selector: selector,
})

ToAPI.start(3000)

All things are done, enjoy ur website swimming.

API

ToAPI.start(port, options)

Start the ToAPI server, u can continue to register route after server started.

  • port
    • the starting port
  • options
    • watiUntil, defaults to domcontentloaded
      • Spec the browser event that represent page data is ready.
      • more options can be see here
    • timeout, defaults to 30000
      • Spec timeout value when requesting to the target page.
// pageA will be timeout after 30000(default) ms
ToAPI.register(pageA)

ToAPI.start(3000, { timeout: 60000 })

// pageB will be timeout after 60000 ms
ToAPI.register(pageB)

ToAPI.register(options)

Register the page route to be served.

  • routeName (optional)
    • The same as koa route
    • ToAPI will parse from matchUrl if not specified.
    • eample: /page/:id
  • matchUrl
    • The target website match route
    • example: http://example.com/page/:id
  • selector (optional)
    • The Temme Selector to spec page
  • waitUntil
    • DefaultsTo: domcontentloaded
  • timeout
    • DefaultsTo: 30000