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

@tides/locations

v0.7.0

Published

Wrapper around NOAA's [Tides and Currents API](https://api.tidesandcurrents.noaa.gov/api/prod/).

Downloads

7

Readme

@tides/noaa

Wrapper around NOAA's Tides and Currents API.

Usage

yarn install @tides/noaa
// or
npm install --save @tides/noaa

The API can be called in 2 ways.

import { coopsApi, COOPSApi } from "@tides/noaa";

// plain function
const getTides = async () => {
  const response = await coopsApi({
    station: "840140",
    units: "english",
    product: "predictions",
    datum: "MLLW",
    begin_date: "20201214",
    end_date: "20201214",
    interval: "hilo"
  }).then(({ data }) => {
    if (!data) return;

    return data;
  });
};

// using the class
const api = new COOPSApi({
  station: "840140",
  units: "english",
  begin_date: "20201214",
  end_date: "20201214"
});

const tides = api
  .get({
    product: "predictions",
    datum: "MLLW",
    interval: "hilo"
  })
  .then(({ data }) => {
    if (!data) return;

    return data;
  });

Params

The params directly coincide with the CO-OPS Data Retrieval API params.

type COOPSApiParams = {
  station: string;
  units: "english" | "metric";
  format?: "json" | "xml" | "csv"; // defaults to json
  timeZone?: "lst_ldt" | "lst" | "gmt"; // defaults to lst_ldt
  date?: "latest" | "recent" | "today";
  beginDate?: string; // yyyMMdd, yyMMdd HH:mm, MM/dd/yyyy, MM/dd/yyyy HH:mm
  endDate?: string; // yyyMMdd, yyMMdd HH:mm, MM/dd/yyyy, MM/dd/yyyy HH:mm
  range?: number;
  product: ValueOf<COOPSProducts>; // see below
  datum?: ValueOf<COOPSDatum>; // see below, required for water level products
  interval?: "h" | "hilo" | "MAX_SLACK" | number;
  velType?: "speed_dir" | "default";
  bin?: number;
  windUnits?: string; // defaults to knots if units === 'english', meters/second otherwise
  noFormat?: boolean; // whether or not to return friendlier formatted data
};

enum COOPSProducts {
  water_level,
  air_temperature,
  water_temperature,
  wind,
  air_pressure,
  air_gap,
  conductivity,
  visibility,
  salinity,
  humidity,
  hourly_height,
  high_low,
  daily_mean,
  monthly_mean,
  one_minute_water_level,
  predictions,
  datums,
  currents,
  currents_predictions
}

// required for water level products
enum COOPSData {
  CRD,
  IGLD,
  LWD,
  MHHW,
  MHW,
  MTL,
  MSL,
  MLW,
  MLLW,
  NAVD,
  STND
}

More information can be found here.

API

coopsApi(params: COOPSApiParams)

Async function wrapper around the CO-OPS Data Retrieval API. Added param windUnits are used for returning friendlier data. You can disable this and get the raw data from CO-OPS by setting the param noFormat to true.

import { coopsApi } from "@tides/noaa";

const getTodaysTides = async () => {
  const response = await coopsApi({
    station: "840140",
    units: "english",
    date: "today",
    product: "predictions",
    interval: "hilo",
    windUnits: "mph", // noaa api will return wind in knots when units === 'english'
    noFormat: false // to get the raw return data from CO-OPS, set this to 'true'
  });

  return response ?? null;
};

const todaysTides = getTodaysTides();
console.log(todaysTides);
// returns an array of tides
//    {
//      time: {
//        local: "2020-12-15T04:47:00.000Z",
//        utc: "2020-12-15T09:47:00:000.Z",
//        display: "\"4:47 AM\""
//      },
//      value: -1.076,
//      symbol: "ft",
//      type: "L",
//    },
//
// setting `noFormat` to `true` will return raw data from CO-OPS
// ie:
// {
//   t: "2020-12-15 04:47",
//   v: "-1.076",
//   type: "L"
// }

new COOPSApi(params: COOPSApiParams)

The COOPSApi class is initialized with the same params and has some extra methods for gathering more specific data.

import { COOPSApi } from "@tides/noaa";

// only some params are required for initialization
const api = new COOPSApi({
  station: "8410140",
  units: "english",
  windUnits: "mph",
  noFormat: false // set to 'true' for raw CO-OPS data
});

// other params are used on a method level (i.e. product, datum)
const tides = api.get({
  product: "predictions",
  datum: "MLLW",
  date: "today",
  interval: "hilo"
});

// the class also contains methods to check for alerts / flood levels for `this.station`
const alerts = api.alerts();
// returns
// {
//   id: "8410140",
//   alert: "HIGH_WATER_NOW" | "HIGH_WATER_TODAY" | "HIGH_WATER_TOMORROW" | null
// }

const floodLevels = api.floodLevels();
// returns null or an array of flood levels
// {
//   type: "minor",
//   value: 20.4
// }