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

patch-suggest

v3.0.1

Published

The commons suggesters for text fields - for patch-* family apps

Downloads

23

Readme

Patch-suggest

A module for easy suggest-mentions of people / channels / emoji in patch-* family apps.

NOTE : requires ssb-suggest plugin installed in your ssb-server

Provides suggestions and styles in a format consumed by suggest-box

You'll need to understand depject (a module for a different way of managing dependency injection), and for the example below, depnest - a lazy way to write nested objects quickly.

Example

const nest = require('depnest')
const { h } = require('mutant')
const suggestBox = require('suggest-box')

exports.gives = nest('app.page.somePage')

exports.needs = nest({
  'about.async.suggest': 'first',
  'channel.async.suggest': 'first',
  'emoji.async.suggest': 'first',
  'meme.async.suggest': 'first',   // requires sbot has ssb-meme plugin
})

exports.create = (api) => {
  return nest('app.page.somePage', page)

  function page (location) {

    var textArea = h('textarea')
    var feedIdsInThread = [ ... ] // some collection of feeds you'd like to ensure make the suggestions

    suggestBox(
      textArea,
      (inputText, cb) => {
        const char = inputText[0]
        const wordFragment = inputText.slice(1)

        if (char === '@') api.about.async.suggest(wordFragment, feedIdsInThread, cb)
        if (char === '#') api.channel.async.suggest(wordFragment, cb)
        if (char === ':') api.emoji.async.suggest(wordFragment, cb)
        if (char === '&') api.meme.async.suggest(wordFragment, cb)
      },
      {cls: 'PatchSuggest'}
    )

    //...
  }
}

API

Each of these depject methods is called to initialize it (starts pre-loading data in the pbackground) and returns a "suggester". The suggester functions return "suggestion" objects which are compatible with the suggest-box module, but you can use them for whatever!

`api.about.async.suggest(word, extraIds, cb)

word - name, or the start of a name you're searching for

extraIds (optional) you can add an Array (or MutantArray) of FeedIds which you would like included in the suggestions. This is a great way to add the context (i.e. the people in the conversation) of a the current page you're in to the suggestions.

`api.channel.async.suggest(word, cb)

word - channel, or the start of a channel you're searching for

`api.emoji.async.suggest(word, cb)

word - emoji, or the start of a emoji you're searching for

`api.meme.async.suggest(word, cb)

word - image name, or some part of an image name you're searching for

  • image name is split into searchable parts of characters _-~.

Requires the plugin ssb-meme to be installed

Styling

To use the styles provided by patch-suggest (recommended), supply the options argument to suggest-box {cls: 'PatchSuggest} (see example above)