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

@that-hatter/scrapi-factory

v0.3.4

Published

Default loader and validator for scrapiyard.

Downloads

246

Readme

"Parses" scrapiyard documentation entries to ensure they are properly formatted to follow the specs. Details about the parsing process are outlined here.

This can be ran standalone for quick local validation, or added as an npm dependency when writing documentation-related projects.


Usage

Validating locally

A dump script can be run locally to generate a JSON file with the validated entries, or an error file. It only runs Steps 1 to 4 in the parsing pipeline.

By default, the script will look for an /api/ folder in the current working directory, so the quickest way to use it is installing and running factory directly inside the scrapiyard folder:

  • Clone the scrapiyard repo if you don't have a local copy yet.
    • git clone https://github.com/ProjectIgnis/scrapiyard
  • Navigate to the scrapiyard folder.
    • cd scrapiyard
  • Install factory.
    • npm i @that-hatter/scrapi-factory
  • Run the dump script.
    • npx dump
  • Check the /dump/ folder for the output (or error).

You can also install factory elsewhere, but you'll need to provide the api path to the dump command using the --api-path option:

  • npx dump -- --api-path="path/to/api"

As a Typescript Package

The parser package can be installed with npm.

npm i @that-hatter/scrapi-factory

It provides loader functions that return strictly-typed parsed outputs. A utility module for working with markdown AST is also included.

The most relevant function is loadYard. It is recommended to use fp-ts for the least amount of friction. Parts of the library are also re-exported with conventional acronyms and additional functions, under the /fp export.

import * as sf from '@that-hatter/scrapi-factory';
import { pipe, TE } from '@that-hatter/scrapi-factory/fp';

const program = pipe(
  sy.loadYard(sy.DEFAULT_OPTIONS),
  TE.map(({ api }) => {
    // ...
  })
);

There are also more granular functions that perform specific steps, such as loadAPI, loadRawAPI, and loadSourceRecord. See dump.ts for an example usage.

If not using fp-ts, you will need to call the result returned by loadYard to get a Promise, and manually check if the wrapped value is a Right (meaning successful) value.

import * as sf from '@that-hatter/scrapi-factory';
import { E } from '@that-hatter/scrapi-factory/fp';

const yard = await sf.loadYard(sy.DEFAULT_OPTIONS)();

if (E.isRight(yard)) {
  const { api } = yard.right;
  // ...
} else {
  throw yard.left;
}

You'll also need to handle Option types when they come up. You can use O.toNullable to convert O.Option<T> into T | null.

import { O } from '@that-hatter/scrapi-factory/fp';

const fnDocSummary = O.toNullable(fnDocEntry.summary);