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

triplet-core

v0.2.1

Published

Core functionality for Triplet multi-client travel planner

Downloads

17

Readme

Triplet Core

This repo contains the open source core parts of the Triplet travel planner app.

The intention is to soon document this library in order to allow people to more easily create applications based on public transport data.

Another intention with releasing this as open source is to allow collaboration on the Triplet clients. The clients are plugins that allow the Triplet Core library to connect to a multitide of travel planner backends.

Currently there are four clients available

Status

The code of the core and clients have been running stable in the Triplet app for some time now, so should you figure out how to use it, you should be safe using it.

Documentation

The code snippet below is all there is for now.

This code sets up a basic structure of components and performs a trip search from your current location to Järntorget. As the location changes and time passes, the trip results will automatically update. This will only work within the Västtrafik area, currently the logic that automatically selects client based on location is part of the Triplet app. It will be released as part of triplet-core once it has been untangled from its Angular roots.

// The client plug-in for Västtrafik
var vtClientFactory = require('triplet-client-vt');

// The trips search engine
var TripsSearch = require('triplet-core/trips-search');

// Current location provider plugin, this one is using html5 geolocation
var NavigatorLocationProvider = require('triplet-core/navigator-location-provider');

// Service that generates Location objects from a location provider and also
// filters unwanted location data
var LocationService = require('triplet-core/location-service');

// Service that uses the stream of Locations to fetch the current nearby stations
var NearbyStations = require('triplet-core/nearby-stations');

// Service that accepts a query string and returns a list of Stations / GeoPoints that
// match that query
var StationSearch = require('triplet-core/station-search');

// Triplet can use any http client that works with the fetch API, i.e. accepts a config object
// and returns a Promise.
var httpClient = fetch || angular.$http || window.myCustomPromiseBasedHTTPClient;

// Join the pieces
var client = vtClientFactory('secretAPIKet', httpClient);
var locationService = new LocationService(new NavigatorLocationProvider());
var nearbyStations = new NearbyStations(client, locationService);
var stationSearch = new StationSearch(client);
var tripsSearch = new TripsSearch(client, nearbyStations);

// Start the location service
locationService.start();

// Whenever there are changes in station search results, set first result
// as trip destination.
stationSearch.bind('change:results', function(results) {
  tripsSearch.to = results[0];
});

// Whenever the trip ends change, or trip data is updated, log the new suggestions
// to console.
tripsSearch.bind('change:results', function(results) {
  console.log(results);
});

stationSearch.queryString = 'Järntorget';

Future improvements

  • Clients should expose config and parser functions for each request type, so instead of injecting a http client in constructor and managing the http conneciton, the client is only responsible for creating http request config and parsing the response.
  • Rewrite everything using RxJS. The core is mostly a set of streams already, and using RxJS would reduce the amount of code and probably improve the code patterns.

License

The MIT License (MIT)

Copyright (c) 2016 Torsten Freyhall

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.