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

surfline

v0.0.14

Published

Surfline API bindings and types in JS with no external dependencies

Downloads

1

Readme

surfline

Surfline API bindings and types in JS with no external dependencies.

The publicly available Surfline API is undocumented, but relatively easy to call. However, the response types are often quite messy, and at times inconsistent.

This library provides more clarity of response types by providing rigorous Typescript bindings for the available Surfline API calls.

install

$ npm install surfline --save

usage

This library exposes three Surfline API calls:

  1. fetchTaxonomy -- used to fetch location entities
  2. fetchForecast -- used to fetch forecasts for spots
  3. fetchSpotInfo -- used to fetch surf spot information
import {fetchTaxonomy} from 'surfline';
import {fetchEarthTaxonomy} from 'surfline/taxonomy';

fetchTaxonomy({id: <some-id>}).then((res: TaxonomyResponse) => {
  // do something with result...
  // eg. fetch all taxonomies in res.contains
})

// `fetchEarthTaxonomy` can also be used as a convenient starting point
fetchEarthTaxonomy().then((res: TaxonomyResponse) => { ... })
import {fetchForecast} from 'surfline';

fetchForecast({spotId: <some-spot-id>, type: 'wave'})
  .then((res: WaveForecast) => {
    // do something with result...
  })
import {fetchSpotInfo} from 'surfline';

fetchSpotInfo({spotIds: [...]}).then((res: SpotInfoResponse) => {
  // do something with result...
})

types

fetchTaxonomy

function fetchTaxonomy(q: TaxonomyQuery): Promise<TaxonomyResponse>

function fetchEarthTaxonomy(q?: {maxDepth: number}): Promise<TaxonomyResponse>

type TaxonomyType = 'spot' | 'subregion' | 'region' | 'geoname';

export type TaxonomyQuery = {
  id: string,

  // Most queries should use `type=taxonomy`
  // If setting `type`, ensure `id` references a taxonomy of that type 
  // (eg. if `type=spot` use `SpotTaxonomy.spot` as id)
  type?: 'taxonomy' | TaxonomyType,

  // `maxDepth` controls how many "levels" of data is returned 
  // eg. if fetching "Earth" taxonomy, a depth of 0 returns continents, 
  // while a depth of 1 returns continents and countries
  maxDepth?: number,
};

// individual xTaxonomy types omitted... see type files for more details
type Taxonomy = SpotTaxonomy | SubregionTaxonomy | RegionTaxonomy | GeonameTaxonomy;

type TaxonomyResponse = Taxonomy & {
  in: Taxonomy[],
  contains: Taxonomy[],
};

fetchForecast

function fetchForecast<T extends ForecastType>(q: ForecastQuery<T>): Promise<ForecastResponse[T]>

export type ForecastType 
  = 'wind' 
  | 'wave' 
  | 'rating' 
  | 'tides' 
  | 'weather' 
  | 'conditions' 
  // Provides an overview all all other forecasts, 
  // but doesn't give the same level of detail as individual forecasts
  | 'combined';

export type ForecastQuery<T extends ForecastType> = {
  spotId: string,
  type: T,

  // Specifies how far out you want the forecast
  // Some forecasts are limited 6 days max w/o access token
  days?: number,

  // Specifies granularity of data
  // (eg. `intervalHours=3` returns 8 forecast items per day)
  // Ignored for type = `tide` (defaults to 1 hour), and `conditions` (defaults to 12 hours)
  intervalHours?: number,
};

// individual xForecast types omitted... see type files for more details
export declare interface ForecastResponse {
  wind: WindForecast;
  wave: WaveForecast;
  rating: RatingForecast;
  tides: TideForecast;
  weather: WeatherForecast;
  conditions: ConditionsForecast;
  combined: CombinedForecast;
}

note: a subset of forecasts are available for subregions via the surfline API, but that is not currently exposed by this library

fetchSpotInfo

function fetchSpotInfo({spotIds}: SpotInfoQuery): Promise<SpotInfoResponse>

type SpotInfoQuery = {
  spotIds: string[]
};

// `SpotInfo` type omitted... see type files for more details
type SpotInfoResponse = {
  associated: {
    units: Units
  },
  data: SpotInfo[]
}

dev

npm install
npm run build

// or

npm run watch