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

@aseemtaneja/kit-list

v0.2.1

Published

A helper for the Script Kit automation app to generate a list of items from an HTML document.

Downloads

19

Readme

kit-list

A helper for the Script Kit automation app to generate a list of choices from an HTML document.

Why this exists?

I made this to scratch an itch of mine. There are sites I visit from time to time to check out what's new. Many of these sites don't provide an API. This helper allows you to 'API-fy' a regular HTML page using CSS selectors and spits out the data in a format that can be readily consumed by John Lindquist's very cool Kit app.

Install

cd into your ~/.kenv folder:

npm install @aseemtaneja/kit-list@latest

Examples

Get a list of all Frontend Masters courses

Create a new script e.g. ~/.kenv/scripts/frontend-masters.js

// Name: Frontend Masters
// Description: Browse courses from frontendmasters.com
// Author: Aseem Taneja
// Twitter: @aseemtaneja

import '@johnlindquist/kit';
const list = await npm('@aseemtaneja/kit-list');

const { choices } = await list('https://frontendmasters.com/courses/', {
        containerSelector: '.MediaItem',
        hrefSelector: 'h2 a',
        descriptionSelector: '.description',
        metaSelector: '.Instructor .name',
      });

const itemUrl = await arg('Go to', choices);

await $`open ${itemUrl}`;

Choose from a list of pages before getting the list of courses

Create a new script e.g. ~/.kenv/scripts/courses.js

// Name: List
// Description: Browse latest courses from your favourite sites
// Author: Aseem Taneja
// Twitter: @aseemtaneja
// Shortcode: course

import '@johnlindquist/kit';
const list = await npm('@aseemtaneja/kit-list');

const PAGES = [
  {
    name: '🥋 frontendmasters',
    description: 'Courses from frontendmasters.com',
    value: {
      url: 'https://frontendmasters.com/courses/',
      selectors: {
        containerSelector: '.MediaItem',
        hrefSelector: 'h2 a',
        descriptionSelector: '.description',
        metaSelector: '.Instructor .name',
      },
    },
  },
  {
    name: '🥚 egghead',
    description: 'Courses from egghead.io',
    value: {
      url: 'https://egghead.io/q?sortBy=created',
      selectors: {
        containerSelector: 'a[href^="/playlists"]',
        titleSelector: '[data-egghead-card-body] h3',
        descriptionSelector: '[data-egghead-card-author] > span',
      },
    },
  },
];

const { url: pageUrl, selectors, options } = await arg('Select', PAGES);

const { choices } = await list(pageUrl, selectors, options);

const itemUrl = await arg('Go to', choices);

await $`open ${itemUrl}`;

API

function list(
  url: string,
  selectors: ItemSelectors,
  listOptions?: ListOptions | undefined
): Promise<{
  data: ItemData[];
  choices: Choice<string>[];
}>

Arguments

url (required)

Type: string

A valid http/https url of the page to be scraped.

selectors (required)

Type: object
  • containerSelector (required) - selector for a wrapper element (doubles as the url selector if no hrefSelector is specified – useful for 'card' layouts where the 'card' is an anchor tag).

    🚨 All other selectors use the container element (specified by the containerSelector) as context

  • hrefSelector (optional) - selector for the anchor tag which specifies the item url (doubles as the title selector if no titleSelector is specified)/
  • titleSelector (optional) - selector for item title.
  • descriptionSelector (optional) - selector for item description.
  • metaSelector (optional) - selector for item meta (prepended to the title).

listOptions (optional)

Type: object
  • meta - object that controls how item meta appears in the choices.
    • hide - hide item meta.
    • afterTitle - append meta to title (instead of prepending it).
  • translate - an options object as expected by @vitalets/google-translate-api which can be used to translate the item titles and descriptions to the desired language.

Return Value

A Promise which resolves to an object with the following properties:

choices

Type: array

An array of 'choice' objects. Each item is a 'choice' object (structurally expected by the Kit app) with the following properties:

  • name - the item title and item meta (if any)
  • description - the item description (if any) or the item url
  • value - the item url

data

Type: array

An array of `item data' objects. Each item in the array has the following properties:

  • title - the item title or 'No title' if one couldn't be found
  • url - the item url or the page url if no item url could be found
  • description - the item description or an empty string
  • meta - the item meta or an empty string

💡 data can be used to format your results in the way you want if what choices returns does not cut it for you.