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

tile-cacher

v0.1.4

Published

Map tile cacher middleware

Downloads

10

Readme

tile-cacher 0.1.4

Node express-like middleware and downloader for map tile caches

pipeline status tile-cacher on NPM license developtment time contributor covenant support development

Middleware

The middleware can be used with HTTP libraries like Express and Polka. When instantiated, if connected to the Internet, it will check the actively cached tile have been cached and remove old cached tiles. It will also schedule the next check inline with the checkInterval option.

Example

examples/middleware.js

import { createReadStream } from 'fs';
import polka from 'polka';
import middleware from 'tile-cacher';
import { options } from './options.js';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';

const __dirname = dirname(fileURLToPath(import.meta.url));

const app = polka();

app.get('/', (req, res) => {
  const stream = createReadStream(join(__dirname, 'index.html'));
  res.setHeader('Content-Type', 'text/html');
  stream.pipe(res);
});
app.get('/tiles/:id/:z/:x/:y.png', middleware(options));

app.listen(3030, () => {
  console.log('tile-cacher middleware listening on port 3030');
});

Tile Cache Check

Example

examples/cacheCheck.js

import { checkCache } from 'tile-cacher';
import { options } from './options.js';

checkCache(options);

Options

Options are the same for both the middlware and the cacheCheck functionality

Example

examples/options.js

export const options = {
  servers: [
    {
      id: 'opentopomap',
      url: 'https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png',
      activelyCache: [
        {
          northLat: -40.975513,
          southLat: -41.100311,
          westLon: 174.994183,
          eastLon: 175.148163,
          maxZoom: 13
        }
      ],
      cache: [
        {
          northLat: -39.975513,
          southLat: -42.100311,
          westLon: 173.994183,
          eastLon: 176.148163,
          maxZoom: 13
        }
      ],
      age: 168
    }
  ],
  checkInterval: 20,
  downloadWaitTime: 1000,
  extension: 'png',
  folder: 'cache',
  logger: {
    log: (...args) => console.log(new Date().toISOString(), 'LOG', ...args),
    warn: (...args) => console.warn(new Date().toISOString(), 'WARN', ...args),
    debug: (...args) => console.debug(new Date().toISOString(), 'DEBUG', ...args),
    info: (...args) => console.info(new Date().toISOString(), 'INFO', ...args),
    error: (...args) => console.error(new Date().toISOString(), 'ERROR', ...args)
  }
};

Development

Feel free to contribute to the code or documentation, or leave issues or suggestions on the issue tracker or email them to us. Please submit security concerns as a confidential issue.

The source is hosted on Gitlab and uses prettier, lint-staged and husky to keep things pretty. As such, when you first clone the repository, as well as installing the npm dependencies, you will also need to install husky.

# Install NPM dependencies
npm install
# Set up husky Git hooks stored in .husky
npx husky install

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

0.1.4 - 2023-03-19

Added

  • Added logger to options typings

Fixed

  • Checking for internet connectivity was throwing if not connected

0.1.3 - 2022-06-02

Added

  • Server response time logging

0.1.2 - 2022-06-02

Fixed

  • Middleware issue not passing through requested tile from remote server
  • Changed to AGPL-3.0 license

0.1.1 - 2022-06-02

Fixed

  • Fixed example code in README

0.1.0 - 2022-06-02

Added

  • Basic tile cache downloading
  • Basic middleware