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

leaflet-search-types

v0.0.11

Published

TypeScript definitions for leaflet-search

Downloads

13

Readme

typings for leaflet-search

huge thanks to @bastisk for the initial typings, but the repo looks unmaintained.

will publish to DefinitelyTyped if this is useful to anyone.

installation

npm install --save-dev leaflet-search-types

usage

you could add these lines to the top of your js file.

/**
 * @typedef {import('leaflet-search-types')}
 * @typedef {import('leaflet')}
 */

content

import * as L from "leaflet";
/**
 * @exports L.Control.Search
 * @exports L.control.search
 */

declare module "leaflet" {
  namespace Control {
    class Search extends Control {
      constructor(options?: SearchConstuctorOptions);
      /**
       * event listener
       * @param layer
       */
      on(
        type: string | "search:collapsed" | "search:expanded" | "search:cancel",
        fn: (e: SearchEvent) => any,
        context?: any
      ): this;

      /**
       * event listener
       * @param type "search:locationfound"
       * @param fn  callback function
       * @param context
       */
      on(
        type: "search:locationfound",
        fn: (e: SearchEventFound) => any,
        context?: any
      ): this;
      /**
       * set layer search at runtime
       * @param layer layer search
       */
      setLayer(layer: LayerGroup): void;
      /**
       * show alert message
       * @param message message to show
       */
      showAlert(message: string): void;
      /**
       * search text by external code
       * @param text text to search
       */
      searchText(text: string): void;
    }

    /**
     * leaflet search options
     */
    interface SearchConstuctorOptions {
      /**
       * url for search by ajax request, ex: `"search.php?q={s}"`. Can be function to returns string for dynamic parameter setting
       * @default ""
       */
      url?: string;
      /**
       * layer where search markers (is a `L.LayerGroup`)
       * @default null
       */
      layer?: LayerGroup;
      /**
       * function to fill `_recordsCache`, passed searching text by first param and callback in second
       * @param text searching text
       * @param callback
       * @default null
       */
      sourceData?: (text: string, callback: (...args: any[]) => any) => any;
      /**
       * jsonp param name for search by jsonp service, ex: `"callback"`
       * @default null
       */
      jsonpParam?: string;
      /**
       * field for remapping location, using array: `['latname','lonname']` for select double fields(ex. `['lat','lon']` ) support dotted format: `'prop.subprop.title'`
       * @default 'loc'
       */
      propertyLoc?: string[] | string;
      /**
       * property in `marker.options `(or `feature.properties` for vector layer) trough filter elements in layer,
       * @default 'title'
       */
      propertyName?: string;
      /**
       * callback for reformat all data from source to indexed data object
       * @default null
       */
      formatData?: (...args: any[]) => any;
      /**
       * callback for filtering data from text searched, params: `textSearch`, `allRecords`
       * @default null
       */
      filterData?: (textSearch: string, allRecords: any) => any;
      /**
       * callback run on location found, params: latlng, title, map
       * @default null
       */
      moveToLocation?: (...args: any[]) => any;
      /**
       * function to return row tip html node(or html string), receive text tooltip in first param
       * @default null
       */
      buildTip?: (...args: any[]) => HTMLElement | any;
      /**
       * container id to insert Search Control
       * @default ""
       */
      container?: string;
      /**
       * default zoom level for move to location
       * @default null
       */
      zoom?: number;
      /**
       * minimal text length for autocomplete
       * @default 1
       */
      minLength?: number;
      /**
       * search elements only by initial text
       * @default true
       */
      initial?: boolean;
      /**
       * search elements in case sensitive text
       * @default false
       */
      casesensitive?: boolean;
      /**
       * complete input with first suggested result and select this filled-in text.
       * @default true
       */
      autoType?: boolean;
      /**
       * delay while typing for show tooltip
       * @default 400
       */
      delayType?: number;
      /**
       * limit max results to show in tooltip. -1 for no limit, 0 for no results
       * @default -1
       */
      tooltipLimit?: number;
      /**
       * auto map `panTo` when click on tooltip
       * @default true
       */
      tipAutoSubmit?: boolean;
      /**
       * auto select first result con enter click
       * @default false
       */
      firstTipSubmit?: boolean;
      /**
       * autoresize on input change
       * @default true
       */
      autoResize?: boolean;
      /**
       * collapse search control at startup
       * @default true
       */
      collapsed?: true;
      /**
       * collapse search control after submit (on button or on tips if enabled `tipAutoSubmit`)
       * @default false
       */
      autoCollapse?: boolean;
      /**
       * delay for autoclosing alert and collapse after blur
       * @default 1200
       */
      autoCollapseTime?: number;
      /**
       * error message
       * @default 'Location not found'
       */
      textErr?: string;
      /**
       * title in cancel button
       * @default 'Cancel'
       */
      textCancel?: string;
      /**
       * placeholder value
       * @default 'Search'
       */
      textPlaceholder?: string;
      /**
       * remove circle and marker on search control collapsed
       * @default false
       */
      hideMarkerOnCollapse?: boolean;
      /**
       * position in the map
       * @default 'topleft'
       */
      position?: string;
      /**
       * custom L.Marker or false for hide
       * @default { icon: false, animate: true, circle: { radius: 10, weight: 3, color: '#e03', stroke: true, fill: false } }
       */
      marker?: SearchMarkerConstructorOptions;
    }

    /**
     * leaflet search marker options
     */
    interface SearchMarkerConstructorOptions {
      /**
       * custom L.Icon for maker location or false for hide
       * @default false
       */
      icon?: Icon | boolean;
      /**
       * animate a circle over location found
       * @default true
       */
      animate?: boolean;
      /**
       * draw a circle in location found
       * @default CircleMarker.options
       */
      circle?: Circle;
    }

    /**
     * kind of a base event
     */
    interface SearchEvent extends LeafletEvent {
      text: string;
      type: string;
    }

    interface SearchEventFound extends SearchEvent {
      /**
       * location
       */
      latlng: LatLng;
      /**
       * title
       */
      title: string;
      /**
       * layer of target
       */
      layer: Layer;
    }
  }
  namespace control {
    /**
     * creates a new search control
     * @param options
     */
    function search(options?: Control.SearchConstuctorOptions): Control.Search;
  }
}