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

gisted

v0.2.0

Published

Use GitHub Gists on your website

Downloads

2

Readme

Gister: Embed GitHub Gists without inline <script> tags

Sometimes you don't want to use GitHub's embed <script> for sharing Gists on your website. Gister allows you to embed GitHub Gists in <code> elements within your HTML identified by data-* attributes with values set to public Gist id's.

The <code> elements can be rendered server or client side before embedding your Gists.

Installation

npm install gisted   (d not r)

bower install gister

API

Gister(dataAttrName [, callback(el)])

Constructs a new instance of Gister. dataAttrName is required.

For example, if your gists will go inside <code data-gist-id> elements then you would create a new instance like new Gister("gist-id").

NOTE: "gist-id" is just one example. dataAttrName can be any string that through concatenation with "data-" creates a valid data-* attribute.

callback is an optional function to invoke for each Gist after it has been embedded into the parent <code> element. The callback will be passed a reference to the <code> element.

fetch()

for server side rendered <code> elements

If the <code> elements are rendered on the server then you want to use fetch. This way you can do new Gister('gistId').fetch() to immediately update all <code data-gistId> elements found in the DOM.

If you load Gister with an inline <script data-attrName='gistId'> tag then fetch is whats used behind the scenes.

observe(selector)

for client side rendered <code> elements

Use MutationObserver to watch the DOM node identified by selector for changes and update the innerHTML of all child <code data-{dataAttrName}> elements with the Gist identified by the value of the data-{dataAttrName} property.

For example, you might update a <div id='content'> element with some HTML that contains a <code data-gistId='00e3c4c4e42c8c4b174a'> element after page load. In that case you would do new Gister('gistId').observe('#content') some time before <div id='content'> is updated to ensure the contents of the gist identified by 00e3c4c4e42c8c4b174a are included on the page.

poll(selector [, duration])

for client side rendered <code> elements

If you want support for older browsers without MutationObserver you can try poll. Its used in exactly the same way as observe except it supports an optional duration parameter to specifiy how many seconds to poll. Polling defaults to 10 seconds otherwise.

NOTE: polling will cease once your Gist has been embedded, regardless of whether duration seconds has elapsed.

How To Use

As window global loaded with an HTML <script> tag:

<script src='/bower_components/gister.js'></script>
<!--
  or to update <code data-gistId> elements in the DOM immediately
  (without using the Gister API at all)
-->
<script src='/bower_components/gister.js' data-attrName='gistId'></script>

As a CommonJS/node module:

var Gister = require('gisted') // note the 'd' not 'r'

// To update <code data-gist> elements in the DOM immediately
new Gister('gist').fetch()
// If the '#container' element is dynamically updated with <code data-gist> nodes
new Gister('gist').observe('#container')

As an AMD module:

require(['gister'], function (Gister) {
   // If using Gister with dynamic (ajax) content
   new Gister('myGist').observe('body')
   // Otherwise update the DOM with Gists immediately
   new Gister('myGist').fetch()
})